]> granicus.if.org Git - icinga2/commitdiff
Some minor plugin fixes
authorGunnar Beutner <gunnar@beutner.name>
Wed, 19 Nov 2014 05:40:58 +0000 (06:40 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Wed, 19 Nov 2014 05:40:58 +0000 (06:40 +0100)
plugins/check_disk.cpp
plugins/check_load.cpp
plugins/check_users.cpp
plugins/thresholds.cpp

index b8a968f057db5e3c04208fc9cca6ca145fed75a9..5620fe5e723a6c3f4a14494f94b998fab8cec3ea 100644 (file)
@@ -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<wstring>(), "warning threshold")
                ("critical,c", po::wvalue<wstring>(), "critical threshold")
-               ("drives,d", po::wvalue<vector<std::wstring>>()->multitoken(), "declare explicitly which drives to check (default checks all)")
+               ("path,p", po::wvalue<vector<std::wstring>>()->multitoken(), "declare explicitly which drives to check (default checks all)")
                ("unit,u", po::wvalue<wstring>(), "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<vector<wstring>>();
+       if (vm.count("path")) 
+               printInfo.drives = vm["path"].as<vector<wstring>>();
 
        if (vm.count("unit")) {
                try {
index c206eea1925d571e9cebdd939cae1b1f5f664ec4..4f69872b0a9d6751e0d801702b4a1bb7df498b14 100644 (file)
  * 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 <boost/program_options.hpp>
+#include <boost/algorithm/string/split.hpp>
+#include <boost/algorithm/string/classification.hpp>
 #include <Pdh.h>
 #include <Shlwapi.h>
 #include <pdhmsg.h>
 #include <iostream>
 
-#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<wstring>());
+                       std::wstring wthreshold = vm["warning"].as<wstring>();
+                       std::vector<std::wstring> 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<wstring>());
+                       std::wstring cthreshold = vm["critical"].as<wstring>();
+                       std::vector<std::wstring> 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;
index 9d37ee73eb104ee4c18bffab1fed7cba2c9f58f0..69c02e2b36e73e55b179eebd7097107bbcc528d0 100644 (file)
@@ -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;
        }
index 40caa7b5d13edcd4c644054232a61e0dc371e9cb..781d2329e788d8bebf8bd6f1c41fa0373714841d 100644 (file)
  * along with this program; if not, write to the Free Software Foundation     *
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
  ******************************************************************************/
-#include <vector>
-#include <iostream>
 
 #include "thresholds.h"
+#include <boost/algorithm/string.hpp>
+#include <boost/lexical_cast.hpp>
+#include <vector>
+#include <iostream>
 
-#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<double>(str1);
-                       double d2 = boost::lexical_cast<double>(str2);
-                       lower = d1; upper = d2; legal = !low; perc = pc; set = true;
+                       boost::algorithm::trim(str1);
+                       lower = boost::lexical_cast<double>(str1);
+                       boost::algorithm::trim(str2);
+                       upper = boost::lexical_cast<double>(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<double>(str);
-                       lower = d; upper = d; legal = !low; perc = pc; set = true;
+                       boost::algorithm::trim(str);
+                       lower = upper = boost::lexical_cast<double>(str);
+                       legal = !low; perc = pc; set = true;
                } catch (const boost::bad_lexical_cast&) {
                        throw std::invalid_argument("Unknown Threshold type");
                }