Changeset 257
- Timestamp:
- 02/18/10 12:22:51 (2 years ago)
- Location:
- trunk
- Files:
-
- 43 edited
-
CMakeLists.txt (modified) (2 diffs)
-
build.cmake (modified) (1 diff)
-
include/NSCAPI.h (modified) (1 diff)
-
include/service/unix_service.hpp (modified) (1 diff)
-
include/settings/macros.h (modified) (1 diff)
-
modules/CheckExternalScripts/CheckExternalScripts.cpp (modified) (6 diffs)
-
modules/CheckExternalScripts/CheckExternalScripts.def (modified) (1 diff)
-
modules/CheckExternalScripts/CheckExternalScripts.h (modified) (4 diffs)
-
modules/CheckExternalScripts/stdafx.h (modified) (1 diff)
-
modules/CheckHelpers/CheckHelpers.cpp (modified) (7 diffs)
-
modules/CheckHelpers/CheckHelpers.h (modified) (2 diffs)
-
modules/CheckHelpers/stdafx.h (modified) (1 diff)
-
modules/CheckSystem/CheckSystem.def (modified) (1 diff)
-
modules/DebugLogMetrics/DebugLogMetrics.def (modified) (1 diff)
-
modules/FileLogger/FileLogger.cpp (modified) (7 diffs)
-
modules/FileLogger/FileLogger.def (modified) (1 diff)
-
modules/FileLogger/FileLogger.h (modified) (2 diffs)
-
modules/FileLogger/stdafx.h (modified) (1 diff)
-
modules/NRPEClient/NRPEClient.cpp (modified) (4 diffs)
-
modules/NRPEClient/NRPEClient.def (modified) (1 diff)
-
modules/NRPEClient/NRPEClient.h (modified) (2 diffs)
-
modules/NRPEClient/stdafx.h (modified) (1 diff)
-
modules/NRPEServer/NRPEServer.cpp (modified) (2 diffs)
-
modules/NRPEServer/NRPEServer.def (modified) (1 diff)
-
modules/NRPEServer/NRPEServer.h (modified) (1 diff)
-
modules/NRPEServer/nrpe_handler.cpp (modified) (3 diffs)
-
modules/NRPEServer/stdafx.h (modified) (1 diff)
-
modules/NSCAAgent/NSCAAgent.cpp (modified) (2 diffs)
-
modules/NSCAAgent/NSCAAgent.h (modified) (2 diffs)
-
modules/NSCAAgent/stdafx.h (modified) (1 diff)
-
modules/NSClientListener/NSClientListener.def (modified) (1 diff)
-
modules/Scheduler/Scheduler.cpp (modified) (6 diffs)
-
modules/Scheduler/Scheduler.h (modified) (1 diff)
-
modules/Scheduler/stdafx.h (modified) (1 diff)
-
service/CMakeLists.txt (modified) (2 diffs)
-
service/NSCPlugin.cpp (modified) (9 diffs)
-
service/NSCPlugin.h (modified) (4 diffs)
-
service/NSClient++.cpp (modified) (11 diffs)
-
service/NSClient++.h (modified) (1 diff)
-
service/commands.hpp (modified) (5 diffs)
-
service/core_api.cpp (modified) (6 diffs)
-
service/core_api.h (modified) (1 diff)
-
service/simple_client.hpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/CMakeLists.txt
r256 r257 167 167 168 168 SET(NSCP_DEF_PLUGIN_CPP 169 ${NSCP_INCLUDE_PATH}/NSCHelper.cpp170 169 ${NSCP_INCLUDE_PATH}/arrayBuffer.cpp 171 170 ${NSCP_INCLUDE_PATH}/simpleini/ConvertUTF.c 172 171 ${NSCP_INCLUDE_PATH}/b64/b64.c 173 172 ${NSCP_INCLUDE_PATH}/utils.cpp 173 ${NSCP_INCLUDE_PATH}/nscapi/nscapi_helper.cpp 174 ${NSCP_INCLUDE_PATH}/nscapi/nscapi_plugin_wrapper.cpp 175 ${NSCP_INCLUDE_PATH}/nscapi/nscapi_core_wrapper.cpp 174 176 ) 175 177 176 178 SET(NSCP_DEF_PLUGIN_HPP 177 ${NSCP_INCLUDE_PATH}/NSCHelper.h178 179 ${NSCP_INCLUDE_PATH}/strEx.h 179 180 ${NSCP_INCLUDE_PATH}/config.h 180 181 ${NSCP_INCLUDE_PATH}/utils.h 181 182 ${NSCP_INCLUDE_PATH}/NSCAPI.h 182 ${NSCP_INCLUDE_PATH}/NSCHelper.h 183 ${NSCP_INCLUDE_PATH}/nsc_module_wrapper.hpp 183 ${NSCP_INCLUDE_PATH}/nscapi/macros.hpp 184 ${NSCP_INCLUDE_PATH}/nscapi/nscapi_helper.hpp 185 ${NSCP_INCLUDE_PATH}/nscapi/nscapi_plugin_wrapper.hpp 186 ${NSCP_INCLUDE_PATH}/nscapi/nscapi_core_wrapper.hpp 184 187 ) 185 188 … … 244 247 endif() 245 248 246 IF("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") 247 SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fPIC" ) 248 SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_DEBUG} -fPIC" ) 249 ENDIF("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") 250 251 249 IF(CMAKE_COMPILER_IS_GNUCXX) 250 IF("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" AND NOT APPLE) 251 SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fPIC" ) 252 SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_DEBUG} -fPIC" ) 253 ENDIF("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" AND NOT APPLE) 254 ENDIF(CMAKE_COMPILER_IS_GNUCXX) 255 256 -
trunk/build.cmake
r256 r257 1 IF(WIN32) 2 1 3 SET(Boost_DEBUG 1) 2 4 3 #set(Boost_USE_STATIC_LIBS ON)5 set(Boost_USE_STATIC_LIBS ON) 4 6 set(BOOST_USE_MULTITHREADED ON) 5 7 6 SET(BOOST_INCLUDEDIR c:/src/include/boost-1_39)7 SET(BOOST_LIBRARYDIR c:/src/lib/x86/)8 SET(BOOST_LIB_SUFFIX vc80-mt)9 #SET(B OOST_LIB_VERSION 1.40)8 SET(BOOST_INCLUDEDIR D:/source/include/) 9 SET(BOOST_LIBRARYDIR D:/source/lib/x86) 10 #SET(BOOST_LIB_SUFFIX vc80-mt) 11 #SET(Boost_VERSION 1.40) 10 12 11 13 12 SET(OPENSSL_INCLUDE_DIR c:/src/include/)13 SET(CMAKE_LIBRARY_PATH c:/src/lib/x86/)14 SET(OPENSSL_INCLUDE_DIR D:/source/include/) 15 SET(CMAKE_LIBRARY_PATH D:/source/lib/x86/) 14 16 15 #SET(PROTOBUF_INCLUDE_DIR C:/src/protobuf-2.3.0/src)16 #SET(PROTOBUF_LIBRARYDIR C:/src/protobuf-2.3.0/vsprojects/Debug)17 #SET(PROTOBUF_BINARYDIR C:/src/protobuf-2.3.0/vsprojects/Debug)17 SET(PROTOBUF_INCLUDE_DIR D:/source/protobuf-2.3.0/src) 18 SET(PROTOBUF_LIBRARYDIR D:/source/protobuf-2.3.0/vsprojects/Debug) 19 SET(PROTOBUF_BINARYDIR D:/source/protobuf-2.3.0/vsprojects/Debug) 18 20 19 21 #SET(PROTOBUF_LIBRARYDIR C:/src/protobuf-2.3.0/vsprojects/Release) 20 22 #SET(PROTOBUF_BINARYDIR C:/src/protobuf-2.3.0/vsprojects/Release) 21 23 24 SET(CRYPTOPP_SOURCE d:/source/libs-c/crypto++-5.6.0) 22 25 23 SET(CRYPTOPP_DIR C:/src/lib-src/Crypto++5.6.0)26 ELSE(WIN32) 24 27 28 ENDIF(WIN32) -
trunk/include/NSCAPI.h
r245 r257 106 106 }; 107 107 108 namespace NSCModuleHelper { 109 typedef void* (*lpNSAPILoader)(wchar_t*); 108 namespace nscapi { 109 110 111 class nscapi_exception { 112 public: 113 std::wstring msg_; 114 nscapi_exception(std::wstring msg) : msg_(msg) {} 115 }; 116 117 namespace core_api { 118 typedef void* (*lpNSAPILoader)(const wchar_t*); 119 120 typedef NSCAPI::errorReturn (*lpNSAPIGetBasePath)(wchar_t*,unsigned int); 121 typedef NSCAPI::errorReturn (*lpNSAPIGetApplicationName)(wchar_t*,unsigned int); 122 typedef NSCAPI::errorReturn (*lpNSAPIGetApplicationVersionStr)(wchar_t*,unsigned int); 123 typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsString)(const wchar_t*,const wchar_t*,const wchar_t*,wchar_t*,unsigned int); 124 typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsInt)(const wchar_t*, const wchar_t*, int); 125 typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsSection)(const wchar_t*, wchar_t***, unsigned int *); 126 typedef NSCAPI::errorReturn (*lpNSAPIReleaseSettingsSectionBuffer)(wchar_t***, unsigned int *); 127 typedef void (*lpNSAPIMessage)(int, const wchar_t*, const int, const wchar_t*); 128 typedef NSCAPI::errorReturn (*lpNSAPIStopServer)(void); 129 typedef NSCAPI::errorReturn (*lpNSAPIExit)(void); 130 typedef NSCAPI::nagiosReturn (*lpNSAPIInject)(const wchar_t*, const char *, const unsigned int, char **, unsigned int *); 131 typedef void (*lpNSAPIDestroyBuffer)(char**); 132 133 typedef NSCAPI::errorReturn (*lpNSAPINotify)(const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn, const char*, unsigned int); 134 135 typedef NSCAPI::boolReturn (*lpNSAPICheckLogMessages)(int); 136 typedef NSCAPI::errorReturn (*lpNSAPIEncrypt)(unsigned int, const wchar_t*, unsigned int, wchar_t*, unsigned int *); 137 typedef NSCAPI::errorReturn (*lpNSAPIDecrypt)(unsigned int, const wchar_t*, unsigned int, wchar_t*, unsigned int *); 138 typedef NSCAPI::errorReturn (*lpNSAPISetSettingsString)(const wchar_t*, const wchar_t*, const wchar_t*); 139 typedef NSCAPI::errorReturn (*lpNSAPISetSettingsInt)(const wchar_t*, const wchar_t*, int); 140 typedef NSCAPI::errorReturn (*lpNSAPIWriteSettings)(int); 141 typedef NSCAPI::errorReturn (*lpNSAPIReadSettings)(int); 142 typedef NSCAPI::errorReturn (*lpNSAPIRehash)(int); 143 typedef NSCAPI::errorReturn (*lpNSAPIDescribeCommand)(const wchar_t*,wchar_t*,unsigned int); 144 typedef NSCAPI::errorReturn (*lpNSAPIGetAllCommandNames)(wchar_t***, unsigned int *); 145 typedef NSCAPI::errorReturn (*lpNSAPIReleaseAllCommandNamessBuffer)(wchar_t***, unsigned int *); 146 typedef NSCAPI::errorReturn (*lpNSAPIRegisterCommand)(unsigned int, const wchar_t*,const wchar_t*); 147 typedef NSCAPI::errorReturn (*lpNSAPISettingsRegKey)(const wchar_t*, const wchar_t*, int, const wchar_t*, const wchar_t*, const wchar_t*, int); 148 typedef NSCAPI::errorReturn (*lpNSAPISettingsRegPath)(const wchar_t*, const wchar_t*, const wchar_t*, int); 149 typedef NSCAPI::errorReturn (*lpNSAPIGetPluginList)(int *len, NSCAPI::plugin_info *list[]); 150 typedef NSCAPI::errorReturn (*lpNSAPIReleasePluginList)(int len, NSCAPI::plugin_info *list[]); 151 typedef NSCAPI::errorReturn (*lpNSAPISettingsSave)(void); 152 } 153 154 namespace plugin_api { 155 typedef int (*lpModuleHelperInit)(unsigned int, ::nscapi::core_api::lpNSAPILoader f); 156 typedef int (*lpLoadModule)(int); 157 typedef int (*lpGetName)(wchar_t*,unsigned int); 158 typedef int (*lpGetDescription)(wchar_t*,unsigned int); 159 typedef int (*lpGetVersion)(int*,int*,int*); 160 typedef int (*lpHasCommandHandler)(); 161 typedef int (*lpHasMessageHandler)(); 162 typedef NSCAPI::nagiosReturn (*lpHandleCommand)(const wchar_t*,const char*,const unsigned int,char**,unsigned int*); 163 typedef int (*lpDeleteBuffer)(char**); 164 typedef int (*lpCommandLineExec)(const unsigned int,wchar_t**); 165 typedef int (*lpHandleMessage)(int,const wchar_t*,const int,const wchar_t*); 166 typedef int (*lpUnLoadModule)(); 167 typedef void (*lpShowTray)(); 168 typedef void (*lpHideTray)(); 169 typedef int (*lpHasNotificationHandler)(); 170 typedef int (*lpHandleNotification)(const wchar_t *channel, const wchar_t* command, NSCAPI::nagiosReturn code, char* result, unsigned int result_len); 171 } 110 172 } -
trunk/include/service/unix_service.hpp
r219 r257 63 63 virtual ~unix_service() { 64 64 } 65 inline void print_debug( std::wstring s) {65 inline void print_debug(const std::wstring s) { 66 66 std::wcout << s << std::endl; 67 67 } 68 inline void print_debug( wchar_t *s) {68 inline void print_debug(const wchar_t *s) { 69 69 std::wcout << s << std::endl; 70 70 } -
trunk/include/settings/macros.h
r245 r257 103 103 DEFINE_SETTING_S(SYSTRAY_EXE, DEFAULT_SECTION, "systray_exe", "nstray.exe"); 104 104 DESCRIBE_SETTING(SYSTRAY_EXE, "TODO", "TODO"); 105 106 107 105 } 108 106 -
trunk/modules/CheckExternalScripts/CheckExternalScripts.cpp
r256 r257 42 42 boost::filesystem::wpath path = str_path; 43 43 if (path.has_relative_path()) 44 path = NSCModuleHelper::getBasePath() / path;44 path = GET_CORE()->getBasePath() / path; 45 45 file_helpers::patterns::pattern_type split_path = file_helpers::patterns::split_pattern(path); 46 46 if (!boost::filesystem::is_directory(split_path.first)) … … 72 72 allowNasty_ = SETTINGS_GET_BOOL(nrpe::ALLOW_NASTY); 73 73 std::list<std::wstring>::const_iterator it; 74 std::list<std::wstring> commands = NSCModuleHelper::getSettingsSection(setting_keys::external_scripts::SCRIPT_SECTION_PATH);74 std::list<std::wstring> commands = GET_CORE()->getSettingsSection(setting_keys::external_scripts::SCRIPT_SECTION_PATH); 75 75 for (it = commands.begin(); it != commands.end(); ++it) { 76 76 if ((*it).empty()) 77 77 continue; 78 78 NSC_DEBUG_MSG_STD(_T("Looking under: ") + setting_keys::external_scripts::SCRIPT_SECTION_PATH + _T(", ") + (*it)); 79 std::wstring s = NSCModuleHelper::getSettingsString(setting_keys::external_scripts::SCRIPT_SECTION_PATH, (*it), _T(""));79 std::wstring s = GET_CORE()->getSettingsString(setting_keys::external_scripts::SCRIPT_SECTION_PATH, (*it), _T("")); 80 80 if (s.empty()) { 81 81 NSC_LOG_ERROR_STD(_T("Invalid command definition: ") + (*it)); … … 86 86 } 87 87 88 commands = NSCModuleHelper::getSettingsSection(setting_keys::external_scripts::ALIAS_SECTION_PATH);88 commands = GET_CORE()->getSettingsSection(setting_keys::external_scripts::ALIAS_SECTION_PATH); 89 89 for (it = commands.begin(); it != commands.end(); ++it) { 90 90 if ((*it).empty()) 91 91 continue; 92 std::wstring s = NSCModuleHelper::getSettingsString(setting_keys::external_scripts::ALIAS_SECTION_PATH, (*it), _T(""));92 std::wstring s = GET_CORE()->getSettingsString(setting_keys::external_scripts::ALIAS_SECTION_PATH, (*it), _T("")); 93 93 if (s.empty()) { 94 94 NSC_LOG_ERROR_STD(_T("Invalid command definition: ") + (*it)); … … 102 102 addAllScriptsFrom(scriptDirectory_); 103 103 } 104 root_ = NSCModuleHelper::getBasePath();104 root_ = GET_CORE()->getBasePath(); 105 105 return true; 106 106 } … … 145 145 } 146 146 if (isAlias) { 147 return NSCModuleHelper::InjectSplitAndCommand(cd.command, args, ' ', message, perf, true);147 return GET_CORE()->InjectSplitAndCommand(cd.command, args, ' ', message, perf, true); 148 148 } else { 149 149 int result = process::executeProcess(process::exec_arguments(root_, cd.command + _T(" ") + args, timeout), message, perf); 150 if (! NSCHelper::isNagiosReturnCode(result)) {150 if (!nscapi::plugin_helper::isNagiosReturnCode(result)) { 151 151 NSC_LOG_ERROR_STD(_T("The command (") + cd.command + _T(") returned an invalid return code: ") + strEx::itos(result)); 152 152 return NSCAPI::returnUNKNOWN; 153 153 } 154 return NSCHelper::int2nagios(result);154 return nscapi::plugin_helper::int2nagios(result); 155 155 /* 156 156 } else if (cd.type == script_dir) { … … 171 171 NSC_WRAPPERS_IGNORE_MSG_DEF(); 172 172 NSC_WRAPPERS_HANDLE_CMD_DEF(gCheckExternalScripts); 173 NSC_WRAPPERS_HANDLE_CONFIGURATION(gCheckExternalScripts);174 173 175 176 MODULE_SETTINGS_START(CheckExternalScripts, _T("NRPE Listener configuration"), _T("..."))177 178 PAGE(_T("NRPE Listsner configuration"))179 180 ITEM_EDIT_TEXT(_T("port"), _T("This is the port the CheckExternalScripts.dll will listen to."))181 ITEM_MAP_TO(_T("basic_ini_text_mapper"))182 OPTION(_T("section"), _T("NRPE"))183 OPTION(_T("key"), _T("port"))184 OPTION(_T("default"), _T("5666"))185 ITEM_END()186 187 ITEM_CHECK_BOOL(_T("allow_arguments"), _T("This option determines whether or not the NRPE daemon will allow clients to specify arguments to commands that are executed."))188 ITEM_MAP_TO(_T("basic_ini_bool_mapper"))189 OPTION(_T("section"), _T("NRPE"))190 OPTION(_T("key"), _T("allow_arguments"))191 OPTION(_T("default"), _T("false"))192 OPTION(_T("true_value"), _T("1"))193 OPTION(_T("false_value"), _T("0"))194 ITEM_END()195 196 ITEM_CHECK_BOOL(_T("allow_nasty_meta_chars"), _T("This might have security implications (depending on what you do with the options)"))197 ITEM_MAP_TO(_T("basic_ini_bool_mapper"))198 OPTION(_T("section"), _T("NRPE"))199 OPTION(_T("key"), _T("allow_nasty_meta_chars"))200 OPTION(_T("default"), _T("false"))201 OPTION(_T("true_value"), _T("1"))202 OPTION(_T("false_value"), _T("0"))203 ITEM_END()204 205 ITEM_CHECK_BOOL(_T("use_ssl"), _T("This option will enable SSL encryption on the NRPE data socket (this increases security somwhat."))206 ITEM_MAP_TO(_T("basic_ini_bool_mapper"))207 OPTION(_T("section"), _T("NRPE"))208 OPTION(_T("key"), _T("use_ssl"))209 OPTION(_T("default"), _T("true"))210 OPTION(_T("true_value"), _T("1"))211 OPTION(_T("false_value"), _T("0"))212 ITEM_END()213 214 PAGE_END()215 ADVANCED_PAGE(_T("Access configuration"))216 217 ITEM_EDIT_OPTIONAL_LIST(_T("Allow connection from:"), _T("This is the hosts that will be allowed to poll performance data from the NRPE server."))218 OPTION(_T("disabledCaption"), _T("Use global settings (defined previously)"))219 OPTION(_T("enabledCaption"), _T("Specify hosts for NRPE server"))220 OPTION(_T("listCaption"), _T("Add all IP addresses (not hosts) which should be able to connect:"))221 OPTION(_T("separator"), _T(","))222 OPTION(_T("disabled"), _T(""))223 ITEM_MAP_TO(_T("basic_ini_text_mapper"))224 OPTION(_T("section"), _T("NRPE"))225 OPTION(_T("key"), _T("allowed_hosts"))226 OPTION(_T("default"), _T(""))227 ITEM_END()228 229 PAGE_END()230 MODULE_SETTINGS_END() -
trunk/modules/CheckExternalScripts/CheckExternalScripts.def
r244 r257 11 11 NSHandleCommand 12 12 NSUnloadModule 13 NSGetConfigurationMeta14 13 NSGetModuleDescription 15 14 NSDeleteBuffer -
trunk/modules/CheckExternalScripts/CheckExternalScripts.h
r245 r257 25 25 #include <execute_process.hpp> 26 26 27 class CheckExternalScripts : public NSCModuleHelper::SimpleCommand {27 class CheckExternalScripts : public nscapi::impl::SimpleCommand { 28 28 private: 29 29 struct command_data { … … 56 56 return _T("Check External Scripts"); 57 57 } 58 NSCModuleWrapper::module_version getModuleVersion() {59 NSCModuleWrapper::module_version version = {0, 0, 1 };58 nscapi::plugin_wrapper::module_version getModuleVersion() { 59 nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 60 60 return version; 61 61 } … … 88 88 command_data cd = command_data(cmd, args); 89 89 commands[key] = cd; 90 NSCModuleHelper::registerCommand(key, _T("Script: ") + cd.to_string());90 GET_CORE()->registerCommand(key, _T("Script: ") + cd.to_string()); 91 91 } 92 92 void addAlias(std::wstring key, std::wstring cmd, std::wstring args) { … … 94 94 command_data cd = command_data(cmd, args); 95 95 alias[key] = cd; 96 NSCModuleHelper::registerCommand(key, _T("Alias for: ") + cd.to_string());96 GET_CORE()->registerCommand(key, _T("Alias for: ") + cd.to_string()); 97 97 } 98 98 }; -
trunk/modules/CheckExternalScripts/stdafx.h
r226 r257 29 29 #include <types.hpp> 30 30 #include <NSCAPI.h> 31 #include <nsc_module_wrapper.hpp> 32 #include <NSCHelper.h> 31 #include <nscapi/plugin.hpp> 33 32 34 33 #ifdef MEMCHECK -
trunk/modules/CheckHelpers/CheckHelpers.cpp
r250 r257 35 35 bool CheckHelpers::loadModule(NSCAPI::moduleLoadMode mode) { 36 36 try { 37 NSCModuleHelper::registerCommand(_T("CheckAlwaysOK"), _T("Run another check and regardless of its return code return OK."));38 NSCModuleHelper::registerCommand(_T("CheckAlwaysCRITICAL"), _T("Run another check and regardless of its return code return CRIT."));39 NSCModuleHelper::registerCommand(_T("CheckAlwaysWARNING"), _T("Run another check and regardless of its return code return WARN."));40 NSCModuleHelper::registerCommand(_T("CheckMultiple"), _T("Run more then one check and return the worst state."));41 NSCModuleHelper::registerCommand(_T("CheckOK"), _T("Just return OK (anything passed along will be used as a message)."));42 NSCModuleHelper::registerCommand(_T("check_ok"), _T("Just return OK (anything passed along will be used as a message)."));43 NSCModuleHelper::registerCommand(_T("CheckWARNING"), _T("Just return WARN (anything passed along will be used as a message)."));44 NSCModuleHelper::registerCommand(_T("CheckCRITICAL"), _T("Just return CRIT (anything passed along will be used as a message)."));45 NSCModuleHelper::registerCommand(_T("CheckVersion"), _T("Just return the nagios version (along with OK status)."));46 } catch ( NSCModuleHelper::NSCMHExcpetion &e) {37 GET_CORE()->registerCommand(_T("CheckAlwaysOK"), _T("Run another check and regardless of its return code return OK.")); 38 GET_CORE()->registerCommand(_T("CheckAlwaysCRITICAL"), _T("Run another check and regardless of its return code return CRIT.")); 39 GET_CORE()->registerCommand(_T("CheckAlwaysWARNING"), _T("Run another check and regardless of its return code return WARN.")); 40 GET_CORE()->registerCommand(_T("CheckMultiple"), _T("Run more then one check and return the worst state.")); 41 GET_CORE()->registerCommand(_T("CheckOK"), _T("Just return OK (anything passed along will be used as a message).")); 42 GET_CORE()->registerCommand(_T("check_ok"), _T("Just return OK (anything passed along will be used as a message).")); 43 GET_CORE()->registerCommand(_T("CheckWARNING"), _T("Just return WARN (anything passed along will be used as a message).")); 44 GET_CORE()->registerCommand(_T("CheckCRITICAL"), _T("Just return CRIT (anything passed along will be used as a message).")); 45 GET_CORE()->registerCommand(_T("CheckVersion"), _T("Just return the nagios version (along with OK status).")); 46 } catch (nscapi::nscapi_exception &e) { 47 47 NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 48 48 } catch (...) { … … 65 65 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 66 66 if (arguments.empty()) { 67 message = NSCHelper::translateReturn(status) + _T(": Lets pretend everything is going to be ok.");67 message = nscapi::plugin_helper::translateReturn(status) + _T(": Lets pretend everything is going to be ok."); 68 68 return status; 69 69 } … … 76 76 NSCAPI::nagiosReturn CheckHelpers::handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 77 77 if (command == _T("CheckVersion")) { 78 message = NSCModuleHelper::getApplicationVersionString();78 message = GET_CORE()->getApplicationVersionString(); 79 79 return NSCAPI::returnOK; 80 80 } else if (command == _T("CheckAlwaysOK")) { … … 84 84 } 85 85 std::wstring new_command = arguments.front(); arguments.pop_front(); 86 NSCModuleHelper::InjectSimpleCommand(new_command, arguments, message, perf);86 GET_CORE()->InjectSimpleCommand(new_command, arguments, message, perf); 87 87 return NSCAPI::returnOK; 88 } else if (command == _T("CheckVersion")) {89 message = NSCModuleHelper::getApplicationVersionString();90 return NSCAPI::returnOK;91 } else if (command == _T("CheckOK")) {92 return checkSimpleStatus(NSCAPI::returnOK, arguments, message, perf);93 } else if (command == _T("CheckWARNING")) {94 return checkSimpleStatus(NSCAPI::returnWARN, arguments, message, perf);95 } else if (command == _T("CheckCRITICAL")) {96 return checkSimpleStatus(NSCAPI::returnCRIT, arguments, message, perf);97 88 } else if (command == _T("CheckAlwaysCRITICAL")) { 98 89 if (arguments.size() < 1) { … … 101 92 } 102 93 std::wstring new_command = arguments.front(); arguments.pop_front(); 103 NSCModuleHelper::InjectSimpleCommand(new_command, arguments, message, perf);94 GET_CORE()->InjectSimpleCommand(new_command, arguments, message, perf); 104 95 return NSCAPI::returnCRIT; 105 96 } else if (command == _T("CheckAlwaysWARNING")) { … … 109 100 } 110 101 std::wstring new_command = arguments.front(); arguments.pop_front(); 111 NSCModuleHelper::InjectSimpleCommand(new_command, arguments, message, perf);102 GET_CORE()->InjectSimpleCommand(new_command, arguments, message, perf); 112 103 return NSCAPI::returnWARN; 113 104 } else if (command == _T("CheckOK")) { … … 153 144 std::list<std::wstring> sub_args; 154 145 std::wstring tMsg, tPerf; 155 NSCAPI::nagiosReturn tRet = NSCModuleHelper::InjectSimpleCommand((*cit2).first.c_str(), (*cit2).second, tMsg, tPerf);156 returnCode = NSCHelper::maxState(returnCode, tRet);146 NSCAPI::nagiosReturn tRet = GET_CORE()->InjectSimpleCommand((*cit2).first.c_str(), (*cit2).second, tMsg, tPerf); 147 returnCode = nscapi::plugin_helper::maxState(returnCode, tRet); 157 148 if (!message.empty()) 158 149 message += _T(", "); -
trunk/modules/CheckHelpers/CheckHelpers.h
r250 r257 23 23 #include <strEx.h> 24 24 25 class CheckHelpers : public NSCModuleHelper::SimpleCommand {25 class CheckHelpers : public nscapi::impl::SimpleCommand { 26 26 private: 27 27 … … 37 37 return _T("Helper function"); 38 38 } 39 NSCModuleWrapper::module_version getModuleVersion() {40 NSCModuleWrapper::module_version version = {0, 3, 0 };39 nscapi::plugin_wrapper::module_version getModuleVersion() { 40 nscapi::plugin_wrapper::module_version version = {0, 3, 0 }; 41 41 return version; 42 42 } -
trunk/modules/CheckHelpers/stdafx.h
r216 r257 28 28 29 29 #include <NSCAPI.h> 30 #include <nsc_module_wrapper.hpp> 31 #include <NSCHelper.h> 30 #include <nscapi/plugin.hpp> 32 31 -
trunk/modules/CheckSystem/CheckSystem.def
r38 r257 11 11 NSHandleCommand 12 12 NSUnloadModule 13 NSGetConfigurationMeta14 13 NSGetModuleDescription 15 14 NSCommandLineExec -
trunk/modules/DebugLogMetrics/DebugLogMetrics.def
r201 r257 11 11 NSHandleCommand 12 12 NSUnloadModule 13 NSGetConfigurationMeta14 13 NSGetModuleDescription -
trunk/modules/FileLogger/FileLogger.cpp
r256 r257 54 54 std::wstring getFolder(std::wstring key) { 55 55 if (key == _T("exe")) { 56 return NSCModuleHelper::getBasePath();56 return GET_CORE()->getBasePath(); 57 57 } else { 58 58 #ifdef WIN32 … … 64 64 #endif 65 65 } 66 return NSCModuleHelper::getBasePath();66 return GET_CORE()->getBasePath(); 67 67 } 68 68 std::string FileLogger::getFileName() { … … 94 94 SETTINGS_REG_KEY_S(log::LOG_MASK); 95 95 96 } catch ( NSCModuleHelper::NSCMHExcpetion &e) {96 } catch (nscapi::nscapi_exception &e) { 97 97 NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 98 98 } catch (...) { … … 103 103 format_ = to_string(SETTINGS_GET_STRING(log::DATEMASK)); 104 104 std::wstring log_mask = SETTINGS_GET_STRING(log::LOG_MASK); 105 log_mask_ = NSCHelper::logging::parse(log_mask);106 NSC_LOG_MESSAGE_STD(_T("Using logmask: ") + NSCHelper::logging::to_string(log_mask_));105 log_mask_ = nscapi::logging::parse(log_mask); 106 NSC_LOG_MESSAGE_STD(_T("Using logmask: ") + nscapi::logging::to_string(log_mask_)); 107 107 init_ = true; 108 std::wstring hello = _T("Starting to log for: ") + NSCModuleHelper::getApplicationName() + _T(" - ") + NSCModuleHelper::getApplicationVersionString();108 std::wstring hello = _T("Starting to log for: ") + GET_CORE()->getApplicationName() + _T(" - ") + GET_CORE()->getApplicationVersionString(); 109 109 handleMessage(NSCAPI::log, __FILEW__, __LINE__, hello.c_str()); 110 110 NSC_LOG_MESSAGE_STD(_T("Log path is: ") + to_wstring(file_)); … … 135 135 */ 136 136 137 void FileLogger::handleMessage(int msgType, TCHAR* file, int line, const TCHAR* message) {137 void FileLogger::handleMessage(int msgType, const wchar_t* file, int line, const TCHAR* message) { 138 138 if (!init_) { 139 139 std::wcout << _T("Discarding: ") << message << std::endl; 140 140 return; 141 141 } 142 if (! NSCHelper::logging::matches(log_mask_, msgType))142 if (!nscapi::logging::matches(log_mask_, msgType)) 143 143 return; 144 144 … … 148 148 } 149 149 stream << to_string(get_formated_date()) 150 << (": ") << to_string( NSCHelper::translateMessageType(msgType))150 << (": ") << to_string(nscapi::plugin_helper::translateMessageType(msgType)) 151 151 << (":") << to_string(std::wstring(file)) 152 152 <<(":") << to_string(line) … … 166 166 NSC_WRAPPERS_HANDLE_MSG_DEF(gFileLogger); 167 167 NSC_WRAPPERS_IGNORE_CMD_DEF(); 168 NSC_WRAPPERS_HANDLE_CONFIGURATION(gFileLogger);169 170 MODULE_SETTINGS_START(FileLogger, _T("File logger configuration"),_T("..."))171 MODULE_SETTINGS_END() -
trunk/modules/FileLogger/FileLogger.def
r245 r257 11 11 NSHandleCommand 12 12 NSUnloadModule 13 NSGetConfigurationMeta14 13 NSGetModuleDescription 15 14 NSDeleteBuffer -
trunk/modules/FileLogger/FileLogger.h
r256 r257 42 42 return _T("File logger"); 43 43 } 44 NSCModuleWrapper::module_version getModuleVersion() {45 NSCModuleWrapper::module_version version = {0, 0, 1 };44 nscapi::plugin_wrapper::module_version getModuleVersion() { 45 nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 46 46 return version; 47 47 } … … 52 52 bool hasCommandHandler(); 53 53 bool hasMessageHandler(); 54 void handleMessage(int msgType, TCHAR* file, int line, const TCHAR* message);54 void handleMessage(int msgType, const wchar_t* file, int line, const TCHAR* message); 55 55 int handleCommand(TCHAR* command, TCHAR **argument, TCHAR *returnBuffer, int returnBufferLen); 56 56 //void writeEntry(std::wstring line); -
trunk/modules/FileLogger/stdafx.h
r245 r257 27 27 28 28 #include <NSCAPI.h> 29 #include <NSCHelper.h> 30 #include <nsc_module_wrapper.hpp> 31 29 #include <nscapi/plugin.hpp> 32 30 #include <config.h> 33 31 -
trunk/modules/NRPEClient/NRPEClient.cpp
r256 r257 45 45 try { 46 46 SETTINGS_REG_PATH(nrpe::CH_SECTION); 47 commands = NSCModuleHelper::getSettingsSection(setting_keys::nrpe::CH_SECTION_PATH);48 } catch ( NSCModuleHelper::NSCMHExcpetion &e) {47 commands = GET_CORE()->getSettingsSection(setting_keys::nrpe::CH_SECTION_PATH); 48 } catch (nscapi::nscapi_exception &e) { 49 49 NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 50 50 } catch (...) { … … 52 52 } 53 53 54 boost::filesystem::wpath p = NSCModuleHelper::getBasePath() + std::wstring(_T("security/nrpe_dh_512.pem"));54 boost::filesystem::wpath p = GET_CORE()->getBasePath() + std::wstring(_T("security/nrpe_dh_512.pem")); 55 55 cert_ = p.string(); 56 56 if (boost::filesystem::is_regular(p)) { … … 63 63 for (std::list<std::wstring>::const_iterator it = commands.begin(); it != commands.end(); ++it) { 64 64 NSC_DEBUG_MSG_STD(*it); 65 std::wstring s = NSCModuleHelper::getSettingsString(setting_keys::nrpe::CH_SECTION_PATH, (*it), _T(""));65 std::wstring s = GET_CORE()->getSettingsString(setting_keys::nrpe::CH_SECTION_PATH, (*it), _T("")); 66 66 if (s.empty()) { 67 67 NSC_LOG_ERROR_STD(_T("Invalid NRPE-client entry: ") + (*it)); … … 276 276 NSC_WRAPPERS_IGNORE_MSG_DEF(); 277 277 NSC_WRAPPERS_HANDLE_CMD_DEF(gNRPEClient); 278 NSC_WRAPPERS_HANDLE_CONFIGURATION(gNRPEClient);279 278 NSC_WRAPPERS_CLI_DEF(gNRPEClient); 280 279 281 282 MODULE_SETTINGS_START(NRPEClient, _T("NRPE Listener configuration"), _T("..."))283 284 PAGE(_T("NRPE Listsner configuration"))285 286 ITEM_EDIT_TEXT(_T("port"), _T("This is the port the NRPEClient.dll will listen to."))287 ITEM_MAP_TO(_T("basic_ini_text_mapper"))288 OPTION(_T("section"), _T("NRPE"))289 OPTION(_T("key"), _T("port"))290 OPTION(_T("default"), _T("5666"))291 ITEM_END()292 293 ITEM_CHECK_BOOL(_T("allow_arguments"), _T("This option determines whether or not the NRPE daemon will allow clients to specify arguments to commands that are executed."))294 ITEM_MAP_TO(_T("basic_ini_bool_mapper"))295 OPTION(_T("section"), _T("NRPE"))296 OPTION(_T("key"), _T("allow_arguments"))297 OPTION(_T("default"), _T("false"))298 OPTION(_T("true_value"), _T("1"))299 OPTION(_T("false_value"), _T("0"))300 ITEM_END()301 302 ITEM_CHECK_BOOL(_T("allow_nasty_meta_chars"), _T("This might have security implications (depending on what you do with the options)"))303 ITEM_MAP_TO(_T("basic_ini_bool_mapper"))304 OPTION(_T("section"), _T("NRPE"))305 OPTION(_T("key"), _T("allow_nasty_meta_chars"))306 OPTION(_T("default"), _T("false"))307 OPTION(_T("true_value"), _T("1"))308 OPTION(_T("false_value"), _T("0"))309 ITEM_END()310 311 ITEM_CHECK_BOOL(_T("use_ssl"), _T("This option will enable SSL encryption on the NRPE data socket (this increases security somwhat."))312 ITEM_MAP_TO(_T("basic_ini_bool_mapper"))313 OPTION(_T("section"), _T("NRPE"))314 OPTION(_T("key"), _T("use_ssl"))315 OPTION(_T("default"), _T("true"))316 OPTION(_T("true_value"), _T("1"))317 OPTION(_T("false_value"), _T("0"))318 ITEM_END()319 320 PAGE_END()321 ADVANCED_PAGE(_T("Access configuration"))322 323 ITEM_EDIT_OPTIONAL_LIST(_T("Allow connection from:"), _T("This is the hosts that will be allowed to poll performance data from the NRPE server."))324 OPTION(_T("disabledCaption"), _T("Use global settings (defined previously)"))325 OPTION(_T("enabledCaption"), _T("Specify hosts for NRPE server"))326 OPTION(_T("listCaption"), _T("Add all IP addresses (not hosts) which should be able to connect:"))327 OPTION(_T("separator"), _T(","))328 OPTION(_T("disabled"), _T(""))329 ITEM_MAP_TO(_T("basic_ini_text_mapper"))330 OPTION(_T("section"), _T("NRPE"))331 OPTION(_T("key"), _T("allowed_hosts"))332 OPTION(_T("default"), _T(""))333 ITEM_END()334 335 PAGE_END()336 MODULE_SETTINGS_END() -
trunk/modules/NRPEClient/NRPEClient.def
r244 r257 11 11 NSHandleCommand 12 12 NSUnloadModule 13 NSGetConfigurationMeta14 13 NSGetModuleDescription 15 14 NSCommandLineExec -
trunk/modules/NRPEClient/NRPEClient.h
r254 r257 25 25 26 26 27 class NRPEClient : public NSCModuleHelper::SimpleCommand {27 class NRPEClient : public nscapi::impl::SimpleCommand { 28 28 private: 29 29 typedef enum { … … 104 104 #endif 105 105 } 106 NSCModuleWrapper::module_version getModuleVersion() {107 NSCModuleWrapper::module_version version = {0, 0, 1 };106 nscapi::plugin_wrapper::module_version getModuleVersion() { 107 nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 108 108 return version; 109 109 } -
trunk/modules/NRPEClient/stdafx.h
r229 r257 40 40 41 41 #include <NSCAPI.h> 42 #include <NSCHelper.h> 43 #include <nsc_module_wrapper.hpp> 42 #include <nscapi/plugin.hpp> 44 43 namespace po = boost::program_options; 45 44 -
trunk/modules/NRPEServer/NRPEServer.cpp
r250 r257 100 100 return false; 101 101 } 102 root_ = NSCModuleHelper::getBasePath();102 root_ = GET_CORE()->getBasePath(); 103 103 return true; 104 104 } … … 304 304 NSC_WRAPPERS_IGNORE_MSG_DEF(); 305 305 NSC_WRAPPERS_IGNORE_CMD_DEF(); 306 NSC_WRAPPERS_HANDLE_CONFIGURATION(gNRPEListener);307 308 309 MODULE_SETTINGS_START(NRPEListener, _T("NRPE Listener configuration"), _T("..."))310 311 PAGE(_T("NRPE Listsner configuration"))312 313 ITEM_EDIT_TEXT(_T("port"), _T("This is the port the NRPEListener.dll will listen to."))314 ITEM_MAP_TO(_T("basic_ini_text_mapper"))315 OPTION(_T("section"), _T("NRPE"))316 OPTION(_T("key"), _T("port"))317 OPTION(_T("default"), _T("5666"))318 ITEM_END()319 320 ITEM_CHECK_BOOL(_T("allow_arguments"), _T("This option determines whether or not the NRPE daemon will allow clients to specify arguments to commands that are executed."))321 ITEM_MAP_TO(_T("basic_ini_bool_mapper"))322 OPTION(_T("section"), _T("NRPE"))323 OPTION(_T("key"), _T("allow_arguments"))324 OPTION(_T("default"), _T("false"))325 OPTION(_T("true_value"), _T("1"))326 OPTION(_T("false_value"), _T("0"))327 ITEM_END()328 329 ITEM_CHECK_BOOL(_T("allow_nasty_meta_chars"), _T("This might have security implications (depending on what you do with the options)"))330 ITEM_MAP_TO(_T("basic_ini_bool_mapper"))331 OPTION(_T("section"), _T("NRPE"))332 OPTION(_T("key"), _T("allow_nasty_meta_chars"))333 OPTION(_T("default"), _T("false"))334 OPTION(_T("true_value"), _T("1"))335 OPTION(_T("false_value"), _T("0"))336 ITEM_END()337 338 ITEM_CHECK_BOOL(_T("use_ssl"), _T("This option will enable SSL encryption on the NRPE data socket (this increases security somwhat."))339 ITEM_MAP_TO(_T("basic_ini_bool_mapper"))340 OPTION(_T("section"), _T("NRPE"))341 OPTION(_T("key"), _T("use_ssl"))342 OPTION(_T("default"), _T("true"))343 OPTION(_T("true_value"), _T("1"))344 OPTION(_T("false_value"), _T("0"))345 ITEM_END()346 347 PAGE_END()348 ADVANCED_PAGE(_T("Access configuration"))349 350 ITEM_EDIT_OPTIONAL_LIST(_T("Allow connection from:"), _T("This is the hosts that will be allowed to poll performance data from the NRPE server."))351 OPTION(_T("disabledCaption"), _T("Use global settings (defined previously)"))352 OPTION(_T("enabledCaption"), _T("Specify hosts for NRPE server"))353 OPTION(_T("listCaption"), _T("Add all IP addresses (not hosts) which should be able to connect:"))354 OPTION(_T("separator"), _T(","))355 OPTION(_T("disabled"), _T(""))356 ITEM_MAP_TO(_T("basic_ini_text_mapper"))357 OPTION(_T("section"), _T("NRPE"))358 OPTION(_T("key"), _T("allowed_hosts"))359 OPTION(_T("default"), _T(""))360 ITEM_END()361 362 PAGE_END()363 MODULE_SETTINGS_END() -
trunk/modules/NRPEServer/NRPEServer.def
r244 r257 11 11 NSHandleCommand 12 12 NSUnloadModule 13 NSGetConfigurationMeta14 13 NSGetModuleDescription 15 14 NSDeleteBuffer -
trunk/modules/NRPEServer/NRPEServer.h
r238 r257 59 59 #endif 60 60 } 61 NSCModuleWrapper::module_version getModuleVersion() {62 NSCModuleWrapper::module_version version = {0, 0, 1 };61 nscapi::plugin_wrapper::module_version getModuleVersion() { 62 nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 63 63 return version; 64 64 } -
trunk/modules/NRPEServer/nrpe_handler.cpp
r226 r257 2 2 #include <boost/asio.hpp> 3 3 #include "nrpe_handler.hpp" 4 #include <NSCHelper.h>5 4 6 5 namespace nrpe { … … 9 8 strEx::token cmd = strEx::getToken(p.getPayload(), '!'); 10 9 if (cmd.first == _T("_NRPE_CHECK")) { 11 return nrpe::packet::create_response(NSCAPI::returnOK, _T("I (") + NSCModuleHelper::getApplicationVersionString() + _T(") seem to be doing fine..."), p.get_payload_length());10 return nrpe::packet::create_response(NSCAPI::returnOK, _T("I (") + nscapi::plugin_singleton->get_core()->getApplicationVersionString() + _T(") seem to be doing fine..."), p.get_payload_length()); 12 11 } 13 12 std::wstring msg, perf; … … 34 33 NSCAPI::nagiosReturn ret = -3; 35 34 try { 36 ret = NSCModuleHelper::InjectSplitAndCommand(cmd.first, cmd.second, '!', msg, perf);35 ret = nscapi::plugin_singleton->get_core()->InjectSplitAndCommand(cmd.first, cmd.second, '!', msg, perf); 37 36 } catch (...) { 38 37 return nrpe::packet::create_response(NSCAPI::returnUNKNOWN, _T("UNKNOWN: Internal exception"), p.get_payload_length()); -
trunk/modules/NRPEServer/stdafx.h
r254 r257 46 46 #include <types.hpp> 47 47 #include <NSCAPI.h> 48 #include <NSCHelper.h> 49 #include <nsc_module_wrapper.hpp> 48 #include <nscapi/plugin.hpp> 50 49 #include <nrpe/nrpe_packet.hpp> 51 50 -
trunk/modules/NSCAAgent/NSCAAgent.cpp
r256 r257 72 72 73 73 74 } catch ( NSCModuleHelper::NSCMHExcpetion &e) {74 } catch (nscapi::nscapi_exception &e) { 75 75 NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 76 76 } catch (...) { … … 124 124 socket.recv_iv(password_, encryption_method_, boost::posix_time::seconds(timeout_)); 125 125 socket.send_nsca(packet, boost::posix_time::seconds(timeout_)); 126 return 1;126 return NSCAPI::isSuccess; 127 127 } catch (std::exception &e) { 128 128 NSC_LOG_ERROR_STD(_T("Failed to send data: ") + to_wstring(e.what())); 129 return NSCAPI::hasFailed; 129 130 } catch (...) { 130 131 NSC_LOG_ERROR_STD(_T("Failed to send data: UNKNOWN")); 132 return NSCAPI::hasFailed; 131 133 } 132 134 } -
trunk/modules/NSCAAgent/NSCAAgent.h
r256 r257 23 23 NSC_WRAPPERS_MAIN(); 24 24 25 class NSCAAgent : public NSCModuleHelper::SimpleNotificationHandler {25 class NSCAAgent : public nscapi::impl::SimpleNotificationHandler { 26 26 private: 27 27 … … 59 59 * @return module version 60 60 */ 61 NSCModuleWrapper::module_version getModuleVersion() {62 NSCModuleWrapper::module_version version = {0, 3, 0 };61 nscapi::plugin_wrapper::module_version getModuleVersion() { 62 nscapi::plugin_wrapper::module_version version = {0, 3, 0 }; 63 63 return version; 64 64 } -
trunk/modules/NSCAAgent/stdafx.h
r256 r257 37 37 38 38 #include <NSCAPI.h> 39 #include <NSCHelper.h> 40 #include <nsc_module_wrapper.hpp> 39 #include <nscapi/plugin.hpp> 41 40 #include <config.h> 42 41 #include <utils.h> -
trunk/modules/NSClientListener/NSClientListener.def
r32 r257 11 11 NSHandleCommand 12 12 NSUnloadModule 13 NSGetConfigurationMeta14 13 NSGetModuleDescription 15 14 -
trunk/modules/Scheduler/Scheduler.cpp
r254 r257 40 40 41 41 SETTINGS_REG_KEY_I(scheduler::THREADS); 42 } catch ( NSCModuleHelper::NSCMHExcpetion &e) {42 } catch (nscapi::nscapi_exception &e) { 43 43 NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 44 44 } catch (...) { … … 59 59 bool found = false; 60 60 scheduler::target def = read_defaut_schedule(setting_keys::scheduler::DEFAULT_SCHEDULE_SECTION_PATH); 61 std::list<std::wstring> items = NSCModuleHelper::getSettingsSection(setting_keys::scheduler::SCHEDULES_SECTION_PATH);61 std::list<std::wstring> items = GET_CORE()->getSettingsSection(setting_keys::scheduler::SCHEDULES_SECTION_PATH); 62 62 63 63 for (std::list<std::wstring>::const_iterator cit = items.begin(); cit != items.end(); ++cit) { 64 64 found = true; 65 add_schedule(*cit, NSCModuleHelper::getSettingsString(setting_keys::scheduler::SCHEDULES_SECTION_PATH, *cit, _T("")), def);65 add_schedule(*cit, GET_CORE()->getSettingsString(setting_keys::scheduler::SCHEDULES_SECTION_PATH, *cit, _T("")), def); 66 66 } 67 67 … … 74 74 75 75 } 76 } catch ( NSCModuleHelper::NSCMHExcpetion &e) {76 } catch (nscapi::nscapi_exception &e) { 77 77 NSC_LOG_ERROR_STD(_T("Exception in module Scheduler: ") + e.msg_); 78 78 return false; … … 86 86 scheduler::target Scheduler::read_defaut_schedule(std::wstring path) { 87 87 scheduler::target item; 88 item.channel = NSCModuleHelper::getSettingsString(path, setting_keys::scheduler::CHANNEL_D, setting_keys::scheduler::CHANNEL_D_DEFAULT);89 item.command = NSCModuleHelper::getSettingsString(path, setting_keys::scheduler::COMMAND_D, setting_keys::scheduler::COMMAND_D_DEFAULT);90 std::wstring report = NSCModuleHelper::getSettingsString(path, setting_keys::scheduler::REPORT_MODE_D, setting_keys::scheduler::REPORT_MODE_D_DEFAULT);91 item.report = NSCHelper::report::parse(report);92 std::wstring duration = NSCModuleHelper::getSettingsString(path, setting_keys::scheduler::INTERVAL_D, setting_keys::scheduler::INTERVAL_D_DEFAULT);88 item.channel = GET_CORE()->getSettingsString(path, setting_keys::scheduler::CHANNEL_D, setting_keys::scheduler::CHANNEL_D_DEFAULT); 89 item.command = GET_CORE()->getSettingsString(path, setting_keys::scheduler::COMMAND_D, setting_keys::scheduler::COMMAND_D_DEFAULT); 90 std::wstring report = GET_CORE()->getSettingsString(path, setting_keys::scheduler::REPORT_MODE_D, setting_keys::scheduler::REPORT_MODE_D_DEFAULT); 91 item.report = nscapi::report::parse(report); 92 std::wstring duration = GET_CORE()->getSettingsString(path, setting_keys::scheduler::INTERVAL_D, setting_keys::scheduler::INTERVAL_D_DEFAULT); 93 93 item.duration = boost::posix_time::seconds(strEx::stoui_as_time_sec(duration, 1)); 94 94 return item; … … 99 99 item.alias = alias; 100 100 item.command = command; 101 item.channel = NSCModuleHelper::getSettingsString(detail_path, setting_keys::scheduler::CHANNEL, def.channel);102 item.command = NSCModuleHelper::getSettingsString(detail_path, setting_keys::scheduler::COMMAND, item.command);101 item.channel = GET_CORE()->getSettingsString(detail_path, setting_keys::scheduler::CHANNEL, def.channel); 102 item.command = GET_CORE()->getSettingsString(detail_path, setting_keys::scheduler::COMMAND, item.command); 103 103 104 104 strEx::parse_command(item.command, item.command, item.arguments); 105 105 106 std::wstring report = NSCModuleHelper::getSettingsString(detail_path, setting_keys::scheduler::REPORT_MODE, NSCHelper::report::to_string(def.report));107 item.report = NSCHelper::report::parse(report);108 std::wstring duration = NSCModuleHelper::getSettingsString(detail_path, setting_keys::scheduler::INTERVAL, to_wstring(def.duration.total_seconds()) + _T("s"));106 std::wstring report = GET_CORE()->getSettingsString(detail_path, setting_keys::scheduler::REPORT_MODE, nscapi::report::to_string(def.report)); 107 item.report = nscapi::report::parse(report); 108 std::wstring duration = GET_CORE()->getSettingsString(detail_path, setting_keys::scheduler::INTERVAL, to_wstring(def.duration.total_seconds()) + _T("s")); 109 109 item.duration = boost::posix_time::seconds(strEx::stoui_as_time_sec(duration, 1)); 110 110 scheduler_.add_task(item); … … 124 124 try { 125 125 std::string response; 126 NSCAPI::nagiosReturn code = NSCModuleHelper::InjectCommand(item.command.c_str(), item.arguments, response);127 if ( NSCHelper::report::matches(item.report, code)) {128 NSCModuleHelper::NotifyChannel(item.channel, item.alias, code, response);126 NSCAPI::nagiosReturn code = GET_CORE()->InjectCommand(item.command.c_str(), item.arguments, response); 127 if (nscapi::report::matches(item.report, code)) { 128 GET_CORE()->NotifyChannel(item.channel, item.alias, code, response); 129 129 } 130 } catch ( NSCModuleHelper::NSCMHExcpetion &e) {130 } catch (nscapi::nscapi_exception &e) { 131 131 NSC_LOG_ERROR_STD(_T("Exception handling: ") + item.alias + _T(": ") + e.msg_); 132 132 scheduler_.remove_task(item.id); -
trunk/modules/Scheduler/Scheduler.h
r245 r257 47 47 return _T("Scheduler"); 48 48 } 49 NSCModuleWrapper::module_version getModuleVersion() {50 NSCModuleWrapper::module_version version = {0, 3, 0 };49 nscapi::plugin_wrapper::module_version getModuleVersion() { 50 nscapi::plugin_wrapper::module_version version = {0, 3, 0 }; 51 51 return version; 52 52 } -
trunk/modules/Scheduler/stdafx.h
r229 r257 30 30 31 31 #include <NSCAPI.h> 32 #include <nsc_module_wrapper.hpp> 33 #include <NSCHelper.h> 32 #include <nscapi/plugin.hpp> 34 33 -
trunk/service/CMakeLists.txt
r254 r257 19 19 settings_manager_impl.cpp 20 20 21 ${NSCP_ DEF_PLUGIN_CPP}21 ${NSCP_INCLUDE_PATH}/nscapi/nscapi_helper.cpp 22 22 23 23 ${NSCP_INCLUDE_PATH}/simpleini/ConvertUTF.c 24 24 ${NSCP_INCLUDE_PATH}/b64/b64.c 25 ${NSCP_INCLUDE_PATH}/arrayBuffer.cpp 25 26 26 27 ) … … 62 63 ${NSCP_INCLUDE_PATH}/service/system_service.hpp 63 64 ${NSCP_INCLUDE_PATH}/service/win32_service.hpp 64 65 ${NSCP_DEF_PLUGIN_HPP} 65 ${NSCP_INCLUDE_PATH}/nscapi/nscapi_helper.hpp 66 66 67 67 ) -
trunk/service/NSCPlugin.cpp
r256 r257 23 23 #include "core_api.h" 24 24 25 unsigned int NSCPlugin::last_plugin_id_ = 0;26 27 28 25 /** 29 26 * Default c-tor … … 33 30 * @param file The file (DLL) to load as a NSC plug in. 34 31 */ 35 NSCPlugin::NSCPlugin(const boost::filesystem::wpath file)32 NSCPlugin::NSCPlugin(const unsigned int id, const boost::filesystem::wpath file) 36 33 : module_(file.string()) 37 34 ,fLoadModule(NULL) … … 43 40 ,fDeleteBuffer(NULL) 44 41 ,fGetDescription(NULL) 45 ,fGetConfigurationMeta(NULL)46 42 ,fGetVersion(NULL) 47 43 ,fCommandLineExec(NULL) … … 53 49 ,lastIsMsgPlugin_(false) 54 50 ,broken_(false) 55 ,plugin_id_( 0)51 ,plugin_id_(id) 56 52 { 57 plugin_id_ = ++last_plugin_id_; 53 58 54 } 59 55 /* … … 67 63 ,fHandleMessage(NULL) 68 64 ,fGetDescription(NULL) 69 ,fGetConfigurationMeta(NULL)70 65 ,fGetVersion(NULL) 71 66 ,fCommandLineExec(NULL) … … 361 356 362 357 try { 363 fLoadModule = ( lpLoadModule)module_.load_proc("NSLoadModule");358 fLoadModule = (nscapi::plugin_api::lpLoadModule)module_.load_proc("NSLoadModule"); 364 359 if (!fLoadModule) 365 360 throw NSPluginException(module_, _T("Could not load NSLoadModule")); 366 361 367 fModuleHelperInit = ( lpModuleHelperInit)module_.load_proc("NSModuleHelperInit");362 fModuleHelperInit = (nscapi::plugin_api::lpModuleHelperInit)module_.load_proc("NSModuleHelperInit"); 368 363 if (!fModuleHelperInit) 369 364 throw NSPluginException(module_, _T("Could not load NSModuleHelperInit")); … … 375 370 } 376 371 377 fGetName = ( lpGetName)module_.load_proc("NSGetModuleName");372 fGetName = (nscapi::plugin_api::lpGetName)module_.load_proc("NSGetModuleName"); 378 373 if (!fGetName) 379 374 throw NSPluginException(module_, _T("Could not load NSGetModuleName")); 380 375 381 fGetVersion = ( lpGetVersion)module_.load_proc("NSGetModuleVersion");376 fGetVersion = (nscapi::plugin_api::lpGetVersion)module_.load_proc("NSGetModuleVersion"); 382 377 if (!fGetVersion) 383 378 throw NSPluginException(module_, _T("Could not load NSGetModuleVersion")); 384 379 385 fGetDescription = ( lpGetDescription)module_.load_proc("NSGetModuleDescription");380 fGetDescription = (nscapi::plugin_api::lpGetDescription)module_.load_proc("NSGetModuleDescription"); 386 381 if (!fGetDescription) 387 382 throw NSPluginException(module_, _T("Could not load NSGetModuleDescription")); 388 383 389 fHasCommandHandler = ( lpHasCommandHandler)module_.load_proc("NSHasCommandHandler");384 fHasCommandHandler = (nscapi::plugin_api::lpHasCommandHandler)module_.load_proc("NSHasCommandHandler"); 390 385 if (!fHasCommandHandler) 391 386 throw NSPluginException(module_, _T("Could not load NSHasCommandHandler")); 392 387 393 fHasMessageHandler = ( lpHasMessageHandler)module_.load_proc("NSHasMessageHandler");388 fHasMessageHandler = (nscapi::plugin_api::lpHasMessageHandler)module_.load_proc("NSHasMessageHandler"); 394 389 if (!fHasMessageHandler) 395 390 throw NSPluginException(module_, _T("Could not load NSHasMessageHandler")); 396 391 397 fHandleCommand = ( lpHandleCommand)module_.load_proc("NSHandleCommand");392 fHandleCommand = (nscapi::plugin_api::lpHandleCommand)module_.load_proc("NSHandleCommand"); 398 393 //if (!fHandleCommand) 399 394 // throw NSPluginException(module_, _T("Could not load NSHandleCommand")); 400 395 401 fDeleteBuffer = ( lpDeleteBuffer)module_.load_proc("NSDeleteBuffer");396 fDeleteBuffer = (nscapi::plugin_api::lpDeleteBuffer)module_.load_proc("NSDeleteBuffer"); 402 397 if (!fDeleteBuffer) 403 398 throw NSPluginException(module_, _T("Could not load NSDeleteBuffer")); 404 399 405 fHandleMessage = ( lpHandleMessage)module_.load_proc("NSHandleMessage");400 fHandleMessage = (nscapi::plugin_api::lpHandleMessage)module_.load_proc("NSHandleMessage"); 406 401 if (!fHandleMessage) 407 402 throw NSPluginException(module_, _T("Could not load NSHandleMessage")); 408 403 409 fUnLoadModule = ( lpUnLoadModule)module_.load_proc("NSUnloadModule");404 fUnLoadModule = (nscapi::plugin_api::lpUnLoadModule)module_.load_proc("NSUnloadModule"); 410 405 if (!fUnLoadModule) 411 406 throw NSPluginException(module_, _T("Could not load NSUnloadModule")); 412 407 413 fGetConfigurationMeta = (lpGetConfigurationMeta)module_.load_proc("NSGetConfigurationMeta"); 414 fCommandLineExec = (lpCommandLineExec)module_.load_proc("NSCommandLineExec"); 415 fHandleNotification = (lpHandleNotification)module_.load_proc("NSHandleNotification"); 416 fHasNotificationHandler = (lpHasNotificationHandler)module_.load_proc("NSHasNotificationHandler"); 408 fCommandLineExec = (nscapi::plugin_api::lpCommandLineExec)module_.load_proc("NSCommandLineExec"); 409 fHandleNotification = (nscapi::plugin_api::lpHandleNotification)module_.load_proc("NSHandleNotification"); 410 fHasNotificationHandler = (nscapi::plugin_api::lpHasNotificationHandler)module_.load_proc("NSHasNotificationHandler"); 417 411 418 fShowTray = ( lpShowTray)module_.load_proc("ShowIcon");419 fHideTray = ( lpHideTray)module_.load_proc("HideIcon");412 fShowTray = (nscapi::plugin_api::lpShowTray)module_.load_proc("ShowIcon"); 413 fHideTray = (nscapi::plugin_api::lpHideTray)module_.load_proc("HideIcon"); 420 414 421 415 } catch (NSPluginException &e) { … … 430 424 431 425 432 std::wstring NSCPlugin::getCongifurationMeta()433 {434 wchar_t *buffer = new wchar_t[4097];435 if (!getConfigurationMeta_(buffer, 4096)) {436 throw NSPluginException(module_, _T("Could not get metadata"));437 }438 std::wstring ret = buffer;439 delete [] buffer;440 return ret;441 }442 bool NSCPlugin::getConfigurationMeta_(wchar_t* buf, unsigned int buflen) {443 if (fGetConfigurationMeta == NULL)444 throw NSPluginException(module_, _T("Critical error (getCongifurationMeta)"));445 try {446 return fGetConfigurationMeta(buflen, buf)?true:false;447 } catch (...) {448 throw NSPluginException(module_, _T("Unhandled exception in getConfigurationMeta."));449 }450 }451 452 426 int NSCPlugin::commandLineExec(const unsigned int argLen, wchar_t **arguments) { 453 427 if (fCommandLineExec== NULL) … … 459 433 } 460 434 } 435 -
trunk/service/NSCPlugin.h
r254 r257 25 25 #include <sstream> 26 26 #include <dll/dll.hpp> 27 #include <boost/noncopyable.hpp> 27 28 28 29 /** … … 103 104 * 104 105 */ 105 class NSCPlugin {106 class NSCPlugin : boost::noncopyable { 106 107 private: 107 108 bool bLoaded_; // Status of plug in 108 109 dll::dll module_; 109 110 bool broken_; 110 static unsigned int last_plugin_id_;111 111 unsigned int plugin_id_; 112 112 113 typedef int (*lpModuleHelperInit)(unsigned int, NSCModuleHelper::lpNSAPILoader f); 114 typedef int (*lpLoadModule)(int); 115 typedef int (*lpGetName)(wchar_t*,unsigned int); 116 typedef int (*lpGetDescription)(wchar_t*,unsigned int); 117 typedef int (*lpGetVersion)(int*,int*,int*); 118 typedef int (*lpHasCommandHandler)(); 119 typedef int (*lpHasMessageHandler)(); 120 typedef NSCAPI::nagiosReturn (*lpHandleCommand)(const wchar_t*,const char*,const unsigned int,char**,unsigned int*); 121 typedef int (*lpDeleteBuffer)(char**); 122 typedef int (*lpCommandLineExec)(const unsigned int,wchar_t**); 123 typedef int (*lpHandleMessage)(int,const wchar_t*,const int,const wchar_t*); 124 typedef int (*lpUnLoadModule)(); 125 typedef int (*lpGetConfigurationMeta)(int, wchar_t*); 126 typedef void (*lpShowTray)(); 127 typedef void (*lpHideTray)(); 128 typedef int (*lpHasNotificationHandler)(); 129 typedef int (*lpHandleNotification)(const wchar_t *channel, const wchar_t* command, NSCAPI::nagiosReturn code, char* result, unsigned int result_len); 130 131 132 lpModuleHelperInit fModuleHelperInit; 133 lpLoadModule fLoadModule; 134 lpGetName fGetName; 135 lpGetVersion fGetVersion; 136 lpGetDescription fGetDescription; 137 lpHasCommandHandler fHasCommandHandler; 138 lpHasMessageHandler fHasMessageHandler; 139 lpHandleCommand fHandleCommand; 140 lpDeleteBuffer fDeleteBuffer; 141 lpHandleMessage fHandleMessage; 142 lpUnLoadModule fUnLoadModule; 143 lpGetConfigurationMeta fGetConfigurationMeta; 144 lpCommandLineExec fCommandLineExec; 145 lpShowTray fShowTray; 146 lpHideTray fHideTray; 147 lpHasNotificationHandler fHasNotificationHandler; 148 lpHandleNotification fHandleNotification; 113 nscapi::plugin_api::lpModuleHelperInit fModuleHelperInit; 114 nscapi::plugin_api::lpLoadModule fLoadModule; 115 nscapi::plugin_api::lpGetName fGetName; 116 nscapi::plugin_api::lpGetVersion fGetVersion; 117 nscapi::plugin_api::lpGetDescription fGetDescription; 118 nscapi::plugin_api::lpHasCommandHandler fHasCommandHandler; 119 nscapi::plugin_api::lpHasMessageHandler fHasMessageHandler; 120 nscapi::plugin_api::lpHandleCommand fHandleCommand; 121 nscapi::plugin_api::lpDeleteBuffer fDeleteBuffer; 122 nscapi::plugin_api::lpHandleMessage fHandleMessage; 123 nscapi::plugin_api::lpUnLoadModule fUnLoadModule; 124 nscapi::plugin_api::lpCommandLineExec fCommandLineExec; 125 nscapi::plugin_api::lpShowTray fShowTray; 126 nscapi::plugin_api::lpHideTray fHideTray; 127 nscapi::plugin_api::lpHasNotificationHandler fHasNotificationHandler; 128 nscapi::plugin_api::lpHandleNotification fHandleNotification; 149 129 150 130 public: 151 NSCPlugin(const boost::filesystem::wpath file);152 NSCPlugin(NSCPlugin &other);131 NSCPlugin(const unsigned int id, const boost::filesystem::wpath file); 132 //NSCPlugin(NSCPlugin &other); 153 133 virtual ~NSCPlugin(void); 154 134 … … 192 172 return file; 193 173 } 174 static std::wstring get_plugin_file(std::wstring key) { 175 #ifdef WIN32 176 return key + _T(".dll"); 177 #else 178 return _T("lib") + key + _T(".so"); 179 #endif 180 } 194 181 bool getLastIsMsgPlugin() { 195 182 return lastIsMsgPlugin_; … … 205 192 bool getDescription_(wchar_t* buf, unsigned int buflen); 206 193 void loadRemoteProcs_(void); 207 bool getConfigurationMeta_(wchar_t* buf, unsigned int buflen);208 194 }; 209 195 -
trunk/service/NSClient++.cpp
r256 r257 35 35 #include "settings_manager_impl.h" 36 36 #include <settings/macros.h> 37 #include <NSCHelper.h>38 37 #include "simple_client.hpp" 39 38 #include "settings_client.hpp" 40 39 #include "service_manager.hpp" 40 #include <nscapi/nscapi_helper.hpp> 41 41 42 42 #include "../libs/protobuf/plugin.proto.h" … … 304 304 } else if ( wcscasecmp( _T("about"), argv[1]+1 ) == 0 ) { 305 305 try { 306 unsigned int next_plugin_id = 0; 306 307 g_bConsoleLog = true; 307 308 LOG_MESSAGE(SZAPPNAME _T(" (C) Michael Medin - michael<at>medin<dot>name")); … … 318 319 LOG_MESSAGE_STD(_T("Found: ") + file); 319 320 if (is_module(pluginPath / file)) { 320 NSCPlugin *plugin = new NSCPlugin( pluginPath / file);321 NSCPlugin *plugin = new NSCPlugin(next_plugin_id++, pluginPath / file); 321 322 std::wstring name = _T("<unknown>"); 322 323 std::wstring description = _T("<unknown>"); … … 459 460 try { 460 461 LOG_DEBUG_STD(_T("Attempting to fake load: ") + file.string()); 461 NSCPlugin plugin( pluginPath / file);462 NSCPlugin plugin(next_plugin_id_++, pluginPath / file); 462 463 plugin.load_dll(); 463 464 plugin.load_plugin(NSCAPI::dontStart); … … 490 491 try { 491 492 LOG_DEBUG_STD(_T("Attempting to fake load: ") + file.string()); 492 NSCPlugin plugin( modPath / file);493 NSCPlugin plugin(next_plugin_id_++, modPath / file); 493 494 plugin.load_dll(); 494 495 plugin.load_plugin(mode); … … 504 505 std::wstring name = file.string(); 505 506 try { 506 NSCPlugin plugin( modPath / file);507 NSCPlugin plugin(next_plugin_id_++, modPath / file); 507 508 name = plugin.getModule(); 508 509 plugin.load_dll(); … … 626 627 Settings::string_list list = settings_manager::get_settings()->get_keys(MAIN_MODULES_SECTION); 627 628 for (Settings::string_list::const_iterator cit = list.begin(); cit != list.end(); ++cit) { 628 LOG_DEBUG_STD(_T("Processing plugin: " + *cit)); 629 std::wstring file = NSCPlugin::get_plugin_file(*cit); 630 LOG_DEBUG_STD(_T("Processing plugin: " + *cit) + _T(" in ") + file); 629 631 try { 630 632 if (settings_manager::get_settings()->get_string(MAIN_MODULES_SECTION, *cit) == _T("disabled")) { 631 LOG_DEBUG_STD(_T("Not booting: ") + *cit+ _T(" since it is disabled."));633 LOG_DEBUG_STD(_T("Not booting: ") + file + _T(" since it is disabled.")); 632 634 continue; 633 635 } … … 636 638 } 637 639 try { 638 loadPlugin(getBasePath() / boost::filesystem::wpath(_T("modules")) / boost::filesystem::wpath( *cit));640 loadPlugin(getBasePath() / boost::filesystem::wpath(_T("modules")) / boost::filesystem::wpath(file)); 639 641 } catch(const NSPluginException& e) { 640 642 LOG_ERROR_CORE_STD(_T("Exception raised: '") + e.error_ + _T("' in module: ") + e.file_); 641 643 //return false; 642 644 } catch (std::exception e) { 643 LOG_ERROR_CORE_STD(_T("exception loading plugin: ") + (*cit)+ strEx::string_to_wstring(e.what()));645 LOG_ERROR_CORE_STD(_T("exception loading plugin: ") + file + strEx::string_to_wstring(e.what())); 644 646 return false; 645 647 } catch (...) { 646 LOG_ERROR_CORE_STD(_T("Unknown exception loading plugin: ") + (*cit));648 LOG_ERROR_CORE_STD(_T("Unknown exception loading plugin: ") + file); 647 649 return false; 648 650 } … … 971 973 */ 972 974 NSClientT::plugin_type NSClientT::loadPlugin(const boost::filesystem::wpath file) { 973 plugin_type plugin(new NSCPlugin( file));975 plugin_type plugin(new NSCPlugin(next_plugin_id_++, file)); 974 976 return addPlugin(plugin); 975 977 } … … 1122 1124 } 1123 1125 NSCAPI::nagiosReturn c = plugin->handleCommand(command, request, response); 1124 LOG_DEBUG_STD(_T("Result ") + std::wstring(command) + _T(": ") + NSCHelper::translateReturn(c) + _T(" {{{") + strEx::strip_hex(to_wstring(response)) + _T("}}}"));1126 LOG_DEBUG_STD(_T("Result ") + std::wstring(command) + _T(": ") + nscapi::plugin_helper::translateReturn(c) + _T(" {{{") + strEx::strip_hex(to_wstring(response)) + _T("}}}")); 1125 1127 return c; 1126 1128 } catch (nsclient::commands::command_exception &e) { … … 1201 1203 OutputDebugString(msg.c_str()); 1202 1204 #else 1203 std::wcout << _T("--BROKEN MESSAGE: ") << msg << _T("--") << std::endl;1205 // std::wcout << _T("--BROKEN MESSAGE: ") << msg << _T("--") << std::endl; 1204 1206 #endif 1205 1207 } -
trunk/service/NSClient++.h
r254 r257 123 123 nsclient::commands commands_; 124 124 nsclient::channels channels_; 125 unsigned int next_plugin_id_; 125 126 126 127 127 128 public: 128 129 // c-tor, d-tor 129 NSClientT(void) : debug_(log_unknown), plugins_loaded_(false), enable_shared_session_(false), commands_(this), channels_(this) {}130 NSClientT(void) : debug_(log_unknown), plugins_loaded_(false), enable_shared_session_(false), commands_(this), channels_(this), next_plugin_id_(0) {} 130 131 virtual ~NSClientT(void) {} 131 132 void enableDebug(bool debug = true) { -
trunk/service/commands.hpp
r245 r257 5 5 #include "NSCPlugin.h" 6 6 #include "logger.hpp" 7 #include <strEx.h> 7 8 8 9 namespace nsclient { … … 40 41 41 42 void add_plugin(plugin_type plugin) { 42 if (!plugin || !plugin->hasCommandHandler()) 43 if (!plugin || !plugin->hasCommandHandler()) { 43 44 return; 45 } 44 46 plugins_[plugin->get_id()] = plugin; 45 47 … … 88 90 std::wstring lc = make_key(cmd); 89 91 if (!have_plugin(plugin_id)) 90 throw command_exception("Failed to find plugin: " + ::to_string(plugin_id) );92 throw command_exception("Failed to find plugin: " + ::to_string(plugin_id) + ": " + unsafe_get_all_plugin_ids()); 91 93 descriptions_[lc] = desc; 92 94 commands_[lc] = plugins_[plugin_id]; 93 95 } 96 private: 94 97 98 std::string unsafe_get_all_plugin_ids() { 99 std::string ret; 100 std::pair<unsigned long,plugin_type> cit; 101 BOOST_FOREACH(cit, plugins_) { 102 ret += ::to_string(cit.first) + ", "; 103 //lst.push_back(::to_wstring(cit.first) + _T("=") + cit.second->getName()); 104 //lst.push_back(::to_wstring(cit.first)); 105 } 106 return ret; 107 } 108 109 110 public: 95 111 std::wstring describe(std::wstring command) { 96 112 boost::shared_lock<boost::shared_mutex> readLock(mutex_, boost::get_system_time() + boost::posix_time::seconds(5)); … … 120 136 } 121 137 138 std::list<std::wstring> list_plugins() { 139 std::list<std::wstring> lst; 140 boost::shared_lock<boost::shared_mutex> readLock(mutex_, boost::get_system_time() + boost::posix_time::seconds(5)); 141 if (!readLock.owns_lock()) { 142 log_error(__FILEW__, __LINE__, _T("Failed to get mutex")); 143 return lst; 144 } 145 std::pair<unsigned long,plugin_type> cit; 146 BOOST_FOREACH(cit, plugins_) { 147 //lst.push_back(::to_wstring(cit.first) + _T("=") + cit.second->getName()); 148 lst.push_back(::to_wstring(cit.first)); 149 } 150 return lst; 151 } 152 122 153 plugin_type get(std::wstring command) { 123 154 boost::shared_lock<boost::shared_mutex> readLock(mutex_, boost::get_system_time() + boost::posix_time::seconds(5)); … … 136 167 137 168 std::wstring to_wstring() { 138 std::wstring ret ;169 std::wstring ret = _T("commands {"); 139 170 BOOST_FOREACH(std::wstring str, list()) { 140 171 if (!ret.empty()) ret += _T(", "); 141 172 ret += str; 142 173 } 174 ret += _T("}, plugins {"); 175 BOOST_FOREACH(std::wstring str, list_plugins()) { 176 if (!ret.empty()) ret += _T(", "); 177 ret += str; 178 } 179 ret += _T("}"); 143 180 return ret; 144 181 } -
trunk/service/core_api.cpp
r254 r257 19 19 #include <config.h> 20 20 #include <msvc_wrappers.h> 21 #include <arrayBuffer.h> 21 22 //#include <settings/settings_ini.hpp> 22 23 //#include <settings/settings_registry.hpp> … … 28 29 #include "settings_manager_impl.h" 29 30 #include <b64/b64.h> 30 #include < NSCHelper.h>31 #include <nscapi/nscapi_helper.hpp> 31 32 #ifdef _WIN32 32 33 #include <ServiceCmd.h> … … 34 35 35 36 #define LOG_ERROR_STD(msg) LOG_ERROR(((std::wstring)msg).c_str()) 36 #define LOG_ERROR(msg) \ 37 NSAPIMessage(NSCAPI::error, __FILEW__, __LINE__, msg) 38 37 #define LOG_ERROR(msg) LOG_ANY(msg, NSCAPI::error) 39 38 #define LOG_CRITICAL_STD(msg) LOG_CRITICAL(((std::wstring)msg).c_str()) 40 #define LOG_CRITICAL(msg) \ 41 NSAPIMessage(NSCAPI::critical, __FILEW__, __LINE__, msg) 39 #define LOG_CRITICAL(msg) LOG_ANY(msg, NSCAPI::critical) 42 40 #define LOG_MESSAGE_STD(msg) LOG_MESSAGE(((std::wstring)msg).c_str()) 43 #define LOG_MESSAGE(msg) \ 44 NSAPIMessage(NSCAPI::log, __FILEW__, __LINE__, msg) 45 41 #define LOG_MESSAGE(msg) LOG_ANY(msg, NSCAPI::log) 46 42 #define LOG_DEBUG_STD(msg) LOG_DEBUG(((std::wstring)msg).c_str()) 47 #define LOG_DEBUG(msg) \48 NSAPIMessage(NSCAPI::debug, __FILEW__, __LINE__, msg) 49 43 #define LOG_DEBUG(msg) LOG_ANY(msg, NSCAPI::debug) 44 45 #define LOG_ANY(msg, type) NSAPIMessage(type, __FILEW__, __LINE__, msg) 50 46 51 47 NSCAPI::errorReturn NSAPIGetSettingsString(const wchar_t* section, const wchar_t* key, const wchar_t* defaultValue, wchar_t* buffer, unsigned int bufLen) { 52 48 try { 53 return NSCHelper::wrapReturnString(buffer, bufLen, settings_manager::get_settings()->get_string(section, key, defaultValue), NSCAPI::isSuccess);49 return nscapi::plugin_helper::wrapReturnString(buffer, bufLen, settings_manager::get_settings()->get_string(section, key, defaultValue), NSCAPI::isSuccess); 54 50 } catch (...) { 55 51 LOG_ERROR_STD(_T("Failed to getString: ") + key); … … 66 62 } 67 63 NSCAPI::errorReturn NSAPIGetBasePath(wchar_t*buffer, unsigned int bufLen) { 68 return NSCHelper::wrapReturnString(buffer, bufLen, mainClient.getBasePath().string(), NSCAPI::isSuccess);64 return nscapi::plugin_helper::wrapReturnString(buffer, bufLen, mainClient.getBasePath().string(), NSCAPI::isSuccess); 69 65 } 70 66 NSCAPI::errorReturn NSAPIGetApplicationName(wchar_t*buffer, unsigned int bufLen) { 71 return NSCHelper::wrapReturnString(buffer, bufLen, SZAPPNAME, NSCAPI::isSuccess);67 return nscapi::plugin_helper::wrapReturnString(buffer, bufLen, SZAPPNAME, NSCAPI::isSuccess); 72 68 } 73 69 NSCAPI::errorReturn NSAPIGetApplicationVersionStr(wchar_t*buffer, unsigned int bufLen) { 74 return NSCHelper::wrapReturnString(buffer, bufLen, SZVERSION, NSCAPI::isSuccess);70 return nscapi::plugin_helper::wrapReturnString(buffer, bufLen, SZVERSION, NSCAPI::isSuccess); 75 71 } 76 72 void NSAPIMessage(int msgType, const wchar_t* file, const int line, const wchar_t* message) { … … 262 258 } 263 259 NSCAPI::errorReturn NSAPIDescribeCommand(const wchar_t* command, wchar_t* buffer, unsigned int bufLen) { 264 return NSCHelper::wrapReturnString(buffer, bufLen, mainClient.describeCommand(command), NSCAPI::isSuccess);260 return nscapi::plugin_helper::wrapReturnString(buffer, bufLen, mainClient.describeCommand(command), NSCAPI::isSuccess); 265 261 } 266 262 NSCAPI::errorReturn NSAPIGetAllCommandNames(arrayBuffer::arrayBuffer* aBuffer, unsigned int *bufLen) { … … 369 365 370 366 371 LPVOID NSAPILoader( wchar_t*buffer) {367 LPVOID NSAPILoader(const wchar_t*buffer) { 372 368 if (wcscasecmp(buffer, _T("NSAPIGetApplicationName")) == 0) 373 369 return reinterpret_cast<LPVOID>(&NSAPIGetApplicationName); -
trunk/service/core_api.h
r254 r257 30 30 // 31 31 32 LPVOID NSAPILoader( wchar_t*buffer);32 LPVOID NSAPILoader(const wchar_t*buffer); 33 33 NSCAPI::errorReturn NSAPIGetApplicationName(wchar_t*buffer, unsigned int bufLen); 34 34 NSCAPI::errorReturn NSAPIGetBasePath(wchar_t*buffer, unsigned int bufLen); -
trunk/service/simple_client.hpp
r245 r257 1 1 #pragma once 2 #include <nscapi/nscapi_helper.hpp> 2 3 3 4 class NSClientT; … … 25 26 */ 26 27 std::wstring s = _T(""); 27 std::wstring buff = _T(""); 28 28 29 while (true) { 29 std::wcin >> s; 30 std::wstring s; 31 std::getline(std::wcin, s); 30 32 if (s == _T("exit")) { 31 33 std::wcout << _T("Exiting...") << std::endl; … … 40 42 std::wcout << *cit << _T(": ") << core_->describeCommand(*cit) << std::endl; 41 43 std::wcout << _T("Listing commands...Done") << std::endl; 42 } else if (s == _T(" off") && buff == _T("debug")) {44 } else if (s == _T("debug off")) { 43 45 std::wcout << _T("Setting debug log off...") << std::endl; 44 46 core_->enableDebug(false); 45 } else if (s == _T(" on") && buff == _T("debug")) {47 } else if (s == _T("debug on")) { 46 48 std::wcout << _T("Setting debug log on...") << std::endl; 47 49 core_->enableDebug(true); … … 51 53 } else if (s == _T("assert")) { 52 54 throw "test"; 53 } else if (std::cin.peek() < 15) { 54 buff += s; 55 strEx::token t = strEx::getToken(buff, ' '); 55 } else { 56 strEx::token t = strEx::getToken(s, ' '); 56 57 std::wstring msg, perf; 57 58 NSCAPI::nagiosReturn ret = core_->inject(t.first, t.second, msg, perf); … … 59 60 std::wcout << _T("No handler for command: ") << t.first << std::endl; 60 61 } else { 61 std::wcout << NSCHelper::translateReturn(ret) << _T(":");62 std:: cout << strEx::wstring_to_string(msg);62 std::wcout << nscapi::plugin_helper::translateReturn(ret) << _T(":"); 63 std::wcout << msg; 63 64 if (!perf.empty()) 64 65 std::cout << "|" << strEx::wstring_to_string(perf); 65 66 std::wcout << std::endl; 66 67 } 67 buff = _T("");68 } else {69 buff += s + _T(" ");70 68 } 71 69 }
Note: See TracChangeset
for help on using the changeset viewer.







