mirror of https://github.com/Icinga/icinga2.git
Fix check_plugins dying with certain parameters
This commit is contained in:
parent
4df3fd4451
commit
22e3e48669
|
@ -170,12 +170,22 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct&
|
|||
if (vm.count("version"))
|
||||
cout << "Version: " << VERSION << endl;
|
||||
|
||||
if (vm.count("warning"))
|
||||
printInfo.warn = parse(vm["warning"].as<wstring>());
|
||||
|
||||
|
||||
if (vm.count("critical"))
|
||||
printInfo.crit = parse(vm["critical"].as<wstring>());
|
||||
if (vm.count("warning")) {
|
||||
try {
|
||||
printInfo.warn = parse(vm["warning"].as<wstring>());
|
||||
} catch (std::invalid_argument& e) {
|
||||
cout << e.what() << endl;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
if (vm.count("critical")) {
|
||||
try {
|
||||
printInfo.crit = parse(vm["critical"].as<wstring>());
|
||||
} catch (std::invalid_argument& e) {
|
||||
cout << e.what() << endl;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
if (vm.count("drives"))
|
||||
printInfo.drives = vm["drives"].as<vector<wstring>>();
|
||||
|
@ -205,11 +215,6 @@ int printOutput(printInfoStruct& printInfo, vector<drive>& vDrives)
|
|||
perf << L" drive=\"" << it->name << L"\";cap=" << it->cap << unit << L";free=" << it->free << unit;
|
||||
}
|
||||
|
||||
if (!printInfo.warn.set && !printInfo.crit.set) {
|
||||
wcout << L"DISK OK " << tFree << unit << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
prePerf << L"|disk=" << tFree << unit << L";" << printInfo.warn.pString() << L";"
|
||||
<< printInfo.crit.pString() << L";0;" << tCap;
|
||||
|
||||
|
|
|
@ -140,11 +140,22 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct&
|
|||
if (vm.count("version"))
|
||||
cout << "Version: " << VERSION << endl;
|
||||
|
||||
if (vm.count("warning"))
|
||||
printInfo.warn = parse(vm["warning"].as<wstring>());
|
||||
|
||||
if (vm.count("critical"))
|
||||
printInfo.crit = parse(vm["critical"].as<wstring>());
|
||||
if (vm.count("warning")) {
|
||||
try {
|
||||
printInfo.warn = parse(vm["warning"].as<wstring>());
|
||||
} catch (std::invalid_argument& e) {
|
||||
cout << e.what() << endl;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
if (vm.count("critical")) {
|
||||
try {
|
||||
printInfo.crit = parse(vm["critical"].as<wstring>());
|
||||
} catch (std::invalid_argument& e) {
|
||||
cout << e.what() << endl;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
@ -152,10 +163,6 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct&
|
|||
int printOutput(printInfoStruct& printInfo)
|
||||
{
|
||||
state state = OK;
|
||||
|
||||
if (!printInfo.warn.set && !printInfo.crit.set) {
|
||||
wcout << L"LOAD OK " << printInfo.load << L"%" << endl;
|
||||
}
|
||||
|
||||
if (printInfo.warn.rend(printInfo.load))
|
||||
state = WARNING;
|
||||
|
|
|
@ -151,11 +151,22 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct&
|
|||
if (vm.count("version"))
|
||||
cout << "Version: " << VERSION << endl;
|
||||
|
||||
if (vm.count("warning"))
|
||||
printInfo.warn = parse(vm["warning"].as<wstring>());
|
||||
|
||||
if (vm.count("critical"))
|
||||
printInfo.crit = parse(vm["critical"].as<wstring>());
|
||||
if (vm.count("warning")) {
|
||||
try {
|
||||
printInfo.warn = parse(vm["warning"].as<wstring>());
|
||||
} catch (std::invalid_argument& e) {
|
||||
cout << e.what() << endl;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
if (vm.count("critical")) {
|
||||
try {
|
||||
printInfo.crit = parse(vm["critical"].as<wstring>());
|
||||
} catch (std::invalid_argument& e) {
|
||||
cout << e.what() << endl;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
@ -172,10 +183,6 @@ int printOutput(printInfoStruct& printInfo, const vector<nInterface>& vInterface
|
|||
tss << L"netI=\"" << it->name << L"\";in=" << it->BytesInSec << L"B/s;out=" << it->BytesOutSec << L"B/s ";
|
||||
}
|
||||
|
||||
if (!printInfo.warn.set && !printInfo.crit.set) {
|
||||
wcout << L"NETWORK OK " << tIn+tOut << endl;
|
||||
}
|
||||
|
||||
if (printInfo.warn.rend(tIn + tOut))
|
||||
state = WARNING;
|
||||
if (printInfo.crit.rend(tIn + tOut))
|
||||
|
|
|
@ -63,11 +63,6 @@ int printOutput(const int numProcs, printInfoStruct& printInfo)
|
|||
{
|
||||
state state = OK;
|
||||
|
||||
if (!printInfo.warn.set && !printInfo.crit.set) {
|
||||
wcout << L"PROCS OK " << numProcs << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (printInfo.warn.rend(numProcs))
|
||||
state = WARNING;
|
||||
|
||||
|
@ -178,11 +173,22 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct&
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (vm.count("warning"))
|
||||
printInfo.warn = parse(vm["warning"].as<wstring>());
|
||||
|
||||
if (vm.count("critical"))
|
||||
printInfo.crit = parse(vm["critical"].as<wstring>());
|
||||
if (vm.count("warning")) {
|
||||
try {
|
||||
printInfo.warn = parse(vm["warning"].as<wstring>());
|
||||
} catch (std::invalid_argument& e) {
|
||||
cout << e.what() << endl;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
if (vm.count("critical")) {
|
||||
try {
|
||||
printInfo.crit = parse(vm["critical"].as<wstring>());
|
||||
} catch (std::invalid_argument& e) {
|
||||
cout << e.what() << endl;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
if (vm.count("user"))
|
||||
printInfo.user = vm["user"].as<wstring>();
|
||||
|
|
|
@ -104,7 +104,7 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct&
|
|||
cout << desc;
|
||||
wprintf(
|
||||
L"\nIt will then output a string looking something like this:\n\n"
|
||||
L"\tSERVICE CRITICAL NOT_RUNNING\n\n"
|
||||
L"\tSERVICE CRITICAL NOT_RUNNING|service=4;!4;!4;1;7\n\n"
|
||||
L"\"SERVICE\" being the type of the check, \"CRITICAL\" the returned status\n"
|
||||
L"and \"1\" is the returned value.\n"
|
||||
L"A service is either running (Code 0x04) or not running (any other).\n"
|
||||
|
@ -150,13 +150,13 @@ int printOutput(const printInfoStruct& printInfo)
|
|||
|
||||
switch (state) {
|
||||
case OK:
|
||||
wcout << L"SERVICE OK RUNNING" << endl;
|
||||
wcout << L"SERVICE OK RUNNING|service=4;!4;!4;1;7" << endl;
|
||||
break;
|
||||
case WARNING:
|
||||
wcout << L"SERVICE WARNING NOT_RUNNING" << endl;
|
||||
wcout << L"SERVICE WARNING NOT_RUNNING|service=" << printInfo.ServiceState << ";!4;!4;1;7" << endl;
|
||||
break;
|
||||
case CRITICAL:
|
||||
wcout << L"SERVICE CRITICAL NOT_RUNNING" << endl;
|
||||
wcout << L"SERVICE CRITICAL NOT_RUNNING|service=" << printInfo.ServiceState << ";!4;!4;1;7" << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -139,11 +139,22 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct&
|
|||
if (vm.count("version"))
|
||||
wcout << L"Version: " << VERSION << endl;
|
||||
|
||||
if (vm.count("warning"))
|
||||
printInfo.warn = parse(vm["warning"].as<wstring>());
|
||||
|
||||
if (vm.count("critical"))
|
||||
printInfo.crit = parse(vm["critical"].as<wstring>());
|
||||
if (vm.count("warning")) {
|
||||
try {
|
||||
printInfo.warn = parse(vm["warning"].as<wstring>());
|
||||
} catch (std::invalid_argument& e) {
|
||||
cout << e.what() << endl;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
if (vm.count("critical")) {
|
||||
try {
|
||||
printInfo.crit = parse(vm["critical"].as<wstring>());
|
||||
} catch (std::invalid_argument& e) {
|
||||
cout << e.what() << endl;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
@ -152,11 +163,6 @@ int printOutput(printInfoStruct& printInfo)
|
|||
{
|
||||
state state = OK;
|
||||
|
||||
if (!printInfo.warn.set && !printInfo.crit.set) {
|
||||
wcout << L"SWAP OK " << printInfo.swap << L"%" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (printInfo.warn.rend(printInfo.swap))
|
||||
state = WARNING;
|
||||
|
||||
|
|
|
@ -67,11 +67,6 @@ int printOutput(const printInfoStruct& printInfo)
|
|||
state state = OK;
|
||||
wstring output = L"UPDATE ";
|
||||
|
||||
if (!printInfo.warn && !printInfo.crit) {
|
||||
wcout << L"UPDATE OK " << printInfo.numUpdates << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (printInfo.important)
|
||||
state = WARNING;
|
||||
|
||||
|
|
|
@ -145,11 +145,22 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct&
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (vm.count("warning"))
|
||||
printInfo.warn = parse(vm["warning"].as<wstring>());
|
||||
|
||||
if (vm.count("critical"))
|
||||
printInfo.crit = parse(vm["critical"].as<wstring>());
|
||||
if (vm.count("warning")) {
|
||||
try {
|
||||
printInfo.warn = parse(vm["warning"].as<wstring>());
|
||||
} catch (std::invalid_argument& e) {
|
||||
cout << e.what() << endl;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
if (vm.count("critical")) {
|
||||
try {
|
||||
printInfo.crit = parse(vm["critical"].as<wstring>());
|
||||
} catch (std::invalid_argument& e) {
|
||||
cout << e.what() << endl;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
if (vm.count("unit")) {
|
||||
try{
|
||||
|
@ -167,11 +178,6 @@ static int printOutput(printInfoStruct& printInfo)
|
|||
{
|
||||
state state = OK;
|
||||
|
||||
if (!printInfo.warn.set && !printInfo.crit.set) {
|
||||
wcout << L"UPTIME OK " << printInfo.time << TunitStr(printInfo.unit) << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (printInfo.warn.rend(printInfo.time))
|
||||
state = WARNING;
|
||||
if (printInfo.crit.rend(printInfo.time))
|
||||
|
|
|
@ -140,11 +140,22 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct&
|
|||
if (vm.count("version"))
|
||||
wcout << L"Version: " << VERSION << endl;
|
||||
|
||||
if (vm.count("warning"))
|
||||
printInfo.warn = parse(vm["warning"].as<wstring>());
|
||||
|
||||
if (vm.count("critical"))
|
||||
printInfo.crit = parse(vm["critical"].as<wstring>());
|
||||
if (vm.count("warning")) {
|
||||
try {
|
||||
printInfo.warn = parse(vm["warning"].as<wstring>());
|
||||
} catch (std::invalid_argument& e) {
|
||||
cout << e.what() << endl;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
if (vm.count("critical")) {
|
||||
try {
|
||||
printInfo.crit = parse(vm["critical"].as<wstring>());
|
||||
} catch (std::invalid_argument& e) {
|
||||
cout << e.what() << endl;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
@ -152,11 +163,6 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct&
|
|||
int printOutput(printInfoStruct& printInfo)
|
||||
{
|
||||
state state = OK;
|
||||
|
||||
if (!printInfo.warn.set && !printInfo.crit.set) {
|
||||
wcout << L"USERS OK " << printInfo.users << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (printInfo.warn.rend(printInfo.users))
|
||||
state = WARNING;
|
||||
|
@ -166,15 +172,15 @@ int printOutput(printInfoStruct& printInfo)
|
|||
|
||||
switch (state) {
|
||||
case OK:
|
||||
wcout << L"USERS OK " << printInfo.users << L"|users=" << printInfo.users << L";"
|
||||
wcout << L"USERS OK " << printInfo.users << L"User|users=" << printInfo.users << L";"
|
||||
<< printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0" << endl;
|
||||
break;
|
||||
case WARNING:
|
||||
wcout << L"USERS WARNING " << printInfo.users << L"|users=" << printInfo.users << L";"
|
||||
wcout << L"USERS WARNING " << printInfo.users << L"User|users=" << printInfo.users << L";"
|
||||
<< printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0" << endl;
|
||||
break;
|
||||
case CRITICAL:
|
||||
wcout << L"USERS CRITICAL " << printInfo.users << L"|users=" << printInfo.users << L";"
|
||||
wcout << L"USERS CRITICAL " << printInfo.users << L"User|users=" << printInfo.users << L";"
|
||||
<< printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0" << endl;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ using std::wstring;
|
|||
threshold parse(const wstring& stri)
|
||||
{
|
||||
if (stri.empty())
|
||||
throw std::invalid_argument("thresholds must not be empty");
|
||||
throw std::invalid_argument("Threshold must not be empty");
|
||||
|
||||
wstring str = stri;
|
||||
|
||||
|
@ -43,7 +43,7 @@ threshold parse(const wstring& stri)
|
|||
std::vector<wstring> svec;
|
||||
boost::split(svec, str, boost::is_any_of(L"-"));
|
||||
if (svec.size() != 2)
|
||||
throw std::invalid_argument("threshold range requires two arguments");
|
||||
throw std::invalid_argument("Threshold range requires two arguments");
|
||||
wstring str1 = svec.at(0), str2 = svec.at(1);
|
||||
|
||||
if (str1.at(str1.length() - 1) == L'%' && str2.at(str2.length() - 1) == L'%') {
|
||||
|
@ -57,7 +57,7 @@ threshold parse(const wstring& stri)
|
|||
double d2 = boost::lexical_cast<double>(str2);
|
||||
return threshold(d1, d2, !low, perc);
|
||||
} catch (const boost::bad_lexical_cast&) {
|
||||
throw std::invalid_argument("threshold must be a number");
|
||||
throw std::invalid_argument("Unknown Threshold type");
|
||||
}
|
||||
} else { //not range
|
||||
if (str.at(str.length() - 1) == L'%') {
|
||||
|
@ -69,7 +69,7 @@ threshold parse(const wstring& stri)
|
|||
return threshold(d, d, !low, perc);
|
||||
|
||||
} catch (const boost::bad_lexical_cast&) {
|
||||
throw std::invalid_argument("threshold must be a number");
|
||||
throw std::invalid_argument("Unknown Threshold type");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue