source: nscp/NSCPlugin.h @ 1e62ed5

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

2005-05-15 MickeM

+ Added NRPE support for checkCounter
+ Updated documentation

  • Make check commands ignore case + Added CheckHelpers module to alter the result of various check and similar things

2005-05-14 MickeM

+ Added support for Volumes (CheckDisk)
+ Added support for checking all drives of a certain kind
+ Added support for altering filter (makes it posible to check removale drives)
+ Created webpage and better documentation

  • Property mode set to 100644
File size: 4.1 KB
Line 
1#pragma once
2
3#include <NSCAPI.h>
4#include <NSCHelper.h>
5
6/**
7 * @ingroup NSClient++
8 * Exception class for the NSCPlugin class.
9 * When an unexpected error occurs in NSCPlugin this exception is thrown.
10 *
11 * @version 1.0
12 * first version
13 *
14 * @date 02-12-2005
15 *
16 * @author mickem
17 *
18 * @par license
19 * This code is absolutely free to use and modify. The code is provided "as is" with
20 * no expressed or implied warranty. The author accepts no liability if it causes
21 * any damage to your computer, causes your pet to fall ill, increases baldness
22 * or makes your car start emitting strange noises when you start it up.
23 * This code has no bugs, just undocumented features!
24 *
25 * @todo
26 * Add status codes to make error type simpler to parse out.
27 *
28 * @bug
29 *
30 */
31class NSPluginException {
32public:
33        std::string file_;      // DLL filename (for which the exception was thrown)
34        std::string error_;     // An error message (human readable format)
35        /**
36         * @param file DLL filename (for which the exception is thrown)
37         * @param error An error message (human readable format)
38         */
39        NSPluginException(std::string file, std::string error) : file_(file), error_(error) {
40        }
41        /**
42         *
43         * @param file DLL filename (for which the exception is thrown)
44         * @param sError An error message (human readable format)
45         * @param nError Error code to be appended at the end of the string
46         * @todo Change this to be some form of standard error code and merge with above.
47         */
48        NSPluginException(std::string file, std::string sError, int nError) : file_(file) {
49                std::stringstream s;
50                s << sError;
51                s << nError;
52                error_ = s.str();
53
54        }
55};
56
57/**
58 * @ingroup NSClient++
59 * NSCPlugin is a wrapper class to wrap all DLL calls and make things simple and clean inside the actual application.<br>
60 * Things tend to be one-to-one by which I mean that a call to a function here should call the corresponding function in the plug in (if loaded).
61 * If things are "broken" NSPluginException is called to indicate this. Error states are returned for normal "conditions".
62 *
63 *
64 * @version 1.0
65 * first version
66 *
67 * @date 02-12-2005
68 *
69 * @author mickem
70 *
71 * @par license
72 * This code is absolutely free to use and modify. The code is provided "as is" with
73 * no expressed or implied warranty. The author accepts no liability if it causes
74 * any damage to your computer, causes your pet to fall ill, increases baldness
75 * or makes your car start emitting strange noises when you start it up.
76 * This code has no bugs, just undocumented features!
77 *
78 * @todo
79 * getVersion() is not implemented as of yet.
80 *
81 * @bug
82 *
83 */
84class NSCPlugin {
85private:
86        bool bLoaded_;                  // Status of plug in
87        HMODULE hModule_;               // module handle to the DLL (once it is loaded)
88        std::string file_;              // Name of the DLL file
89
90        typedef INT (*lpModuleHelperInit)(NSCModuleHelper::lpNSAPILoader f);
91        typedef INT (*lpLoadModule)();
92        typedef INT (*lpGetName)(char*,unsigned int);
93        typedef INT (*lpHasCommandHandler)();
94        typedef INT (*lpHasMessageHandler)();
95        typedef NSCAPI::nagiosReturn (*lpHandleCommand)(const char*,const unsigned int, char**,char*,unsigned int,char *,unsigned int);
96        typedef INT (*lpHandleMessage)(int,const char*,const int,const char*);
97        typedef INT (*lpUnLoadModule)();
98
99        lpModuleHelperInit fModuleHelperInit;
100        lpLoadModule fLoadModule;
101        lpGetName fGetName;
102        lpHasCommandHandler fHasCommandHandler;
103        lpHasMessageHandler fHasMessageHandler;
104        lpHandleCommand fHandleCommand;
105        lpHandleMessage fHandleMessage;
106        lpUnLoadModule fUnLoadModule;
107
108public:
109        NSCPlugin(const std::string file);
110        NSCPlugin(NSCPlugin &other);
111        virtual ~NSCPlugin(void);
112
113        std::string getName(void);
114        void load(void);
115        bool getVersion(int *major, int *minor, int *revision);
116        bool hasCommandHandler(void);
117        bool hasMessageHandler(void);
118        NSCAPI::nagiosReturn handleCommand(const char *command, const unsigned int argLen, char **arguments, char* returnMessageBuffer, unsigned int returnMessageBufferLen, char* returnPerfBuffer, unsigned int returnPerfBufferLen);
119        void handleMessage(int msgType, const char* file, const int line, const char *message);
120        void unload(void);
121
122private:
123        bool isLoaded() const {
124                return bLoaded_;
125        }
126        bool getName_(char* buf, unsigned int buflen);
127        void loadRemoteProcs_(void);
128};
129
130
Note: See TracBrowser for help on using the repository browser.