diff --git a/CMakeLists.txt b/CMakeLists.txt index 97ef3f5..7e2acf0 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.3) project(nagios_plugins) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -U__STRICT_ANSI__") -set(SOURCE_FILES check_memfree/check_memfree.cpp check_memfree/range.cpp check_memfree/aux.cpp) +set(SOURCE_FILES check_memfree/check_memfree.cpp check_memfree/check_memfree.h check_memfree/range.cpp check_memfree/range.h check_memfree/aux.cpp check_memfree/auxiliar.cpp check_memfree/auxiliar.h) add_executable(nagios_plugins ${SOURCE_FILES}) \ No newline at end of file diff --git a/check_memfree/aux.cpp b/check_memfree/auxiliar.cpp index 4da535f..9599ce0 100755 --- a/check_memfree/aux.cpp +++ b/check_memfree/auxiliar.cpp @@ -1,51 +1,55 @@ -#include "aux.h" - -void timer_handler (int signum) -{ - if(signum == SIGVTALRM) - { - cout << servicename << " CRITICAL - timeout occurred" << endl; - exit(2); - } -} - -int str2int(string str) -{ - int num; - stringstream sstream; - sstream << str; - if(!(sstream >> num)) - { - throw integerConversionException("Integer conversion error"); - } - return num; -} - -string int2str(int x) -{ - string str; - stringstream sstream; - sstream << x; - sstream >> str; - return str; -} - -int exec(string cmd, string *output) -{ - *output = ""; - FILE* pipe = popen(cmd.c_str(), "r"); - if (!pipe) - { - cout << "Error opening child process" << endl; - exit(3); - } - char buffer[128]; - while(!feof(pipe)) - { - if(fgets(buffer, 128, pipe) != NULL) - { - *output += buffer; - } - } - return pclose(pipe)/256; -} +// +// Created by Imanol on 28-may-16. +// + +#include "auxiliar.h" + +void timer_handler (int signum) +{ + if(signum == SIGVTALRM) + { + cout << servicename << " CRITICAL - timeout occurred" << endl; + exit(2); + } +} + +int str2int(string str) +{ + int num; + stringstream sstream; + sstream << str; + if(!(sstream >> num)) + { + throw integerConversionException("Integer conversion error"); + } + return num; +} + +string int2str(int x) +{ + string str; + stringstream sstream; + sstream << x; + sstream >> str; + return str; +} + +int exec(string cmd, string *output) +{ + *output = ""; + FILE* pipe = popen(cmd.c_str(), "r"); + if (!pipe) + { + cout << "Error opening child process" << endl; + exit(3); + } + char buffer[128]; + while(!feof(pipe)) + { + if(fgets(buffer, 128, pipe) != NULL) + { + *output += buffer; + } + } + return pclose(pipe)/256; +} \ No newline at end of file diff --git a/check_memfree/aux.h b/check_memfree/auxiliar.h index 9a3dc7a..74adba2 100755 --- a/check_memfree/aux.h +++ b/check_memfree/auxiliar.h @@ -1,31 +1,35 @@ -#ifndef AUX_H -#define AUX_H - -#include -#include -#include - -#include -#include -#include - -using namespace std; - -extern char *servicename; - -int str2int(string str); -string int2str(int x); -int exec(string cmd, string *output); -void timer_handler (int signum); - -class integerConversionException : public exception -{ - private: - string s; - public: - integerConversionException(std::string ss) : s(ss) {} - ~integerConversionException() throw () {} - const char* what() const throw() { return s.c_str(); } -}; - -#endif +// +// Created by Imanol on 28-may-16. +// + +#ifndef NAGIOS_PLUGINS_AUXILIAR_H +#define NAGIOS_PLUGINS_AUXILIAR_H + +#include +#include +#include + +#include +#include +#include + +using namespace std; + +extern char *servicename; + +int str2int(string str); +string int2str(int x); +int exec(string cmd, string *output); +void timer_handler (int signum); + +class integerConversionException : public exception +{ +private: + string s; +public: + integerConversionException(std::string ss) : s(ss) {} + ~integerConversionException() throw () {} + const char* what() const throw() { return s.c_str(); } +}; + +#endif //NAGIOS_PLUGINS_AUXILIAR_H diff --git a/check_memfree_freebsd/aux.cpp b/check_memfree_freebsd/auxiliar.cpp index 4da535f..9599ce0 100755 --- a/check_memfree_freebsd/aux.cpp +++ b/check_memfree_freebsd/auxiliar.cpp @@ -1,51 +1,55 @@ -#include "aux.h" - -void timer_handler (int signum) -{ - if(signum == SIGVTALRM) - { - cout << servicename << " CRITICAL - timeout occurred" << endl; - exit(2); - } -} - -int str2int(string str) -{ - int num; - stringstream sstream; - sstream << str; - if(!(sstream >> num)) - { - throw integerConversionException("Integer conversion error"); - } - return num; -} - -string int2str(int x) -{ - string str; - stringstream sstream; - sstream << x; - sstream >> str; - return str; -} - -int exec(string cmd, string *output) -{ - *output = ""; - FILE* pipe = popen(cmd.c_str(), "r"); - if (!pipe) - { - cout << "Error opening child process" << endl; - exit(3); - } - char buffer[128]; - while(!feof(pipe)) - { - if(fgets(buffer, 128, pipe) != NULL) - { - *output += buffer; - } - } - return pclose(pipe)/256; -} +// +// Created by Imanol on 28-may-16. +// + +#include "auxiliar.h" + +void timer_handler (int signum) +{ + if(signum == SIGVTALRM) + { + cout << servicename << " CRITICAL - timeout occurred" << endl; + exit(2); + } +} + +int str2int(string str) +{ + int num; + stringstream sstream; + sstream << str; + if(!(sstream >> num)) + { + throw integerConversionException("Integer conversion error"); + } + return num; +} + +string int2str(int x) +{ + string str; + stringstream sstream; + sstream << x; + sstream >> str; + return str; +} + +int exec(string cmd, string *output) +{ + *output = ""; + FILE* pipe = popen(cmd.c_str(), "r"); + if (!pipe) + { + cout << "Error opening child process" << endl; + exit(3); + } + char buffer[128]; + while(!feof(pipe)) + { + if(fgets(buffer, 128, pipe) != NULL) + { + *output += buffer; + } + } + return pclose(pipe)/256; +} \ No newline at end of file diff --git a/check_memfree_freebsd/aux.h b/check_memfree_freebsd/auxiliar.h index 9a3dc7a..74adba2 100755 --- a/check_memfree_freebsd/aux.h +++ b/check_memfree_freebsd/auxiliar.h @@ -1,31 +1,35 @@ -#ifndef AUX_H -#define AUX_H - -#include -#include -#include - -#include -#include -#include - -using namespace std; - -extern char *servicename; - -int str2int(string str); -string int2str(int x); -int exec(string cmd, string *output); -void timer_handler (int signum); - -class integerConversionException : public exception -{ - private: - string s; - public: - integerConversionException(std::string ss) : s(ss) {} - ~integerConversionException() throw () {} - const char* what() const throw() { return s.c_str(); } -}; - -#endif +// +// Created by Imanol on 28-may-16. +// + +#ifndef NAGIOS_PLUGINS_AUXILIAR_H +#define NAGIOS_PLUGINS_AUXILIAR_H + +#include +#include +#include + +#include +#include +#include + +using namespace std; + +extern char *servicename; + +int str2int(string str); +string int2str(int x); +int exec(string cmd, string *output); +void timer_handler (int signum); + +class integerConversionException : public exception +{ +private: + string s; +public: + integerConversionException(std::string ss) : s(ss) {} + ~integerConversionException() throw () {} + const char* what() const throw() { return s.c_str(); } +}; + +#endif //NAGIOS_PLUGINS_AUXILIAR_H diff --git a/check_smart/aux.cpp b/check_smart/auxiliar.cpp index 4da535f..9599ce0 100755 --- a/check_smart/aux.cpp +++ b/check_smart/auxiliar.cpp @@ -1,51 +1,55 @@ -#include "aux.h" - -void timer_handler (int signum) -{ - if(signum == SIGVTALRM) - { - cout << servicename << " CRITICAL - timeout occurred" << endl; - exit(2); - } -} - -int str2int(string str) -{ - int num; - stringstream sstream; - sstream << str; - if(!(sstream >> num)) - { - throw integerConversionException("Integer conversion error"); - } - return num; -} - -string int2str(int x) -{ - string str; - stringstream sstream; - sstream << x; - sstream >> str; - return str; -} - -int exec(string cmd, string *output) -{ - *output = ""; - FILE* pipe = popen(cmd.c_str(), "r"); - if (!pipe) - { - cout << "Error opening child process" << endl; - exit(3); - } - char buffer[128]; - while(!feof(pipe)) - { - if(fgets(buffer, 128, pipe) != NULL) - { - *output += buffer; - } - } - return pclose(pipe)/256; -} +// +// Created by Imanol on 28-may-16. +// + +#include "auxiliar.h" + +void timer_handler (int signum) +{ + if(signum == SIGVTALRM) + { + cout << servicename << " CRITICAL - timeout occurred" << endl; + exit(2); + } +} + +int str2int(string str) +{ + int num; + stringstream sstream; + sstream << str; + if(!(sstream >> num)) + { + throw integerConversionException("Integer conversion error"); + } + return num; +} + +string int2str(int x) +{ + string str; + stringstream sstream; + sstream << x; + sstream >> str; + return str; +} + +int exec(string cmd, string *output) +{ + *output = ""; + FILE* pipe = popen(cmd.c_str(), "r"); + if (!pipe) + { + cout << "Error opening child process" << endl; + exit(3); + } + char buffer[128]; + while(!feof(pipe)) + { + if(fgets(buffer, 128, pipe) != NULL) + { + *output += buffer; + } + } + return pclose(pipe)/256; +} \ No newline at end of file diff --git a/check_smart/aux.h b/check_smart/auxiliar.h index 9a3dc7a..74adba2 100755 --- a/check_smart/aux.h +++ b/check_smart/auxiliar.h @@ -1,31 +1,35 @@ -#ifndef AUX_H -#define AUX_H - -#include -#include -#include - -#include -#include -#include - -using namespace std; - -extern char *servicename; - -int str2int(string str); -string int2str(int x); -int exec(string cmd, string *output); -void timer_handler (int signum); - -class integerConversionException : public exception -{ - private: - string s; - public: - integerConversionException(std::string ss) : s(ss) {} - ~integerConversionException() throw () {} - const char* what() const throw() { return s.c_str(); } -}; - -#endif +// +// Created by Imanol on 28-may-16. +// + +#ifndef NAGIOS_PLUGINS_AUXILIAR_H +#define NAGIOS_PLUGINS_AUXILIAR_H + +#include +#include +#include + +#include +#include +#include + +using namespace std; + +extern char *servicename; + +int str2int(string str); +string int2str(int x); +int exec(string cmd, string *output); +void timer_handler (int signum); + +class integerConversionException : public exception +{ +private: + string s; +public: + integerConversionException(std::string ss) : s(ss) {} + ~integerConversionException() throw () {} + const char* what() const throw() { return s.c_str(); } +}; + +#endif //NAGIOS_PLUGINS_AUXILIAR_H diff --git a/check_tftp/aux.cpp b/check_tftp/auxiliar.cpp index 4da535f..9599ce0 100755 --- a/check_tftp/aux.cpp +++ b/check_tftp/auxiliar.cpp @@ -1,51 +1,55 @@ -#include "aux.h" - -void timer_handler (int signum) -{ - if(signum == SIGVTALRM) - { - cout << servicename << " CRITICAL - timeout occurred" << endl; - exit(2); - } -} - -int str2int(string str) -{ - int num; - stringstream sstream; - sstream << str; - if(!(sstream >> num)) - { - throw integerConversionException("Integer conversion error"); - } - return num; -} - -string int2str(int x) -{ - string str; - stringstream sstream; - sstream << x; - sstream >> str; - return str; -} - -int exec(string cmd, string *output) -{ - *output = ""; - FILE* pipe = popen(cmd.c_str(), "r"); - if (!pipe) - { - cout << "Error opening child process" << endl; - exit(3); - } - char buffer[128]; - while(!feof(pipe)) - { - if(fgets(buffer, 128, pipe) != NULL) - { - *output += buffer; - } - } - return pclose(pipe)/256; -} +// +// Created by Imanol on 28-may-16. +// + +#include "auxiliar.h" + +void timer_handler (int signum) +{ + if(signum == SIGVTALRM) + { + cout << servicename << " CRITICAL - timeout occurred" << endl; + exit(2); + } +} + +int str2int(string str) +{ + int num; + stringstream sstream; + sstream << str; + if(!(sstream >> num)) + { + throw integerConversionException("Integer conversion error"); + } + return num; +} + +string int2str(int x) +{ + string str; + stringstream sstream; + sstream << x; + sstream >> str; + return str; +} + +int exec(string cmd, string *output) +{ + *output = ""; + FILE* pipe = popen(cmd.c_str(), "r"); + if (!pipe) + { + cout << "Error opening child process" << endl; + exit(3); + } + char buffer[128]; + while(!feof(pipe)) + { + if(fgets(buffer, 128, pipe) != NULL) + { + *output += buffer; + } + } + return pclose(pipe)/256; +} \ No newline at end of file diff --git a/check_tftp/aux.h b/check_tftp/auxiliar.h index 9a3dc7a..74adba2 100755 --- a/check_tftp/aux.h +++ b/check_tftp/auxiliar.h @@ -1,31 +1,35 @@ -#ifndef AUX_H -#define AUX_H - -#include -#include -#include - -#include -#include -#include - -using namespace std; - -extern char *servicename; - -int str2int(string str); -string int2str(int x); -int exec(string cmd, string *output); -void timer_handler (int signum); - -class integerConversionException : public exception -{ - private: - string s; - public: - integerConversionException(std::string ss) : s(ss) {} - ~integerConversionException() throw () {} - const char* what() const throw() { return s.c_str(); } -}; - -#endif +// +// Created by Imanol on 28-may-16. +// + +#ifndef NAGIOS_PLUGINS_AUXILIAR_H +#define NAGIOS_PLUGINS_AUXILIAR_H + +#include +#include +#include + +#include +#include +#include + +using namespace std; + +extern char *servicename; + +int str2int(string str); +string int2str(int x); +int exec(string cmd, string *output); +void timer_handler (int signum); + +class integerConversionException : public exception +{ +private: + string s; +public: + integerConversionException(std::string ss) : s(ss) {} + ~integerConversionException() throw () {} + const char* what() const throw() { return s.c_str(); } +}; + +#endif //NAGIOS_PLUGINS_AUXILIAR_H