From f861e9a68f0b15de823d791ec49d22c159a28c38 Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Fri, 27 May 2016 22:38:41 +0200 Subject: [PATCH] Begin migration to clion and code update --- .gitignore | 1 + CMakeLists.txt | 7 +++++++ aux.cpp | 51 --------------------------------------------------- aux.h | 31 ------------------------------- check_memfree/aux.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ check_memfree/aux.h | 31 +++++++++++++++++++++++++++++++ check_memfree_freebsd/aux.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ check_memfree_freebsd/aux.h | 31 +++++++++++++++++++++++++++++++ check_smart/aux.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ check_smart/aux.h | 31 +++++++++++++++++++++++++++++++ check_tftp/aux.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ check_tftp/aux.h | 31 +++++++++++++++++++++++++++++++ 12 files changed, 336 insertions(+), 82 deletions(-) create mode 100644 .gitignore create mode 100755 CMakeLists.txt delete mode 100644 aux.cpp delete mode 100644 aux.h create mode 100755 check_memfree/aux.cpp create mode 100755 check_memfree/aux.h create mode 100755 check_memfree_freebsd/aux.cpp create mode 100755 check_memfree_freebsd/aux.h create mode 100755 check_smart/aux.cpp create mode 100755 check_smart/aux.h create mode 100755 check_tftp/aux.cpp create mode 100755 check_tftp/aux.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..97ef3f5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.3) +project(nagios_plugins) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + +set(SOURCE_FILES check_memfree/check_memfree.cpp check_memfree/range.cpp check_memfree/aux.cpp) +add_executable(nagios_plugins ${SOURCE_FILES}) \ No newline at end of file diff --git a/aux.cpp b/aux.cpp deleted file mode 100644 index 4da535f..0000000 --- a/aux.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#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; -} diff --git a/aux.h b/aux.h deleted file mode 100644 index 9a3dc7a..0000000 --- a/aux.h +++ /dev/null @@ -1,31 +0,0 @@ -#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 diff --git a/check_memfree/aux.cpp b/check_memfree/aux.cpp new file mode 100755 index 0000000..4da535f --- /dev/null +++ b/check_memfree/aux.cpp @@ -0,0 +1,51 @@ +#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; +} diff --git a/check_memfree/aux.h b/check_memfree/aux.h new file mode 100755 index 0000000..9a3dc7a --- /dev/null +++ b/check_memfree/aux.h @@ -0,0 +1,31 @@ +#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 diff --git a/check_memfree_freebsd/aux.cpp b/check_memfree_freebsd/aux.cpp new file mode 100755 index 0000000..4da535f --- /dev/null +++ b/check_memfree_freebsd/aux.cpp @@ -0,0 +1,51 @@ +#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; +} diff --git a/check_memfree_freebsd/aux.h b/check_memfree_freebsd/aux.h new file mode 100755 index 0000000..9a3dc7a --- /dev/null +++ b/check_memfree_freebsd/aux.h @@ -0,0 +1,31 @@ +#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 diff --git a/check_smart/aux.cpp b/check_smart/aux.cpp new file mode 100755 index 0000000..4da535f --- /dev/null +++ b/check_smart/aux.cpp @@ -0,0 +1,51 @@ +#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; +} diff --git a/check_smart/aux.h b/check_smart/aux.h new file mode 100755 index 0000000..9a3dc7a --- /dev/null +++ b/check_smart/aux.h @@ -0,0 +1,31 @@ +#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 diff --git a/check_tftp/aux.cpp b/check_tftp/aux.cpp new file mode 100755 index 0000000..4da535f --- /dev/null +++ b/check_tftp/aux.cpp @@ -0,0 +1,51 @@ +#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; +} diff --git a/check_tftp/aux.h b/check_tftp/aux.h new file mode 100755 index 0000000..9a3dc7a --- /dev/null +++ b/check_tftp/aux.h @@ -0,0 +1,31 @@ +#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 -- libgit2 0.22.2