From 023cfc15bbbaa6a6602d27c61814fb1fa2a7cda3 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 19 Nov 2014 06:40:58 +0100 Subject: [PATCH] Some minor plugin fixes --- plugins/check_disk.cpp | 6 +++--- plugins/check_load.cpp | 19 +++++++++++++------ plugins/check_users.cpp | 6 +++--- plugins/thresholds.cpp | 22 ++++++++++++---------- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/plugins/check_disk.cpp b/plugins/check_disk.cpp index b8a968f05..5620fe5e7 100644 --- a/plugins/check_disk.cpp +++ b/plugins/check_disk.cpp @@ -98,7 +98,7 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& ("version,v", "print version and exit") ("warning,w", po::wvalue(), "warning threshold") ("critical,c", po::wvalue(), "critical threshold") - ("drives,d", po::wvalue>()->multitoken(), "declare explicitly which drives to check (default checks all)") + ("path,p", po::wvalue>()->multitoken(), "declare explicitly which drives to check (default checks all)") ("unit,u", po::wvalue(), "assign unit possible are: B, kB, MB, GB, TB") ; @@ -186,8 +186,8 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& } } - if (vm.count("drives")) - printInfo.drives = vm["drives"].as>(); + if (vm.count("path")) + printInfo.drives = vm["path"].as>(); if (vm.count("unit")) { try { diff --git a/plugins/check_load.cpp b/plugins/check_load.cpp index c206eea19..4f69872b0 100644 --- a/plugins/check_load.cpp +++ b/plugins/check_load.cpp @@ -16,15 +16,16 @@ * along with this program; if not, write to the Free Software Foundation * * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ + +#include "thresholds.h" +#include +#include +#include #include #include #include #include -#include "thresholds.h" - -#include "boost/program_options.hpp" - #define VERSION 1.0 namespace po = boost::program_options; @@ -142,7 +143,10 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& if (vm.count("warning")) { try { - printInfo.warn = threshold(vm["warning"].as()); + std::wstring wthreshold = vm["warning"].as(); + std::vector tokens; + boost::algorithm::split(tokens, wthreshold, boost::algorithm::is_any_of(",")); + printInfo.warn = threshold(tokens[0]); } catch (std::invalid_argument& e) { cout << e.what() << endl; return 3; @@ -150,7 +154,10 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& } if (vm.count("critical")) { try { - printInfo.crit = threshold(vm["critical"].as()); + std::wstring cthreshold = vm["critical"].as(); + std::vector tokens; + boost::algorithm::split(tokens, cthreshold, boost::algorithm::is_any_of(",")); + printInfo.crit = threshold(tokens[0]); } catch (std::invalid_argument& e) { cout << e.what() << endl; return 3; diff --git a/plugins/check_users.cpp b/plugins/check_users.cpp index 9d37ee73e..69c02e2b3 100644 --- a/plugins/check_users.cpp +++ b/plugins/check_users.cpp @@ -172,15 +172,15 @@ int printOutput(printInfoStruct& printInfo) switch (state) { case OK: - wcout << L"USERS OK " << printInfo.users << L"User|users=" << printInfo.users << L";" + wcout << L"USERS OK " << printInfo.users << L" User(s)|users=" << printInfo.users << L";" << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0" << endl; break; case WARNING: - wcout << L"USERS WARNING " << printInfo.users << L"User|users=" << printInfo.users << L";" + wcout << L"USERS WARNING " << printInfo.users << L" User(s)|users=" << printInfo.users << L";" << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0" << endl; break; case CRITICAL: - wcout << L"USERS CRITICAL " << printInfo.users << L"User|users=" << printInfo.users << L";" + wcout << L"USERS CRITICAL " << printInfo.users << L" User(s)|users=" << printInfo.users << L";" << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0" << endl; break; } diff --git a/plugins/thresholds.cpp b/plugins/thresholds.cpp index 40caa7b5d..781d2329e 100644 --- a/plugins/thresholds.cpp +++ b/plugins/thresholds.cpp @@ -16,14 +16,13 @@ * along with this program; if not, write to the Free Software Foundation * * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include -#include #include "thresholds.h" +#include +#include +#include +#include -#include "boost/algorithm/string.hpp" -#include "boost/lexical_cast.hpp" - using namespace boost::algorithm; using std::wstring; @@ -100,9 +99,11 @@ threshold::threshold(const wstring& stri) } try { - double d1 = boost::lexical_cast(str1); - double d2 = boost::lexical_cast(str2); - lower = d1; upper = d2; legal = !low; perc = pc; set = true; + boost::algorithm::trim(str1); + lower = boost::lexical_cast(str1); + boost::algorithm::trim(str2); + upper = boost::lexical_cast(str2); + legal = !low; perc = pc; set = true; } catch (const boost::bad_lexical_cast&) { throw std::invalid_argument("Unknown Threshold type"); } @@ -112,8 +113,9 @@ threshold::threshold(const wstring& stri) str = wstring(str.begin(), str.end() - 1); } try { - double d = boost::lexical_cast(str); - lower = d; upper = d; legal = !low; perc = pc; set = true; + boost::algorithm::trim(str); + lower = upper = boost::lexical_cast(str); + legal = !low; perc = pc; set = true; } catch (const boost::bad_lexical_cast&) { throw std::invalid_argument("Unknown Threshold type"); } -- 2.40.0