source: nscp/modules/CheckHelpers/CheckHelpers.cpp @ af5bc4b

0.4.00.4.10.4.2stable
Last change on this file since af5bc4b was af5bc4b, checked in by Michael Medin <michael@…>, 8 years ago

2005-05-18 MickeM

  • Fixed bug in NSC.ini (section title for Check System was wrong) + Added multitasking for plugins (now two plugins can handle requests simultaniously)
  • Fixed som minor issues here and there
  • Property mode set to 100644
File size: 3.5 KB
Line 
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
10CheckHelpers gCheckHelpers;
11
12BOOL 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
18CheckHelpers::CheckHelpers() {
19}
20CheckHelpers::~CheckHelpers() {
21}
22
23
24bool CheckHelpers::loadModule() {
25        return true;
26}
27bool CheckHelpers::unloadModule() {
28        return true;
29}
30
31std::string CheckHelpers::getModuleName() {
32        return "CheckHelpers Various helper function to extend other checks.";
33}
34NSCModuleWrapper::module_version CheckHelpers::getModuleVersion() {
35        NSCModuleWrapper::module_version version = {0, 3, 0 };
36        return version;
37}
38
39bool CheckHelpers::hasCommandHandler() {
40        return true;
41}
42bool CheckHelpers::hasMessageHandler() {
43        return false;
44}
45
46NSCAPI::nagiosReturn CheckHelpers::handleCommand(const strEx::blindstr command, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) {
47        if (command == "CheckAlwaysOK") {
48                if (argLen < 2) {
49                        msg = "ERROR: Missing arguments.";
50                        return NSCAPI::returnUNKNOWN;
51                }
52                NSCModuleHelper::InjectCommand(char_args[0], argLen-1, &char_args[1], msg, perf);
53                return NSCAPI::returnOK;
54        } else if (command == "CheckAlwaysCRITICAL") {
55                if (argLen < 2) {
56                        msg = "ERROR: Missing arguments.";
57                        return NSCAPI::returnUNKNOWN;
58                }
59                NSCModuleHelper::InjectCommand(char_args[0], argLen-1, &char_args[1], msg, perf);
60                return NSCAPI::returnCRIT;
61        } else if (command == "CheckAlwaysWARNING") {
62                if (argLen < 2) {
63                        msg = "ERROR: Missing arguments.";
64                        return NSCAPI::returnUNKNOWN;
65                }
66                NSCModuleHelper::InjectCommand(char_args[0], argLen-1, &char_args[1], msg, perf);
67                return NSCAPI::returnWARN;
68        } else if (command == "CheckMultiple") {
69                return checkMultiple(argLen, char_args, msg, perf);
70        }
71        return NSCAPI::returnIgnored;
72}
73NSCAPI::nagiosReturn CheckHelpers::checkMultiple(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf)
74{
75        NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK;
76        std::list<std::string> args = arrayBuffer::arrayBuffer2list(argLen, char_args);
77        if (args.empty()) {
78                msg = "Missing argument(s).";
79                return NSCAPI::returnCRIT;
80        }
81        typedef std::pair<std::string, std::list<std::string> > sub_command;
82        std::list<sub_command> commands;
83        sub_command currentCommand;
84        std::list<std::string>::const_iterator cit;
85        for (cit=args.begin();cit!=args.end();++cit) {
86                std::string arg = *cit;
87                std::pair<std::string,std::string> p = strEx::split(arg,"=");
88                if (p.first == "command") {
89                        if (!currentCommand.first.empty())
90                                commands.push_back(currentCommand);
91                        currentCommand.first = p.second;
92                        currentCommand.second.clear();
93                } else {
94                        currentCommand.second.push_back(*cit);
95                }
96        }
97        if (!currentCommand.first.empty())
98                commands.push_back(currentCommand);
99        std::list<sub_command>::iterator cit2;
100        for (cit2 = commands.begin(); cit2 != commands.end(); ++cit2) {
101                unsigned int length = 0;
102                char ** args = arrayBuffer::list2arrayBuffer((*cit2).second, length);
103                std::string tMsg, tPerf;
104                NSCAPI::nagiosReturn tRet = NSCModuleHelper::InjectCommand((*cit2).first.c_str(), length, args, tMsg, tPerf);
105                arrayBuffer::destroyArrayBuffer(args, length);
106                returnCode = NSCHelper::maxState(returnCode, tRet);
107                if (!msg.empty())
108                        msg += ", ";
109                msg += tMsg;
110                perf += tPerf;
111        }
112        return returnCode;
113}
114
115
116NSC_WRAPPERS_MAIN_DEF(gCheckHelpers);
117NSC_WRAPPERS_IGNORE_MSG_DEF();
118NSC_WRAPPERS_HANDLE_CMD_DEF(gCheckHelpers);
Note: See TracBrowser for help on using the repository browser.