Changeset c391984 in nscp
- Timestamp:
- 04/03/11 23:05:52 (2 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- b7d17f8
- Parents:
- 2d69ab6
- Files:
-
- 3 added
- 24 edited
-
CMakeLists.txt (modified) (1 diff)
-
docs/CMakeLists.txt (added)
-
files/CMakeLists.txt (added)
-
files/old-settings.map (modified) (3 diffs)
-
helpers/installers/installer/Product.wxs (modified) (10 diffs)
-
include/config.h.in (modified) (3 diffs)
-
include/nrpe/server/connection.cpp (modified) (2 diffs)
-
include/nrpe/server/ssl_connection.cpp (modified) (2 diffs)
-
include/nscapi/functions.hpp (added)
-
include/nscapi/nscapi_core_wrapper.cpp (modified) (1 diff)
-
include/nscapi/nscapi_plugin_wrapper.hpp (modified) (4 diffs)
-
include/pdh/collectors.hpp (modified) (2 diffs)
-
include/strEx.h (modified) (1 diff)
-
include/unicode_char.hpp (modified) (1 diff)
-
libs/lua/CMakeLists.txt (modified) (1 diff)
-
libs/protobuf/CMakeLists.txt (modified) (1 diff)
-
libs/protobuf/plugin.proto (modified) (1 diff)
-
modules/CheckExternalScripts/CheckExternalScripts.cpp (modified) (2 diffs)
-
modules/CheckExternalScripts/CheckExternalScripts.h (modified) (2 diffs)
-
modules/CheckSystem/CheckSystem.cpp (modified) (2 diffs)
-
modules/CheckSystem/PDHCollector.cpp (modified) (3 diffs)
-
modules/CheckSystem/PDHCollector.h (modified) (2 diffs)
-
modules/NRPEServer/handler_impl.hpp (modified) (1 diff)
-
scripts/CMakeLists.txt (modified) (1 diff)
-
service/NSClient++.cpp (modified) (5 diffs)
-
service/logger.hpp (modified) (1 diff)
-
service/simple_client.hpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
CMakeLists.txt
r197b263 rc391984 390 390 391 391 ADD_SUBDIRECTORY("scripts") 392 ADD_SUBDIRECTORY("files") 393 ADD_SUBDIRECTORY("docs") 392 394 393 395 LOAD_SECTIONS(ALL_MODULE_NAMES "modules/*/module.cmake" "Modules") -
files/old-settings.map
r569a179 rc391984 34 34 log/file=/settings/log/file 35 35 log/date_mask=/settings/log/date mask 36 log/debug=/settings/log/level 36 37 # log/debug 37 38 # log/root_folder … … 48 49 NRPE/command_timeout=/settings/NRPE/server/command timeout 49 50 NRPE/allow_arguments=/settings/NRPE/server/allow arguments 50 NRPE/allow_nasty_meta_chars=/settings/NRPE/server/allow nasty meta chars51 NRPE/allow_nasty_meta_chars=/settings/NRPE/server/allow nasty characters 51 52 NRPE/use_ssl=/settings/NRPE/server/ssl 52 53 # NRPE/script_dir … … 62 63 External Script/command_timeout=/settings/external scripts/command timeout 63 64 External Script/allow_arguments=/settings/external scripts/allow arguments 64 External Script/allow_nasty_meta_chars=/settings/external scripts/allow _nasty_meta_chars65 External Script/allow_nasty_meta_chars=/settings/external scripts/allow nasty characters 65 66 External Script/script_dir=/settings/external scripts/script folder 66 67 -
helpers/installers/installer/Product.wxs
r2d69ab6 rc391984 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <Wix xmlns="http://schemas.microsoft.com/wix/2003/01/wi"> 3 <!-- 4 <?define boost = "false" ?> 5 --> 6 <?ifdef var.boost ?> 7 <?define PlatForm = "$(var.arch)" ?> 8 <?define Mode = "Nightly" ?> 9 <?define SysTray.ConfigurationName = "BOOST BUILD" ?> 10 <?else?> 11 <?if "$(var.SysTray.ConfigurationName)" = "Debug|Win32"?> 12 <?define PlatForm = "Win32" ?> 13 <?define Mode = "Debug" ?> 14 <?elseif "$(var.SysTray.ConfigurationName)" = "Debug|x64"?> 15 <?define PlatForm = "x64" ?> 16 <?define Mode = "Debug" ?> 17 <?elseif "$(var.SysTray.ConfigurationName)" = "Nightly|Win32"?> 18 <?define PlatForm = "Win32" ?> 19 <?define Mode = "Nightly" ?> 20 <?elseif "$(var.SysTray.ConfigurationName)" = "Nightly|x64"?> 21 <?define PlatForm = "x64" ?> 22 <?define Mode = "Nightly" ?> 23 <?else?> 24 <?define PlatForm = "Unknown: plattform" ?> 25 <?endif?> 26 <?endif?> 3 <?define PlatForm = "$(var.arch)" ?> 4 <?define Mode = "Nightly" ?> 5 <?define SysTray.ConfigurationName = "BOOST BUILD" ?> 27 6 28 7 <?if "$(var.PlatForm)" = "x64"?> … … 46 25 <?define Source = "../../$(var.PlatForm)/$(var.Mode)/" ?> 47 26 <?endif?> 48 <!--49 <?ifndef var.Helpers ?>50 <?define Helpers = "../../$(var.PlatForm)/$(var.Mode)-helpers/" ?>51 <?endif?>52 -->53 27 54 28 <?define Version.String = "$(var.Version.Major).$(var.Version.Minor).$(var.Version.Revision).$(var.Version.Build)" ?> … … 105 79 <!-- 106 80 <File Id="NSClientINI" Name="NSC.ini" LongName="NSC.ini" DiskId="1" Source="$(var.Path.ini)/NSC.ini" Vital="yes"/> 107 <?ifdef var.boost ?> 108 <File Id="Changelog" Name="change.log" LongName="changelog.txt" DiskId="1" Source="$(var.Source)/changelog.txt" Vital="no"/> 109 <?else?> 110 <File Id="Changelog" Name="change.log" LongName="changelog.txt" DiskId="1" Source="$(var.Source)/changelog" Vital="no"/> 111 <?endif?> 81 --> 82 <File Id="Changelog" Name="change.log" LongName="changelog.txt" DiskId="1" Source="$(var.Source)/changelog" Vital="no"/> 112 83 <File Id="Counters" Name="counters.def" LongName="counters.defs" DiskId="1" Source="$(var.Source)/counters.defs" Vital="no"/> 113 84 <File Id="License" Name="license.txt" LongName="license.txt" DiskId="1" Source="$(var.Source)/license.txt" Vital="no"/> 114 -->85 115 86 <RemoveFile Id="LogFile1" Name="nsclient.log" On="uninstall" /> 116 87 <RemoveFile Id="LogFile2" Name="nsc.log" On="uninstall" /> … … 121 92 <Component Id="ServiceRegistration" Guid="F6636DB0-A0B9-4dA2-B74C-$(var.Postfix.GUID)" Win64="$(var.Win64)" /> 122 93 <Component Id="Documentation" Guid="9B490E67-5472-4267-889C-$(var.Postfix.GUID)" Win64="$(var.Win64)"> 123 <!-- 124 <File Id="doc.usage.nagios" Name="nagios.pdf" LongName="Nagios Usage Guide.pdf" DiskId="1" Source="$(var.Source)/Nagios Usage Guide.pdf" Vital="no" > 94 <File Id="doc.usage.nagios" Name="nagios.pdf" LongName="Nagios Usage Guide.pdf" DiskId="1" Source="$(var.Source)/docs/Nagios Usage Guide.pdf" Vital="no" > 125 95 <Shortcut Id="Startmenu.doc.nagios" Directory="ProgramMenuDir" Name="nagios" 126 96 LongName="Nagios Usage Guide" WorkingDirectory="INSTALLDIR" Description="Nagios Usage Guide"/> 127 97 </File> 128 <File Id="doc.reference" Name="nsclient.pdf" LongName="NSClient++ Reference Manual.pdf" DiskId="1" Source="$(var.Source)/ NSClient++ Reference Manual.pdf" Vital="no" >98 <File Id="doc.reference" Name="nsclient.pdf" LongName="NSClient++ Reference Manual.pdf" DiskId="1" Source="$(var.Source)/docs/NSClient++ Reference Manual.pdf" Vital="no" > 129 99 <Shortcut Id="Startmenu.doc.ref" Directory="ProgramMenuDir" Name="refman" 130 100 LongName="NSClient++ Reference Manual" WorkingDirectory="INSTALLDIR" Description="NSClient++ Reference Manual"/> 131 101 </File> 132 -->133 102 </Component> 103 <Directory Id="INSTALLLOCATION_SECURITY" Name="security"> 104 <Component Id="NRPEServerCert" Guid="5A0246F8-5167-45db-2E46-$(var.Postfix.GUID)" Win64="$(var.Win64)"> 105 <File Id="NRPECert" Name="nrpe_dh.pem" LongName="nrpe_dh_512.pem" DiskId="1" Source="$(var.Source)/security/nrpe_dh_512.pem" Vital="no"/> 106 </Component> 107 </Directory> 134 108 <Directory Id="INSTALLLOCATION_MODS" Name="modules"> 135 <Component Id="NRPEListener" Guid="5A0246F8-5167-45db-B246-$(var.Postfix.GUID)" Win64="$(var.Win64)"> 136 <!-- 137 <File Id="NRPEListenerDLL" Name="NRPELsnr.dll" LongName="NRPEListener.dll" DiskId="1" Source="$(var.Source)/modules/NRPEListener.dll" Vital="no" /> 109 <Component Id="NRPEServer" Guid="5A0246F8-5167-45db-B246-$(var.Postfix.GUID)" Win64="$(var.Win64)"> 110 <File Id="NRPEListenerDLL" Name="NRPELsnr.dll" LongName="NRPEListener.dll" DiskId="1" Source="$(var.Source)/modules/NRPEServer.dll" Vital="no" /> 138 111 <File Id="NRPEClientDLL" Name="NRPEClnt.dll" LongName="NRPEClient.dll" DiskId="1" Source="$(var.Source)/modules/NRPEClient.dll" Vital="no" /> 139 -->140 112 </Component> 141 113 <Component Id="NSCListener" Guid="6DAF8BB9-9A56-48f5-B2C5-$(var.Postfix.GUID)" Win64="$(var.Win64)"> 142 <!-- 143 <File Id="NSCListenerDLL" Name="NSCLsnr.dll" LongName="NSClientListener.dll" DiskId="1" Source="$(var.Source)/modules/NSClientListener.dll" Vital="no" /> 144 --> 114 <File Id="NSCListenerDLL" Name="NSCLsnr.dll" LongName="NSClientListener.dll" DiskId="1" Source="$(var.Source)/modules/NSClientServer.dll" Vital="no" /> 145 115 </Component> 146 116 <Component Id="NSCA" Guid="8820A304-C596-4393-A72F-$(var.Postfix.GUID)" Win64="$(var.Win64)"> 147 <!--148 117 <File Id="NSCAAgentDLL" Name="NSCAAgnt.dll" LongName="NSCAAgent.dll" DiskId="1" Source="$(var.Source)/modules/NSCAAgent.dll" Vital="no" /> 149 -->118 <File Id="SchedulerDLL" Name="Sched.dll" LongName="Scheduler.dll" DiskId="1" Source="$(var.Source)/modules/Scheduler.dll" Vital="no" /> 150 119 </Component> 151 120 <Component Id="Plugins" Guid="9B490E67-5472-4266-96DC-$(var.Postfix.GUID)" Win64="$(var.Win64)"> … … 160 129 <File Id="ModFileLogger.dll" Name="Logger.dll" LongName="FileLogger.dll" DiskId="1" Source="$(var.Source)/modules/FileLogger.dll" Vital="no" /> 161 130 <File Id="ModLUAScript.dll" Name="LUAScr.dll" LongName="LUAScript.dll" DiskId="1" Source="$(var.Source)/modules/LUAScript.dll" Vital="no" /> 131 <File Id="ModCheckNSCP.dll" Name="CNSCP.dll" LongName="CheckNSCP.dll" DiskId="1" Source="$(var.Source)/modules/CheckNSCP.dll" Vital="no" /> 162 132 <!-- 163 133 <File Id="ModRemoteConfiguration.dll" Name="RmtCfg.dll" LongName="RemoteConfiguration.dll" DiskId="1" Source="$(var.Source)/modules/RemoteConfiguration.dll" Vital="no" /> … … 167 137 <File Id="ModCheckTaskSched.dll" Name="TaskSch.dll" LongName="CheckTaskSched.dll" DiskId="1" Source="$(var.Source)/modules/CheckTaskSched.dll" Vital="no" /> 168 138 <File Id="ModCheckTaskSched2.dll" Name="TaskSch2.dll" LongName="CheckTaskSched2.dll" DiskId="1" Source="$(var.Source)/modules/CheckTaskSched2.dll" Vital="no" /> 169 <File Id="ModCheckNSCP.dll" Name="CNSCP.dll" LongName="CheckNSCP.dll" DiskId="1" Source="$(var.Source)/modules/CheckNSCP.dll" Vital="no" />170 139 </Component> 171 140 </Directory> 172 141 <Directory Id="INSTALLLOCATION_SCRIPTS" Name="scripts"> 173 142 <Component Id="Scripts" Guid="9B490E67-5472-4268-96DF-$(var.Postfix.GUID)" Win64="$(var.Win64)"> 174 <!--175 143 <File Id="script001" Name="c_60s.bat" LongName="check_60s.bat" DiskId="1" Source="$(var.Source)/scripts/check_60s.bat" Vital="no" /> 176 144 <File Id="script002" Name="c_btry.vbs" LongName="check_battery.vbs" DiskId="1" Source="$(var.Source)/scripts/check_battery.vbs" Vital="no" /> … … 182 150 <File Id="sample002" Name="c_test.ps1" LongName="check_test.ps1" DiskId="1" Source="$(var.Source)/scripts/check_test.ps1" Vital="no" /> 183 151 <File Id="sample003" Name="c_test.vbs" LongName="check_test.vbs" DiskId="1" Source="$(var.Source)/scripts/check_test.vbs" Vital="no" /> 152 <!-- 184 153 <File Id="lua001" Name="test.lua" LongName="test.lua" DiskId="1" Source="$(var.Source)/scripts/test.lua" Vital="no" /> 185 154 --> … … 187 156 <Directory Id="INSTALLLOCATION_SCRIPTS_LIB" Name="lib"> 188 157 <Component Id="ScriptLibs" Guid="9B490E67-5472-4267-96DF-$(var.Postfix.GUID)" Win64="$(var.Win64)"> 189 <!--190 158 <File Id="lib001" Name="nagplug.vbs" LongName="NagiosPlugins.vbs" DiskId="1" Source="$(var.Source)/scripts/lib/NagiosPlugins.vbs" Vital="no" /> 191 159 <File Id="lib002" Name="wrapper.vbs" LongName="wrapper.vbs" DiskId="1" Source="$(var.Source)/scripts/lib/wrapper.vbs" Vital="no" /> 192 -->193 160 </Component> 194 161 </Directory> … … 223 190 </Feature> 224 191 <Feature Id="NRPEPlugins" Title="NRPE Support" Description="NRPE Listener Plugin. Support for the more vercitile NRPE protocol (check_nrpe)" Level="1" Absent="disallow"> 225 <ComponentRef Id="NRPEListener" /> 192 <ComponentRef Id="NRPEServer" /> 193 <ComponentRef Id="NRPEServerCert" /> 226 194 </Feature> 227 195 <Feature Id="NSCPlugins" Title="NSClient support" Description="NSClient Listener Plugin. Support for the old NSClient protocol (check_nt)" Level="1" Absent="disallow"> … … 274 242 <Row> 275 243 <Data Column="Id">SVC</Data> 276 <Data Column="ShortName"> NSClientpp</Data>244 <Data Column="ShortName">nscp</Data> 277 245 <Data Column="LongName">$(var.App.Title) ($(var.PlatForm))</Data> 278 246 <Data Column="Description">Monitoring agent for nagios (and others) used to respond to status queries.</Data> 279 247 <Data Column="Component_">ServiceRegistration</Data> 280 <Data Column="Program">[#NSClientEXE] </Data>248 <Data Column="Program">[#NSClientEXE] --service --run --name nscp</Data> 281 249 <Data Column="Dependencies"></Data> 282 250 </Row> -
include/config.h.in
r1f24a1c rc391984 33 33 #endif 34 34 35 #define SZAPPNAME WSTR("NSClient++")35 #define APPLICATION_NAME WSTR("NSClient++") 36 36 37 37 // Version … … 40 40 //#define SZBETATAG " BETA " 41 41 #define _SZVERSION WSTR(STRPRODUCTVER) WSTR(SZBETATAG) WSTR(STRPRODUCTDATE) 42 #define SZVERSION _SZVERSION42 #define CURRENT_SERVICE_VERSION _SZVERSION 43 43 //STRPRODUCTVER SZBETATAG STRPRODUCTDATE 44 44 //FILEVER[0] … … 55 55 56 56 // internal name of the service 57 #define SZSERVICENAME WSTR("NSClientpp")57 #define DEFAULT_SERVICE_NAME WSTR("NSClientpp") 58 58 59 59 // Description of service 60 #define SZSERVICEDESCRIPTION WSTR("Nagios Windows Agent (Provides performance data for Nagios server)")60 #define DEFAULT_SERVICE_DESC WSTR("Windows Monitoring Agent (Provides performance data for monitoring solutions like Nagios)") 61 61 62 62 // displayed name of the service 63 #define S ZSERVICEDISPLAYNAME SZSERVICENAME WSTR(" (Nagios) ") SZVERSION WSTR(" ") SZARCH63 #define SERVICE_NAME SZAPPNAME WSTR(" ") CURRENT_SERVICE_VERSION WSTR(" ") SZARCH 64 64 65 65 // list of service dependencies - "dep1\0dep2\0\0" 66 #define SZDEPENDENCIES _T("")66 #define DEFAULT_SERVICE_DEPS _T("") 67 67 68 68 // Buffer size of incoming data (notice this is the maximum request length!) -
include/nrpe/server/connection.cpp
r1ecd26f rc391984 59 59 60 60 void connection::handle_read_request(const boost::system::error_code& e, std::size_t bytes_transferred) { 61 handler_->log_debug(__FILE__, __LINE__, _T("handle_read data connection"));62 61 if (!e) { 63 62 bool result; … … 99 98 100 99 void connection::handle_write_response(const boost::system::error_code& e) { 101 handler_->log_debug(__FILE__, __LINE__, _T("Written data"));102 100 if (!e) { 103 101 // Initiate graceful connection closure. -
include/nrpe/server/ssl_connection.cpp
r1ecd26f rc391984 22 22 23 23 void ssl_connection::stop() { 24 handler_->log_debug(__FILE__, __LINE__, _T("stopped data connection"));25 24 } 26 25 27 26 void ssl_connection::start() { 28 handler_->log_debug(__FILE__, __LINE__, _T("starting ssl_connection"));29 27 socket_.async_handshake(boost::asio::ssl::stream_base::server, 30 28 strand_.wrap( … … 32 30 ) 33 31 ); 34 handler_->log_debug(__FILE__, __LINE__, _T("starting ssl_connection (started)"));35 32 } 36 33 37 34 void ssl_connection::handle_handshake(const boost::system::error_code& error) { 38 handler_->log_debug(__FILE__, __LINE__, _T("handle_handshake ssl_connection"));39 35 if (!error) 40 36 connection::start(); -
include/nscapi/nscapi_core_wrapper.cpp
r7443b58 rc391984 149 149 } 150 150 ::PluginCommand::Response payload = rsp_msg.payload(0); 151 msg = to_wstring(payload.message()); 152 CORE_LOG_ERROR_STD(_T("Attempting to parse perf data")); 153 perf = to_wstring(::nscapi::functions::build_performance_data(payload)); 154 CORE_LOG_ERROR_STD(_T("Attempting to parse perf data: '") + perf + _T("'")); 151 msg = utf8::cvt<std::wstring>(payload.message()); 152 perf = utf8::cvt<std::wstring>(::nscapi::functions::build_performance_data(payload)); 155 153 } 156 154 return ret; -
include/nscapi/nscapi_plugin_wrapper.hpp
r7443b58 rc391984 33 33 #include <strEx.h> 34 34 #include <nscapi/settings_proxy.hpp> 35 #include <nscapi/functions.hpp> 35 36 36 37 #include "../libs/protobuf/plugin.proto.h" … … 38 39 39 40 using namespace nscp::helpers; 40 41 #ifdef WIN3242 //#include <windows.h>43 #endif44 45 41 46 42 namespace nscapi { … … 96 92 extern helper_singleton* plugin_singleton; 97 93 98 class functions { 99 public: 100 static PluginCommand::Response_Code nagios_to_gpb(int ret) { 101 if (ret == NSCAPI::returnOK) 102 return PluginCommand::Response_Code_OK; 103 if (ret == NSCAPI::returnWARN) 104 return PluginCommand::Response_Code_WARNING; 105 if (ret == NSCAPI::returnCRIT) 106 return PluginCommand::Response_Code_CRITCAL; 107 return PluginCommand::Response_Code_UNKNOWN; 108 } 109 110 static double trim_to_double(std::wstring s) { 111 std::wstring::size_type pend = s.find_first_not_of(_T("0123456789,.")); 112 if (pend != std::wstring::npos) 113 s = s.substr(0,pend); 114 strEx::replace(s, _T(","), _T(".")); 115 return strEx::stod(s); 116 } 117 118 static void parse_performance_data(PluginCommand::Response *resp, std::wstring &perf) { 119 strEx::splitList items = strEx::splitEx(perf, _T(" ")); 120 for (strEx::splitList::const_iterator cit = items.begin(); cit != items.end(); ++cit) { 121 strEx::splitVector items = strEx::splitV(*cit, _T(";")); 122 if (items.size() < 3) 123 break; 124 125 ::PluginCommand::PerformanceData* perfData = resp->add_perf(); 126 perfData->set_type(PluginCommand::PerformanceData_Type_FLOAT); 127 std::pair<std::wstring,std::wstring> fitem = strEx::split(items[0], _T("=")); 128 perfData->set_alias(to_string(fitem.first)); 129 ::PluginCommand::PerformanceData_FloatValue* floatPerfData = perfData->mutable_float_value(); 130 131 std::wstring::size_type pend = fitem.second.find_first_not_of(_T("0123456789,.")); 132 if (pend == std::wstring::npos) { 133 floatPerfData->set_value(trim_to_double(fitem.second.c_str())); 134 } else { 135 floatPerfData->set_value(trim_to_double(fitem.second.substr(0,pend).c_str())); 136 floatPerfData->set_unit(to_string(fitem.second.substr(pend))); 137 } 138 floatPerfData->set_warning(trim_to_double(items[1])); 139 floatPerfData->set_critical(trim_to_double(items[2])); 140 if (items.size() >= 5) { 141 floatPerfData->set_minimum(trim_to_double(items[3])); 142 floatPerfData->set_maximum(trim_to_double(items[4])); 143 } 144 } 145 } 146 static std::string build_performance_data(::PluginCommand::Response &payload) { 147 std::string ret; 148 for (int i=0;i<payload.perf_size();i++) { 149 ::PluginCommand::PerformanceData perfData = payload.perf(i); 150 if (!ret.empty()) 151 ret += " "; 152 ret += perfData.alias() + "="; 153 if (perfData.has_float_value()) { 154 ::PluginCommand::PerformanceData_FloatValue fval = perfData.float_value(); 155 ret += to_string(fval.value()); 156 if (fval.has_unit()) 157 ret += fval.unit(); 158 if (!fval.has_warning()) continue; 159 ret += ";" + to_string(fval.warning()); 160 if (!fval.has_critical()) continue; 161 ret += ";" + to_string(fval.critical()); 162 if (!fval.has_minimum()) continue; 163 ret += ";" + to_string(fval.minimum()); 164 if (!fval.has_maximum()) continue; 165 ret += ";" + to_string(fval.maximum()); 166 } 167 } 168 return ret; 169 } 170 }; 94 171 95 172 96 namespace impl { … … 218 142 public: 219 143 NSCAPI::nagiosReturn handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &response) { 220 221 std::wstring command = char_command; 222 PluginCommand::RequestMessage request_message; 223 request_message.ParseFromString(request); 224 225 if (request_message.payload_size() != 1) { 226 return NSCAPI::returnIgnored; 227 } 228 ::PluginCommand::Request payload = request_message.payload().Get(0); 229 std::list<std::wstring> args; 230 for (int i=0;i<payload.arguments_size();i++) { 231 args.push_back(to_wstring(payload.arguments(i))); 232 } 144 nscapi::functions::decoded_simple_command_data data = nscapi::functions::process_simple_command_request(char_command, request); 233 145 std::wstring msg, perf; 234 NSCAPI::nagiosReturn ret = handleCommand(command, args, msg, perf); 235 236 PluginCommand::ResponseMessage response_message; 237 ::PluginCommand::Header* hdr = response_message.mutable_header(); 238 239 hdr->set_type(PluginCommand::Header_Type_RESPONSE); 240 hdr->set_version(PluginCommand::Header_Version_VERSION_1); 241 242 PluginCommand::Response *resp = response_message.add_payload(); 243 resp->set_command(to_string(command)); 244 resp->set_message(to_string(msg)); 245 ::nscapi::functions::parse_performance_data(resp, perf); 246 247 resp->set_version(PluginCommand::Response_Version_VERSION_1); 248 resp->set_result(nscapi::functions::nagios_to_gpb(ret)); 249 response_message.SerializeToString(&response); 250 return ret; 146 NSCAPI::nagiosReturn ret = handleCommand(data.command, data.args, msg, perf); 147 return nscapi::functions::process_simple_command_result(data.command, ret, msg, perf, response); 251 148 } 252 149 -
include/pdh/collectors.hpp
r1ecd26f rc391984 283 283 public: 284 284 RoundINTPDHBufferListenerImpl() : buffer(NULL), length(0), current(0), hasValue_(false), parent_(NULL) {} 285 RoundINTPDHBufferListenerImpl(int length_) : length(length_), current(0), hasValue_(false), parent_(NULL) { 286 PDHCounterMutexHandler mutex(&mutex_); 287 if (!mutex.hasLock()) 288 return; 289 buffer = new TType[length]; 290 for (unsigned int i=0; i<length;i++) 291 buffer[i] = 0; 285 RoundINTPDHBufferListenerImpl(int length_) : buffer(NULL), length(0), current(0), hasValue_(false), parent_(NULL) { 286 resize(length_); 292 287 } 293 288 virtual ~RoundINTPDHBufferListenerImpl() { … … 343 338 if (!hasValue_) 344 339 throw PDHException(get_name(), _T("No value has been collected yet")); 345 if ((backItems == 0) || (backItems >= length)) 346 throw PDHException(get_name(), _T("Strange error buffer pointers are f*cked up")); 340 if (backItems == 0) 341 throw PDHException(get_name(), _T("No timeframe given on command line (ie. time=0)")); 342 if (backItems >= length) 343 throw PDHException(get_name(), _T("Length given larger then interval: ") + strEx::itos(backItems) + _T(" >= ") + strEx::itos(length)); 347 344 double ret = 0; 348 345 if (current >= backItems) { -
include/strEx.h
r1f24a1c rc391984 850 850 } 851 851 852 852 namespace utf8 { 853 /** Converts a std::wstring into a std::string with UTF-8 encoding. */ 854 template<typename StringT> 855 StringT cvt(std::wstring const & string); 856 857 /** Converts a std::String with UTF-8 encoding into a std::wstring. */ 858 template<typename StringT> 859 StringT cvt(std::string const & string ); 860 861 /** Nop specialization for std::string. */ 862 template <> 863 inline std::string cvt(std::string const & string) { 864 return string; 865 } 866 867 /** Nop specialization for std::wstring. */ 868 template<> 869 inline std::wstring cvt(std::wstring const & rc_string) { 870 return rc_string; 871 } 872 873 template<> 874 inline std::string cvt(std::wstring const & str) { 875 // figure out how many narrow characters we are going to get 876 int nChars = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), str.length(), NULL, 0, NULL, NULL); 877 if (nChars == 0) 878 return ""; 879 880 // convert the wide string to a narrow string 881 // nb: slightly naughty to write directly into the string like this 882 std::string buf; 883 buf.resize(nChars); 884 WideCharToMultiByte(CP_UTF8, 0, str.c_str(), str.length(), const_cast<char*>(buf.c_str()), nChars, NULL, NULL); 885 return buf ; 886 } 887 888 template<> 889 inline std::wstring cvt(std::string const & str) { 890 // figure out how many wide characters we are going to get 891 int nChars = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), NULL, 0); 892 if (nChars == 0) 893 return L""; 894 895 // convert the narrow string to a wide string 896 // nb: slightly naughty to write directly into the string like this 897 std::wstring buf; 898 buf.resize(nChars); 899 MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), const_cast<wchar_t*>(buf.c_str()), nChars); 900 return buf; 901 } 902 } -
include/unicode_char.hpp
r7f9c823 rc391984 10 10 11 11 #endif 12 13 #include <unicode/ustring.h> -
libs/lua/CMakeLists.txt
r1f24a1c rc391984 9 9 SET(HAVE_LUA TRUE) 10 10 SET(LUA_SOURCE_DIR ${LUA_INCLUE_DIR}) 11 ELSE (LUA_ SOURCE_DIR)11 ELSE (LUA_INCLUE_DIR) 12 12 message(STATUS "Lua was not found in ${LUA_SOURCE_DIR} (LUA_SOURCE_DIR)") 13 ENDIF (LUA_ SOURCE_DIR)13 ENDIF (LUA_INCLUE_DIR) 14 14 ENDIF (HAVE_LUA) 15 15 -
libs/protobuf/CMakeLists.txt
r1ecd26f rc391984 9 9 10 10 SET(SRCS 11 plugin.proto 12 log.proto 13 11 14 ${PROTO_PLUGIN_SRC} 12 15 ${PROTO_LOG_SRC} -
libs/protobuf/plugin.proto
r8988f9e rc391984 82 82 required Code result = 9; 83 83 required string message = 10; 84 repeated PerformanceData perf = 11; 84 optional string legacyPerf = 11; 85 repeated PerformanceData perf = 12; 85 86 86 87 } -
modules/CheckExternalScripts/CheckExternalScripts.cpp
r7443b58 rc391984 135 135 } 136 136 137 138 NSCAPI::nagiosReturn CheckExternalScripts::handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 139 command_list::const_iterator cit = commands.find(command); 137 NSCAPI::nagiosReturn CheckExternalScripts::handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &response) { 138 nscapi::functions::decoded_simple_command_data data = nscapi::functions::process_simple_command_request(char_command, request); 139 140 command_list::const_iterator cit = commands.find(data.command); 140 141 bool isAlias = false; 141 142 if (cit == commands.end()) { 142 cit = alias.find( command);143 cit = alias.find(data.command); 143 144 if (cit == alias.end()) 144 145 return NSCAPI::returnIgnored; … … 147 148 148 149 const command_data cd = (*cit).second; 149 std::wstring args = cd.arguments; 150 std::list<std::wstring> args = cd.arguments; 151 bool first = true; 150 152 if (isAlias || allowArgs_) { 151 int i=1; 152 BOOST_FOREACH(std::wstring str, arguments) { 153 if (!isAlias && !allowNasty_) { 154 if (str.find_first_of(NASTY_METACHARS) != std::wstring::npos) { 155 NSC_LOG_ERROR(_T("Request string contained illegal metachars!")); 156 return NSCAPI::returnIgnored; 153 BOOST_FOREACH(std::wstring &arg, args) { 154 int i=1; 155 BOOST_FOREACH(std::wstring str, data.args) { 156 if (first && !isAlias && !allowNasty_) { 157 if (str.find_first_of(NASTY_METACHARS) != std::wstring::npos) { 158 return nscapi::functions::process_simple_command_result(data.command, NSCAPI::returnUNKNOWN, _T("Request contained illegal characters!"), _T(""), response); 159 } 157 160 } 161 strEx::replace(arg, _T("$ARG") + strEx::itos(i++) + _T("$"), str); 158 162 } 159 strEx::replace(args, _T("$ARG") + strEx::itos(i++) + _T("$"), str); 160 } 161 } 163 } 164 } 165 166 167 std::wstring xargs; 168 BOOST_FOREACH(std::wstring s, args) { 169 if (!xargs.empty()) 170 xargs += _T(" "); 171 xargs += s; 172 } 173 174 NSC_LOG_MESSAGE(_T("Arguments: ") + xargs); 175 176 162 177 if (isAlias) { 178 std::wstring message; 163 179 try { 164 return GET_CORE()->Inject SplitAndCommand(cd.command, args, ' ', message, perf, true);180 return GET_CORE()->InjectCommand(cd.command, args, response); 165 181 } catch (boost::escaped_list_error &e) { 166 182 NSC_LOG_MESSAGE(_T("Failed to parse alias expression: ") + strEx::string_to_wstring(e.what())); 167 183 NSC_LOG_MESSAGE(_T("We will now try parsing the old syntax instead...")); 168 return GET_CORE()->Inject SplitAndCommand(cd.command, args, ' ', message, perf, false);184 return GET_CORE()->InjectCommand(cd.command, args, response); 169 185 } 170 186 } else { 171 int result = process::executeProcess(process::exec_arguments(root_, cd.command + _T(" ") + args, timeout), message, perf); 187 std::wstring message, perf; 188 int result = process::executeProcess(process::exec_arguments(root_, cd.command + _T(" ") + xargs, timeout), message, perf); 172 189 if (!nscapi::plugin_helper::isNagiosReturnCode(result)) { 173 NSC_LOG_ERROR_STD(_T("The command (") + cd.command + _T(") returned an invalid return code: ") + strEx::itos(result)); 174 return NSCAPI::returnUNKNOWN; 175 } 176 return nscapi::plugin_helper::int2nagios(result); 177 } 178 179 } 190 return nscapi::functions::process_simple_command_result(data.command, NSCAPI::returnUNKNOWN, _T("The command (") + cd.command + _T(") returned an invalid return code: ") + strEx::itos(result), _T(""), response); 191 } 192 return nscapi::functions::process_simple_command_result(data.command, nscapi::plugin_helper::int2nagios(result), message, perf, response); 193 } 194 } 195 // 196 // 197 // 198 // std::wstring msg, perf; 199 // NSCAPI::nagiosReturn ret = handleCommand(data.command, data.args, msg, perf); 200 // return nscapi::functions::process_simple_command_result(data.command, ret, msg, perf); 201 // } 202 // 203 // NSCAPI::nagiosReturn CheckExternalScripts::handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 204 // command_list::const_iterator cit = commands.find(command); 205 // bool isAlias = false; 206 // if (cit == commands.end()) { 207 // cit = alias.find(command); 208 // if (cit == alias.end()) 209 // return NSCAPI::returnIgnored; 210 // isAlias = true; 211 // } 212 // 213 // const command_data cd = (*cit).second; 214 // std::wstring args = cd.arguments; 215 // if (isAlias || allowArgs_) { 216 // int i=1; 217 // BOOST_FOREACH(std::wstring str, arguments) { 218 // if (!isAlias && !allowNasty_) { 219 // if (str.find_first_of(NASTY_METACHARS) != std::wstring::npos) { 220 // NSC_LOG_ERROR(_T("Request string contained illegal metachars!")); 221 // return NSCAPI::returnIgnored; 222 // } 223 // } 224 // strEx::replace(args, _T("$ARG") + strEx::itos(i++) + _T("$"), str); 225 // } 226 // } 227 // if (isAlias) { 228 // try { 229 // return GET_CORE()->InjectSplitAndCommand(cd.command, args, ' ', message, perf, true); 230 // } catch (boost::escaped_list_error &e) { 231 // NSC_LOG_MESSAGE(_T("Failed to parse alias expression: ") + strEx::string_to_wstring(e.what())); 232 // NSC_LOG_MESSAGE(_T("We will now try parsing the old syntax instead...")); 233 // return GET_CORE()->InjectSplitAndCommand(cd.command, args, ' ', message, perf, false); 234 // } 235 // } else { 236 // int result = process::executeProcess(process::exec_arguments(root_, cd.command + _T(" ") + args, timeout), message, perf); 237 // if (!nscapi::plugin_helper::isNagiosReturnCode(result)) { 238 // NSC_LOG_ERROR_STD(_T("The command (") + cd.command + _T(") returned an invalid return code: ") + strEx::itos(result)); 239 // return NSCAPI::returnUNKNOWN; 240 // } 241 // return nscapi::plugin_helper::int2nagios(result); 242 // } 243 // 244 // } 180 245 181 246 -
modules/CheckExternalScripts/CheckExternalScripts.h
r7443b58 rc391984 25 25 #include <execute_process.hpp> 26 26 27 class CheckExternalScripts : public nscapi::impl:: SimpleCommand, nscapi::impl::simple_plugin {27 class CheckExternalScripts : public nscapi::impl::simple_plugin { 28 28 private: 29 29 struct command_data { 30 30 command_data() {} 31 command_data(std::wstring command_, std::wstring arguments_) : command(command_), arguments(arguments_) {} 31 command_data(std::wstring command_, std::wstring arguments_) : command(command_) { 32 parser_arguments(arguments_); 33 } 34 void parser_arguments(std::wstring args) { 35 boost::tokenizer<boost::escaped_list_separator<wchar_t>, std::wstring::const_iterator, std::wstring> 36 tok(args, boost::escaped_list_separator<wchar_t>(L'\\', L' ', L'\"')); 37 BOOST_FOREACH(std::wstring s, tok) { 38 arguments.push_back(s); 39 } 40 } 41 std::wstring get_argument() { 42 std::wstring args; 43 BOOST_FOREACH(std::wstring s, arguments) { 44 if (!args.empty()) 45 args += _T(" "); 46 args += s; 47 } 48 return args; 49 } 50 32 51 std::wstring command; 33 std:: wstringarguments;52 std::list<std::wstring> arguments; 34 53 std::wstring to_string() { 35 return command + _T("(") + arguments + _T(")"); 54 std::wstring args; 55 BOOST_FOREACH(std::wstring s, arguments) { 56 if (!args.empty()) 57 args += _T(" "); 58 args += s; 59 } 60 return command + _T("(") + get_argument() + _T(")"); 36 61 } 37 62 }; … … 68 93 bool hasCommandHandler(); 69 94 bool hasMessageHandler(); 70 NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 95 NSCAPI::nagiosReturn handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &response); 96 //NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 71 97 std::wstring getConfigurationMeta(); 72 98 -
modules/CheckSystem/CheckSystem.cpp
r7443b58 rc391984 66 66 bool CheckSystem::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 67 67 PDHCollector::system_counter_data *data = new PDHCollector::system_counter_data; 68 data->check_intervall = 10 ;68 data->check_intervall = 100; 69 69 try { 70 70 typedef std::map<std::wstring,std::wstring> counter_map_type; … … 91 91 92 92 settings.alias().add_key_to_settings() 93 (_T("default"), sh::bool_key(&default_counters, true), 94 _T("HOSTNAME"), _T("The host name of this host if set to blank (default) the windows name of the computer will be used.")) 93 (_T("default"), sh::bool_key(&default_counters, true), 94 _T("DEFAULT COUNTERS"), _T("Load the default counters: ") PDH_SYSTEM_KEY_CPU _T(", ") PDH_SYSTEM_KEY_MCB _T(", ") PDH_SYSTEM_KEY_MCL _T(" and ") PDH_SYSTEM_KEY_UPT _T(" If not you need to specify these manually. ") ) 95 96 (_T("default"), sh::bool_key(&default_counters, true), 97 _T("DEFAULT COUNTERS"), _T("Load the default counters: ") PDH_SYSTEM_KEY_CPU _T(", ") PDH_SYSTEM_KEY_MCB _T(", ") PDH_SYSTEM_KEY_MCL _T(" and ") PDH_SYSTEM_KEY_UPT _T(" If not you need to specify these manually. ") ) 98 99 (_T("default buffer length"), sh::wstring_key(&data->buffer_length, _T("1h")), 100 _T("DEFAULT INTERVALL"), _T("Used to define the default intervall for range buffer checks (ie. CPU).")) 95 101 // 96 102 // (_T("hostname cache"), sh::bool_key(&cacheNscaHost_), -
modules/CheckSystem/PDHCollector.cpp
r7443b58 rc391984 46 46 return boost::shared_ptr<PDHCollectors::PDHCollector>(new PDHCollectors::StaticPDHCounterListener<__int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex>); 47 47 } else if (data_type == type_int64 && data_format == format_large && collection_strategy == rrd) { 48 return boost::shared_ptr<PDHCollectors::PDHCollector>(new PDHCollectors::RoundINTPDHBufferListener<__int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex>(get_buffer_length(check_intervall))); 48 unsigned int buffer_size = get_buffer_length(check_intervall); 49 return boost::shared_ptr<PDHCollectors::PDHCollector>(new PDHCollectors::RoundINTPDHBufferListener<__int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex>(buffer_size)); 49 50 } 50 51 return boost::shared_ptr<PDHCollectors::PDHCollector>(); … … 76 77 77 78 check_intervall_ = data->check_intervall; 79 std::wstring default_buffer_length = data->buffer_length; 78 80 PDH::PDHQuery pdh; 79 81 bool bInit = true; … … 91 93 try { 92 94 NSC_DEBUG_MSG_STD(_T("Loading counter: ") + c.alias + _T(" = ") + c.path); 95 c.set_default_buffer_size(default_buffer_length); 93 96 collector_ptr collector = c.create(check_intervall_); 94 97 if (collector) { -
modules/CheckSystem/PDHCollector.h
r7443b58 rc391984 84 84 85 85 boost::shared_ptr<PDHCollectors::PDHCollector> create(int check_intervall); 86 void set_default_buffer_size(std::wstring buffer_size_) { 87 buffer_size = buffer_size_; 88 } 86 89 87 90 int get_buffer_length(int check_intervall) { … … 100 103 }; 101 104 102 int check_intervall; 105 unsigned int check_intervall; 106 std::wstring buffer_length; 103 107 104 108 std::list<counter> counters; -
modules/NRPEServer/handler_impl.hpp
r1ecd26f rc391984 34 34 virtual void set_perf_data(bool v) { 35 35 noPerfData_ = !v; 36 if (noPerfData_) 37 log_debug(__FILE__, __LINE__, _T("Performance data disabled!")); 36 38 } 37 39 -
scripts/CMakeLists.txt
r87cf3c4 rc391984 8 8 SET(script_ALL ${scripts_BAT} ${scripts_VBS} ${scripts_PS1}) 9 9 10 INSTALL(FILES ${script_ALL} DESTINATION "scripts") 11 INSTALL(FILES ${scripts_LIB} DESTINATION "scripts/lib") 10 MESSAGE(STATUS "Copying script:") 11 FOREACH(file ${script_ALL}) 12 get_filename_component(filename ${file} NAME) 13 MESSAGE(STATUS " + ${filename}") 14 FILE(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/scripts) 15 ENDFOREACH(file ${script_ALL}) 12 16 17 18 FOREACH(file ${scripts_LIB}) 19 get_filename_component(filename ${file} NAME) 20 MESSAGE(STATUS " + lib - ${filename}") 21 FILE(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/scripts/lib) 22 ENDFOREACH(file ${scripts_LIB}) -
service/NSClient++.cpp
r2d69ab6 rc391984 39 39 #include "service_manager.hpp" 40 40 #include <nscapi/nscapi_helper.hpp> 41 #include <nscapi/functions.hpp> 42 41 43 #include <settings/client/settings_client.hpp> 42 44 #include "cli_parser.hpp" … … 238 240 { 239 241 srand( (unsigned)time( NULL ) ); 240 241 242 cli_parser parser(&mainClient); 242 243 if (argc > 0) { 244 LOG_INFO_CORE(_T("Got arguments on command line")); 245 for (int i=0;i<argc;i++) { 246 LOG_INFO_CORE((std::wstring)_T("arg: ") + argv[i]); 247 } 248 } else { 249 LOG_INFO_CORE(_T("Got NO arguments on command line")); 250 } 251 parser.parse(argc, argv); 252 253 return -1; 243 return parser.parse(argc, argv); 254 244 255 245 int nRetCode = 0; … … 1043 1033 return NSCAPI::returnUNKNOWN; 1044 1034 } 1045 msg = to_wstring(rsp_msg.payload(0).message()); 1035 msg = utf8::cvt<std::wstring>(rsp_msg.payload(0).message()); 1036 perf = utf8::cvt<std::wstring>(nscapi::functions::build_performance_data(rsp_msg.payload(0))); 1046 1037 if ( (ret == NSCAPI::returnInvalidBufferLen) || (ret == NSCAPI::returnIgnored) ) { 1047 1038 return ret; … … 1066 1057 std::wstring cmd = nsclient::commands::make_key(raw_command); 1067 1058 if (logDebug()) { 1068 LOG_DEBUG_CORE_STD(_T("Injecting: ") + cmd + _T(" : {{{") + strEx::strip_hex(to_wstring(request)) + _T("}}}"));1059 LOG_DEBUG_CORE_STD(_T("Injecting: ") + cmd + _T("...")); 1069 1060 } 1070 1061 /*if (shared_client_.get() != NULL && shared_client_->hasMaster()) { … … 1096 1087 } 1097 1088 NSCAPI::nagiosReturn c = plugin->handleCommand(cmd.c_str(), request, response); 1098 LOG_DEBUG_CORE_STD(_T("Result ") + cmd + _T(": ") + nscapi::plugin_helper::translateReturn(c) + _T(" {{{") + strEx::strip_hex(to_wstring(response)) + _T("}}}"));1089 LOG_DEBUG_CORE_STD(_T("Result ") + cmd + _T(": ") + nscapi::plugin_helper::translateReturn(c)); 1099 1090 return c; 1100 1091 } catch (nsclient::commands::command_exception &e) { -
service/logger.hpp
r2d69ab6 rc391984 49 49 msg->set_file(file); 50 50 msg->set_line(line); 51 msg->set_message( to_string(logMessage));51 msg->set_message(utf8::cvt<std::string>(logMessage)); 52 52 if (!message.SerializeToString(&str)) { 53 53 return "Failed to generate message"; -
service/simple_client.hpp
r2d69ab6 rc391984 8 8 public: 9 9 simple_client(NSClient *core) : core_(core) {} 10 11 void log(std::wstring msg) { 12 std::string s = nsclient::logger_helper::create_info(__FILE__, __LINE__, msg); 13 core_->reportMessage(s); 14 } 10 15 void start() { 11 16 core_->enableDebug(true); … … 64 69 NSCAPI::nagiosReturn ret = core_->inject(t.first, t.second, msg, perf); 65 70 if (ret == NSCAPI::returnIgnored) { 66 std::wcout << _T("No handler for command: ") << t.first << std::endl;71 log(_T("No handler for command: ") + t.first); 67 72 } else { 68 std::wcout << nscapi::plugin_helper::translateReturn(ret) << _T(":"); 69 std::wcout << msg; 73 log(nscapi::plugin_helper::translateReturn(ret) + _T(":") + msg); 70 74 if (!perf.empty()) 71 std::cout << "|" << strEx::wstring_to_string(perf); 72 std::wcout << std::endl; 75 log(_T(" Perfoamcen data: ") + perf); 73 76 } 74 77 }
Note: See TracChangeset
for help on using the changeset viewer.








