diff --git a/plugins/check_disk.cpp b/plugins/check_disk.cpp index 5620fe5e7..b8b92ca8b 100644 --- a/plugins/check_disk.cpp +++ b/plugins/check_disk.cpp @@ -59,7 +59,7 @@ static bool getFreeAndCap(drive&, const Bunit&); int wmain(int argc, wchar_t **argv) { vector vDrives; - printInfoStruct printInfo{ false, false}; + printInfoStruct printInfo{ }; po::variables_map vm; int ret; @@ -68,6 +68,9 @@ int wmain(int argc, wchar_t **argv) if (ret != -1) return ret; + printInfo.warn.legal = !printInfo.warn.legal; + printInfo.crit.legal = !printInfo.crit.legal; + if (printInfo.drives.empty()) ret = check_drives(vDrives); else @@ -77,8 +80,10 @@ int wmain(int argc, wchar_t **argv) return ret; for (vector::iterator it = vDrives.begin(); it != vDrives.end(); ++it) { - if (!getFreeAndCap(*it, printInfo.unit)) + if (!getFreeAndCap(*it, printInfo.unit)) { + wcout << L"Failed to access drive at " << it->name << endl; return 3; + } } return printOutput(printInfo, vDrives); @@ -93,9 +98,8 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& po::options_description desc("Options"); desc.add_options() - (",h", "print usage message and exit") - ("help", "print help message and exit") - ("version,v", "print version and exit") + ("help,h", "print usage message and exit") + ("version,V", "print version and exit") ("warning,w", po::wvalue(), "warning threshold") ("critical,c", po::wvalue(), "critical threshold") ("path,p", po::wvalue>()->multitoken(), "declare explicitly which drives to check (default checks all)") @@ -132,8 +136,7 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& L"and \"23.8304%%\" is the returned value.\n" L"The performance data is found behind the \"|\", in order:\n" L"returned value, warning threshold, critical threshold, minimal value and,\n" - L"if applicable, the maximal value. Performance data will only be displayed when\n" - L"you set at least one threshold\n" + L"if applicable, the maximal value.\n" L"This program will also print out additional performance data disk by disk\n\n" L"%s' exit codes denote the following:\n\n" L" 0\tOK,\n\tNo Thresholds were broken or the programs check part was not executed\n" @@ -142,10 +145,9 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& L" 3\tUNKNOWN, \n\tThe program experienced an internal or input error\n\n" L"Threshold syntax:\n\n" L"-w THRESHOLD\n" - L"warn if threshold is broken, which means VALUE > THRESHOLD\n" - L"(unless stated differently)\n\n" + L"warn if threshold is broken, which means VALUE < THRESHOLD\n\n" L"-w !THRESHOLD\n" - L"inverts threshold check, VALUE < THRESHOLD (analogous to above)\n\n" + L"inverts threshold check, VALUE > THRESHOLD (analogous to above)\n\n" L"-w [THR1-THR2]\n" L"warn is VALUE is inside the range spanned by THR1 and THR2\n\n" L"-w ![THR1-THR2]\n" @@ -161,11 +163,6 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& return 0; } - if (vm.count("h")) { - cout << desc << endl; - return 0; - } - if (vm.count("version")) cout << "Version: " << VERSION << endl; @@ -211,11 +208,12 @@ int printOutput(printInfoStruct& printInfo, vector& vDrives) for (vector::iterator it = vDrives.begin(); it != vDrives.end(); ++it) { tCap += it->cap; tFree += it->free; - perf << L" drive=\"" << it->name << L"\";cap=" << it->cap << unit << L";free=" << it->free << unit; + perf << std::fixed << L" " << it->name << L"=" << removeZero(it->free) << unit << L";" + << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0;" << removeZero(tCap); } - prePerf << L"|disk=" << tFree << unit << L";" << printInfo.warn.pString() << L";" - << printInfo.crit.pString() << L";0;" << tCap; + prePerf << L" | disk=" << removeZero(tFree) << unit << L";" << printInfo.warn.pString() << L";" + << printInfo.crit.pString() << L";0;" << removeZero(tCap); if (printInfo.warn.perc) { if (printInfo.warn.rend((tFree / tCap) * 100.0)) @@ -313,6 +311,10 @@ int check_drives(vector& vDrives, printInfoStruct& printInfo) if (it->at(it->length() - 1) != *slash) it->append(slash); + if (std::wstring::npos == it->find(L":\\")) { + wcout << "A \":\" is required after the drive name of " << *it << endl; + return 3; + } vDrives.push_back(drive(*it)); } return -1; @@ -325,8 +327,8 @@ bool getFreeAndCap(drive& drive, const Bunit& unit) return FALSE; } - drive.cap = (tempTotal.QuadPart / pow(1024.0, unit)); - drive.free = (tempFree.QuadPart / pow(1024.0, unit)); + drive.cap = round((tempTotal.QuadPart / pow(1024.0, unit))); + drive.free = round((tempFree.QuadPart / pow(1024.0, unit))); return TRUE; } \ No newline at end of file diff --git a/plugins/check_load.cpp b/plugins/check_load.cpp index 8adaceaab..1a4637c9c 100644 --- a/plugins/check_load.cpp +++ b/plugins/check_load.cpp @@ -67,9 +67,8 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& po::options_description desc; desc.add_options() - (",h", "print usage message and exit") - ("help", "print help message and exit") - ("version,v", "print version and exit") + ("help,h", "print usage message and exit") + ("version,V", "print version and exit") ("warning,w", po::wvalue(), "warning value (in percent)") ("critical,c", po::wvalue(), "critical value (in percent)") ; @@ -91,11 +90,6 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& return 3; } - if (vm.count("h")) { - cout << desc << endl; - return 0; - } - if (vm.count("help")) { wcout << progName << " Help\n\tVersion: " << VERSION << endl; wprintf( @@ -176,7 +170,7 @@ int printOutput(printInfoStruct& printInfo) state = CRITICAL; std::wstringstream perf; - perf << L"%|load=" << printInfo.load << L"%;" << printInfo.warn.pString() << L";" + perf << L"% | load=" << printInfo.load << L"%;" << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0;100" << endl; switch (state) { diff --git a/plugins/check_network.cpp b/plugins/check_network.cpp index 688f78fbc..8e0589dc5 100644 --- a/plugins/check_network.cpp +++ b/plugins/check_network.cpp @@ -75,9 +75,8 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& po::options_description desc("Options"); desc.add_options() - (",h", "print usage and exit") - ("help", "print help message and exit") - ("version,v", "print version and exit") + ("help,h", "print usage and exit") + ("version,V", "print version and exit") ("warning,w", po::wvalue(), "warning value") ("critical,c", po::wvalue(), "critical value") ; @@ -99,11 +98,6 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& return 3; } - if (vm.count("h")) { - cout << desc << endl; - return 0; - } - if (vm.count("help")) { wcout << progName << " Help\n\tVersion: " << VERSION << endl; wprintf( @@ -187,17 +181,17 @@ int printOutput(printInfoStruct& printInfo, const vector& vInterface if (printInfo.crit.rend(tIn + tOut)) state = CRITICAL; - perfDataFirst << L"network=" << tIn + tOut << L"B/s;" << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";" << L"0 "; + perfDataFirst << L"network=" << tIn + tOut << L"B/s;" << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";" << L"0; "; switch (state) { case OK: - wcout << L"NETWORK OK " << tIn + tOut << L"B/s|" << perfDataFirst.str() << tss.str() << endl; + wcout << L"NETWORK OK " << tIn + tOut << L"B/s | " << perfDataFirst.str() << tss.str() << endl; break; case WARNING: - wcout << L"NETWORK WARNING " << tIn + tOut << L"B/s|" << perfDataFirst.str() << tss.str() << endl; + wcout << L"NETWORK WARNING " << tIn + tOut << L"B/s | " << perfDataFirst.str() << tss.str() << endl; break; case CRITICAL: - wcout << L"NETWORK CRITICAL " << tIn + tOut << L"B/s|" << perfDataFirst.str() << tss.str() << endl; + wcout << L"NETWORK CRITICAL " << tIn + tOut << L"B/s | " << perfDataFirst.str() << tss.str() << endl; break; } diff --git a/plugins/check_ping.cpp b/plugins/check_ping.cpp index 2d7b500ab..0e4c61fc9 100644 --- a/plugins/check_ping.cpp +++ b/plugins/check_ping.cpp @@ -125,11 +125,6 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& return 3; } - if (vm.count("-4") && vm.count("-6")) { - cout << "Conflicting options \"4\" and \"6\"" << endl; - return 3; - } - if (vm.count("help")) { wcout << progName << " Help\n\tVersion: " << VERSION << endl; wprintf( @@ -176,6 +171,11 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& return 0; } + if (vm.count("-4") && vm.count("-6")) { + cout << "Conflicting options \"4\" and \"6\"" << endl; + return 3; + } + if (vm.count("warning")) { std::vector sVec = splitMultiOptions(vm["warning"].as()); if (sVec.size() != 2) { @@ -278,6 +278,11 @@ int check_ping4(const printInfoStruct& pi, response& response) return 3; } + if (*term != L'\0') { + std::wcout << pi.host << " is not a valid ip address" << std::endl; + return 3; + } + if ((hIcmp = IcmpCreateFile()) == INVALID_HANDLE_VALUE) goto die; diff --git a/plugins/check_procs.cpp b/plugins/check_procs.cpp index 942c027db..5fd3456ed 100644 --- a/plugins/check_procs.cpp +++ b/plugins/check_procs.cpp @@ -69,18 +69,22 @@ int printOutput(const int numProcs, printInfoStruct& printInfo) if (printInfo.crit.rend(numProcs)) state = CRITICAL; + wstring user = L""; + if (!printInfo.user.empty()) + user.append(L" processes of user ").append(printInfo.user); + switch (state) { case OK: - wcout << L"PROCS OK " << numProcs << L"|procs=" << numProcs << L";" - << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0" << endl; + wcout << L"PROCS OK " << numProcs << user << L" | procs=" << numProcs << L";" + << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0;" << endl; break; case WARNING: - wcout << L"PROCS WARNING " << numProcs << L"|procs=" << numProcs << L";" - << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0" << endl; + wcout << L"PROCS WARNING " << numProcs << user << L" | procs=" << numProcs << L";" + << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0;" << endl; break; case CRITICAL: - wcout << L"PROCS CRITICAL " << numProcs << L"|procs=" << numProcs << L";" - << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0" << endl; + wcout << L"PROCS CRITICAL " << numProcs << user << L" | procs=" << numProcs << L";" + << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0;" << endl; break; } @@ -96,9 +100,8 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& po::options_description desc; desc.add_options() - ("h", "print help message and exit") - ("help", "print verbose help and exit") - ("version,v", "print version and exit") + ("help,h", "print help message and exit") + ("version,V", "print version and exit") ("warning,w", po::wvalue(), "warning threshold") ("critical,c", po::wvalue(), "critical threshold") ("user,u", po::wvalue(), "count only processes by user [arg]") @@ -120,11 +123,6 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& std::cout << e.what() << endl << desc << endl; return 3; } - - if (vm.count("h")) { - std::cout << desc << endl; - return 0; - } if (vm.count("help")) { wcout << progName << " Help\n\tVersion: " << VERSION << endl; diff --git a/plugins/check_service.cpp b/plugins/check_service.cpp index ccfd19677..e5eed192f 100644 --- a/plugins/check_service.cpp +++ b/plugins/check_service.cpp @@ -67,9 +67,8 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& po::options_description desc; desc.add_options() - (",h", "print help message and exit") - ("help", "print verbose help and exit") - ("version,v", "print version and exit") + ("help,h", "print help message and exit") + ("version,V", "print version and exit") ("service,s", po::wvalue(), "service to check (required)") ("warn,w", "return warning (1) instead of critical (2),\n when service is not running") ; @@ -90,12 +89,7 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& cout << e.what() << endl << desc << endl; return 3; } - - if (vm.count("h")) { - cout << desc << endl; - return 0; - } - + if (vm.count("help")) { wcout << progName << " Help\n\tVersion: " << VERSION << endl; wprintf( @@ -145,18 +139,23 @@ int printOutput(const printInfoStruct& printInfo) wstring perf; state state = OK; + if (!printInfo.ServiceState) { + wcout << L"SERVICE CRITICAL NOT_FOUND | service=" << printInfo.ServiceState << ";!4;!4;1;7" << endl; + return 3; + } + if (printInfo.ServiceState != 0x04) printInfo.warn ? state = WARNING : state = CRITICAL; switch (state) { case OK: - wcout << L"SERVICE OK RUNNING|service=4;!4;!4;1;7" << endl; + wcout << L"SERVICE OK RUNNING | service=4;!4;!4;1;7" << endl; break; case WARNING: - wcout << L"SERVICE WARNING NOT_RUNNING|service=" << printInfo.ServiceState << ";!4;!4;1;7" << endl; + wcout << L"SERVICE WARNING NOT_RUNNING | service=" << printInfo.ServiceState << ";!4;!4;1;7" << endl; break; case CRITICAL: - wcout << L"SERVICE CRITICAL NOT_RUNNING|service=" << printInfo.ServiceState << ";!4;!4;1;7" << endl; + wcout << L"SERVICE CRITICAL NOT_RUNNING | service=" << printInfo.ServiceState << ";!4;!4;1;7" << endl; break; } @@ -194,7 +193,7 @@ int ServiceStatus(const printInfoStruct& printInfo) return state; } } - wcout << L"Service " << printInfo.service << L" could not be found\n"; + return 0; delete[] reinterpret_cast(lpServices); return -1; diff --git a/plugins/check_swap.cpp b/plugins/check_swap.cpp index 8e5fdadaa..6889f9c94 100644 --- a/plugins/check_swap.cpp +++ b/plugins/check_swap.cpp @@ -66,9 +66,8 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& po::options_description desc; desc.add_options() - (",h", "print help message and exit") - ("help", "print verbose help and exit") - ("version,v", "print version and exit") + ("help,h", "print help message and exit") + ("version,V", "print version and exit") ("warning,w", po::wvalue(), "warning threshold") ("critical,c", po::wvalue(), "critical threshold") ; @@ -90,11 +89,6 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& return 3; } - if (vm.count("h")) { - cout << desc << endl; - return 0; - } - if (vm.count("help")) { wcout << progName << " Help\n\tVersion: " << VERSION << endl; wprintf( @@ -171,15 +165,15 @@ int printOutput(printInfoStruct& printInfo) switch (state) { case OK: - wcout << L"SWAP OK " << printInfo.swap << L"%|swap=" << printInfo.swap << L"%;" + wcout << L"SWAP OK " << printInfo.swap << L"% | swap=" << printInfo.swap << L"%;" << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0;100" << endl; break; case WARNING: - wcout << L"SWAP WARNING " << printInfo.swap << L"%|swap=" << printInfo.swap << L"%;" + wcout << L"SWAP WARNING " << printInfo.swap << L"% | swap=" << printInfo.swap << L"%;" << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0;100" << endl; break; case CRITICAL: - wcout << L"SWAP CRITICAL " << printInfo.swap << L"%|swap=" << printInfo.swap << L"%;" + wcout << L"SWAP CRITICAL " << printInfo.swap << L"% | swap=" << printInfo.swap << L"%;" << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0;100" << endl; break; } diff --git a/plugins/check_update.cpp b/plugins/check_update.cpp index 952057000..2d2930f25 100644 --- a/plugins/check_update.cpp +++ b/plugins/check_update.cpp @@ -85,8 +85,8 @@ int printOutput(const printInfoStruct& printInfo) break; } - wcout << output << printInfo.numUpdates << L"|update=" << printInfo.numUpdates << L";" - << printInfo.warn << L";" << printInfo.crit << L";0" << endl; + wcout << output << printInfo.numUpdates << L" | update=" << printInfo.numUpdates << L";" + << printInfo.warn << L";" << printInfo.crit << L";0;" << endl; return state; } @@ -100,9 +100,8 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& po::options_description desc; desc.add_options() - (",h", "print help message and exit") - ("help", "print verbose help and exit") - ("version,v", "print version and exit") + ("help,h", "print help message and exit") + ("version,V", "print version and exit") ("warning,w", "warn if there are important updates available") ("critical,c", "critical if there are important updates that require a reboot") ("possible-reboot", "treat \"update may need to reboot\" as \"update needs to reboot\"") @@ -124,11 +123,6 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& cout << e.what() << endl << desc << endl; return 3; } - - if (vm.count("h")) { - cout << desc << endl; - return 0; - } if (vm.count("help")) { wcout << progName << " Help\n\tVersion: " << VERSION << endl; diff --git a/plugins/check_uptime.cpp b/plugins/check_uptime.cpp index 3b3e91a79..9dcaa1182 100644 --- a/plugins/check_uptime.cpp +++ b/plugins/check_uptime.cpp @@ -44,7 +44,7 @@ static int parseArguments(int, wchar_t **, po::variables_map&, printInfoStruct&) static int printOutput(printInfoStruct&); static void getUptime(printInfoStruct&); -int main(int argc, wchar_t **argv) +int wmain(int argc, wchar_t **argv) { po::variables_map vm; printInfoStruct printInfo = { }; @@ -67,9 +67,8 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& po::options_description desc; desc.add_options() - (",h", "print help message and exit") - ("help", "print verbose help and exit") - ("version,v", "print version and exit") + ("help,h", "print help message and exit") + ("version,V", "print version and exit") ("warning,w", po::wvalue(), "warning threshold (Uses -unit)") ("critical,c", po::wvalue(), "critical threshold (Uses -unit)") ("unit,u", po::wvalue(), "desired unit of output\nh\t- hours\nm\t- minutes\ns\t- seconds (default)\nms\t- milliseconds") @@ -92,11 +91,6 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& return 3; } - if (vm.count("h")) { - cout << desc << endl; - return 0; - } - if (vm.count("help")) { wcout << progName << " Help\n\tVersion: " << VERSION << endl; wprintf( @@ -185,19 +179,19 @@ static int printOutput(printInfoStruct& printInfo) switch (state) { case OK: - wcout << L"UPTIME OK " << printInfo.time << TunitStr(printInfo.unit) << L"|uptime=" << printInfo.time - << TunitStr(printInfo.unit) << L";" << printInfo.warn.pString() << L";" - << printInfo.crit.pString() << L";0" << endl; + wcout << L"UPTIME OK " << printInfo.time << TunitStr(printInfo.unit) << L" | uptime=" << printInfo.time + << TunitStr(printInfo.unit) << L";" << printInfo.warn.pString() << L";" + << printInfo.crit.pString() << L";0;" << endl; break; case WARNING: - wcout << L"UPTIME WARNING " << printInfo.time << TunitStr(printInfo.unit) << L"|uptime=" << printInfo.time + wcout << L"UPTIME WARNING " << printInfo.time << TunitStr(printInfo.unit) << L" | uptime=" << printInfo.time << TunitStr(printInfo.unit) << L";" << printInfo.warn.pString() << L";" - << printInfo.crit.pString() << L";0" << endl; + << printInfo.crit.pString() << L";0;" << endl; break; case CRITICAL: - wcout << L"UPTIME CRITICAL " << printInfo.time << TunitStr(printInfo.unit) << L"|uptime=" << printInfo.time + wcout << L"UPTIME CRITICAL " << printInfo.time << TunitStr(printInfo.unit) << L" | uptime=" << printInfo.time << TunitStr(printInfo.unit) << L";" << printInfo.warn.pString() << L";" - << printInfo.crit.pString() << L";0" << endl; + << printInfo.crit.pString() << L";0;" << endl; break; } diff --git a/plugins/check_users.cpp b/plugins/check_users.cpp index 69c02e2b3..6cab0970c 100644 --- a/plugins/check_users.cpp +++ b/plugins/check_users.cpp @@ -67,9 +67,8 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& po::options_description desc; desc.add_options() - (",h", "print help message and exit") - ("help", "print verbose help and exit") - ("version,v", "print version and exit") + ("help,h", "print help message and exit") + ("version,V", "print version and exit") ("warning,w", po::wvalue(), "warning threshold") ("critical,c", po::wvalue(), "critical threshold") ; @@ -91,11 +90,6 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& return 3; } - if (vm.count("h")) { - cout << desc << endl; - return 0; - } - if (vm.count("help")) { wcout << progName << " Help\n\tVersion: " << VERSION << endl; wprintf( @@ -172,16 +166,16 @@ int printOutput(printInfoStruct& printInfo) switch (state) { case OK: - wcout << L"USERS OK " << printInfo.users << L" User(s)|users=" << printInfo.users << L";" - << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0" << endl; + wcout << L"USERS OK " << printInfo.users << L" User(s) logged in | 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(s)|users=" << printInfo.users << L";" - << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0" << endl; + wcout << L"USERS WARNING " << printInfo.users << L" User(s) logged in | 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(s)|users=" << printInfo.users << L";" - << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0" << endl; + wcout << L"USERS CRITICAL " << printInfo.users << L" User(s) logged in | users=" << printInfo.users << L";" + << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0;" << endl; break; }