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>>();
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;
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;
}
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;
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;
}
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))
{
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;
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>();
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"
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;
}
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;
}
{
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;
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;
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{
{
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))
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;
}
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;
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;
}
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;
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'%') {
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'%') {
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");
}
}
}