| 1 | // CheckEventLog.cpp : Defines the entry point for the DLL application. |
|---|
| 2 | // |
|---|
| 3 | |
|---|
| 4 | #include "stdafx.h" |
|---|
| 5 | #include "CheckHelpers.h" |
|---|
| 6 | #include <strEx.h> |
|---|
| 7 | #include <time.h> |
|---|
| 8 | #include <utils.h> |
|---|
| 9 | |
|---|
| 10 | CheckHelpers gCheckHelpers; |
|---|
| 11 | |
|---|
| 12 | BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) |
|---|
| 13 | { |
|---|
| 14 | NSCModuleWrapper::wrapDllMain(hModule, ul_reason_for_call); |
|---|
| 15 | return TRUE; |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | CheckHelpers::CheckHelpers() { |
|---|
| 19 | } |
|---|
| 20 | CheckHelpers::~CheckHelpers() { |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | bool CheckHelpers::loadModule() { |
|---|
| 25 | return true; |
|---|
| 26 | } |
|---|
| 27 | bool CheckHelpers::unloadModule() { |
|---|
| 28 | return true; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | bool CheckHelpers::hasCommandHandler() { |
|---|
| 32 | return true; |
|---|
| 33 | } |
|---|
| 34 | bool CheckHelpers::hasMessageHandler() { |
|---|
| 35 | return false; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | NSCAPI::nagiosReturn CheckHelpers::handleCommand(const strEx::blindstr command, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) { |
|---|
| 39 | if (command == "CheckAlwaysOK") { |
|---|
| 40 | if (argLen < 2) { |
|---|
| 41 | msg = "ERROR: Missing arguments."; |
|---|
| 42 | return NSCAPI::returnUNKNOWN; |
|---|
| 43 | } |
|---|
| 44 | NSCModuleHelper::InjectCommand(char_args[0], argLen-1, &char_args[1], msg, perf); |
|---|
| 45 | return NSCAPI::returnOK; |
|---|
| 46 | } else if (command == "CheckAlwaysCRITICAL") { |
|---|
| 47 | if (argLen < 2) { |
|---|
| 48 | msg = "ERROR: Missing arguments."; |
|---|
| 49 | return NSCAPI::returnUNKNOWN; |
|---|
| 50 | } |
|---|
| 51 | NSCModuleHelper::InjectCommand(char_args[0], argLen-1, &char_args[1], msg, perf); |
|---|
| 52 | return NSCAPI::returnCRIT; |
|---|
| 53 | } else if (command == "CheckAlwaysWARNING") { |
|---|
| 54 | if (argLen < 2) { |
|---|
| 55 | msg = "ERROR: Missing arguments."; |
|---|
| 56 | return NSCAPI::returnUNKNOWN; |
|---|
| 57 | } |
|---|
| 58 | NSCModuleHelper::InjectCommand(char_args[0], argLen-1, &char_args[1], msg, perf); |
|---|
| 59 | return NSCAPI::returnWARN; |
|---|
| 60 | } else if (command == "CheckMultiple") { |
|---|
| 61 | return checkMultiple(argLen, char_args, msg, perf); |
|---|
| 62 | } |
|---|
| 63 | return NSCAPI::returnIgnored; |
|---|
| 64 | } |
|---|
| 65 | NSCAPI::nagiosReturn CheckHelpers::checkMultiple(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) |
|---|
| 66 | { |
|---|
| 67 | NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; |
|---|
| 68 | std::list<std::string> args = arrayBuffer::arrayBuffer2list(argLen, char_args); |
|---|
| 69 | if (args.empty()) { |
|---|
| 70 | msg = "Missing argument(s)."; |
|---|
| 71 | return NSCAPI::returnCRIT; |
|---|
| 72 | } |
|---|
| 73 | typedef std::pair<std::string, std::list<std::string> > sub_command; |
|---|
| 74 | std::list<sub_command> commands; |
|---|
| 75 | sub_command currentCommand; |
|---|
| 76 | std::list<std::string>::const_iterator cit; |
|---|
| 77 | for (cit=args.begin();cit!=args.end();++cit) { |
|---|
| 78 | std::string arg = *cit; |
|---|
| 79 | std::pair<std::string,std::string> p = strEx::split(arg,"="); |
|---|
| 80 | if (p.first == "command") { |
|---|
| 81 | if (!currentCommand.first.empty()) |
|---|
| 82 | commands.push_back(currentCommand); |
|---|
| 83 | currentCommand.first = p.second; |
|---|
| 84 | currentCommand.second.clear(); |
|---|
| 85 | } else { |
|---|
| 86 | currentCommand.second.push_back(*cit); |
|---|
| 87 | } |
|---|
| 88 | } |
|---|
| 89 | if (!currentCommand.first.empty()) |
|---|
| 90 | commands.push_back(currentCommand); |
|---|
| 91 | std::list<sub_command>::iterator cit2; |
|---|
| 92 | for (cit2 = commands.begin(); cit2 != commands.end(); ++cit2) { |
|---|
| 93 | unsigned int length = 0; |
|---|
| 94 | char ** args = arrayBuffer::list2arrayBuffer((*cit2).second, length); |
|---|
| 95 | std::string tMsg, tPerf; |
|---|
| 96 | NSCAPI::nagiosReturn tRet = NSCModuleHelper::InjectCommand((*cit2).first.c_str(), length, args, tMsg, tPerf); |
|---|
| 97 | arrayBuffer::destroyArrayBuffer(args, length); |
|---|
| 98 | returnCode = NSCHelper::maxState(returnCode, tRet); |
|---|
| 99 | if (!msg.empty()) |
|---|
| 100 | msg += ", "; |
|---|
| 101 | msg += tMsg; |
|---|
| 102 | perf += tPerf; |
|---|
| 103 | } |
|---|
| 104 | return returnCode; |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | NSC_WRAPPERS_MAIN_DEF(gCheckHelpers); |
|---|
| 109 | NSC_WRAPPERS_IGNORE_MSG_DEF(); |
|---|
| 110 | NSC_WRAPPERS_HANDLE_CMD_DEF(gCheckHelpers); |
|---|