Changeset a44cb15 in nscp
- Timestamp:
- 09/02/11 07:38:44 (21 months ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- a14aa07
- Parents:
- 3b11e65
- Files:
-
- 38 edited
-
changelog (modified) (1 diff)
-
include/NSCAPI.h (modified) (2 diffs)
-
include/nscapi/functions.hpp (modified) (3 diffs)
-
include/nscapi/macros.hpp (modified) (3 diffs)
-
include/nscapi/nscapi_core_wrapper.cpp (modified) (4 diffs)
-
include/nscapi/nscapi_core_wrapper.hpp (modified) (4 diffs)
-
include/nscapi/nscapi_plugin_wrapper.cpp (modified) (3 diffs)
-
include/nscapi/nscapi_plugin_wrapper.hpp (modified) (5 diffs)
-
modules/CheckDisk/CheckDisk.cpp (modified) (1 diff)
-
modules/CheckDisk/CheckDisk.h (modified) (1 diff)
-
modules/CheckEventLog/CheckEventLog.cpp (modified) (1 diff)
-
modules/CheckEventLog/CheckEventLog.h (modified) (1 diff)
-
modules/CheckExternalScripts/CheckExternalScripts.h (modified) (2 diffs)
-
modules/CheckHelpers/CheckHelpers.cpp (modified) (1 diff)
-
modules/CheckHelpers/CheckHelpers.h (modified) (1 diff)
-
modules/CheckNSCP/CheckNSCP.cpp (modified) (1 diff)
-
modules/CheckSystem/CheckSystem.cpp (modified) (1 diff)
-
modules/CheckTaskSched/CheckTaskSched.cpp (modified) (1 diff)
-
modules/CheckTaskSched2/CheckTaskSched2.cpp (modified) (1 diff)
-
modules/CheckWMI/CheckWMI.cpp (modified) (1 diff)
-
modules/NRPEClient/NRPEClient.cpp (modified) (1 diff)
-
modules/NRPEClient/NRPEClient.h (modified) (1 diff)
-
modules/NSCAAgent/NSCAAgent.cpp (modified) (2 diffs)
-
modules/NSCAAgent/NSCAAgent.h (modified) (1 diff)
-
modules/NSCPClient/NSCPClient.cpp (modified) (2 diffs)
-
modules/NSCPClient/NSCPClient.h (modified) (1 diff)
-
modules/PythonScript/PythonScript.cpp (modified) (8 diffs)
-
modules/PythonScript/PythonScript.def (modified) (1 diff)
-
modules/PythonScript/PythonScript.h (modified) (2 diffs)
-
modules/PythonScript/script_wrapper.cpp (modified) (3 diffs)
-
modules/PythonScript/script_wrapper.hpp (modified) (2 diffs)
-
modules/Scheduler/Scheduler.cpp (modified) (1 diff)
-
scripts/python/test.py (modified) (4 diffs)
-
service/NSClient++.cpp (modified) (3 diffs)
-
service/NSClient++.h (modified) (1 diff)
-
service/core_api.cpp (modified) (2 diffs)
-
service/core_api.h (modified) (1 diff)
-
service/plugin_list.hpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
changelog
r81e420c ra44cb15 5 5 * Fixa dependonservice LanManWorkStation (old win) 6 6 * Fix RtlStringFromGUID problem on NT4 7 8 2011-09-01 MickeM 9 * Implemented registration of channels (so no longer faked) 10 * Added settings key to change the NSCAAgent channel name 11 * Addded proper channel handling to PythonScript module 12 * Improved error handling in channels API 13 * Rewrote wrapper API to use templates and classes instead of macros (ish) 14 * Improved the internal plugin wrapping API to support multiple plugin load 15 * Fixed so PythonScript module supports multiple plugin load (with new argument for plugin_id) 16 * Added API for registrying routers and handling routing (almost there now) 17 18 2011-09-01 MickeM 19 * Fixed issue with messages due to new API 7 20 8 21 2011-08-31 MickeM -
include/NSCAPI.h
r81e420c ra44cb15 152 152 typedef void (*lpNSAPIDestroyBuffer)(char**); 153 153 154 typedef NSCAPI::errorReturn (*lpNSAPINotify)(const wchar_t* , const wchar_t*, NSCAPI::nagiosReturn, const char*, unsigned int);154 typedef NSCAPI::errorReturn (*lpNSAPINotify)(const wchar_t* channel, const wchar_t* command, const char* buffer, unsigned int buffer_len); 155 155 156 156 typedef NSCAPI::boolReturn (*lpNSAPICheckLogMessages)(int); … … 171 171 typedef NSCAPI::errorReturn (*lpNSAPIReleasePluginList)(int len, NSCAPI::plugin_info *list[]); 172 172 typedef NSCAPI::errorReturn (*lpNSAPISettingsSave)(void); 173 typedef NSCAPI::errorReturn (*lpNSAPIRegisterSubmissionListener)(unsigned int plugin_id, const wchar_t* channel); 174 typedef NSCAPI::errorReturn (*lpNSAPIRegisterRoutingListener)(unsigned int plugin_id, const wchar_t* channel); 175 173 176 } 174 177 -
include/nscapi/functions.hpp
r81e420c ra44cb15 174 174 } 175 175 176 static voidparse_simple_query_response(std::string &response, std::wstring &msg, std::wstring &perf) {176 static int parse_simple_query_response(std::string &response, std::wstring &msg, std::wstring &perf) { 177 177 Plugin::QueryResponseMessage message; 178 178 message.ParseFromString(response); … … 180 180 181 181 if (message.payload_size() == 0) { 182 return ;182 return NSCAPI::returnUNKNOWN; 183 183 } else if (message.payload_size() > 1) { 184 184 throw nscapi_exception(_T("Whoops, invalid payload size (for now)")); … … 188 188 msg = utf8::cvt<std::wstring>(payload.message()); 189 189 perf = utf8::cvt<std::wstring>(build_performance_data(payload)); 190 return gbp_to_nagios_status(payload.result()); 190 191 } 191 192 -
include/nscapi/macros.hpp
r3b11e65 ra44cb15 2 2 #include <unicode_char.hpp> 3 3 #include <boost/shared_ptr.hpp> 4 #include < map>4 #include <NSCAPI.h> 5 5 6 6 ////////////////////////////////////////////////////////////////////////// … … 26 26 #define NSC_WRAPPERS_CHANNELS() \ 27 27 extern "C" int NSHasNotificationHandler(unsigned int plugin_id); \ 28 extern "C" int NSHandleNotification(unsigned int plugin_id, const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn,const char*, unsigned int);28 extern "C" int NSHandleNotification(unsigned int plugin_id, const wchar_t*, const wchar_t*, const char*, unsigned int); 29 29 30 30 #define NSC_WRAPPERS_ROUTING() \ … … 76 76 #endif 77 77 78 template<class impl_type>79 struct plugin_instance_data {80 typedef std::map<unsigned int, boost::shared_ptr<impl_type> > plugin_list_type;81 plugin_list_type plugins;82 boost::shared_ptr<impl_type> get(unsigned int id) {83 typename plugin_list_type::iterator it = plugins.find(id);84 if (it != plugins.end())85 return it->second;86 boost::shared_ptr<impl_type> impl = boost::shared_ptr<impl_type>(new impl_type());87 plugins[id] = impl;88 return impl;89 }90 void erase(unsigned int id) {91 plugins.erase(id);92 }93 };94 95 78 96 79 #define NSC_WRAPPERS_MAIN_DEF(impl_class) \ 97 static plugin_instance_data<impl_class> plugin_instance; \ 98 extern int NSModuleHelperInit(unsigned int id, nscapi::core_api::lpNSAPILoader f) { \ 99 try { \ 100 return GET_PLUGIN()->wrapModuleHelperInit(id, f); \ 101 } catch (...) { \ 102 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapModuleHelperInit(...)")); \ 103 return NSCAPI::hasFailed; \ 104 } \ 105 } \ 80 typedef impl_class plugin_impl_class; \ 81 static nscapi::plugin_instance_data<plugin_impl_class> plugin_instance; \ 82 extern int NSModuleHelperInit(unsigned int id, nscapi::core_api::lpNSAPILoader f) { return nscapi::basic_wrapper_static<plugin_impl_class>::NSModuleHelperInit(f); } \ 106 83 extern int NSLoadModuleEx(unsigned int id, wchar_t* alias, int mode) { \ 107 try { \ 108 return GET_PLUGIN()->wrapLoadModule(plugin_instance.get(id)->loadModuleEx(alias, mode)); \ 109 } catch (...) { \ 110 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapLoadModule(...)")); \ 111 return NSCAPI::hasFailed; \ 112 } \ 113 } \ 114 extern int NSLoadModule() { \ 115 return NSCAPI::hasFailed; \ 116 } \ 117 extern int NSGetModuleName(wchar_t* buf, int buflen) { \ 118 try { \ 119 return GET_PLUGIN()->wrapGetModuleName(buf, buflen, impl_class::getModuleName()); \ 120 } catch (...) { \ 121 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapGetModuleName(...)")); \ 122 return NSCAPI::hasFailed; \ 123 } \ 124 } \ 125 extern int NSGetModuleDescription(wchar_t* buf, int buflen) { \ 126 try { \ 127 return GET_PLUGIN()->wrapGetModuleName(buf, buflen, impl_class::getModuleDescription()); \ 128 } catch (...) { \ 129 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapGetModuleName(...)")); \ 130 return NSCAPI::hasFailed; \ 131 } \ 132 } \ 133 extern int NSGetModuleVersion(int *major, int *minor, int *revision) { \ 134 try { \ 135 return GET_PLUGIN()->wrapGetModuleVersion(major, minor, revision, impl_class::getModuleVersion()); \ 136 } catch (...) { \ 137 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapGetModuleVersion(...)")); \ 138 return NSCAPI::hasFailed; \ 139 } \ 140 } \ 84 nscapi::basic_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \ 85 return wrapper.NSLoadModuleEx(id, alias, mode); } \ 86 extern int NSLoadModule() { return nscapi::basic_wrapper_static<plugin_impl_class>::NSLoadModule(); } \ 87 extern int NSGetModuleName(wchar_t* buf, int buflen) { return nscapi::basic_wrapper_static<plugin_impl_class>::NSGetModuleName(buf, buflen); } \ 88 extern int NSGetModuleDescription(wchar_t* buf, int buflen) { return nscapi::basic_wrapper_static<plugin_impl_class>::NSGetModuleDescription(buf, buflen); } \ 89 extern int NSGetModuleVersion(int *major, int *minor, int *revision) { return nscapi::basic_wrapper_static<plugin_impl_class>::NSGetModuleVersion(major, minor, revision); } \ 141 90 extern int NSUnloadModule(unsigned int id) { \ 142 try { \ 143 int ret = GET_PLUGIN()->wrapUnloadModule(plugin_instance.get(id)->unloadModule()); \ 144 plugin_instance.erase(id); \ 145 return ret; \ 146 } catch (...) { \ 147 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapGetModuleVersion(...)")); \ 148 return NSCAPI::hasFailed; \ 149 } \ 150 } \ 151 extern void NSDeleteBuffer(char**buffer) { \ 152 try { \ 153 GET_PLUGIN()->wrapDeleteBuffer(buffer); \ 154 } catch (...) { \ 155 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapModuleHelperInit(...)")); \ 156 } \ 157 } 91 nscapi::basic_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \ 92 return wrapper.NSUnloadModule(); } \ 93 extern void NSDeleteBuffer(char**buffer) { nscapi::basic_wrapper_static<plugin_impl_class>::NSDeleteBuffer(buffer); } 94 158 95 #define NSC_WRAPPERS_HANDLE_MSG_DEF(toObject) \ 159 96 extern void NSHandleMessage(unsigned int id, const char* request_buffer, unsigned int request_buffer_len) { \ 160 try { \ 161 std::string request(request_buffer, request_buffer_len); \ 162 plugin_instance.get(id)->handleMessageRAW(request); \ 163 } catch (...) { \ 164 NSC_LOG_CRITICAL(_T("Unknown exception in: handleMessage(...)")); \ 165 } \ 166 } \ 97 nscapi::message_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \ 98 return wrapper.NSHandleMessage(request_buffer, request_buffer_len); } \ 167 99 extern NSCAPI::boolReturn NSHasMessageHandler(unsigned int id) { \ 168 try { \ 169 return GET_PLUGIN()->wrapHasMessageHandler(plugin_instance.get(id)->hasMessageHandler()); \ 170 } catch (...) { \ 171 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasMessageHandler(...)")); \ 172 return NSCAPI::isfalse; \ 173 } \ 174 } 100 nscapi::message_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \ 101 return wrapper.NSHasMessageHandler(); } 102 103 #define NSC_WRAPPERS_HANDLE_CMD_DEF() \ 104 extern NSCAPI::nagiosReturn NSHandleCommand(unsigned int id, const wchar_t* command, const char* request_buffer, const unsigned int request_buffer_len, char** reply_buffer, unsigned int *reply_buffer_len) { \ 105 nscapi::command_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \ 106 return wrapper.NSHandleCommand(command, request_buffer, request_buffer_len, reply_buffer, reply_buffer_len); } \ 107 extern NSCAPI::boolReturn NSHasCommandHandler(unsigned int id) { \ 108 nscapi::command_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \ 109 return wrapper.NSHasCommandHandler(); } 110 111 #define NSC_WRAPPERS_ROUTING_DEF() \ 112 extern NSCAPI::nagiosReturn NSRouteMessage(unsigned int id, const wchar_t* channel, const wchar_t* command, const char* request_buffer, const unsigned int request_buffer_len) { \ 113 nscapi::routing_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \ 114 return wrapper.NSRouteMessage(channel, command, request_buffer, request_buffer_len); } \ 115 extern NSCAPI::boolReturn NSHasRoutingHandler(unsigned int id) { \ 116 nscapi::routing_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \ 117 return wrapper.NSHasRoutingHandler(); } 118 119 #define NSC_WRAPPERS_HANDLE_NOTIFICATION_DEF() \ 120 extern int NSHandleNotification(unsigned int id, const wchar_t* channel, const wchar_t* command, const char* result_buffer, unsigned int result_buffer_len) { \ 121 nscapi::submission_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \ 122 return wrapper.NSHandleNotification(channel, command, result_buffer, result_buffer_len); } \ 123 extern NSCAPI::boolReturn NSHasNotificationHandler(unsigned int id) { \ 124 nscapi::submission_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \ 125 return wrapper.NSHasNotificationHandler(); } 126 127 #define NSC_WRAPPERS_CLI_DEF() \ 128 extern int NSCommandLineExec(unsigned int id, wchar_t *command, char *request_buffer, unsigned int request_len, char **response_buffer, unsigned int *response_len) { \ 129 nscapi::cliexec_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \ 130 return wrapper.NSCommandLineExec(command, request_buffer, request_len, response_buffer, response_len); } 131 175 132 #define NSC_WRAPPERS_IGNORE_MSG_DEF() \ 176 133 extern void NSHandleMessage(unsigned int id, const char* data, unsigned int len) {} \ 177 134 extern NSCAPI::boolReturn NSHasMessageHandler(unsigned int id) { return NSCAPI::isfalse; } 178 #define NSC_WRAPPERS_HANDLE_CMD_DEF() \ 179 extern NSCAPI::nagiosReturn NSHandleCommand(unsigned int id, const wchar_t* command, const char* request_buffer, const unsigned int request_buffer_len, char** reply_buffer, unsigned int *reply_buffer_len) \ 180 { \ 181 try { \ 182 std::string request(request_buffer, request_buffer_len), reply; \ 183 NSCAPI::nagiosReturn retCode = plugin_instance.get(id)->handleRAWCommand(command, request, reply); \ 184 return GET_PLUGIN()->wrapHandleCommand(retCode, reply, reply_buffer, reply_buffer_len); \ 185 } catch (...) { \ 186 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHandleCommand(...)")); \ 187 return NSCAPI::returnIgnored; \ 188 } \ 189 } \ 190 extern NSCAPI::boolReturn NSHasCommandHandler(unsigned int id) { \ 191 try { \ 192 return GET_PLUGIN()->wrapHasCommandHandler(plugin_instance.get(id)->hasCommandHandler()); \ 193 } catch (...) { \ 194 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasCommandHandler(...)")); \ 195 return NSCAPI::isfalse; \ 196 } \ 197 } 198 #define NSC_WRAPPERS_ROUTING_DEF() \ 199 extern NSCAPI::nagiosReturn NSRouteMessage(unsigned int id, const wchar_t* channel, const wchar_t* command, const char* request_buffer, const unsigned int request_buffer_len) \ 200 { \ 201 try { \ 202 std::string request(request_buffer, request_buffer_len), reply; \ 203 return GET_PLUGIN()->wrapRouteMessage(plugin_instance.get(id)->RAWRouteMessage(channel, command, request)); \ 204 } catch (...) { \ 205 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHandleCommand(...)")); \ 206 return NSCAPI::returnIgnored; \ 207 } \ 208 } \ 209 extern NSCAPI::boolReturn NSHasRoutingHandler(unsigned int id) { \ 210 try { \ 211 return GET_PLUGIN()->wrapHasRoutingHandler(plugin_instance.get(id)->hasRoutingHandler()); \ 212 } catch (...) { \ 213 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasCommandHandler(...)")); \ 214 return NSCAPI::isfalse; \ 215 } \ 216 } 135 217 136 #define NSC_WRAPPERS_IGNORE_CMD_DEF() \ 218 extern NSCAPI::nagiosReturn NSHandleCommand(unsigned int id, const wchar_t* IN_cmd, const unsigned int IN_argsLen, wchar_t **IN_args, \ 219 wchar_t *OUT_retBufMessage, unsigned int IN_retBufMessageLen, wchar_t *OUT_retBufPerf, unsigned int IN_retBufPerfLen) { \ 220 return NSCAPI::returnIgnored; \ 221 } \ 137 extern NSCAPI::nagiosReturn NSHandleCommand(unsigned int id, const wchar_t* IN_cmd, const unsigned int IN_argsLen, wchar_t **IN_args, wchar_t *OUT_retBufMessage, unsigned int IN_retBufMessageLen, wchar_t *OUT_retBufPerf, unsigned int IN_retBufPerfLen) { return NSCAPI::returnIgnored; } \ 222 138 extern NSCAPI::boolReturn NSHasCommandHandler(unsigned int id) { return NSCAPI::isfalse; } 139 223 140 #define NSC_WRAPPERS_IGNORE_NOTIFICATION_DEF() \ 224 extern void NSHandleNotification(const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn, const char*, unsigned int) {} \141 extern int NSHandleNotification(unsigned int id, const wchar_t* channel, const wchar_t* command, const char* result_buffer, unsigned int result_buffer_len) {} \ 225 142 extern NSCAPI::boolReturn NSHasNotificationHandler(unsigned int id) { return NSCAPI::isfalse; } 226 #define NSC_WRAPPERS_HANDLE_NOTIFICATION_DEF() \227 extern NSCAPI::nagiosReturn NSHandleNotification(unsigned int id, const wchar_t* channel, const wchar_t* command, NSCAPI::nagiosReturn code, const char* result_buffer, unsigned int result_buffer_len) \228 { \229 try { \230 std::string result(result_buffer, result_buffer_len); \231 return GET_PLUGIN()->wrapHandleNotification(plugin_instance.get(id)->handleRAWNotification(channel, command, code, result)); \232 } catch (...) { \233 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasNotificationHandler(...)")); \234 return NSCAPI::returnIgnored; \235 } \236 } \237 extern NSCAPI::boolReturn NSHasNotificationHandler(unsigned int id) { \238 try { \239 return GET_PLUGIN()->wrapHasNotificationHandler(plugin_instance.get(id)->hasNotificationHandler()); \240 } catch (...) { \241 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasNotificationHandler(...)")); \242 return NSCAPI::isfalse; \243 } \244 }245 246 247 #define NSC_WRAPPERS_CLI_DEF() \248 extern int NSCommandLineExec(unsigned int id, wchar_t *command, char *request_buffer, unsigned int request_len, char **response_buffer, unsigned int *response_len) { \249 try { \250 std::string request = std::string(request_buffer, request_len); \251 std::string response; \252 NSCAPI::nagiosReturn retCode = plugin_instance.get(id)->commandRAWLineExec(command, request, response); \253 return GET_PLUGIN()->wrapCommandLineExec(retCode, response, response_buffer, response_len); \254 } catch (const std::exception &e) { \255 NSC_LOG_CRITICAL(_T("Exception in: commandLineExec(...)") + utf8::cvt<std::wstring>(e.what())); \256 std::wcerr << _T("Exception in: commandLineExec(...)") << utf8::cvt<std::wstring>(e.what()) << std::endl; \257 return NSCAPI::hasFailed; \258 } catch (...) { \259 NSC_LOG_CRITICAL(_T("Unknown exception in: commandLineExec(...)")); \260 std::wcerr << _T("Unknown exception in: commandLineExec(...)") << std::endl; \261 return NSCAPI::hasFailed; \262 } \263 } \264 143 265 144 -
include/nscapi/nscapi_core_wrapper.cpp
rd7e265d ra44cb15 129 129 std::string request; 130 130 nscapi::functions::create_simple_query_response(command, code, message, perf, request); 131 NSCAPI::nagiosReturn ret = NotifyChannel(channel, command, code, request); 132 } 133 134 135 NSCAPI::errorReturn nscapi::core_wrapper::NotifyChannel(std::wstring channel, std::wstring command, NSCAPI::nagiosReturn code, std::string result) { 131 NSCAPI::nagiosReturn ret = submit_message(channel, command, request); 132 } 133 134 NSCAPI::errorReturn nscapi::core_wrapper::submit_message(std::wstring channel, std::wstring command, std::string buffer) { 136 135 if (!fNSAPINotify) 137 136 throw nscapi::nscapi_exception(_T("NSCore has not been initiated...")); 138 return fNSAPINotify(channel.c_str(), command.c_str(), code, result.c_str(), result.size());137 return fNSAPINotify(channel.c_str(), command.c_str(), buffer.c_str(), buffer.size()); 139 138 } 140 139 … … 544 543 return ret; 545 544 } 546 void nscapi::core_wrapper::registerCommand( std::wstring command, std::wstring description) {545 void nscapi::core_wrapper::registerCommand(unsigned int id, std::wstring command, std::wstring description) { 547 546 if (!fNSAPIRegisterCommand) 548 547 throw nscapi::nscapi_exception(_T("NSCore has not been initiated...")); 549 if (fNSAPIRegisterCommand(id_, command.c_str(), description.c_str()) != NSCAPI::isSuccess) { 550 CORE_LOG_ERROR_STD(_T("Failed to register command: ") + command + _T(" in plugin: ") + to_wstring(id_)); 548 if (fNSAPIRegisterCommand(id, command.c_str(), description.c_str()) != NSCAPI::isSuccess) { 549 CORE_LOG_ERROR_STD(_T("Failed to register command: ") + command + _T(" in plugin: ") + to_wstring(id)); 550 } 551 } 552 553 void nscapi::core_wrapper::registerSubmissionListener(unsigned int id, std::wstring channel) { 554 if (!fNSAPIRegisterSubmissionListener) 555 throw nscapi::nscapi_exception(_T("NSCore has not been initiated...")); 556 if (fNSAPIRegisterSubmissionListener(id, channel.c_str()) != NSCAPI::isSuccess) { 557 CORE_LOG_ERROR_STD(_T("Failed to register channel: ") + channel + _T(" in plugin: ") + to_wstring(id)); 558 } 559 } 560 void nscapi::core_wrapper::registerRoutingListener(unsigned int id, std::wstring channel) { 561 if (!fNSAPIRegisterRoutingListener) 562 throw nscapi::nscapi_exception(_T("NSCore has not been initiated...")); 563 if (fNSAPIRegisterRoutingListener(id, channel.c_str()) != NSCAPI::isSuccess) { 564 CORE_LOG_ERROR_STD(_T("Failed to register channel: ") + channel + _T(" in plugin: ") + to_wstring(id)); 551 565 } 552 566 } … … 583 597 * @return NSCAPI::success or NSCAPI::failure 584 598 */ 585 bool nscapi::core_wrapper::load_endpoints(unsigned int id, nscapi::core_api::lpNSAPILoader f) { 586 id_ = id; 599 bool nscapi::core_wrapper::load_endpoints(nscapi::core_api::lpNSAPILoader f) { 587 600 fNSAPIGetApplicationName = (nscapi::core_api::lpNSAPIGetApplicationName)f(_T("NSAPIGetApplicationName")); 588 601 fNSAPIGetApplicationVersionStr = (nscapi::core_api::lpNSAPIGetApplicationVersionStr)f(_T("NSAPIGetApplicationVersionStr")); … … 624 637 fNSAPIExpandPath = (nscapi::core_api::lpNSAPIExpandPath)f(_T("NSAPIExpandPath")); 625 638 639 fNSAPIRegisterSubmissionListener = (nscapi::core_api::lpNSAPIRegisterSubmissionListener)f(_T("NSAPIRegisterSubmissionListener")); 640 fNSAPIRegisterRoutingListener = (nscapi::core_api::lpNSAPIRegisterRoutingListener)f(_T("NSAPIRegisterRoutingListener")); 641 626 642 return true; 627 643 } -
include/nscapi/nscapi_core_wrapper.hpp
r2c95d22 ra44cb15 69 69 nscapi::core_api::lpNSAPIReleasePluginList fNSAPIReleasePluginList; 70 70 nscapi::core_api::lpNSAPISettingsSave fNSAPISettingsSave; 71 72 unsigned int buffer_length_; 73 unsigned int id_; 71 nscapi::core_api::lpNSAPIRegisterSubmissionListener fNSAPIRegisterSubmissionListener; 72 nscapi::core_api::lpNSAPIRegisterRoutingListener fNSAPIRegisterRoutingListener; 74 73 75 74 public: … … 116 115 , fNSAPISettingsSave(NULL) 117 116 , fNSAPIExpandPath(NULL) 118 , buffer_length_(-1)119 , id_(-1)120 117 {} 121 118 … … 145 142 146 143 void submit_simple_message(std::wstring channel, std::wstring command, NSCAPI::nagiosReturn code, std::wstring & message, std::wstring & perf); 147 NSCAPI::errorReturn NotifyChannel(std::wstring channel, std::wstring command, NSCAPI::nagiosReturn code, std::string result); 148 //NSCAPI::nagiosReturn InjectCommand(const std::wstring command, const std::list<std::wstring> argument, std::string & result); 149 //NSCAPI::nagiosReturn InjectSplitAndCommand(const wchar_t* command, wchar_t* buffer, wchar_t splitChar, std::wstring & message, std::wstring & perf); 150 //NSCAPI::nagiosReturn InjectSplitAndCommand(const std::wstring command, const std::wstring buffer, wchar_t splitChar, std::wstring & message, std::wstring & perf, bool escape = false); 144 NSCAPI::errorReturn submit_message(std::wstring channel, std::wstring command, std::string buffer); 145 151 146 void StopService(void); 152 147 void Exit(void); … … 165 160 std::list<std::wstring> getAllCommandNames(); 166 161 std::wstring describeCommand(std::wstring command); 167 void registerCommand(std::wstring command, std::wstring description); 162 void registerCommand(unsigned int id, std::wstring command, std::wstring description); 163 void registerSubmissionListener(unsigned int id, std::wstring channel); 164 void registerRoutingListener(unsigned int id, std::wstring channel); 165 168 166 unsigned int getBufferLength(); 169 170 171 bool load_endpoints(unsigned int id, nscapi::core_api::lpNSAPILoader f); 167 bool load_endpoints(nscapi::core_api::lpNSAPILoader f); 172 168 173 169 }; -
include/nscapi/nscapi_plugin_wrapper.cpp
r81e420c ra44cb15 38 38 using namespace nscp::helpers; 39 39 40 extern nscapi::helper_singleton* nscapi::plugin_singleton;40 //extern nscapi::helper_singleton* nscapi::plugin_singleton; 41 41 /** 42 42 * Wrap a return string. … … 89 89 */ 90 90 int nscapi::plugin_wrapper::wrapModuleHelperInit(unsigned int id, nscapi::core_api::lpNSAPILoader f) { 91 return nscapi::plugin_singleton->get_core()->load_endpoints(id,f)?NSCAPI::isSuccess:NSCAPI::hasFailed;91 return GET_CORE()->load_endpoints(f)?NSCAPI::isSuccess:NSCAPI::hasFailed; 92 92 } 93 93 /** … … 273 273 } 274 274 275 NSCAPI::nagiosReturn nscapi::impl::SimpleNotificationHandler::handleRAWNotification(const wchar_t* channel, const wchar_t* command, NSCAPI::nagiosReturn code,std::string result) {275 NSCAPI::nagiosReturn nscapi::impl::SimpleNotificationHandler::handleRAWNotification(const wchar_t* channel, const wchar_t* command, std::string result) { 276 276 try { 277 277 std::wstring msg, perf; 278 nscapi::functions::parse_simple_query_response(result, msg, perf);278 int code = nscapi::functions::parse_simple_query_response(result, msg, perf); 279 279 return handleSimpleNotification(channel, command, code, msg, perf); 280 280 } catch (std::exception &e) { -
include/nscapi/nscapi_plugin_wrapper.hpp
r81e420c ra44cb15 24 24 #include <list> 25 25 #include <vector> 26 #include <map> 26 27 27 28 #include <boost/make_shared.hpp> … … 30 31 #include <NSCAPI.h> 31 32 #include <nscapi/settings_proxy.hpp> 33 #include <nscapi/macros.hpp> 34 #include <nscapi/nscapi_helper.hpp> 32 35 33 36 … … 77 80 78 81 }; 82 79 83 class core_wrapper; 80 84 class helper_singleton { … … 96 100 97 101 namespace impl { 98 99 class simple_plugin { 100 public: 102 struct simple_plugin { 103 int id_; 101 104 inline nscapi::core_wrapper* get_core() { 102 return nscapi::plugin_singleton->get_core(); 105 return plugin_singleton->get_core(); 106 } 107 inline unsigned int get_id() { 108 return id_; 109 } 110 inline void set_id(unsigned int id) { 111 id_ = id; 103 112 } 104 113 inline boost::shared_ptr<nscapi::settings_proxy> get_settings_proxy() { 105 return boost::shared_ptr<nscapi::settings_proxy>(new nscapi::settings_proxy(nscapi::plugin_singleton->get_core())); 106 } 114 return boost::shared_ptr<nscapi::settings_proxy>(new nscapi::settings_proxy(get_core())); 115 } 116 void register_command(std::wstring command, std::wstring description) { 117 get_core()->registerCommand(get_id(), _T("submit_nscp"), _T("Submit a query to a remote host via NSCP")); 118 } 119 107 120 }; 108 121 109 122 class SimpleNotificationHandler { 110 123 public: 111 NSCAPI::nagiosReturn handleRAWNotification(const wchar_t* channel, const wchar_t* command, NSCAPI::nagiosReturn code,std::string result);124 NSCAPI::nagiosReturn handleRAWNotification(const wchar_t* channel, const wchar_t* command, std::string result); 112 125 virtual NSCAPI::nagiosReturn handleSimpleNotification(const std::wstring channel, const std::wstring command, NSCAPI::nagiosReturn code, std::wstring msg, std::wstring perf) = 0; 113 126 … … 139 152 }; 140 153 */ 141 } 154 }; 155 156 157 158 template<class impl_type> 159 struct plugin_instance_data { 160 typedef std::map<unsigned int, boost::shared_ptr<impl_type> > plugin_list_type; 161 plugin_list_type plugins; 162 boost::shared_ptr<impl_type> get(unsigned int id) { 163 typename plugin_list_type::iterator it = plugins.find(id); 164 if (it != plugins.end()) 165 return it->second; 166 boost::shared_ptr<impl_type> impl = boost::shared_ptr<impl_type>(new impl_type()); 167 plugins[id] = impl; 168 return impl; 169 } 170 void erase(unsigned int id) { 171 plugins.erase(id); 172 } 173 }; 174 175 struct helpers { 176 static void wrap_string(std::string &string, char** buffer, unsigned int *buffer_len) { 177 // TODO: Make this global to allow remote deletion!!! 178 unsigned int buf_len = string.size(); 179 *buffer = new char[buf_len + 10]; 180 memcpy(*buffer, string.c_str(), buf_len+1); 181 (*buffer)[buf_len] = 0; 182 (*buffer)[buf_len+1] = 0; 183 *buffer_len = buf_len; 184 } 185 int static wrap_string(wchar_t *buffer, unsigned int bufLen, std::wstring str, int defaultReturnCode ) { 186 // @todo deprecate this 187 if (str.length() >= bufLen) { 188 std::wstring sstr = str.substr(0, bufLen-2); 189 NSC_DEBUG_MSG_STD(_T("String (") + strEx::itos(str.length()) + _T(") to long to fit inside buffer(") + strEx::itos(bufLen) + _T(") : ") + sstr); 190 return NSCAPI::isInvalidBufferLen; 191 } 192 wcsncpy(buffer, str.c_str(), bufLen); 193 return defaultReturnCode; 194 } 195 196 }; 197 template<class impl_class> 198 struct basic_wrapper_static { 199 200 static int NSModuleHelperInit(nscapi::core_api::lpNSAPILoader f) { 201 try { 202 return nscapi::plugin_singleton->get_core()->load_endpoints(f)?NSCAPI::isSuccess:NSCAPI::hasFailed; 203 } catch (...) { 204 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapModuleHelperInit")); 205 return NSCAPI::hasFailed; 206 } 207 } 208 static int NSLoadModule() { 209 return NSCAPI::hasFailed; 210 } 211 static int NSGetModuleName(wchar_t* buf, int buflen) { 212 try { 213 return helpers::wrap_string(buf, buflen, impl_class::getModuleName(), NSCAPI::isSuccess); 214 } catch (...) { 215 NSC_LOG_CRITICAL(_T("Unknown exception in: NSGetModuleName")); 216 } 217 return NSCAPI::hasFailed; 218 } 219 static int NSGetModuleDescription(wchar_t* buf, int buflen) { 220 try { 221 return helpers::wrap_string(buf, buflen, impl_class::getModuleDescription(), NSCAPI::isSuccess); 222 } catch (...) { 223 NSC_LOG_CRITICAL(_T("Unknown exception in: NSGetModuleDescription")); 224 } 225 return NSCAPI::hasFailed; 226 } 227 static int NSGetModuleVersion(int *major, int *minor, int *revision) { 228 try { 229 nscapi::plugin_wrapper::module_version version = impl_class::getModuleVersion(); 230 *major = version.major; 231 *minor = version.minor; 232 *revision = version.revision; 233 return NSCAPI::isSuccess; 234 } catch (...) { 235 NSC_LOG_CRITICAL(_T("Unknown exception in: NSGetModuleVersion")); 236 } 237 return NSCAPI::hasFailed; 238 } 239 static void NSDeleteBuffer(char** buffer) { 240 try { 241 delete [] *buffer; 242 } catch (...) { 243 NSC_LOG_CRITICAL(_T("Unknown exception in: NSDeleteBuffer")); 244 } 245 } 246 }; 247 248 template<class impl_class> 249 struct basic_wrapper { 250 boost::shared_ptr<impl_class> instance; 251 basic_wrapper(boost::shared_ptr<impl_class> instance) : instance(instance) {} 252 int NSLoadModuleEx(unsigned int id, wchar_t* alias, int mode) { 253 try { 254 instance->set_id(id); 255 if (instance->loadModuleEx(alias, mode)) 256 return NSCAPI::isSuccess; 257 } catch (...) { 258 NSC_LOG_CRITICAL(_T("Unknown exception in: NSLoadModuleEx")); 259 } 260 return NSCAPI::hasFailed; 261 } 262 int NSUnloadModule() { 263 try { 264 if (instance->unloadModule()) 265 return NSCAPI::isSuccess; 266 } catch (...) { 267 NSC_LOG_CRITICAL(_T("Unknown exception in: NSUnloadModule")); 268 } 269 return NSCAPI::hasFailed; 270 } 271 }; 272 template<class impl_class> 273 struct message_wrapper { 274 boost::shared_ptr<impl_class> instance; 275 message_wrapper(boost::shared_ptr<impl_class> instance) : instance(instance) {} 276 void NSHandleMessage(const char* request_buffer, unsigned int request_buffer_len) { 277 try { 278 instance->handleMessageRAW(std::string(request_buffer, request_buffer_len)); 279 } catch (...) { 280 NSC_LOG_CRITICAL(_T("Unknown exception in: NSHandleMessage")); 281 } 282 } 283 NSCAPI::boolReturn NSHasMessageHandler() { 284 try { 285 if (instance->hasMessageHandler()) 286 return NSCAPI::istrue; 287 } catch (...) { 288 NSC_LOG_CRITICAL(_T("Unknown exception in: NSHasMessageHandler")); 289 } 290 return NSCAPI::isfalse; 291 } 292 }; 293 template<class impl_class> 294 struct command_wrapper { 295 boost::shared_ptr<impl_class> instance; 296 command_wrapper(boost::shared_ptr<impl_class> instance) : instance(instance) {} 297 298 NSCAPI::nagiosReturn NSHandleCommand(const wchar_t* command, const char* request_buffer, const unsigned int request_buffer_len, char** reply_buffer, unsigned int *reply_buffer_len) { 299 try { 300 std::string request(request_buffer, request_buffer_len), reply; 301 NSCAPI::nagiosReturn retCode = instance->handleRAWCommand(command, request, reply); 302 helpers::wrap_string(reply, reply_buffer, reply_buffer_len); 303 if (!nscapi::plugin_helper::isMyNagiosReturn(retCode)) { 304 NSC_LOG_ERROR(_T("A module returned an invalid return code")); 305 } 306 return retCode; 307 } catch (...) { 308 NSC_LOG_CRITICAL(_T("Unknown exception in: NSHandleCommand")); 309 } 310 return NSCAPI::returnIgnored; 311 } 312 NSCAPI::boolReturn NSHasCommandHandler() { 313 try { 314 if (instance->hasCommandHandler()) 315 return NSCAPI::istrue; 316 } catch (...) { 317 NSC_LOG_CRITICAL(_T("Unknown exception in: NSHasCommandHandler")); 318 } 319 return NSCAPI::isfalse; 320 } 321 }; 322 323 template<class impl_class> 324 struct routing_wrapper { 325 boost::shared_ptr<impl_class> instance; 326 routing_wrapper(boost::shared_ptr<impl_class> instance) : instance(instance) {} 327 328 NSCAPI::nagiosReturn NSRouteMessage(const wchar_t* channel, const wchar_t* command, const char* request_buffer, const unsigned int request_buffer_len, char** reply_buffer, unsigned int *reply_buffer_len) { 329 try { 330 std::string request(request_buffer, request_buffer_len), reply; 331 NSCAPI::nagiosReturn retCode = instance->RAWRouteMessage(channel, command, request, reply); 332 helpers::wrap_string(reply, reply_buffer, reply_buffer_len); 333 return retCode; 334 } catch (...) { 335 NSC_LOG_CRITICAL(_T("Unknown exception in: NSRouteMessage")); 336 } 337 return NSCAPI::returnIgnored; 338 } 339 NSCAPI::boolReturn NSHasRoutingHandler() { 340 try { 341 if (instance->hasRoutingHandler()) 342 return NSCAPI::istrue; 343 } catch (...) { 344 NSC_LOG_CRITICAL(_T("Unknown exception in: NSHasRoutingHandler")); 345 } 346 return NSCAPI::isfalse; 347 } 348 }; 349 350 template<class impl_class> 351 struct submission_wrapper { 352 boost::shared_ptr<impl_class> instance; 353 submission_wrapper(boost::shared_ptr<impl_class> instance) : instance(instance) {} 354 355 NSCAPI::nagiosReturn NSHandleNotification(const wchar_t* channel, const wchar_t* command, const char* result_buffer, unsigned int result_buffer_len) { 356 try { 357 std::string request(result_buffer, result_buffer_len); 358 NSCAPI::nagiosReturn retCode = instance->handleRAWNotification(channel, command, request); 359 } catch (...) { 360 NSC_LOG_CRITICAL(_T("Unknown exception in: NSHandleNotification")); 361 } 362 return NSCAPI::returnIgnored; 363 } 364 NSCAPI::boolReturn NSHasNotificationHandler() { 365 try { 366 if (instance->hasNotificationHandler()) 367 return NSCAPI::istrue; 368 } catch (...) { 369 NSC_LOG_CRITICAL(_T("Unknown exception in: NSHasNotificationHandler")); 370 } 371 return NSCAPI::isfalse; 372 } 373 }; 374 375 template<class impl_class> 376 struct cliexec_wrapper { 377 boost::shared_ptr<impl_class> instance; 378 cliexec_wrapper(boost::shared_ptr<impl_class> instance) : instance(instance) {} 379 380 int NSCommandLineExec(wchar_t *command, char *request_buffer, unsigned int request_buffer_len, char **response_buffer, unsigned int *response_buffer_len) { 381 try { 382 std::string request(request_buffer, request_buffer_len), reply; 383 NSCAPI::nagiosReturn retCode = instance->commandRAWLineExec(command, request, reply); 384 helpers::wrap_string(reply, response_buffer, response_buffer_len); 385 return retCode; 386 } catch (...) { 387 NSC_LOG_CRITICAL(_T("Unknown exception in: NSCommandLineExec")); 388 } 389 return NSCAPI::hasFailed; 390 } 391 }; 142 392 }; -
modules/CheckDisk/CheckDisk.cpp
r81e420c ra44cb15 54 54 bool CheckDisk::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 55 55 try { 56 get_core()->registerCommand(_T("CheckFileSize"), _T("Check or directory a file and verify its size."));57 get_core()->registerCommand(_T("CheckDriveSize"), _T("Check the size (free-space) of a drive or volume."));58 get_core()->registerCommand(_T("CheckFile2"), _T("(deprecated) Check various aspects of a file and/or folder."));59 get_core()->registerCommand(_T("CheckFiles"), _T("Check various aspects of a file and/or folder."));56 register_command(_T("CheckFileSize"), _T("Check or directory a file and verify its size.")); 57 register_command(_T("CheckDriveSize"), _T("Check the size (free-space) of a drive or volume.")); 58 register_command(_T("CheckFile2"), _T("(deprecated) Check various aspects of a file and/or folder.")); 59 register_command(_T("CheckFiles"), _T("Check various aspects of a file and/or folder.")); 60 60 61 61 sh::settings_registry settings(get_settings_proxy()); -
modules/CheckDisk/CheckDisk.h
r81e420c ra44cb15 25 25 #include <checkHelpers.hpp> 26 26 27 class CheckDisk : public nscapi::impl::simple_command, nscapi::impl::simple_plugin {27 class CheckDisk : public nscapi::impl::simple_command, public nscapi::impl::simple_plugin { 28 28 private: 29 29 bool show_errors_; -
modules/CheckEventLog/CheckEventLog.cpp
r81e420c ra44cb15 70 70 bool CheckEventLog::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 71 71 try { 72 get_core()->registerCommand(_T("CheckEventLog"), _T("Check for errors in the event logger!"));72 register_command(_T("CheckEventLog"), _T("Check for errors in the event logger!")); 73 73 74 74 sh::settings_registry settings(get_settings_proxy()); -
modules/CheckEventLog/CheckEventLog.h
r81e420c ra44cb15 27 27 28 28 29 class CheckEventLog : public nscapi::impl::simple_command, nscapi::impl::simple_plugin {29 class CheckEventLog : public nscapi::impl::simple_command, public nscapi::impl::simple_plugin { 30 30 private: 31 31 bool debug_; -
modules/CheckExternalScripts/CheckExternalScripts.h
r81e420c ra44cb15 117 117 command_data cd = command_data(tok.first, tok.second); 118 118 commands[key.c_str()] = cd; 119 get_core()->registerCommand(key.c_str(), _T("Script: ") + cd.to_string());119 register_command(key.c_str(), _T("Script: ") + cd.to_string()); 120 120 } 121 121 void add_alias(std::wstring key, std::wstring command) { … … 124 124 command_data cd = command_data(tok.first, tok.second); 125 125 alias[key.c_str()] = cd; 126 get_core()->registerCommand(key.c_str(), _T("Alias for: ") + cd.to_string());126 register_command(key.c_str(), _T("Alias for: ") + cd.to_string()); 127 127 } 128 128 void add_wrapping(std::wstring key, std::wstring command) { -
modules/CheckHelpers/CheckHelpers.cpp
r81e420c ra44cb15 43 43 bool CheckHelpers::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 44 44 try { 45 get_core()->registerCommand(_T("CheckAlwaysOK"), _T("Run another check and regardless of its return code return OK."));46 get_core()->registerCommand(_T("CheckAlwaysCRITICAL"), _T("Run another check and regardless of its return code return CRIT."));47 get_core()->registerCommand(_T("CheckAlwaysWARNING"), _T("Run another check and regardless of its return code return WARN."));48 get_core()->registerCommand(_T("CheckMultiple"), _T("Run more then one check and return the worst state."));49 get_core()->registerCommand(_T("CheckOK"), _T("Just return OK (anything passed along will be used as a message)."));50 get_core()->registerCommand(_T("check_ok"), _T("Just return OK (anything passed along will be used as a message)."));51 get_core()->registerCommand(_T("CheckWARNING"), _T("Just return WARN (anything passed along will be used as a message)."));52 get_core()->registerCommand(_T("CheckCRITICAL"), _T("Just return CRIT (anything passed along will be used as a message)."));53 get_core()->registerCommand(_T("CheckVersion"), _T("Just return the nagios version (along with OK status)."));45 register_command(_T("CheckAlwaysOK"), _T("Run another check and regardless of its return code return OK.")); 46 register_command(_T("CheckAlwaysCRITICAL"), _T("Run another check and regardless of its return code return CRIT.")); 47 register_command(_T("CheckAlwaysWARNING"), _T("Run another check and regardless of its return code return WARN.")); 48 register_command(_T("CheckMultiple"), _T("Run more then one check and return the worst state.")); 49 register_command(_T("CheckOK"), _T("Just return OK (anything passed along will be used as a message).")); 50 register_command(_T("check_ok"), _T("Just return OK (anything passed along will be used as a message).")); 51 register_command(_T("CheckWARNING"), _T("Just return WARN (anything passed along will be used as a message).")); 52 register_command(_T("CheckCRITICAL"), _T("Just return CRIT (anything passed along will be used as a message).")); 53 register_command(_T("CheckVersion"), _T("Just return the nagios version (along with OK status).")); 54 54 } catch (nscapi::nscapi_exception &e) { 55 55 NSC_LOG_ERROR_STD(_T("Failed to register command: ") + utf8::cvt<std::wstring>(e.what())); -
modules/CheckHelpers/CheckHelpers.h
r81e420c ra44cb15 23 23 #include <strEx.h> 24 24 25 class CheckHelpers : public nscapi::impl::simple_command, nscapi::impl::simple_plugin {25 class CheckHelpers : public nscapi::impl::simple_command, public nscapi::impl::simple_plugin { 26 26 private: 27 27 -
modules/CheckNSCP/CheckNSCP.cpp
r81e420c ra44cb15 48 48 settings.notify(); 49 49 50 get_core()->registerCommand(_T("check_nscp"), _T("Check the internal healt of NSClient++."));50 register_command(_T("check_nscp"), _T("Check the internal healt of NSClient++.")); 51 51 } catch (nscapi::nscapi_exception &e) { 52 52 NSC_LOG_ERROR_STD(_T("Failed to register command: ") + utf8::cvt<std::wstring>(e.what())); -
modules/CheckSystem/CheckSystem.cpp
r81e420c ra44cb15 136 136 } 137 137 138 get_core()->registerCommand(_T("checkCPU"), _T("Check the CPU load of the computer."));139 get_core()->registerCommand(_T("checkUpTime"), _T("Check the up-time of the computer."));140 get_core()->registerCommand(_T("checkServiceState"), _T("Check the state of one or more of the computer services."));141 get_core()->registerCommand(_T("checkProcState"), _T("Check the state of one or more of the processes running on the computer."));142 get_core()->registerCommand(_T("checkMem"), _T("Check free/used memory on the system."));143 get_core()->registerCommand(_T("checkCounter"), _T("Check a PDH counter."));144 get_core()->registerCommand(_T("listCounterInstances"), _T("List all instances for a counter."));145 get_core()->registerCommand(_T("checkSingleRegEntry"), _T("Check registry key"));138 register_command(_T("checkCPU"), _T("Check the CPU load of the computer.")); 139 register_command(_T("checkUpTime"), _T("Check the up-time of the computer.")); 140 register_command(_T("checkServiceState"), _T("Check the state of one or more of the computer services.")); 141 register_command(_T("checkProcState"), _T("Check the state of one or more of the processes running on the computer.")); 142 register_command(_T("checkMem"), _T("Check free/used memory on the system.")); 143 register_command(_T("checkCounter"), _T("Check a PDH counter.")); 144 register_command(_T("listCounterInstances"), _T("List all instances for a counter.")); 145 register_command(_T("checkSingleRegEntry"), _T("Check registry key")); 146 146 } catch (nscapi::nscapi_exception &e) { 147 147 NSC_LOG_ERROR_STD(_T("Failed to register command: ") + utf8::cvt<std::wstring>(e.what())); -
modules/CheckTaskSched/CheckTaskSched.cpp
r81e420c ra44cb15 44 44 bool CheckTaskSched::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 45 45 try { 46 get_core()->registerCommand(_T("CheckTaskSchedValue"), _T("Run a WMI query and check the resulting value (the values of each row determin the state)."));47 get_core()->registerCommand(_T("CheckTaskSched"), _T("Run a WMI query and check the resulting rows (the number of hits determine state)."));46 register_command(_T("CheckTaskSchedValue"), _T("Run a WMI query and check the resulting value (the values of each row determin the state).")); 47 register_command(_T("CheckTaskSched"), _T("Run a WMI query and check the resulting rows (the number of hits determine state).")); 48 48 49 49 SETTINGS_REG_PATH(task_scheduler::SECTION); -
modules/CheckTaskSched2/CheckTaskSched2.cpp
r81e420c ra44cb15 43 43 bool CheckTaskSched2::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 44 44 try { 45 get_core()->registerCommand(_T("CheckTaskSchedValue"), _T("Run a WMI query and check the resulting value (the values of each row determin the state)."));46 get_core()->registerCommand(_T("CheckTaskSched"), _T("Run a WMI query and check the resulting rows (the number of hits determine state)."));45 register_command(_T("CheckTaskSchedValue"), _T("Run a WMI query and check the resulting value (the values of each row determin the state).")); 46 register_command(_T("CheckTaskSched"), _T("Run a WMI query and check the resulting rows (the number of hits determine state).")); 47 47 48 48 SETTINGS_REG_PATH(task_scheduler::SECTION); -
modules/CheckWMI/CheckWMI.cpp
r81e420c ra44cb15 89 89 bool CheckWMI::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 90 90 try { 91 get_core()->registerCommand(_T("CheckWMIValue"), _T("Run a WMI query and check the resulting value (the values of each row determin the state)."));92 get_core()->registerCommand(_T("CheckWMI"), _T("Run a WMI query and check the resulting rows (the number of hits determine state)."));91 register_command(_T("CheckWMIValue"), _T("Run a WMI query and check the resulting value (the values of each row determin the state).")); 92 register_command(_T("CheckWMI"), _T("Run a WMI query and check the resulting rows (the number of hits determine state).")); 93 93 94 94 sh::settings_registry settings(get_settings_proxy()); -
modules/NRPEClient/NRPEClient.cpp
r81e420c ra44cb15 189 189 commands[key.c_str()] = command_data; 190 190 191 GET_CORE()->registerCommand(key.c_str(), command_data.toString());191 register_command(key.c_str(), command_data.toString()); 192 192 193 193 } catch (boost::program_options::validation_error &e) { -
modules/NRPEClient/NRPEClient.h
r81e420c ra44cb15 28 28 29 29 30 class NRPEClient : public nscapi::impl::simple_command, nscapi::impl::simple_plugin, public nscapi::impl::simple_command_line_exec {30 class NRPEClient : public nscapi::impl::simple_command, public nscapi::impl::simple_plugin, public nscapi::impl::simple_command_line_exec { 31 31 private: 32 32 typedef enum { -
modules/NSCAAgent/NSCAAgent.cpp
r81e420c ra44cb15 79 79 _T("PAYLOAD LENGTH"), _T("The password to use. Again has to be the same as the server or it wont work at all.")) 80 80 81 (_T("channel"), sh::wstring_key(&channel_, _T("NSCA")), 82 _T("CHANNEL"), _T("The channel to listen to.")) 83 81 84 ; 82 85 … … 104 107 settings.register_all(); 105 108 settings.notify(); 109 110 get_core()->registerSubmissionListener(get_id(), channel_); 106 111 107 112 } catch (nscapi::nscapi_exception &e) { -
modules/NSCAAgent/NSCAAgent.h
r81e420c ra44cb15 36 36 unsigned int timeout_; 37 37 int time_delta_; 38 std::wstring channel_; 38 39 39 40 public: -
modules/NSCPClient/NSCPClient.cpp
r81e420c ra44cb15 51 51 try { 52 52 53 get_core()->registerCommand(_T("query_nscp"), _T("Submit a query to a remote host via NSCP"));54 get_core()->registerCommand(_T("submit_nscp"), _T("Submit a query to a remote host via NSCP"));53 register_command(_T("query_nscp"), _T("Submit a query to a remote host via NSCP")); 54 register_command(_T("submit_nscp"), _T("Submit a query to a remote host via NSCP")); 55 55 //"/settings/NSCP/client/handlers" 56 56 sh::settings_registry settings(get_settings_proxy()); … … 161 161 commands[key.c_str()] = command_data; 162 162 163 GET_CORE()->registerCommand(key.c_str(), command_data.toString());163 register_command(key.c_str(), command_data.toString()); 164 164 165 165 } catch (boost::program_options::validation_error &e) { -
modules/NSCPClient/NSCPClient.h
r81e420c ra44cb15 28 28 29 29 30 class NSCPClient : public nscapi::impl::simple_command, nscapi::impl::simple_plugin, public nscapi::impl::simple_command_line_exec {30 class NSCPClient : public nscapi::impl::simple_command, public nscapi::impl::simple_plugin, public nscapi::impl::simple_command_line_exec { 31 31 private: 32 32 struct nscp_connection_data { -
modules/PythonScript/PythonScript.cpp
r81e420c ra44cb15 101 101 } 102 102 103 python_script::python_script( const script_container& script){103 python_script::python_script(unsigned int plugin_id, const std::string alias, const script_container& script) : alias(alias), plugin_id(plugin_id) { 104 104 _exec(utf8::cvt<std::string>(script.script.string())); 105 callFunction("init", utf8::cvt<std::string>(script.alias));105 callFunction("init", plugin_id, alias, utf8::cvt<std::string>(script.alias)); 106 106 } 107 107 python_script::~python_script(){ … … 117 117 } 118 118 } 119 void python_script::callFunction(const std::string& functionName, const std::string &str){119 void python_script::callFunction(const std::string& functionName, unsigned int i1, const std::string &s1, const std::string &s2){ 120 120 try { 121 121 object scriptFunction = extract<object>(localDict[functionName]); 122 122 if(scriptFunction) 123 scriptFunction( str);123 scriptFunction(i1, s1, s2); 124 124 } catch(error_already_set e) { 125 125 script_wrapper::log_exception(); … … 131 131 dict globalDict = extract<dict>(main_module.attr("__dict__")); 132 132 localDict = globalDict.copy(); 133 //localDict.attr("plugin_id") = plugin_id; 134 //localDict.attr("plugin_alias") = alias; 133 135 134 136 PyRun_SimpleString("import cStringIO"); … … 175 177 176 178 BOOST_FOREACH(script_container &script, scripts_) { 177 instances_.push_back(boost::shared_ptr<python_script>(new python_script( script)));179 instances_.push_back(boost::shared_ptr<python_script>(new python_script(get_id(), utf8::cvt<std::string>(alias), script))); 178 180 } 179 181 … … 266 268 267 269 NSCAPI::nagiosReturn PythonScript::commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &response) { 268 boost::shared_ptr<script_wrapper::function_wrapper> inst = script_wrapper::function_wrapper::create( );270 boost::shared_ptr<script_wrapper::function_wrapper> inst = script_wrapper::function_wrapper::create(get_id()); 269 271 std::string cmd = utf8::cvt<std::string>(char_command); 270 272 if (inst->has_cmdline(cmd)) { … … 283 285 284 286 NSCAPI::nagiosReturn PythonScript::handleRAWCommand(const wchar_t* command, const std::string &request, std::string &response) { 285 boost::shared_ptr<script_wrapper::function_wrapper> inst = script_wrapper::function_wrapper::create( );287 boost::shared_ptr<script_wrapper::function_wrapper> inst = script_wrapper::function_wrapper::create(get_id()); 286 288 std::string cmd = utf8::cvt<std::string>(command); 287 289 if (inst->has_function(cmd)) { … … 305 307 306 308 307 NSCAPI::nagiosReturn PythonScript::handleRAWNotification(const std::wstring &channel, const std::wstring &command, NSCAPI::nagiosReturn code,std::string &request) {308 boost::shared_ptr<script_wrapper::function_wrapper> inst = script_wrapper::function_wrapper::create( );309 NSCAPI::nagiosReturn PythonScript::handleRAWNotification(const std::wstring &channel, const std::wstring &command, std::string &request) { 310 boost::shared_ptr<script_wrapper::function_wrapper> inst = script_wrapper::function_wrapper::create(get_id()); 309 311 std::string cmd = utf8::cvt<std::string>(command); 310 312 std::string chnl = utf8::cvt<std::string>(channel); … … 314 316 if (inst->has_simple_message_handler(chnl)) { 315 317 std::wstring msg, perf; 316 nscapi::functions::parse_simple_query_response(request, msg, perf);318 int code = nscapi::functions::parse_simple_query_response(request, msg, perf); 317 319 return inst->handle_simple_message(chnl, cmd, code, msg, perf); 318 320 } -
modules/PythonScript/PythonScript.def
r39c73cd ra44cb15 15 15 NSCommandLineExec 16 16 NSDeleteBuffer 17 NSHasNotificationHandler 18 NSHandleNotification -
modules/PythonScript/PythonScript.h
r81e420c ra44cb15 34 34 35 35 struct python_script : public boost::noncopyable { 36 unsigned int plugin_id; 37 std::string alias; 36 38 boost::python::dict localDict; 37 python_script( const script_container& script);39 python_script(unsigned int plugin_id, const std::string alias, const script_container& script); 38 40 ~python_script(); 39 41 void callFunction(const std::string& functionName); 40 void callFunction(const std::string& functionName, const std::string &str);42 void callFunction(const std::string& functionName, unsigned int i1, const std::string &s1, const std::string &s2); 41 43 void _exec(const std::string &scriptfile); 42 44 }; … … 84 86 NSCAPI::nagiosReturn handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &response); 85 87 NSCAPI::nagiosReturn commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &response); 86 NSCAPI::nagiosReturn handleRAWNotification(const std::wstring &channel, const std::wstring &command, NSCAPI::nagiosReturn code,std::string &request);88 NSCAPI::nagiosReturn handleRAWNotification(const std::wstring &channel, const std::wstring &command, std::string &request); 87 89 88 90 //NSCAPI::nagiosReturn RunLUA(const unsigned int argLen, wchar_t **char_args, std::wstring &message, std::wstring &perf); -
modules/PythonScript/script_wrapper.cpp
r81e420c ra44cb15 31 31 32 32 void script_wrapper::function_wrapper::subscribe_simple_function(std::string channel, PyObject* callable) { 33 functions::get()->simple_handler[channel] = callable; 33 try { 34 core->registerSubmissionListener(plugin_id, utf8::cvt<std::wstring>(channel)); 35 functions::get()->simple_handler[channel] = callable; 36 } catch (const std::exception &e) { 37 NSC_LOG_ERROR_STD(_T("Failed to subscribe to channel ") + utf8::cvt<std::wstring>(channel) + _T(": ") + utf8::cvt<std::wstring>(e.what())); 38 } catch (...) { 39 NSC_LOG_ERROR_STD(_T("Failed to subscribe to channel ") + utf8::cvt<std::wstring>(channel)); 40 } 34 41 } 35 42 void script_wrapper::function_wrapper::subscribe_function(std::string channel, PyObject* callable) { 36 functions::get()->normal_handler[channel] = callable; 43 try { 44 core->registerSubmissionListener(plugin_id, utf8::cvt<std::wstring>(channel)); 45 functions::get()->normal_handler[channel] = callable; 46 } catch (const std::exception &e) { 47 NSC_LOG_ERROR_STD(_T("Failed to subscribe to channel ") + utf8::cvt<std::wstring>(channel) + _T(": ") + utf8::cvt<std::wstring>(e.what())); 48 } catch (...) { 49 NSC_LOG_ERROR_STD(_T("Failed to subscribe to channel ") + utf8::cvt<std::wstring>(channel)); 50 } 37 51 } 38 52 … … 40 54 void script_wrapper::function_wrapper::register_simple_function(std::string name, PyObject* callable, std::string desc) { 41 55 try { 42 core->registerCommand( utf8::cvt<std::wstring>(name), utf8::cvt<std::wstring>(desc));56 core->registerCommand(plugin_id, utf8::cvt<std::wstring>(name), utf8::cvt<std::wstring>(desc)); 43 57 functions::get()->simple_functions[name] = callable; 44 58 } catch (...) { … … 48 62 void script_wrapper::function_wrapper::register_function(std::string name, PyObject* callable, std::string desc) { 49 63 try { 50 core->registerCommand( utf8::cvt<std::wstring>(name), utf8::cvt<std::wstring>(desc));64 core->registerCommand(plugin_id, utf8::cvt<std::wstring>(name), utf8::cvt<std::wstring>(desc)); 51 65 functions::get()->normal_functions[name] = callable; 52 66 } catch (...) { -
modules/PythonScript/script_wrapper.hpp
r81e420c ra44cb15 47 47 private: 48 48 nscapi::core_wrapper* core; 49 unsigned int plugin_id; 49 50 function_wrapper() {} 50 51 public: … … 54 55 return *this; 55 56 } 56 function_wrapper(nscapi::core_wrapper* core ) : core(core) {}57 function_wrapper(nscapi::core_wrapper* core, unsigned int plugin_id) : core(core), plugin_id(plugin_id) {} 57 58 typedef std::map<std::string,PyObject*> function_map_type; 58 59 //typedef boost::python::tuple simple_return; 59 60 60 61 61 static boost::shared_ptr<function_wrapper> create( ) {62 return boost::shared_ptr<function_wrapper>(new function_wrapper(nscapi::plugin_singleton->get_core() ));62 static boost::shared_ptr<function_wrapper> create(unsigned int plugin_id) { 63 return boost::shared_ptr<function_wrapper>(new function_wrapper(nscapi::plugin_singleton->get_core(), plugin_id)); 63 64 } 64 65 -
modules/Scheduler/Scheduler.cpp
r81e420c ra44cb15 159 159 NSCAPI::nagiosReturn code = GET_CORE()->simple_query(item.command.c_str(), item.arguments, response); 160 160 if (nscapi::report::matches(item.report, code)) { 161 GET_CORE()-> NotifyChannel(item.channel, item.alias, code, response);161 GET_CORE()->submit_message(item.channel, item.alias, response); 162 162 } 163 163 } catch (nscapi::nscapi_exception &e) { -
scripts/python/test.py
r81e420c ra44cb15 19 19 20 20 def test_channel(channel, command, code, message, perf): 21 log('inside test_channel: %s'%channel) 21 global prefix 22 log('inside test_channel: %s with prefix %s'%(channel, prefix)) 22 23 log('Data: %d %s %s'%(code, message, perf)) 23 24 … … 89 90 90 91 response = plugin_pb2.QueryResponseMessage() 91 response.header.type = plugin_pb2.Common.Header.QUERY_RESPONSE92 92 response.header.version = plugin_pb2.Common.VERSION_1 93 93 … … 99 99 return (status.OK, response.SerializeToString()) 100 100 101 def init( alias):101 def init(plugin_id, plugin_alias, script_alias): 102 102 global prefix 103 if alias:104 prefix = '%s_'% alias103 if script_alias: 104 prefix = '%s_'%script_alias 105 105 106 log('Script: test.py with alias: %s '%alias)106 log('Script: test.py with alias: %s (%s:%d)'%(script_alias, plugin_alias, plugin_id)) 107 107 108 108 conf = Settings.get() … … 112 112 113 113 log('Testing to register a function') 114 reg = Registry.get( )114 reg = Registry.get(plugin_id) 115 115 reg.simple_function('%stest'%prefix, test, 'This is a sample command') 116 116 reg.simple_function('%snormal'%prefix, normal, 'This is a sample command') -
service/NSClient++.cpp
r81e420c ra44cb15 948 948 949 949 plugins_.insert(plugins_.end(), plugin); 950 commands_.add_plugin(plugin); 951 channels_.add_plugin(plugin); 952 if (plugin->hasNotificationHandler()) { 953 channels_.register_listener(plugin->get_id(), _T("NSCA")); 954 } 950 if (plugin->hasCommandHandler()) 951 commands_.add_plugin(plugin); 952 if (plugin->hasNotificationHandler()) 953 channels_.add_plugin(plugin); 955 954 if (plugin->hasMessageHandler()) 956 955 logger_master_.add_plugin(plugin); … … 1202 1201 } 1203 1202 1203 NSCAPI::errorReturn NSClientT::register_submission_listener(unsigned int plugin_id, const wchar_t* channel) { 1204 channels_.register_listener(plugin_id, channel); 1205 return NSCAPI::isSuccess; 1206 } 1207 NSCAPI::errorReturn NSClientT::register_routing_listener(unsigned int plugin_id, const wchar_t* channel) { 1208 routers_.register_listener(plugin_id, channel); 1209 return NSCAPI::isSuccess; 1210 } 1211 1204 1212 NSCAPI::errorReturn NSClientT::send_notification(const wchar_t* channel, const wchar_t* command, char* buffer, unsigned int buffer_len) { 1205 1213 boost::shared_lock<boost::shared_mutex> readLock(m_mutexRW, boost::get_system_time() + boost::posix_time::milliseconds(5000)); … … 1221 1229 } 1222 1230 } catch (nsclient::plugins_list_exception &e) { 1223 LOG_ERROR_CORE(_T("Error o routing channel: ") + std::wstring(channel) + _T(": ") + to_wstring(e.what()));1231 LOG_ERROR_CORE(_T("Error routing channel: ") + std::wstring(channel) + _T(": ") + to_wstring(e.what()) + _T("Current channels: ") + channels_.to_wstring()); 1224 1232 return NSCAPI::hasFailed; 1225 1233 } catch (...) { -
service/NSClient++.h
r81e420c ra44cb15 172 172 int simple_exec(std::wstring module, std::wstring command, std::vector<std::wstring> arguments, std::list<std::wstring> &resp); 173 173 NSCAPI::nagiosReturn exec_command(const wchar_t* raw_command, std::string &request, std::string &response); 174 NSCAPI::errorReturn register_submission_listener(unsigned int plugin_id, const wchar_t* channel); 175 NSCAPI::errorReturn register_routing_listener(unsigned int plugin_id, const wchar_t* channel); 174 176 175 177 struct service_controller { -
service/core_api.cpp
r81e420c ra44cb15 478 478 if (wcscasecmp(buffer, _T("NSAPIExpandPath")) == 0) 479 479 return reinterpret_cast<LPVOID>(&NSAPIExpandPath); 480 if (wcscasecmp(buffer, _T("NSAPIRegisterSubmissionListener")) == 0) 481 return reinterpret_cast<LPVOID>(&NSAPIRegisterSubmissionListener); 482 if (wcscasecmp(buffer, _T("NSAPIRegisterRoutingListener")) == 0) 483 return reinterpret_cast<LPVOID>(&NSAPIRegisterRoutingListener); 480 484 481 485 LOG_ERROR_STD(_T("Function not found: ") + buffer); … … 483 487 } 484 488 489 NSCAPI::errorReturn NSAPIRegisterSubmissionListener(unsigned int plugin_id, const wchar_t* channel) { 490 return mainClient.register_submission_listener(plugin_id, channel); 491 } 492 NSCAPI::errorReturn NSAPIRegisterRoutingListener(unsigned int plugin_id, const wchar_t* channel) { 493 return mainClient.register_routing_listener(plugin_id, channel); 494 } 495 496 // channels_.register_listener(plugin->get_id(), _T("NSCA")); 497 485 498 NSCAPI::errorReturn NSAPINotify(const wchar_t* channel, const wchar_t* command, char* result, unsigned int result_len) { 486 499 return mainClient.send_notification(channel, command, result, result_len); -
service/core_api.h
r81e420c ra44cb15 63 63 void NSAPIDestroyBuffer(char**); 64 64 NSCAPI::errorReturn NSAPIExpandPath(const wchar_t*,wchar_t*,unsigned int); 65 NSCAPI::errorReturn NSAPIRegisterSubmissionListener(unsigned int plugin_id, const wchar_t* channel); 66 NSCAPI::errorReturn NSAPIRegisterRoutingListener(unsigned int plugin_id, const wchar_t* channel); -
service/plugin_list.hpp
r81e420c ra44cb15 105 105 ret += str; 106 106 } 107 return ret; 107 return ret + parent::to_wstring(); 108 } 109 std::string to_string() { 110 std::string ret; 111 BOOST_FOREACH(std::wstring str, list()) { 112 if (!ret.empty()) ret += ", "; 113 ret += utf8::cvt<std::string>(str); 114 } 115 return ret + parent::to_string(); 108 116 } 109 117 … … 149 157 } 150 158 } 159 std::wstring to_wstring() { 160 std::wstring ret; 161 BOOST_FOREACH(listener_list_type::value_type i, listeners_) { 162 ret += _T(", "); 163 ret += i.first; 164 } 165 return ret; 166 } 167 std::string to_string() { 168 std::string ret; 169 BOOST_FOREACH(listener_list_type::value_type i, listeners_) { 170 ret += ", "; 171 ret += utf8::cvt<std::string>(i.first); 172 } 173 return ret; 174 } 175 151 176 }; 152 177 … … 163 188 } 164 189 std::wstring lc = make_key(channel); 165 if (!have_plugin(plugin_id)) 166 throw plugins_list_exception("Failed to find plugin: " + ::to_string(plugin_id)); 190 if (!have_plugin(plugin_id)) { 191 writeLock.release(); 192 throw plugins_list_exception("Failed to find plugin: " + ::to_string(plugin_id) + ", Plugins: " + to_string()); 193 } 167 194 listeners_[lc].insert(plugin_id); 168 195 } … … 174 201 plugins_list_listeners_impl::listener_list_type::iterator cit = listeners_.find(lc); 175 202 if (cit == listeners_.end()) { 176 throw plugins_list_exception("Channel not found: " + to_string(channel));203 return std::list<plugin_type>(); // throw plugins_list_exception("Channel not found: '" + ::to_string(channel) + "'" + to_string()); 177 204 } 178 205 std::list<plugin_type> ret;
Note: See TracChangeset
for help on using the changeset viewer.








