source: nscp/NSClient++.h @ aaa9a22

0.4.00.4.10.4.2stable
Last change on this file since aaa9a22 was 452fd41, checked in by Michael Medin <michael@…>, 8 years ago
  • Changed the Thread class a bit (mutex -> signal, and CreatThread? does not return the instance)
  • Moved settings "keys" fro NRPE to config.h
  • Changed build options (added Distribution) which builds a zip file under ./dist (requires 7z installed)
  • Minor tweaks to error/debug logging and small fixes "here and there"
  • Property mode set to 100644
File size: 4.3 KB
Line 
1#pragma once
2
3#include "resource.h"
4#include <ServiceCmd.h>
5#include <NTService.h>
6#include "NSCPlugin.h"
7#include <Mutex.h>
8#include <NSCAPI.h>
9
10
11/**
12 * @ingroup NSClient++
13 * Main NSClient++ core class. This is the service core and as such is responsible for pretty much everything.
14 * It also acts as a broker for all plugins and other sub threads and such.
15 *
16 * @version 1.0
17 * first version
18 *
19 * @date 02-12-2005
20 *
21 * @author mickem
22 *
23 * @par license
24 * This code is absolutely free to use and modify. The code is provided "as is" with
25 * no expressed or implied warranty. The author accepts no liability if it causes
26 * any damage to your computer, causes your pet to fall ill, increases baldness
27 * or makes your car start emitting strange noises when you start it up.
28 * This code has no bugs, just undocumented features!
29 *
30 * @todo Plugininfy the socket somehow ?
31 * It is technically possible to make the socket a plug-in but would it be a good idea ?
32 *
33 * @bug
34 *
35 */
36class NSClientT {
37private:
38        typedef NSCPlugin* plugin_type;
39        typedef std::list<plugin_type> pluginList;
40        pluginList plugins_;
41        pluginList commandHandlers_;
42        pluginList messageHandlers_;
43        std::string basePath;
44        MutexHandler pluginMutex;
45        MutexHandler messageMutex;
46
47public:
48        // c-tor, d-tor
49        NSClientT(void) {}
50        virtual ~NSClientT(void) {}
51
52        // Service helper functions
53        void InitiateService(void);
54        void TerminateService(void);
55        static void WINAPI service_main_dispatch(DWORD dwArgc, LPTSTR *lpszArgv);
56        static void WINAPI service_ctrl_dispatch(DWORD dwCtrlCode);
57
58        // Member functions
59        std::string getBasePath(void);
60        NSCAPI::nagiosReturn injectRAW(const char* command, const unsigned int argLen, char **argument, char *returnMessageBuffer, unsigned int returnMessageBufferLen, char *returnPerfBuffer, unsigned int returnPerfBufferLen);
61//      std::string inject(const std::string buffer);
62        std::string execute(std::string password, std::string cmd, std::list<std::string> args);
63        void reportMessage(int msgType, const char* file, const int line, std::string message);
64
65        void loadPlugins(const std::list<std::string> plugins);
66        void loadPlugin(const std::string plugin);
67        void loadPlugins(void);
68        void unloadPlugins(void);
69
70private:
71        void addPlugin(plugin_type plugin);
72
73};
74
75typedef NTService<NSClientT> NSClient;
76
77//////////////////////////////////////////////////////////////////////////
78// Various NSAPI callback functions (available for plug-ins to make calls back to the core.
79// <b>NOTICE</b> No threading is allowed so technically every thread is responsible for marshaling things back.
80// Though I think this is not the case at the moment.
81//
82
83LPVOID NSAPILoader(char*buffer);
84NSCAPI::errorReturn NSAPIGetApplicationName(char*buffer, unsigned int bufLen);
85NSCAPI::errorReturn NSAPIGetBasePath(char*buffer, unsigned int bufLen);
86NSCAPI::errorReturn NSAPIGetApplicationVersionStr(char*buffer, unsigned int bufLen);
87NSCAPI::errorReturn NSAPIGetSettingsString(const char* section, const char* key, const char* defaultValue, char* buffer, unsigned int bufLen);
88int NSAPIGetSettingsInt(const char* section, const char* key, int defaultValue);
89void NSAPIMessage(int msgType, const char* file, const int line, const char* message);
90void NSAPIStopServer(void);
91NSCAPI::nagiosReturn NSAPIInject(const char* command, const unsigned int argLen, char **argument, char *returnMessageBuffer, unsigned int returnMessageBufferLen, char *returnPerfBuffer, unsigned int returnPerfBufferLen);
92NSCAPI::errorReturn NSAPIGetSettingsSection(const char*, char***, unsigned int *);
93//////////////////////////////////////////////////////////////////////////
94// Log macros to simplify logging
95// Generally names are of the form LOG_<severity>[_STD]
96// Where _STD indicates that strings are force wrapped inside a std::string
97//
98#define LOG_ERROR_STD(msg) LOG_ERROR(((std::string)msg).c_str())
99#define LOG_ERROR(msg) \
100        NSAPIMessage(NSCAPI::error, __FILE__, __LINE__, msg)
101#define LOG_CRITICAL_STD(msg) LOG_CRITICAL(((std::string)msg).c_str())
102#define LOG_CRITICAL(msg) \
103        NSAPIMessage(NSCAPI::critical, __FILE__, __LINE__, msg)
104#define LOG_MESSAGE_STD(msg) LOG_MESSAGE(((std::string)msg).c_str())
105#define LOG_MESSAGE(msg) \
106        NSAPIMessage(NSCAPI::log, __FILE__, __LINE__, msg)
107#define LOG_DEBUG_STD(msg) LOG_DEBUG(((std::string)msg).c_str())
108#define LOG_DEBUG(msg) \
109        NSAPIMessage(NSCAPI::debug, __FILE__, __LINE__, msg)
Note: See TracBrowser for help on using the repository browser.