mirror of https://github.com/Icinga/icinga2.git
Some minor plugin fixes
This commit is contained in:
parent
bf6a205edf
commit
023cfc15bb
|
@ -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 {
|
||||
|
|
|
@ -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 <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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 "thresholds.h"
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
#include "thresholds.h"
|
||||
|
||||
#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");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue