Changeset 2906cda in nscp
- Timestamp:
- 02/13/12 22:50:59 (16 months ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- c710cc7
- Parents:
- 76540c3
- Files:
-
- 7 edited
-
changelog (modified) (1 diff)
-
helpers/installers/installer/Product.wxs (modified) (3 diffs)
-
modules/DistributedClient/DistributedClient.cpp (modified) (10 diffs)
-
modules/DistributedClient/DistributedClient.h (modified) (6 diffs)
-
modules/NSCPClient/NSCPClient.h (modified) (1 diff)
-
version.hpp (modified) (1 diff)
-
version.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
changelog
r76540c3 r2906cda 2 2 * Process times and similar ? 3 3 * Fix configuration GUI (low priority) 4 * Add API for rehashing the daemon (or implement it the API is there but does nothing)5 4 * Fixa dependonservice LanManWorkStation (old win) 6 5 * Fix RtlStringFromGUID problem on NT4 6 7 2012-02-13 MickeM 8 * Fixed installer issue (could not start service) 7 9 8 10 2012-02-12 MickeM -
helpers/installers/installer/Product.wxs
rf7a074d r2906cda 43 43 <Shortcut Id="StartmenuNSClientTest" Directory="ProgramMenuDir" 44 44 Name="$(var.App.Title) ($(var.arch), test)" WorkingDirectory="INSTALLDIR" Icon="nscp.exe" 45 Advertise="yes" IconIndex="0" Arguments=" --test" Description="Run $(var.App.Title) in test mode" />45 Advertise="yes" IconIndex="0" Arguments="test" Description="Run $(var.App.Title) in test mode" /> 46 46 <fire:FirewallException Id="FWX1" Name="NSClient++ Monitoring Agent" Scope="any" IgnoreFailure="yes" /> 47 47 </File> … … 50 50 Type="ownProcess" Start="auto" ErrorControl="normal" Interactive="no" 51 51 Description="Monitoring agent for nagios (and others) used to respond to status queries" 52 Arguments=" --service --run --name [SERVICE_NAME]" />52 Arguments="service --run --name [SERVICE_NAME]" /> 53 53 <ServiceControl Id="StartSWCNSCP" Name="[SERVICE_NAME]" Start="install" Stop="both" Wait="yes" Remove="uninstall" /> 54 54 <RemoveFolder Id="RemoveMenuShortcuts" Directory="ProgramMenuDir" On="uninstall" /> … … 57 57 <Shortcut Id="StartmenuNSClientStart" Directory="ProgramMenuDir" Name="Start $(var.App.Title) ($(var.arch))" 58 58 WorkingDirectory='INSTALLDIR' Icon="nscp.exe" IconIndex="0" 59 Arguments=" --service --name [SERVICE_NAME] --start" Description="Start the $(var.App.Title) service" />59 Arguments="service --name [SERVICE_NAME] --start" Description="Start the $(var.App.Title) service" /> 60 60 <Shortcut Id="StartmenuNSClientStop" Directory="ProgramMenuDir" Name="Stop $(var.App.Title) ($(var.arch))" 61 61 WorkingDirectory='INSTALLDIR' Icon="nscp.exe" IconIndex="0" 62 Arguments=" --service --name [SERVICE_NAME] --stop" Description="Stop the $(var.App.Title) service" />62 Arguments="service --name [SERVICE_NAME] --stop" Description="Stop the $(var.App.Title) service" /> 63 63 <Shortcut Id="StarmentNSCHelp" Directory="ProgramMenuDir" Name="Documentation" 64 64 Target="[HELP_LINK]" Icon="doc.ico" -
modules/DistributedClient/DistributedClient.cpp
rba63b95 r2906cda 35 35 namespace sh = nscapi::settings_helper; 36 36 37 const std::wstring DistributedClient::command_prefix = _T("dnscp"); 37 38 /** 38 39 * Default c-tor … … 59 60 std::map<std::wstring,std::wstring> commands; 60 61 61 std::wstring certificate;62 unsigned int timeout = 30, buffer_length = 1024;63 bool use_ssl = true;64 62 try { 65 63 66 register_command(_T("query_dist"), _T("Submit a query to a remote host via NSCP"));67 register_command(_T("submit_dist"), _T("Submit a query to a remote host via NSCP"));68 register_command(_T("exec_dist"), _T("Execute remote command on a remote host via NSCP"));69 64 70 65 sh::settings_registry settings(get_settings_proxy()); … … 89 84 ; 90 85 91 settings.alias().add_key_to_settings(_T("targets/default"))92 93 (_T("timeout"), sh::uint_key(&timeout, 30),94 _T("TIMEOUT"), _T("Timeout when reading/writing packets to/from sockets."))95 96 (_T("use ssl"), sh::bool_key(&use_ssl, true),97 _T("ENABLE SSL ENCRYPTION"), _T("This option controls if SSL should be enabled."))98 99 (_T("certificate"), sh::wpath_key(&certificate, _T("${certificate-path}/nrpe_dh_512.pem")),100 _T("SSL CERTIFICATE"), _T(""))101 102 (_T("payload length"), sh::uint_key(&buffer_length, 1024),103 _T("PAYLOAD LENGTH"), _T("Length of payload to/from the NRPE agent. This is a hard specific value so you have to \"configure\" (read recompile) your NRPE agent to use the same value for it to work."))104 ;105 106 86 settings.register_all(); 107 87 settings.notify(); 108 88 89 targets.add_missing(get_settings_proxy(), target_path, _T("default"), _T(""), true); 90 91 109 92 get_core()->registerSubmissionListener(get_id(), channel_); 110 111 if (!targets.has_target(_T("default"))) { 112 add_target(_T("default"), _T("default")); 113 targets.rebuild(); 114 } 115 nscapi::target_handler::optarget t = targets.find_target(_T("default")); 116 if (t) { 117 if (!t->has_option("certificate")) 118 t->options[_T("certificate")] = certificate; 119 if (!t->has_option("timeout")) 120 t->options[_T("timeout")] = strEx::itos(timeout); 121 if (!t->has_option("payload length")) 122 t->options[_T("payload length")] = strEx::itos(buffer_length); 123 if (!t->has_option("ssl")) 124 t->options[_T("ssl")] = use_ssl?_T("true"):_T("false"); 125 targets.add(*t); 126 } else { 127 NSC_LOG_ERROR(_T("Default target not found!")); 128 } 93 register_command(_T("dnscp_query"), _T("Submit a query to a remote host via NSCP")); 94 register_command(_T("dnscp_forward"), _T("Forward query to remote NSCP host")); 95 register_command(_T("dnscp_submit"), _T("Submit a query to a remote host via NSCP")); 96 register_command(_T("dnscp_exec"), _T("Execute remote command on a remote host via NSCP")); 97 register_command(_T("dnscp_help"), _T("Help on using NSCP Client")); 129 98 130 99 } catch (nscapi::nscapi_exception &e) { … … 154 123 void DistributedClient::add_target(std::wstring key, std::wstring arg) { 155 124 try { 156 nscapi::target_handler::target t = targets.add(get_settings_proxy(), target_path , key, arg); 157 if (t.has_option(_T("certificate"))) { 158 boost::filesystem::wpath p = t.options[_T("certificate")]; 159 if (!boost::filesystem::is_regular(p)) { 160 p = get_core()->getBasePath() / p; 161 t.options[_T("certificate")] = utf8::cvt<std::wstring>(p.string()); 162 targets.add(t); 163 } 164 if (boost::filesystem::is_regular(p)) { 165 NSC_DEBUG_MSG_STD(_T("Using certificate: ") + p.string()); 166 } else { 167 NSC_LOG_ERROR_STD(_T("Certificate not found: ") + p.string()); 168 } 169 } 125 targets.add(get_settings_proxy(), target_path , key, arg); 126 } catch (const std::exception &e) { 127 NSC_LOG_ERROR_STD(_T("Failed to add target: ") + key + _T(", ") + utf8::to_unicode(e.what())); 170 128 } catch (...) { 171 129 NSC_LOG_ERROR_STD(_T("Failed to add target: ") + key); … … 195 153 196 154 NSCAPI::nagiosReturn DistributedClient::handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &result) { 197 nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_query_request(char_command, request); 198 std::wstring cmd = client::command_line_parser::parse_command(data.command, _T("syslog")); 155 std::wstring cmd = client::command_line_parser::parse_command(char_command, command_prefix); 156 157 Plugin::QueryRequestMessage message; 158 message.ParseFromString(request); 159 199 160 client::configuration config; 200 setup(config); 201 if (!client::command_line_parser::is_command(cmd)) 202 return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, request, result); 203 return commands.exec_simple(config, data.target, char_command, data.args, result); 161 setup(config, message.header()); 162 163 return commands.process_query(cmd, config, message, result); 204 164 } 205 165 206 166 int DistributedClient::commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &result) { 207 nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_exec_request(char_command, request); 208 std::wstring cmd = client::command_line_parser::parse_command(char_command, _T("syslog")); 209 if (!client::command_line_parser::is_command(cmd)) 210 return NSCAPI::returnIgnored; 167 std::wstring cmd = client::command_line_parser::parse_command(char_command, command_prefix); 168 169 Plugin::ExecuteRequestMessage message; 170 message.ParseFromString(request); 171 211 172 client::configuration config; 212 setup(config); 213 return client::command_line_parser::do_execute_command_as_exec(config, cmd, data.args, result); 173 setup(config, message.header()); 174 175 return commands.process_exec(cmd, config, message, result); 214 176 } 215 177 216 178 NSCAPI::nagiosReturn DistributedClient::handleRAWNotification(const wchar_t* channel, std::string request, std::string &result) { 179 Plugin::SubmitRequestMessage message; 180 message.ParseFromString(request); 181 217 182 client::configuration config; 218 setup(config); 219 return client::command_line_parser::do_relay_submit(config, request, result); 183 setup(config, message.header()); 184 185 return client::command_line_parser::do_relay_submit(config, message, result); 220 186 } 221 187 … … 236 202 } 237 203 238 void DistributedClient::setup(client::configuration &config ) {204 void DistributedClient::setup(client::configuration &config, const ::Plugin::Common_Header& header) { 239 205 boost::shared_ptr<clp_handler_impl> handler = boost::shared_ptr<clp_handler_impl>(new clp_handler_impl(this)); 240 206 add_local_options(config.local, config.data); 241 207 242 net::wurl url; 243 url.protocol = _T("dnscp"); 244 url.port = 5669; 245 nscapi::target_handler::optarget opt = targets.find_target(_T("default")); 208 config.data->recipient.id = header.recipient_id(); 209 std::wstring recipient = utf8::cvt<std::wstring>(config.data->recipient.id); 210 if (!targets.has_object(recipient)) { 211 NSC_LOG_ERROR(_T("Target not found (using default): ") + recipient); 212 recipient = _T("default"); 213 } 214 nscapi::targets::optional_target_object opt = targets.find_object(recipient); 215 246 216 if (opt) { 247 nscapi::target_handler::target t = *opt; 248 url.host = t.host; 249 if (t.has_option("port")) { 250 try { 251 url.port = strEx::stoi(t.options[_T("port")]); 252 } catch (...) {} 253 } 254 std::string keys[] = {"certificate", "timeout", "payload length", "ssl"}; 255 BOOST_FOREACH(std::string s, keys) { 256 config.data->recipient.data[s] = utf8::cvt<std::string>(t.options[utf8::cvt<std::wstring>(s)]); 257 } 258 } 259 config.data->recipient.id = "default"; 260 config.data->recipient.address = utf8::cvt<std::string>(url.to_string()); 217 nscapi::targets::target_object t = *opt; 218 nscapi::functions::destination_container def = t.to_destination_container(); 219 config.data->recipient.apply(def); 220 } 261 221 config.data->host_self.id = "self"; 262 222 //config.data->host_self.host = hostname_; … … 266 226 } 267 227 268 DistributedClient::connection_data DistributedClient::parse_header(const ::Plugin::Common_Header &header ) {228 DistributedClient::connection_data DistributedClient::parse_header(const ::Plugin::Common_Header &header, client::configuration::data_type data) { 269 229 nscapi::functions::destination_container recipient; 270 230 nscapi::functions::parse_destination(header, header.recipient_id(), recipient, true); 271 return connection_data(recipient );231 return connection_data(recipient, data->recipient); 272 232 } 273 233 … … 286 246 return ret; 287 247 } 288 int DistributedClient::clp_handler_impl::query(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) { 248 int DistributedClient::clp_handler_impl::query(client::configuration::data_type data, const Plugin::QueryRequestMessage &request_message, std::string &reply) { 249 const ::Plugin::Common_Header& request_header = request_message.header(); 289 250 int ret = NSCAPI::returnUNKNOWN; 290 Plugin::QueryRequestMessage request_message; 291 request_message.ParseFromString(request); 292 connection_data con = parse_header(*header); 251 connection_data con = parse_header(request_header, data); 293 252 294 253 Plugin::QueryResponseMessage response_message; 295 nscapi::functions::make_return_header(response_message.mutable_header(), *header);254 nscapi::functions::make_return_header(response_message.mutable_header(), request_header); 296 255 297 256 std::list<nscp::packet> chunks; 298 257 chunks.push_back(nscp::factory::create_envelope_request(1)); 299 chunks.push_back(nscp::factory::create_payload(nscp::data::command_request, request , 0));258 chunks.push_back(nscp::factory::create_payload(nscp::data::command_request, request_message.SerializeAsString(), 0)); 300 259 chunks = instance->send(con, chunks); 301 260 BOOST_FOREACH(nscp::packet &chunk, chunks) { … … 316 275 } 317 276 318 int DistributedClient::clp_handler_impl::submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) { 277 int DistributedClient::clp_handler_impl::submit(client::configuration::data_type data, const Plugin::SubmitRequestMessage &request_message, std::string &reply) { 278 const ::Plugin::Common_Header& request_header = request_message.header(); 319 279 int ret = NSCAPI::returnUNKNOWN; 320 Plugin::SubmitRequestMessage request_message; 321 request_message.ParseFromString(request); 322 connection_data con = parse_header(*header); 280 connection_data con = parse_header(request_header, data); 323 281 Plugin::SubmitResponseMessage response_message; 324 nscapi::functions::make_return_header(response_message.mutable_header(), *header);282 nscapi::functions::make_return_header(response_message.mutable_header(), request_header); 325 283 326 284 std::list<nscp::packet> chunks; 327 chunks.push_back(nscp::factory::create_payload(nscp::data::command_response, request , 0));285 chunks.push_back(nscp::factory::create_payload(nscp::data::command_response, request_message.SerializeAsString(), 0)); 328 286 chunks = instance->send(con, chunks); 329 287 BOOST_FOREACH(nscp::packet &chunk, chunks) { … … 344 302 } 345 303 346 int DistributedClient::clp_handler_impl::exec(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) { 304 int DistributedClient::clp_handler_impl::exec(client::configuration::data_type data, const Plugin::ExecuteRequestMessage &request_message, std::string &reply) { 305 const ::Plugin::Common_Header& request_header = request_message.header(); 347 306 int ret = NSCAPI::returnOK; 348 Plugin::ExecuteRequestMessage request_message; 349 request_message.ParseFromString(request); 350 connection_data con = parse_header(*header); 307 connection_data con = parse_header(request_header, data); 351 308 352 309 Plugin::ExecuteResponseMessage response_message; 353 nscapi::functions::make_return_header(response_message.mutable_header(), *header);310 nscapi::functions::make_return_header(response_message.mutable_header(), request_header); 354 311 355 312 std::list<nscp::packet> chunks; 356 313 chunks.push_back(nscp::factory::create_envelope_request(1)); 357 chunks.push_back(nscp::factory::create_payload(nscp::data::exec_request, request , 0));314 chunks.push_back(nscp::factory::create_payload(nscp::data::exec_request, request_message.SerializeAsString(), 0)); 358 315 chunks = instance->send(con, chunks); 359 316 BOOST_FOREACH(nscp::packet &chunk, chunks) { -
modules/DistributedClient/DistributedClient.h
rf33c12f r2906cda 22 22 23 23 #include <boost/tuple/tuple.hpp> 24 #include <boost/filesystem.hpp> 24 25 25 26 #include <client/command_line_parser.hpp> … … 37 38 38 39 namespace po = boost::program_options; 39 40 namespace sh = nscapi::settings_helper; 40 41 41 42 class DistributedClient : public nscapi::impl::simple_plugin { … … 44 45 std::wstring channel_; 45 46 std::wstring target_path; 47 const static std::wstring command_prefix; 46 48 47 nscapi::target_handler targets; 49 struct custom_reader { 50 typedef nscapi::targets::target_object object_type; 51 typedef nscapi::targets::target_object target_object; 52 53 static void init_default(target_object &target) { 54 target.set_property_int(_T("timeout"), 30); 55 target.set_property_bool(_T("ssl"), true); 56 target.set_property_string(_T("certificate"), _T("${certificate-path}/nrpe_dh_512.pem")); 57 target.set_property_int(_T("payload length"), 1024); 58 } 59 60 static void add_custom_keys(sh::settings_registry &settings, boost::shared_ptr<nscapi::settings_proxy> proxy, object_type &object) { 61 settings.path(object.path).add_key() 62 63 (_T("timeout"), sh::int_fun_key<int>(boost::bind(&object_type::set_property_int, &object, _T("timeout"), _1), 30), 64 _T("TIMEOUT"), _T("Timeout when reading/writing packets to/from sockets.")) 65 66 ; 67 } 68 69 static void post_process_target(target_object &target) { 70 nscapi::core_wrapper* core = GET_CORE(); 71 if (core == NULL) { 72 NSC_LOG_ERROR_STD(_T("Invalid core")); 73 return; 74 } 75 if (target.has_option(_T("certificate"))) { 76 std::wstring value = target.options[_T("certificate")]; 77 boost::filesystem::wpath p = value; 78 if (!boost::filesystem::is_regular(p)) { 79 p = core->getBasePath() / p; 80 if (boost::filesystem::is_regular(p)) { 81 value = p.string(); 82 } else { 83 value = core->expand_path(value); 84 } 85 target.options[_T("certificate")] = value; 86 } 87 if (boost::filesystem::is_regular(p)) { 88 NSC_DEBUG_MSG_STD(_T("Using certificate: ") + p.string()); 89 } else { 90 NSC_LOG_ERROR_STD(_T("Certificate not found: ") + p.string()); 91 } 92 } 93 } 94 95 }; 96 97 nscapi::targets::handler<custom_reader> targets; 48 98 client::command_manager commands; 49 99 … … 51 101 std::string address; 52 102 int timeout; 53 int buffer_length;54 bool use_ssl;55 103 56 connection_data(nscapi::functions::destination_container recipient) {57 timeout = recipient.get_int_data("timeout", 30);58 59 address = recipient.address;104 connection_data(nscapi::functions::destination_container arguments, nscapi::functions::destination_container target) { 105 arguments.import(target); 106 timeout = arguments.get_int_data("timeout", 30); 107 address = arguments.address.to_string(); 60 108 } 61 109 … … 73 121 clp_handler_impl(DistributedClient *instance) : instance(instance) {} 74 122 75 int query(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply);76 int submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply);77 int exec(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply);123 int query(client::configuration::data_type data, const Plugin::QueryRequestMessage &request_message, std::string &reply); 124 int submit(client::configuration::data_type data, const Plugin::SubmitRequestMessage &request_message, std::string &reply); 125 int exec(client::configuration::data_type data, const Plugin::ExecuteRequestMessage &request_message, std::string &reply); 78 126 79 127 virtual nscapi::functions::destination_container lookup_target(std::wstring &id) { 128 nscapi::targets::optional_target_object opt = instance->targets.find_object(id); 129 if (opt) 130 return opt->to_destination_container(); 80 131 nscapi::functions::destination_container ret; 81 nscapi::target_handler::optarget t = instance->targets.find_target(id);82 if (t) {83 if (!t->alias.empty())84 ret.id = utf8::cvt<std::string>(t->alias);85 if (!t->host.empty())86 ret.host = utf8::cvt<std::string>(t->host);87 if (t->has_option("address"))88 ret.address = utf8::cvt<std::string>(t->options[_T("address")]);89 else90 ret.address = utf8::cvt<std::string>(t->host);91 BOOST_FOREACH(const nscapi::target_handler::target::options_type::value_type &kvp, t->options) {92 ret.data[utf8::cvt<std::string>(kvp.first)] = utf8::cvt<std::string>(kvp.second);93 }94 }95 132 return ret; 96 133 } … … 143 180 bool submit_nscp(std::list<std::wstring> &arguments, std::wstring &result); 144 181 145 static connection_data parse_header(const ::Plugin::Common_Header &header );182 static connection_data parse_header(const ::Plugin::Common_Header &header, client::configuration::data_type data); 146 183 147 184 private: 148 185 void add_local_options(po::options_description &desc, client::configuration::data_type data); 149 void setup(client::configuration &config );186 void setup(client::configuration &config, const ::Plugin::Common_Header& header); 150 187 void add_command(std::wstring key, std::wstring args); 151 188 void add_target(std::wstring key, std::wstring args); -
modules/NSCPClient/NSCPClient.h
r0f7b655 r2906cda 66 66 _T("SSL CERTIFICATE"), _T("")) 67 67 68 (_T("payload length"), sh::int_fun_key<int>(boost::bind(&object_type::set_property_int, &object, _T("payload length"), _1), 1024),69 _T("PAYLOAD LENGTH"), _T("Length of payload to/from the NRPE agent. This is a hard specific value so you have to \"configure\" (read recompile) your NRPE agent to use the same value for it to work."))70 68 ; 71 69 } -
version.hpp
r76540c3 r2906cda 1 1 #ifndef VERSION_HPP 2 2 #define VERSION_HPP 3 #define PRODUCTVER 0,4,0,13 24 #define STRPRODUCTVER "0,4,0,13 2"5 #define STRPRODUCTDATE "2012-02-1 2"3 #define PRODUCTVER 0,4,0,134 4 #define STRPRODUCTVER "0,4,0,134" 5 #define STRPRODUCTDATE "2012-02-13" 6 6 #endif // VERSION_HPP -
version.txt
r76540c3 r2906cda 1 1 version=0.4.0 2 build=13 23 date=2012-02-1 22 build=134 3 date=2012-02-13
Note: See TracChangeset
for help on using the changeset viewer.








