Changeset 0f7b655 in nscp
- Timestamp:
- 02/08/12 23:42:00 (16 months ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- 76540c3
- Parents:
- e396b2f
- Files:
-
- 24 edited
-
changelog (modified) (2 diffs)
-
include/client/command_line_parser.cpp (modified) (8 diffs)
-
include/client/command_line_parser.hpp (modified) (4 diffs)
-
include/nsca/server/connection.cpp (modified) (1 diff)
-
include/nsca/server/parser.hpp (modified) (1 diff)
-
include/nscapi/functions.hpp (modified) (2 diffs)
-
modules/NRPEClient/NRPEClient.cpp (modified) (9 diffs)
-
modules/NRPEClient/NRPEClient.h (modified) (4 diffs)
-
modules/NSCAClient/NSCAClient.cpp (modified) (11 diffs)
-
modules/NSCAClient/NSCAClient.h (modified) (6 diffs)
-
modules/NSCPClient/NSCPClient.cpp (modified) (10 diffs)
-
modules/NSCPClient/NSCPClient.h (modified) (7 diffs)
-
modules/PythonScript/script_wrapper.cpp (modified) (1 diff)
-
modules/SMTPClient/SMTPClient.cpp (modified) (8 diffs)
-
modules/SMTPClient/SMTPClient.h (modified) (6 diffs)
-
modules/SyslogClient/SyslogClient.cpp (modified) (10 diffs)
-
modules/SyslogClient/SyslogClient.h (modified) (6 diffs)
-
scripts/python/test_all.py (modified) (1 diff)
-
scripts/python/test_eventlog.py (modified) (1 diff)
-
scripts/python/test_nrpe.py (modified) (3 diffs)
-
scripts/python/test_nsca.py (modified) (7 diffs)
-
scripts/python/test_python.py (modified) (1 diff)
-
scripts/python/test_stress.py (modified) (1 diff)
-
scripts/python/test_w32_system.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
changelog
re396b2f r0f7b655 6 6 * Fix RtlStringFromGUID problem on NT4 7 7 8 2012-02-05 MickeM 9 * Added test cases for targets to NRPE 10 * Added test cases for targets to NSCA 11 * Added test cases for lenghts to NSCA 12 * Changed to python API sleep uses milliseconds (not seconds as before) 13 Makes NSCA unittests go much faster (as I can wait much less) 14 * Fixed a lot of bugs related to target handling. 15 * implemented target refactoring on all Client modules. 8 16 9 17 2012-02-05 MickeM … … 20 28 * Implemented full settings API for LuaScript (next RC will have to wait till next weekend) 21 29 22 2012-01-31 MickeM 30 2012-01-31 MickeM1 23 31 * Fixed issue with parsing "invalid external commands". 24 32 If parsing falies it will notify you but use the legacy split string method instead. -
include/client/command_line_parser.cpp
re396b2f r0f7b655 95 95 } 96 96 97 int client::command_line_parser::do_execute_command_as_query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, const std::string &request,std::string &result) {97 int client::command_line_parser::do_execute_command_as_query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result) { 98 98 if (!config.validate()) 99 99 throw cli_exception("Invalid data: " + config.to_string()); … … 102 102 } else if (command == _T("query")) { 103 103 return do_query(config, command, arguments, result); 104 } else if (command == _T("forward")) {105 return do_forward(config, request, result);106 104 } else if (command == _T("exec")) { 107 105 int ret = do_exec(config, command, arguments, result); … … 136 134 } 137 135 136 137 int client::command_manager::process_query(std::wstring cmd, client::configuration &config, const Plugin::QueryRequestMessage &message, std::string &result) { 138 if (cmd == _T("forward")) 139 return config.handler->query(config.data, message, result); 140 141 // TODO: Loop though commands here! 142 if (message.payload_size() != 1) { 143 return nscapi::functions::create_simple_query_response_unknown(cmd, _T("Multiple payloads currently not supported"), result); 144 } 145 nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_query_request(message.payload(0)); 146 if (client::command_line_parser::is_command(cmd)) 147 return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, result); 148 return exec_simple(config, data.target, cmd, data.args, result); 149 } 150 151 int client::command_manager::process_exec(std::wstring cmd, client::configuration &config, const Plugin::ExecuteRequestMessage &message, std::string &result) { 152 if (cmd == _T("forward")) 153 return config.handler->exec(config.data, message, result); 154 155 // TODO: Loop though commands here! 156 if (message.payload_size() != 1) { 157 return nscapi::functions::create_simple_exec_response_unknown(cmd, std::wstring(_T("Multiple payloads currently not supported")), result); 158 } 159 nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_exec_request(cmd, message); 160 if (client::command_line_parser::is_command(cmd)) 161 return client::command_line_parser::do_execute_command_as_exec(config, cmd, data.args, result); 162 return exec_simple(config, data.target, cmd, data.args, result); 163 } 164 138 165 int client::command_manager::exec_simple(configuration &config, const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::string &response) { 139 166 command_type::const_iterator cit = commands.find(command); … … 179 206 modify_header(config, message.mutable_header(), config.data->recipient); 180 207 nscapi::functions::append_simple_query_request_payload(message.add_payload(), config.data->command, config.data->arguments); 181 return config.handler->query(config.data, message.mutable_header(), message.SerializeAsString(), response); 182 } 183 184 int client::command_line_parser::do_forward(configuration &config, const std::string &request, std::string &response) { 185 /* 186 if (!config.data->target_id.empty()) { 187 if (!config.target_lookup) 188 throw cli_exception("No target interface given when looking for targets"); 189 config.data->recipient.import(config.target_lookup->lookup_target(config.data->target_id)); 190 } 191 */ 192 Plugin::QueryRequestMessage message; 193 message.ParseFromString(request); 194 return config.handler->query(config.data, message.mutable_header(), request, response); 208 return config.handler->query(config.data, message, response); 195 209 } 196 210 … … 222 236 std::string response; 223 237 nscapi::functions::append_simple_exec_request_payload(message.add_payload(), config.data->command, config.data->arguments); 224 return config.handler->exec(config.data, message .mutable_header(), message.SerializeAsString(), response);238 return config.handler->exec(config.data, message, response); 225 239 } 226 240 … … 241 255 if (!config.target_lookup) 242 256 throw cli_exception("No target interface given when looking for targets"); 243 config.data->recipient.import(config.target_lookup->lookup_target(config.data->target_id)); 257 config.data->recipient.apply(config.target_lookup->lookup_target(config.data->target_id)); 258 //po::store(parsed, vm); 259 po::notify(vm); 244 260 } 245 261 … … 250 266 nscapi::functions::append_simple_submit_request_payload(message.add_payload(), config.data->command, parse_result(config.data->result), config.data->message); 251 267 252 return config.handler->submit(config.data, message .mutable_header(), message.SerializeAsString(), result);268 return config.handler->submit(config.data, message, result); 253 269 } 254 270 void client::command_line_parser::modify_header(configuration &config, ::Plugin::Common_Header* header, nscapi::functions::destination_container &recipient) { … … 266 282 } 267 283 268 int client::command_line_parser::do_relay_submit(configuration &config, const std::string &request, std::string &response) { 269 Plugin::SubmitRequestMessage message; 270 message.ParseFromString(request); 271 modify_header(config, message.mutable_header(), config.data->recipient); 272 return config.handler->submit(config.data, message.mutable_header(), message.SerializeAsString(), response); 273 } 274 284 int client::command_line_parser::do_relay_submit(configuration &config, Plugin::SubmitRequestMessage &request_message, std::string &response) { 285 modify_header(config, request_message.mutable_header(), config.data->recipient); 286 return config.handler->submit(config.data, request_message, response); 287 } 288 -
include/client/command_line_parser.hpp
r7354aa1 r0f7b655 111 111 112 112 struct clp_handler { 113 virtual int query(configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) = 0;114 virtual int submit(configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &response) = 0;115 virtual int exec(configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) = 0;113 virtual int query(configuration::data_type data, const Plugin::QueryRequestMessage &request_message, std::string &reply) = 0; 114 virtual int submit(configuration::data_type data, const Plugin::SubmitRequestMessage &request_message, std::string &response) = 0; 115 virtual int exec(configuration::data_type data, const Plugin::ExecuteRequestMessage &request_message, std::string &reply) = 0; 116 116 }; 117 117 struct command_manager { … … 126 126 } 127 127 128 int process_query(std::wstring cmd, client::configuration &config, const Plugin::QueryRequestMessage &message, std::string &result); 129 int process_exec(std::wstring cmd, client::configuration &config, const Plugin::ExecuteRequestMessage &message, std::string &result); 130 131 128 132 }; 129 133 … … 138 142 139 143 static int do_execute_command_as_exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result); 140 static int do_execute_command_as_query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, const std::string &request,std::string &result);141 static int do_relay_submit(configuration &config, const std::string &request, std::string &response);144 static int do_execute_command_as_query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result); 145 static int do_relay_submit(configuration &config, Plugin::SubmitRequestMessage &request_message, std::string &response); 142 146 143 147 static std::wstring parse_command(std::wstring command, std::wstring prefix) { … … 164 168 165 169 static int do_query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result); 166 static int do_forward(configuration &config, const std::string &request, std::string &result);167 170 static int do_exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result); 168 171 static int do_submit(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result); -
include/nsca/server/connection.cpp
r2ec2eb6 r0f7b655 58 58 void connection::timeout(const boost::system::error_code& e) { 59 59 if (e != boost::asio::error::operation_aborted) { 60 handler_->log_debug(__FILE__, __LINE__, _T("Timeout <<<-"));60 handler_->log_debug(__FILE__, __LINE__, _T("Timeout reading:") + strEx::itos(parser_.get_payload_lenght())); 61 61 boost::system::error_code ignored_ec; 62 62 socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec); -
include/nsca/server/parser.hpp
r2ec2eb6 r0f7b655 45 45 packet_length_ = nsca::length::get_packet_length(length); 46 46 } 47 int get_payload_lenght() const { return payload_length_; } 47 48 std::string::size_type size() { 48 49 return buffer_.size(); -
include/nscapi/functions.hpp
re396b2f r0f7b655 326 326 if (host.id() == tag) { 327 327 data.id = tag; 328 data.address.import(net::parse(host.address())); 328 if (!host.address().empty()) 329 data.address.import(net::parse(host.address())); 329 330 if (!host.comment().empty()) 330 331 data.comment = host.comment(); … … 744 745 } 745 746 static decoded_simple_command_data parse_simple_exec_request(const wchar_t* char_command, const std::string &request) { 746 decoded_simple_command_data data;747 748 data.command = char_command;749 747 Plugin::ExecuteRequestMessage message; 750 748 message.ParseFromString(request); 749 750 return parse_simple_exec_request(char_command, message); 751 } 752 static decoded_simple_command_data parse_simple_exec_request(const std::wstring cmd, const Plugin::ExecuteRequestMessage &message) { 753 decoded_simple_command_data data; 754 data.command = cmd; 751 755 if (message.has_header()) 752 756 data.target = utf8::cvt<std::wstring>(message.header().recipient_id()); -
modules/NRPEClient/NRPEClient.cpp
re396b2f r0f7b655 32 32 namespace sh = nscapi::settings_helper; 33 33 34 const std::wstring NRPEClient::command_prefix = _T("nrpe"); 34 35 /** 35 36 * Default c-tor … … 55 56 bool NRPEClient::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 56 57 57 std::wstring certificate;58 unsigned int timeout = 30, buffer_length = 1024;59 bool use_ssl = true;60 58 try { 61 59 … … 119 117 void NRPEClient::add_target(std::wstring key, std::wstring arg) { 120 118 try { 121 nscapi::targets::target_object t =targets.add(get_settings_proxy(), target_path , key, arg);119 targets.add(get_settings_proxy(), target_path , key, arg); 122 120 } catch (const std::exception &e) { 123 121 NSC_LOG_ERROR_STD(_T("Failed to add target: ") + key + _T(", ") + utf8::to_unicode(e.what())); … … 149 147 150 148 NSCAPI::nagiosReturn NRPEClient::handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &result) { 149 std::wstring cmd = client::command_line_parser::parse_command(char_command, command_prefix); 150 151 151 Plugin::QueryRequestMessage message; 152 152 message.ParseFromString(request); 153 if (message.payload_size() != 1) { 154 return nscapi::functions::create_simple_query_response_unknown(char_command, _T("Multiple payloads currently not supported"), result); 155 } 156 std::string recipient = message.header().recipient_id(); 157 nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_query_request(message.payload(0)); 158 std::wstring cmd = client::command_line_parser::parse_command(char_command, _T("nrpe")); 153 159 154 client::configuration config; 160 config.data->recipient.id = recipient; 161 setup(config); 162 if (client::command_line_parser::is_command(cmd)) 163 return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, request, result); 164 return commands.exec_simple(config, data.target, cmd, data.args, result); 155 setup(config, message.header()); 156 157 return commands.process_query(cmd, config, message, result); 165 158 } 166 159 167 160 NSCAPI::nagiosReturn NRPEClient::commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &result) { 168 nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_exec_request(char_command, request); 169 std::wstring cmd = client::command_line_parser::parse_command(char_command, _T("syslog")); 170 if (!client::command_line_parser::is_command(cmd)) 171 return NSCAPI::returnIgnored; 161 std::wstring cmd = client::command_line_parser::parse_command(char_command, command_prefix); 162 163 Plugin::ExecuteRequestMessage message; 164 message.ParseFromString(request); 165 172 166 client::configuration config; 173 setup(config); 174 return client::command_line_parser::do_execute_command_as_exec(config, cmd, data.args, result); 167 setup(config, message.header()); 168 169 return commands.process_exec(cmd, config, message, result); 175 170 } 176 171 177 172 NSCAPI::nagiosReturn NRPEClient::handleRAWNotification(const wchar_t* channel, std::string request, std::string &result) { 173 Plugin::SubmitRequestMessage message; 174 message.ParseFromString(request); 175 178 176 client::configuration config; 179 setup(config); 180 return client::command_line_parser::do_relay_submit(config, request, result); 177 setup(config, message.header()); 178 179 return client::command_line_parser::do_relay_submit(config, message, result); 181 180 } 182 181 … … 198 197 } 199 198 200 void NRPEClient::setup(client::configuration &config ) {199 void NRPEClient::setup(client::configuration &config, const ::Plugin::Common_Header& header) { 201 200 boost::shared_ptr<clp_handler_impl> handler = boost::shared_ptr<clp_handler_impl>(new clp_handler_impl(this)); 202 201 add_local_options(config.local, config.data); 203 202 204 config.data->recipient. address = net::parse("nrpe://localhost:5666");203 config.data->recipient.id = header.recipient_id(); 205 204 std::wstring recipient = utf8::cvt<std::wstring>(config.data->recipient.id); 206 205 if (!targets.has_object(recipient)) { … … 215 214 config.data->recipient.apply(def); 216 215 } 217 config.data->recipient.id = "default";218 216 config.data->host_self.id = "self"; 219 217 //config.data->host_self.host = hostname_; … … 233 231 // 234 232 235 int NRPEClient::clp_handler_impl::query(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) { 236 Plugin::QueryRequestMessage request_message; 237 request_message.ParseFromString(request); 238 connection_data con = this->instance->parse_header(*header, data); 233 int NRPEClient::clp_handler_impl::query(client::configuration::data_type data, const Plugin::QueryRequestMessage &request_message, std::string &reply) { 234 const ::Plugin::Common_Header& request_header = request_message.header(); 235 connection_data con = parse_header(request_header, data); 239 236 240 237 Plugin::QueryResponseMessage response_message; 241 nscapi::functions::make_return_header(response_message.mutable_header(), *header);238 nscapi::functions::make_return_header(response_message.mutable_header(), request_header); 242 239 243 240 for (int i=0;i<request_message.payload_size();i++) { … … 255 252 } 256 253 257 int NRPEClient::clp_handler_impl::submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) { 258 Plugin::SubmitRequestMessage request_message; 259 request_message.ParseFromString(request); 260 connection_data con = this->instance->parse_header(*header, data); 254 int NRPEClient::clp_handler_impl::submit(client::configuration::data_type data, const Plugin::SubmitRequestMessage &request_message, std::string &reply) { 255 const ::Plugin::Common_Header& request_header = request_message.header(); 256 connection_data con = parse_header(request_header, data); 261 257 std::wstring channel = utf8::cvt<std::wstring>(request_message.channel()); 262 258 263 259 Plugin::SubmitResponseMessage response_message; 264 nscapi::functions::make_return_header(response_message.mutable_header(), *header);260 nscapi::functions::make_return_header(response_message.mutable_header(), request_header); 265 261 266 262 for (int i=0;i<request_message.payload_size();++i) { … … 277 273 } 278 274 279 int NRPEClient::clp_handler_impl::exec(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) { 280 Plugin::ExecuteRequestMessage request_message; 281 request_message.ParseFromString(request); 282 connection_data con = this->instance->parse_header(*header, data); 275 int NRPEClient::clp_handler_impl::exec(client::configuration::data_type data, const Plugin::ExecuteRequestMessage &request_message, std::string &reply) { 276 const ::Plugin::Common_Header& request_header = request_message.header(); 277 connection_data con = parse_header(request_header, data); 283 278 284 279 Plugin::ExecuteResponseMessage response_message; 285 nscapi::functions::make_return_header(response_message.mutable_header(), *header);280 nscapi::functions::make_return_header(response_message.mutable_header(), request_header); 286 281 287 282 for (int i=0;i<request_message.payload_size();i++) { -
modules/NRPEClient/NRPEClient.h
re396b2f r0f7b655 40 40 std::wstring channel_; 41 41 std::wstring target_path; 42 const static std::wstring command_prefix; 42 43 43 44 struct custom_reader { … … 110 111 connection_data(nscapi::functions::destination_container arguments, nscapi::functions::destination_container target) { 111 112 arguments.import(target); 112 cert = arguments.get_string_data("certificate" , "");113 cert = arguments.get_string_data("certificate"); 113 114 timeout = arguments.get_int_data("timeout", 30); 114 115 buffer_length = arguments.get_int_data("payload length", 1024); … … 140 141 clp_handler_impl(NRPEClient *instance) : instance(instance) {} 141 142 142 int query(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply);143 int submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply);144 int exec(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply);143 int query(client::configuration::data_type data, const Plugin::QueryRequestMessage &request_message, std::string &reply); 144 int submit(client::configuration::data_type data, const Plugin::SubmitRequestMessage &request_message, std::string &reply); 145 int exec(client::configuration::data_type data, const Plugin::ExecuteRequestMessage &request_message, std::string &reply); 145 146 146 147 virtual nscapi::functions::destination_container lookup_target(std::wstring &id) { 147 nscapi::targets::optional_target_object t = instance->targets.find_object(id);148 if ( t)149 return t->to_destination_container();148 nscapi::targets::optional_target_object opt = instance->targets.find_object(id); 149 if (opt) 150 return opt->to_destination_container(); 150 151 nscapi::functions::destination_container ret; 151 152 return ret; … … 201 202 static nrpe::packet send_ssl(std::string cert, std::string host, std::string port, int timeout, nrpe::packet packet); 202 203 203 connection_data parse_header(const ::Plugin::Common_Header &header, client::configuration::data_type data);204 static connection_data parse_header(const ::Plugin::Common_Header &header, client::configuration::data_type data); 204 205 205 206 private: 206 207 void add_local_options(po::options_description &desc, client::configuration::data_type data); 207 void setup(client::configuration &config );208 void setup(client::configuration &config, const ::Plugin::Common_Header& header); 208 209 void add_command(std::wstring key, std::wstring args); 209 210 void add_target(std::wstring key, std::wstring args); -
modules/NSCAClient/NSCAClient.cpp
re396b2f r0f7b655 33 33 namespace sh = nscapi::settings_helper; 34 34 35 const std::wstring NSCAAgent::command_prefix = _T("nsca"); 35 36 /** 36 37 * Default c-tor … … 53 54 return false; 54 55 } 55 /*56 DEFINE_SETTING_S(REPORT_MODE, NSCA_SERVER_SECTION, "report", "all");57 DESCRIBE_SETTING(REPORT_MODE, "REPORT MODE", "What to report to the server (any of the following: all, critical, warning, unknown, ok)");58 */59 56 60 57 bool NSCAAgent::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 61 58 62 63 std::wstring encryption, password, nscahost;64 std::string delay;65 unsigned int timeout = 30, payload_length = 512, nscaport = 5666;66 59 try { 60 67 61 sh::settings_registry settings(get_settings_proxy()); 68 62 settings.set_alias(_T("NSCA"), alias, _T("client")); … … 90 84 ; 91 85 92 settings.alias().add_path_to_settings(_T("server"))93 (_T("NSCA SERVER"), _T("Configure the NSCA server to report to."))94 ;95 96 86 settings.register_all(); 97 87 settings.notify(); 98 88 89 targets.add_missing(get_settings_proxy(), target_path, _T("default"), _T(""), true); 90 91 99 92 get_core()->registerSubmissionListener(get_id(), channel_); 93 94 register_command(_T("nsca_query"), _T("Check remote NRPE host")); 95 register_command(_T("nsca_submit"), _T("Submit (via query) remote NRPE host")); 96 register_command(_T("nsca_forward"), _T("Forward query to remote NRPE host")); 97 register_command(_T("nsca_exec"), _T("Execute (via query) remote NRPE host")); 98 register_command(_T("nsca_help"), _T("Help on using NRPE Client")); 100 99 101 100 if (hostname_ == "auto") { … … 151 150 void NSCAAgent::add_target(std::wstring key, std::wstring arg) { 152 151 try { 153 nscapi::targets::target_object t = targets.add(get_settings_proxy(), target_path , key, arg); 152 targets.add(get_settings_proxy(), target_path , key, arg); 153 } catch (const std::exception &e) { 154 NSC_LOG_ERROR_STD(_T("Failed to add target: ") + key + _T(", ") + utf8::to_unicode(e.what())); 154 155 } catch (...) { 155 156 NSC_LOG_ERROR_STD(_T("Failed to add target: ") + key); … … 179 180 180 181 NSCAPI::nagiosReturn NSCAAgent::handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &result) { 181 nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_query_request(char_command, request); 182 std::wstring cmd = client::command_line_parser::parse_command(data.command, _T("nsca")); 182 std::wstring cmd = client::command_line_parser::parse_command(char_command, command_prefix); 183 184 Plugin::QueryRequestMessage message; 185 message.ParseFromString(request); 186 183 187 client::configuration config; 184 setup(config); 185 if (!client::command_line_parser::is_command(cmd)) 186 return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, request, result); 187 return commands.exec_simple(config, data.target, char_command, data.args, result); 188 setup(config, message.header()); 189 190 return commands.process_query(cmd, config, message, result); 188 191 } 189 192 190 193 NSCAPI::nagiosReturn NSCAAgent::commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &result) { 191 nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_exec_request(char_command, request); 192 std::wstring cmd = client::command_line_parser::parse_command(char_command, _T("nsca")); 193 if (!client::command_line_parser::is_command(cmd)) 194 return NSCAPI::returnIgnored; 194 std::wstring cmd = client::command_line_parser::parse_command(char_command, command_prefix); 195 196 Plugin::ExecuteRequestMessage message; 197 message.ParseFromString(request); 198 195 199 client::configuration config; 196 setup(config); 197 return client::command_line_parser::do_execute_command_as_exec(config, cmd, data.args, result); 200 setup(config, message.header()); 201 202 return commands.process_exec(cmd, config, message, result); 198 203 } 199 204 200 205 NSCAPI::nagiosReturn NSCAAgent::handleRAWNotification(const wchar_t* channel, std::string request, std::string &result) { 206 Plugin::SubmitRequestMessage message; 207 message.ParseFromString(request); 208 201 209 client::configuration config; 202 setup(config); 203 return client::command_line_parser::do_relay_submit(config, request, result); 210 setup(config, message.header()); 211 212 return client::command_line_parser::do_relay_submit(config, message, result); 204 213 } 205 214 … … 213 222 "Length of payload (has to be same as on the server)") 214 223 215 (" buffer-length,l", po::value<unsigned int>()->notifier(boost::bind(&nscapi::functions::destination_container::set_int_data, &data->recipient, "payload length", _1)),224 ("payload-length,l", po::value<unsigned int>()->notifier(boost::bind(&nscapi::functions::destination_container::set_int_data, &data->recipient, "payload length", _1)), 216 225 "Length of payload (has to be same as on the server)") 217 226 … … 233 242 } 234 243 235 void NSCAAgent::setup(client::configuration &config ) {244 void NSCAAgent::setup(client::configuration &config, const ::Plugin::Common_Header& header) { 236 245 boost::shared_ptr<clp_handler_impl> handler(new clp_handler_impl(this)); 237 246 add_local_options(config.local, config.data); 238 247 239 config.data->recipient.id = "default"; 240 config.data->recipient.address = net::parse("nsca://localhost:5667"); 241 242 nscapi::targets::optional_target_object opt = targets.find_object(_T("default")); 248 config.data->recipient.id = header.recipient_id(); 249 std::wstring recipient = utf8::cvt<std::wstring>(config.data->recipient.id); 250 if (!targets.has_object(recipient)) { 251 NSC_LOG_ERROR(_T("Target not found (using default): ") + recipient); 252 recipient = _T("default"); 253 } 254 nscapi::targets::optional_target_object opt = targets.find_object(recipient); 255 243 256 if (opt) { 244 257 nscapi::targets::target_object t = *opt; 245 258 nscapi::functions::destination_container def = t.to_destination_container(); 246 config.data->recipient. import(def);259 config.data->recipient.apply(def); 247 260 } 248 261 config.data->host_self.id = "self"; … … 253 266 } 254 267 255 NSCAAgent::connection_data NSCAAgent::parse_header(const ::Plugin::Common_Header &header ) {268 NSCAAgent::connection_data NSCAAgent::parse_header(const ::Plugin::Common_Header &header, client::configuration::data_type data) { 256 269 nscapi::functions::destination_container recipient, sender; 257 270 nscapi::functions::parse_destination(header, header.recipient_id(), recipient, true); 258 271 nscapi::functions::parse_destination(header, header.sender_id(), sender, true); 259 return connection_data(recipient, sender);272 return connection_data(recipient, data->recipient, sender); 260 273 } 261 274 … … 264 277 // 265 278 266 int NSCAAgent::clp_handler_impl::query(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) { 267 Plugin::QueryRequestMessage request_message; 268 request_message.ParseFromString(request); 269 connection_data con = parse_header(*header); 279 int NSCAAgent::clp_handler_impl::query(client::configuration::data_type data, const Plugin::QueryRequestMessage &request_message, std::string &reply) { 280 const ::Plugin::Common_Header& request_header = request_message.header(); 281 connection_data con = parse_header(request_header, data); 270 282 271 283 Plugin::QueryResponseMessage response_message; 272 nscapi::functions::make_return_header(response_message.mutable_header(), *header);284 nscapi::functions::make_return_header(response_message.mutable_header(), request_header); 273 285 274 286 std::list<nsca::packet> list; … … 288 300 } 289 301 290 int NSCAAgent::clp_handler_impl::submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) { 291 Plugin::SubmitRequestMessage message; 292 message.ParseFromString(request); 293 connection_data con = parse_header(*header); 294 std::wstring channel = utf8::cvt<std::wstring>(message.channel()); 302 int NSCAAgent::clp_handler_impl::submit(client::configuration::data_type data, const Plugin::SubmitRequestMessage &request_message, std::string &reply) { 303 const ::Plugin::Common_Header& request_header = request_message.header(); 304 connection_data con = parse_header(request_header, data); 305 std::wstring channel = utf8::cvt<std::wstring>(request_message.channel()); 295 306 296 307 Plugin::SubmitResponseMessage response_message; 297 nscapi::functions::make_return_header(response_message.mutable_header(), *header);308 nscapi::functions::make_return_header(response_message.mutable_header(), request_header); 298 309 299 310 std::list<nsca::packet> list; 300 311 301 for (int i=0;i < message.payload_size(); ++i) {312 for (int i=0;i < request_message.payload_size(); ++i) { 302 313 nsca::packet packet(con.sender_hostname, con.buffer_length, con.time_delta); 303 314 std::wstring alias, msg; 304 packet.code = nscapi::functions::parse_simple_submit_request_payload( message.payload(i), alias, msg);315 packet.code = nscapi::functions::parse_simple_submit_request_payload(request_message.payload(i), alias, msg); 305 316 if (alias != _T("host_check")) 306 317 packet.service = utf8::cvt<std::string>(alias); … … 315 326 } 316 327 317 int NSCAAgent::clp_handler_impl::exec(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) { 318 Plugin::ExecuteRequestMessage request_message; 319 request_message.ParseFromString(request); 320 connection_data con = parse_header(*header); 328 int NSCAAgent::clp_handler_impl::exec(client::configuration::data_type data, const Plugin::ExecuteRequestMessage &request_message, std::string &reply) { 329 const ::Plugin::Common_Header& request_header = request_message.header(); 330 connection_data con = parse_header(request_header, data); 321 331 322 332 Plugin::ExecuteResponseMessage response_message; 323 nscapi::functions::make_return_header(response_message.mutable_header(), *header);333 nscapi::functions::make_return_header(response_message.mutable_header(), request_header); 324 334 325 335 std::list<nsca::packet> list; -
modules/NSCAClient/NSCAClient.h
re396b2f r0f7b655 40 40 std::wstring channel_; 41 41 std::wstring target_path; 42 const static std::wstring command_prefix; 42 43 std::string hostname_; 43 44 bool cacheNscaHost_; … … 53 54 target.set_property_int(_T("payload length"), 512); 54 55 } 55 static void post_process_target(target_object &target) {}56 56 57 57 static void add_custom_keys(sh::settings_registry &settings, boost::shared_ptr<nscapi::settings_proxy> proxy, object_type &object) { … … 74 74 ; 75 75 } 76 static void post_process_target(target_object &target) { 77 } 76 78 }; 77 79 … … 88 90 int time_delta; 89 91 90 connection_data(nscapi::functions::destination_container recipient, nscapi::functions::destination_container sender) { 92 connection_data(nscapi::functions::destination_container recipient, nscapi::functions::destination_container target, nscapi::functions::destination_container sender) { 93 recipient.import(target); 91 94 timeout = recipient.get_int_data("timeout", 30); 92 95 buffer_length = recipient.get_int_data("payload length", 512); … … 126 129 clp_handler_impl(NSCAAgent *instance) : instance(instance) {} 127 130 128 int query(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply);129 int submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply);130 int exec(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply);131 int query(client::configuration::data_type data, const Plugin::QueryRequestMessage &request_message, std::string &reply); 132 int submit(client::configuration::data_type data, const Plugin::SubmitRequestMessage &request_message, std::string &reply); 133 int exec(client::configuration::data_type data, const Plugin::ExecuteRequestMessage &request_message, std::string &reply); 131 134 132 135 virtual nscapi::functions::destination_container lookup_target(std::wstring &id) { … … 181 184 boost::tuple<int,std::wstring> send(connection_data data, const std::list<nsca::packet> packets); 182 185 void add_options(po::options_description &desc, connection_data &command_data); 183 static connection_data parse_header(const ::Plugin::Common_Header &header );186 static connection_data parse_header(const ::Plugin::Common_Header &header, client::configuration::data_type data); 184 187 185 188 private: 186 189 void add_local_options(po::options_description &desc, client::configuration::data_type data); 187 void setup(client::configuration &config );190 void setup(client::configuration &config, const ::Plugin::Common_Header& header); 188 191 void add_command(std::wstring key, std::wstring args); 189 192 void add_target(std::wstring key, std::wstring args); -
modules/NSCPClient/NSCPClient.cpp
re396b2f r0f7b655 34 34 namespace sh = nscapi::settings_helper; 35 35 36 const std::wstring NSCPClient::command_prefix = _T("nscp"); 36 37 /** 37 38 * Default c-tor … … 58 59 std::map<std::wstring,std::wstring> commands; 59 60 60 std::wstring certificate;61 unsigned int timeout = 30, buffer_length = 1024;62 bool use_ssl = true;63 61 try { 64 62 65 register_command(_T("query_nscp"), _T("Submit a query to a remote host via NSCP"));66 register_command(_T("submit_nscp"), _T("Submit a query to a remote host via NSCP"));67 register_command(_T("exec_nscp"), _T("Execute remote command on a remote host via NSCP"));68 63 69 64 sh::settings_registry settings(get_settings_proxy()); … … 91 86 settings.notify(); 92 87 88 targets.add_missing(get_settings_proxy(), target_path, _T("default"), _T(""), true); 89 90 93 91 get_core()->registerSubmissionListener(get_id(), channel_); 92 register_command(_T("nscp_query"), _T("Submit a query to a remote host via NSCP")); 93 register_command(_T("nscp_forward"), _T("Forward query to remote NSCP host")); 94 register_command(_T("nscp_submit"), _T("Submit a query to a remote host via NSCP")); 95 register_command(_T("nscp_exec"), _T("Execute remote command on a remote host via NSCP")); 96 register_command(_T("nscp_help"), _T("Help on using NSCP Client")); 94 97 95 98 } catch (nscapi::nscapi_exception &e) { … … 120 123 try { 121 124 targets.add(get_settings_proxy(), target_path , key, arg); 125 } catch (const std::exception &e) { 126 NSC_LOG_ERROR_STD(_T("Failed to add target: ") + key + _T(", ") + utf8::to_unicode(e.what())); 122 127 } catch (...) { 123 128 NSC_LOG_ERROR_STD(_T("Failed to add target: ") + key); … … 147 152 148 153 NSCAPI::nagiosReturn NSCPClient::handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &result) { 149 nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_query_request(char_command, request); 150 std::wstring cmd = client::command_line_parser::parse_command(data.command, _T("syslog")); 154 std::wstring cmd = client::command_line_parser::parse_command(char_command, command_prefix); 155 156 Plugin::QueryRequestMessage message; 157 message.ParseFromString(request); 158 151 159 client::configuration config; 152 setup(config); 153 if (!client::command_line_parser::is_command(cmd)) 154 return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, request, result); 155 return commands.exec_simple(config, data.target, char_command, data.args, result); 160 setup(config, message.header()); 161 162 return commands.process_query(cmd, config, message, result); 156 163 } 157 164 158 165 NSCAPI::nagiosReturn NSCPClient::commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &result) { 159 nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_exec_request(char_command, request); 160 std::wstring cmd = client::command_line_parser::parse_command(char_command, _T("syslog")); 161 if (!client::command_line_parser::is_command(cmd)) 162 return NSCAPI::returnIgnored; 166 std::wstring cmd = client::command_line_parser::parse_command(char_command, command_prefix); 167 168 Plugin::ExecuteRequestMessage message; 169 message.ParseFromString(request); 170 163 171 client::configuration config; 164 setup(config); 165 return client::command_line_parser::do_execute_command_as_exec(config, cmd, data.args, result); 172 setup(config, message.header()); 173 174 return commands.process_exec(cmd, config, message, result); 166 175 } 167 176 168 177 NSCAPI::nagiosReturn NSCPClient::handleRAWNotification(const wchar_t* channel, std::string request, std::string &result) { 178 Plugin::SubmitRequestMessage message; 179 message.ParseFromString(request); 180 169 181 client::configuration config; 170 setup(config); 171 return client::command_line_parser::do_relay_submit(config, request, result); 182 setup(config, message.header()); 183 184 return client::command_line_parser::do_relay_submit(config, message, result); 172 185 } 173 186 … … 188 201 } 189 202 190 void NSCPClient::setup(client::configuration &config ) {203 void NSCPClient::setup(client::configuration &config, const ::Plugin::Common_Header& header) { 191 204 boost::shared_ptr<clp_handler_impl> handler = boost::shared_ptr<clp_handler_impl>(new clp_handler_impl(this)); 192 205 add_local_options(config.local, config.data); 193 206 194 config.data->recipient.id = "default"; 195 config.data->recipient.address = net::parse("nscp://localhost:5668"); 196 nscapi::targets::optional_target_object opt = targets.find_object(_T("default")); 207 config.data->recipient.id = header.recipient_id(); 208 std::wstring recipient = utf8::cvt<std::wstring>(config.data->recipient.id); 209 if (!targets.has_object(recipient)) { 210 NSC_LOG_ERROR(_T("Target not found (using default): ") + recipient); 211 recipient = _T("default"); 212 } 213 nscapi::targets::optional_target_object opt = targets.find_object(recipient); 214 197 215 if (opt) { 198 nscapi::functions::destination_container def = opt->to_destination_container(); 199 config.data->recipient.import(def); 216 nscapi::targets::target_object t = *opt; 217 nscapi::functions::destination_container def = t.to_destination_container(); 218 config.data->recipient.apply(def); 200 219 } 201 220 config.data->host_self.id = "self"; … … 206 225 } 207 226 208 NSCPClient::connection_data NSCPClient::parse_header(const ::Plugin::Common_Header &header ) {227 NSCPClient::connection_data NSCPClient::parse_header(const ::Plugin::Common_Header &header, client::configuration::data_type data) { 209 228 nscapi::functions::destination_container recipient; 210 229 nscapi::functions::parse_destination(header, header.recipient_id(), recipient, true); 211 return connection_data(recipient );230 return connection_data(recipient, data->recipient); 212 231 } 213 232 … … 226 245 return ret; 227 246 } 228 int NSCPClient::clp_handler_impl::query(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) { 247 int NSCPClient::clp_handler_impl::query(client::configuration::data_type data, const Plugin::QueryRequestMessage &request_message, std::string &reply) { 248 const ::Plugin::Common_Header& request_header = request_message.header(); 229 249 int ret = NSCAPI::returnUNKNOWN; 230 Plugin::QueryRequestMessage request_message; 231 request_message.ParseFromString(request); 232 connection_data con = parse_header(*header); 250 connection_data con = parse_header(request_header, data); 233 251 234 252 Plugin::QueryResponseMessage response_message; 235 nscapi::functions::make_return_header(response_message.mutable_header(), *header);253 nscapi::functions::make_return_header(response_message.mutable_header(), request_header); 236 254 237 255 std::list<nscp::packet> chunks; 238 256 chunks.push_back(nscp::factory::create_envelope_request(1)); 239 chunks.push_back(nscp::factory::create_payload(nscp::data::command_request, request , 0));257 chunks.push_back(nscp::factory::create_payload(nscp::data::command_request, request_message.SerializeAsString(), 0)); 240 258 chunks = instance->send(con, chunks); 241 259 BOOST_FOREACH(nscp::packet &chunk, chunks) { … … 256 274 } 257 275 258 int NSCPClient::clp_handler_impl::submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) { 276 int NSCPClient::clp_handler_impl::submit(client::configuration::data_type data, const Plugin::SubmitRequestMessage &request_message, std::string &reply) { 277 const ::Plugin::Common_Header& request_header = request_message.header(); 259 278 int ret = NSCAPI::returnUNKNOWN; 260 Plugin::SubmitRequestMessage request_message; 261 request_message.ParseFromString(request); 262 connection_data con = parse_header(*header); 279 connection_data con = parse_header(request_header, data); 263 280 Plugin::SubmitResponseMessage response_message; 264 nscapi::functions::make_return_header(response_message.mutable_header(), *header);281 nscapi::functions::make_return_header(response_message.mutable_header(), request_header); 265 282 266 283 std::list<nscp::packet> chunks; 267 chunks.push_back(nscp::factory::create_payload(nscp::data::command_response, request , 0));284 chunks.push_back(nscp::factory::create_payload(nscp::data::command_response, request_message.SerializeAsString(), 0)); 268 285 chunks = instance->send(con, chunks); 269 286 BOOST_FOREACH(nscp::packet &chunk, chunks) { … … 284 301 } 285 302 286 int NSCPClient::clp_handler_impl::exec(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) { 303 int NSCPClient::clp_handler_impl::exec(client::configuration::data_type data, const Plugin::ExecuteRequestMessage &request_message, std::string &reply) { 304 const ::Plugin::Common_Header& request_header = request_message.header(); 287 305 int ret = NSCAPI::returnOK; 288 Plugin::ExecuteRequestMessage request_message; 289 request_message.ParseFromString(request); 290 connection_data con = parse_header(*header); 306 connection_data con = parse_header(request_header, data); 291 307 292 308 Plugin::ExecuteResponseMessage response_message; 293 nscapi::functions::make_return_header(response_message.mutable_header(), *header);309 nscapi::functions::make_return_header(response_message.mutable_header(), request_header); 294 310 295 311 std::list<nscp::packet> chunks; 296 312 chunks.push_back(nscp::factory::create_envelope_request(1)); 297 chunks.push_back(nscp::factory::create_payload(nscp::data::exec_request, request , 0));313 chunks.push_back(nscp::factory::create_payload(nscp::data::exec_request, request_message.SerializeAsString(), 0)); 298 314 chunks = instance->send(con, chunks); 299 315 BOOST_FOREACH(nscp::packet &chunk, chunks) { -
modules/NSCPClient/NSCPClient.h
re396b2f r0f7b655 36 36 namespace sh = nscapi::settings_helper; 37 37 38 39 38 class NSCPClient : public nscapi::impl::simple_plugin { 40 39 private: … … 42 41 std::wstring channel_; 43 42 std::wstring target_path; 43 const static std::wstring command_prefix; 44 44 45 45 struct custom_reader { … … 53 53 target.set_property_int(_T("payload length"), 1024); 54 54 } 55 56 //static void post_process_target(target_object &target) {}57 55 58 56 static void add_custom_keys(sh::settings_registry &settings, boost::shared_ptr<nscapi::settings_proxy> proxy, object_type &object) { … … 111 109 int timeout; 112 110 113 connection_data(nscapi::functions::destination_container recipient) { 114 cert = recipient.get_string_data("certificate"); 115 timeout = recipient.get_int_data("timeout", 30); 116 use_ssl = recipient.get_bool_data("ssl"); 117 if (recipient.has_data("no ssl")) 118 use_ssl = !recipient.get_bool_data("no ssl"); 119 host = recipient.address.host; 120 port = recipient.address.get_port(5668); 111 connection_data(nscapi::functions::destination_container arguments, nscapi::functions::destination_container target) { 112 arguments.import(target); 113 cert = arguments.get_string_data("certificate"); 114 timeout = arguments.get_int_data("timeout", 30); 115 use_ssl = arguments.get_bool_data("ssl"); 116 if (arguments.has_data("no ssl")) 117 use_ssl = !arguments.get_bool_data("no ssl"); 118 if (arguments.has_data("use ssl")) 119 use_ssl = arguments.get_bool_data("use ssl"); 120 121 host = arguments.address.host; 122 port = arguments.address.get_port(5668); 121 123 } 122 124 … … 126 128 ss << _T(", port: ") << utf8::cvt<std::wstring>(port); 127 129 ss << _T(", timeout: ") << timeout; 130 ss << _T(", use_ssl: ") << use_ssl; 128 131 ss << _T(", certificate: ") << utf8::cvt<std::wstring>(cert); 129 ss << _T(", use_ssl: ") << use_ssl;130 132 return ss.str(); 131 133 } … … 137 139 clp_handler_impl(NSCPClient *instance) : instance(instance) {} 138 140 139 int query(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply);140 int submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply);141 int exec(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply);141 int query(client::configuration::data_type data, const Plugin::QueryRequestMessage &request_message, std::string &reply); 142 int submit(client::configuration::data_type data, const Plugin::SubmitRequestMessage &request_message, std::string &reply); 143 int exec(client::configuration::data_type data, const Plugin::ExecuteRequestMessage &request_message, std::string &reply); 142 144 143 145 virtual nscapi::functions::destination_container lookup_target(std::wstring &id) { 144 nscapi::functions::destination_container ret;145 146 nscapi::targets::optional_target_object opt = instance->targets.find_object(id); 146 147 if (opt) 147 148 return opt->to_destination_container(); 149 nscapi::functions::destination_container ret; 148 150 return ret; 149 151 } … … 202 204 bool submit_nscp(std::list<std::wstring> &arguments, std::wstring &result); 203 205 204 static connection_data parse_header(const ::Plugin::Common_Header &header );206 static connection_data parse_header(const ::Plugin::Common_Header &header, client::configuration::data_type data); 205 207 206 208 private: 207 209 void add_local_options(po::options_description &desc, client::configuration::data_type data); 208 void setup(client::configuration &config );210 void setup(client::configuration &config, const ::Plugin::Common_Header& header); 209 211 void add_command(std::wstring key, std::wstring args); 210 212 void add_target(std::wstring key, std::wstring args); -
modules/PythonScript/script_wrapper.cpp
ra87ce04 r0f7b655 128 128 } 129 129 } 130 void script_wrapper::sleep(unsigned int seconds) {131 { 132 thread_unlocker unlocker; 133 { 134 boost::this_thread::sleep(boost::posix_time::milliseconds( 1000));130 void script_wrapper::sleep(unsigned int ms) { 131 { 132 thread_unlocker unlocker; 133 { 134 boost::this_thread::sleep(boost::posix_time::milliseconds(ms)); 135 135 136 136 } -
modules/SMTPClient/SMTPClient.cpp
re396b2f r0f7b655 35 35 namespace sh = nscapi::settings_helper; 36 36 37 const std::wstring SMTPClient::command_prefix = _T("smtp"); 37 38 /** 38 39 * Default c-tor … … 79 80 80 81 ; 82 81 83 settings.register_all(); 82 84 settings.notify(); 83 85 86 targets.add_missing(get_settings_proxy(), target_path, _T("default"), _T(""), true); 87 88 84 89 get_core()->registerSubmissionListener(get_id(), channel_); 90 register_command(_T("smtp_query"), _T("Check remote SMTP host")); 91 register_command(_T("smtp_submit"), _T("Submit (via query) remote SMTP host")); 92 register_command(_T("smtp_forward"), _T("Forward query to remote SMTP host")); 93 register_command(_T("smtp_exec"), _T("Execute (via query) remote SMTP host")); 94 register_command(_T("smtp_help"), _T("Help on using SMTP Client")); 85 95 } catch (nscapi::nscapi_exception &e) { 86 96 NSC_LOG_ERROR_STD(_T("NSClient API exception: ") + utf8::to_unicode(e.what())); … … 110 120 try { 111 121 targets.add(get_settings_proxy(), target_path , key, arg); 122 } catch (const std::exception &e) { 123 NSC_LOG_ERROR_STD(_T("Failed to add target: ") + key + _T(", ") + utf8::to_unicode(e.what())); 112 124 } catch (...) { 113 125 NSC_LOG_ERROR_STD(_T("Failed to add target: ") + key); … … 139 151 140 152 NSCAPI::nagiosReturn SMTPClient::handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &result) { 141 nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_query_request(char_command, request); 142 std::wstring cmd = client::command_line_parser::parse_command(data.command, _T("syslog")); 153 std::wstring cmd = client::command_line_parser::parse_command(char_command, command_prefix); 154 155 Plugin::QueryRequestMessage message; 156 message.ParseFromString(request); 157 143 158 client::configuration config; 144 setup(config); 145 if (!client::command_line_parser::is_command(cmd)) 146 return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, request, result); 147 return commands.exec_simple(config, data.target, char_command, data.args, result); 159 setup(config, message.header()); 160 161 return commands.process_query(cmd, config, message, result); 148 162 } 149 163 150 164 NSCAPI::nagiosReturn SMTPClient::commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &result) { 151 nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_exec_request(char_command, request); 152 std::wstring cmd = client::command_line_parser::parse_command(char_command, _T("syslog")); 153 if (!client::command_line_parser::is_command(cmd)) 154 return NSCAPI::returnIgnored; 165 std::wstring cmd = client::command_line_parser::parse_command(char_command, command_prefix); 166 167 Plugin::ExecuteRequestMessage message; 168 message.ParseFromString(request); 169 155 170 client::configuration config; 156 setup(config); 157 return client::command_line_parser::do_execute_command_as_exec(config, cmd, data.args, result); 171 setup(config, message.header()); 172 173 return commands.process_exec(cmd, config, message, result); 158 174 } 159 175 160 176 NSCAPI::nagiosReturn SMTPClient::handleRAWNotification(const wchar_t* channel, std::string request, std::string &result) { 177 Plugin::SubmitRequestMessage message; 178 message.ParseFromString(request); 179 161 180 client::configuration config; 162 setup(config); 163 return client::command_line_parser::do_relay_submit(config, request, result); 181 setup(config, message.header()); 182 183 return client::command_line_parser::do_relay_submit(config, message, result); 164 184 } 165 185 … … 182 202 } 183 203 184 void SMTPClient::setup(client::configuration &config ) {204 void SMTPClient::setup(client::configuration &config, const ::Plugin::Common_Header& header) { 185 205 boost::shared_ptr<clp_handler_impl> handler = boost::shared_ptr<clp_handler_impl>(new clp_handler_impl(this)); 186 206 add_local_options(config.local, config.data); 187 207 188 config.data->recipient.id = "default"; 189 config.data->recipient.address = net::parse("smtp://localhost:25"); 190 nscapi::targets::optional_target_object opt = targets.find_object(_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 191 216 if (opt) { 192 nscapi::functions::destination_container def = opt->to_destination_container(); 193 config.data->recipient.import(def); 217 nscapi::targets::target_object t = *opt; 218 nscapi::functions::destination_container def = t.to_destination_container(); 219 config.data->recipient.apply(def); 194 220 } 195 221 config.data->host_self.id = "self"; … … 200 226 } 201 227 202 SMTPClient::connection_data SMTPClient::parse_header(const ::Plugin::Common_Header &header ) {228 SMTPClient::connection_data SMTPClient::parse_header(const ::Plugin::Common_Header &header, client::configuration::data_type data) { 203 229 nscapi::functions::destination_container recipient; 204 230 nscapi::functions::parse_destination(header, header.recipient_id(), recipient, true); 205 return connection_data(recipient );231 return connection_data(recipient, data->recipient); 206 232 } 207 233 208 234 ////////////////////////////////////////////////////////////////////////// 209 235 // Parser implementations 210 int SMTPClient::clp_handler_impl::query(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) {236 int SMTPClient::clp_handler_impl::query(client::configuration::data_type data, const Plugin::QueryRequestMessage &request_message, std::string &reply) { 211 237 NSC_LOG_ERROR_STD(_T("SMTP does not support query patterns")); 212 238 return NSCAPI::hasFailed; 213 239 } 214 240 215 int SMTPClient::clp_handler_impl::submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) { 216 Plugin::SubmitRequestMessage request_message; 217 request_message.ParseFromString(request); 218 connection_data con = parse_header(*header); 241 int SMTPClient::clp_handler_impl::submit(client::configuration::data_type data, const Plugin::SubmitRequestMessage &request_message, std::string &reply) { 242 const ::Plugin::Common_Header& request_header = request_message.header(); 243 connection_data con = parse_header(request_header, data); 219 244 std::wstring channel = utf8::cvt<std::wstring>(request_message.channel()); 220 245 221 246 Plugin::SubmitResponseMessage response_message; 222 nscapi::functions::make_return_header(response_message.mutable_header(), *header);247 nscapi::functions::make_return_header(response_message.mutable_header(), request_header); 223 248 224 249 for (int i=0;i < request_message.payload_size(); ++i) { … … 234 259 nscapi::functions::append_simple_submit_response_payload(response_message.add_payload(), "TODO", NSCAPI::returnOK, "Message send successfully"); 235 260 } 236 237 261 response_message.SerializeToString(&reply); 238 262 return NSCAPI::isSuccess; … … 240 264 } 241 265 242 int SMTPClient::clp_handler_impl::exec(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) {266 int SMTPClient::clp_handler_impl::exec(client::configuration::data_type data, const Plugin::ExecuteRequestMessage &request_message, std::string &reply) { 243 267 NSC_LOG_ERROR_STD(_T("SMTP does not support exec patterns")); 244 268 return NSCAPI::hasFailed; -
modules/SMTPClient/SMTPClient.h
re396b2f r0f7b655 37 37 std::wstring channel_; 38 38 std::wstring target_path; 39 const static std::wstring command_prefix; 39 40 40 41 struct custom_reader { 41 42 typedef nscapi::targets::target_object object_type; 42 43 typedef nscapi::targets::target_object target_object; 43 44 44 45 45 static void init_default(target_object &target) { … … 49 49 target.set_property_string(_T("template"), _T("Hello, this is %source% reporting %message%!")); 50 50 } 51 static void post_process_target(target_object &target) {}52 51 53 52 static void add_custom_keys(sh::settings_registry &settings, boost::shared_ptr<nscapi::settings_proxy> proxy, object_type &object) { … … 67 66 ; 68 67 } 68 static void post_process_target(target_object &target) { 69 } 69 70 }; 70 71 … … 80 81 int timeout; 81 82 82 connection_data(nscapi::functions::destination_container recipient) { 83 recipient_str = recipient.get_string_data("recipient"); 84 timeout = recipient.get_int_data("timeout", 30); 85 sender = recipient.get_string_data("sender"); 86 template_string = recipient.get_string_data("template"); 83 connection_data(nscapi::functions::destination_container arguments, nscapi::functions::destination_container target) { 84 arguments.import(target); 85 recipient_str = arguments.get_string_data("recipient"); 86 timeout = arguments.get_int_data("timeout", 30); 87 sender = arguments.get_string_data("sender"); 88 template_string = arguments.get_string_data("template"); 87 89 88 host = recipient.address.host;89 port = recipient.address.get_port(25);90 host = arguments.address.host; 91 port = arguments.address.get_port(25); 90 92 } 91 93 … … 107 109 clp_handler_impl(SMTPClient *instance) : instance(instance) {} 108 110 109 int query(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply);110 int submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply);111 int exec(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply);111 int query(client::configuration::data_type data, const Plugin::QueryRequestMessage &request_message, std::string &reply); 112 int submit(client::configuration::data_type data, const Plugin::SubmitRequestMessage &request_message, std::string &reply); 113 int exec(client::configuration::data_type data, const Plugin::ExecuteRequestMessage &request_message, std::string &reply); 112 114 113 115 virtual nscapi::functions::destination_container lookup_target(std::wstring &id) { 114 nscapi::functions::destination_container ret;115 116 nscapi::targets::optional_target_object opt = instance->targets.find_object(id); 116 117 if (opt) 117 118 return opt->to_destination_container(); 119 nscapi::functions::destination_container ret; 118 120 return ret; 119 121 } … … 156 158 157 159 private: 158 static connection_data parse_header(const ::Plugin::Common_Header &header );160 static connection_data parse_header(const ::Plugin::Common_Header &header, client::configuration::data_type data); 159 161 160 162 private: 161 163 void add_local_options(po::options_description &desc, client::configuration::data_type data); 162 void setup(client::configuration &config );164 void setup(client::configuration &config, const ::Plugin::Common_Header& header); 163 165 void add_command(std::wstring key, std::wstring args); 164 166 void add_target(std::wstring key, std::wstring args); -
modules/SyslogClient/SyslogClient.cpp
re396b2f r0f7b655 35 35 namespace ip = boost::asio::ip; 36 36 37 const std::wstring SyslogClient::command_prefix = _T("syslog"); 37 38 /** 38 39 * Default c-tor … … 90 91 severities["debug"] = 7; 91 92 92 std::wstring severity, facility, tag_syntax, message_syntax;93 std::wstring ok_severity, warn_severity, crit_severity, unknown_severity;94 93 try { 95 94 sh::settings_registry settings(get_settings_proxy()); … … 117 116 settings.notify(); 118 117 118 targets.add_missing(get_settings_proxy(), target_path, _T("default"), _T(""), true); 119 120 119 121 get_core()->registerSubmissionListener(get_id(), channel_); 120 122 register_command(_T("syslog_query"), _T("Check remote NRPE host")); 123 register_command(_T("syslog_submit"), _T("Submit (via query) remote NRPE host")); 124 register_command(_T("syslog_forward"), _T("Forward query to remote NRPE host")); 125 register_command(_T("syslog_exec"), _T("Execute (via query) remote NRPE host")); 126 register_command(_T("syslog_help"), _T("Help on using NRPE Client")); 121 127 } catch (nscapi::nscapi_exception &e) { 122 128 NSC_LOG_ERROR_STD(_T("NSClient API exception: ") + utf8::to_unicode(e.what())); … … 140 146 try { 141 147 targets.add(get_settings_proxy(), target_path , key, arg); 148 } catch (const std::exception &e) { 149 NSC_LOG_ERROR_STD(_T("Failed to add target: ") + key + _T(", ") + utf8::to_unicode(e.what())); 142 150 } catch (...) { 143 151 NSC_LOG_ERROR_STD(_T("Failed to add target: ") + key); … … 167 175 168 176 NSCAPI::nagiosReturn SyslogClient::handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &result) { 169 nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_query_request(char_command, request); 170 std::wstring cmd = client::command_line_parser::parse_command(data.command, _T("syslog")); 177 std::wstring cmd = client::command_line_parser::parse_command(char_command, command_prefix); 178 179 Plugin::QueryRequestMessage message; 180 message.ParseFromString(request); 181 171 182 client::configuration config; 172 setup(config); 173 if (!client::command_line_parser::is_command(cmd)) 174 return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, request, result); 175 return commands.exec_simple(config, data.target, char_command, data.args, result); 183 setup(config, message.header()); 184 185 return commands.process_query(cmd, config, message, result); 176 186 } 177 187 178 188 NSCAPI::nagiosReturn SyslogClient::commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &result) { 179 nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_exec_request(char_command, request); 180 std::wstring cmd = client::command_line_parser::parse_command(char_command, _T("syslog")); 181 if (!client::command_line_parser::is_command(cmd)) 182 return NSCAPI::returnIgnored; 189 std::wstring cmd = client::command_line_parser::parse_command(char_command, command_prefix); 190 191 Plugin::ExecuteRequestMessage message; 192 message.ParseFromString(request); 193 183 194 client::configuration config; 184 setup(config); 185 return client::command_line_parser::do_execute_command_as_exec(config, cmd, data.args, result); 195 setup(config, message.header()); 196 197 return commands.process_exec(cmd, config, message, result); 186 198 } 187 199 188 200 NSCAPI::nagiosReturn SyslogClient::handleRAWNotification(const wchar_t* channel, std::string request, std::string &result) { 201 Plugin::SubmitRequestMessage message; 202 message.ParseFromString(request); 203 189 204 client::configuration config; 190 setup(config); 191 return client::command_line_parser::do_relay_submit(config, request, result); 205 setup(config, message.header()); 206 207 return client::command_line_parser::do_relay_submit(config, message, result); 192 208 } 193 209 … … 224 240 } 225 241 226 void SyslogClient::setup(client::configuration &config ) {242 void SyslogClient::setup(client::configuration &config, const ::Plugin::Common_Header& header) { 227 243 boost::shared_ptr<clp_handler_impl> handler = boost::shared_ptr<clp_handler_impl>(new clp_handler_impl(this)); 228 244 add_local_options(config.local, config.data); 229 245 230 config.data->recipient.id = "default"; 231 config.data->recipient.address = net::parse("syslog://localhost:514"); 232 nscapi::targets::optional_target_object opt = targets.find_object(_T("default")); 246 config.data->recipient.id = header.recipient_id(); 247 std::wstring recipient = utf8::cvt<std::wstring>(config.data->recipient.id); 248 if (!targets.has_object(recipient)) { 249 NSC_LOG_ERROR(_T("Target not found (using default): ") + recipient); 250 recipient = _T("default"); 251 } 252 nscapi::targets::optional_target_object opt = targets.find_object(recipient); 253 233 254 if (opt) { 234 nscapi::functions::destination_container def = opt->to_destination_container(); 235 config.data->recipient.import(def); 255 nscapi::targets::target_object t = *opt; 256 nscapi::functions::destination_container def = t.to_destination_container(); 257 config.data->recipient.apply(def); 236 258 } 237 259 config.data->host_self.id = "self"; … … 242 264 } 243 265 244 SyslogClient::connection_data SyslogClient::parse_header(const ::Plugin::Common_Header &header ) {266 SyslogClient::connection_data SyslogClient::parse_header(const ::Plugin::Common_Header &header, client::configuration::data_type data) { 245 267 nscapi::functions::destination_container recipient; 246 268 nscapi::functions::parse_destination(header, header.recipient_id(), recipient, true); 247 return connection_data(recipient );269 return connection_data(recipient, data->recipient); 248 270 } 249 271 … … 252 274 // 253 275 254 int SyslogClient::clp_handler_impl::query(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) {276 int SyslogClient::clp_handler_impl::query(client::configuration::data_type data, const Plugin::QueryRequestMessage &request_message, std::string &reply) { 255 277 NSC_LOG_ERROR_STD(_T("SYSLOG does not support query patterns")); 256 278 nscapi::functions::create_simple_query_response_unknown(_T("UNKNOWN"), _T("SYSLOG does not support query patterns"), reply); … … 258 280 } 259 281 260 int SyslogClient::clp_handler_impl::submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) { 261 Plugin::SubmitRequestMessage request_message; 262 request_message.ParseFromString(request); 263 connection_data con = parse_header(*header); 282 int SyslogClient::clp_handler_impl::submit(client::configuration::data_type data, const Plugin::SubmitRequestMessage &request_message, std::string &reply) { 283 const ::Plugin::Common_Header& request_header = request_message.header(); 284 connection_data con = parse_header(request_header, data); 264 285 265 286 Plugin::SubmitResponseMessage response_message; 266 nscapi::functions::make_return_header(response_message.mutable_header(), *header);287 nscapi::functions::make_return_header(response_message.mutable_header(), request_header); 267 288 268 289 //TODO: Map seveity! … … 295 316 } 296 317 297 int SyslogClient::clp_handler_impl::exec(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) {318 int SyslogClient::clp_handler_impl::exec(client::configuration::data_type data, const Plugin::ExecuteRequestMessage &request_message, std::string &reply) { 298 319 NSC_LOG_ERROR_STD(_T("SYSLOG does not support exec patterns")); 299 320 nscapi::functions::create_simple_exec_response_unknown("UNKNOWN", "SYSLOG does not support exec patterns", reply); -
modules/SyslogClient/SyslogClient.h
re396b2f r0f7b655 38 38 std::wstring channel_; 39 39 std::wstring target_path; 40 const static std::wstring command_prefix; 40 41 41 42 struct custom_reader { … … 54 55 } 55 56 56 static void post_process_target(target_object &target) {}57 57 58 58 static void add_custom_keys(sh::settings_registry &settings, boost::shared_ptr<nscapi::settings_proxy> proxy, object_type &object) { … … 83 83 _T("TODO"), _T("")) 84 84 ; 85 } 86 static void post_process_target(target_object &target) { 85 87 } 86 88 }; … … 103 105 std::string ok_severity, warn_severity, crit_severity, unknown_severity; 104 106 105 connection_data(nscapi::functions::destination_container recipient) { 107 connection_data(nscapi::functions::destination_container recipient, nscapi::functions::destination_container target) { 108 recipient.import(target); 106 109 severity = recipient.data["severity"]; 107 110 facility = recipient.data["facility"]; … … 135 138 clp_handler_impl(SyslogClient *instance) : instance(instance) {} 136 139 137 int query(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply);138 int submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply);139 int exec(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply);140 int query(client::configuration::data_type data, const Plugin::QueryRequestMessage &request_message, std::string &reply); 141 int submit(client::configuration::data_type data, const Plugin::SubmitRequestMessage &request_message, std::string &reply); 142 int exec(client::configuration::data_type data, const Plugin::ExecuteRequestMessage &request_message, std::string &reply); 140 143 141 144 virtual nscapi::functions::destination_container lookup_target(std::wstring &id) { 142 nscapi::functions::destination_container ret;143 145 nscapi::targets::optional_target_object opt = instance->targets.find_object(id); 144 146 if (opt) 145 147 return opt->to_destination_container(); 148 nscapi::functions::destination_container ret; 146 149 return ret; 147 150 } … … 186 189 private: 187 190 boost::tuple<int,std::wstring> send(connection_data con, std::list<std::string> messages); 188 static connection_data parse_header(const ::Plugin::Common_Header &header );191 static connection_data parse_header(const ::Plugin::Common_Header &header, client::configuration::data_type data); 189 192 190 193 private: 191 194 void add_local_options(po::options_description &desc, client::configuration::data_type data); 192 void setup(client::configuration &config );195 void setup(client::configuration &config, const ::Plugin::Common_Header& header); 193 196 void add_command(std::wstring key, std::wstring args); 194 197 void add_target(std::wstring key, std::wstring args); -
scripts/python/test_all.py
r441a022 r0f7b655 1 from NSCP import Settings, Registry, Core, log, status, log_error , sleep1 from NSCP import Settings, Registry, Core, log, status, log_error 2 2 from test_helper import BasicTest, TestResult, Callable, setup_singleton, install_testcases, init_testcases, shutdown_testcases 3 3 -
scripts/python/test_eventlog.py
rf7a074d r0f7b655 73 73 result = TestResult() 74 74 result.add_message(self.test_create('Application Error', 1000, '0', 'error', ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']), 'Testing to create a log message') 75 sleep( 1)75 sleep(500) 76 76 log(self.last_message) 77 77 log('%s'%self.last_message) -
scripts/python/test_nrpe.py
re396b2f r0f7b655 187 187 else: 188 188 log('Waiting for %s (%s/%s)'%(uid,alias,target)) 189 sleep( 1)189 sleep(500) 190 190 if found: 191 191 return result … … 194 194 def test_one(self, ssl=True, length=1024, state = status.UNKNOWN, tag = 'TODO'): 195 195 result = TestResult('Testing NRPE: %s/%s/%s with various targets'%(ssl, length, tag)) 196 result.add(self.submit_payload('%s/%s/%s'%(ssl, length, tag), ssl, length, '%ssrc%s'%(tag, tag), state, '%smsg%s'%(tag, tag), '', "valid")) 197 result.add(self.submit_payload('%s/%s/%s'%(ssl, length, tag), ssl, length, '%ssrc%s'%(tag, tag), state, '%smsg%s'%(tag, tag), '', "test_rp")) 198 result.add(self.submit_payload('%s/%s/%s'%(ssl, length, tag), ssl, length, '%ssrc%s'%(tag, tag), state, '%smsg%s'%(tag, tag), '', "invalid")) 196 for t in ['valid', 'test_rp', 'invalid']: 197 result.add(self.submit_payload('%s/%s/%s'%(ssl, length, tag), ssl, length, '%ssrc%s'%(tag, tag), state, '%smsg%s'%(tag, tag), '', t)) 199 198 return result 200 199 … … 207 206 core.reload('test_nrpe_server') 208 207 209 # /settings/NRPE/test_nrpe_client/targets/default210 208 conf.set_string('/settings/NRPE/test_nrpe_client/targets/default', 'address', 'nrpe://127.0.0.1:35666') 211 209 conf.set_bool('/settings/NRPE/test_nrpe_client/targets/default', 'use ssl', not ssl) -
scripts/python/test_nsca.py
re396b2f r0f7b655 151 151 if not self.has_response(uuid): 152 152 log('Waiting for %s (%d/10)'%(uuid, i+1)) 153 sleep( 1)153 sleep(200) 154 154 else: 155 155 log('Got response %s'%uuid) … … 164 164 if not rmsg.got_simple_response or not rmsg.got_response: 165 165 log('Waiting for delayed response %s s/m: %s/%s - (%d/10)'%(uuid, rmsg.got_simple_response, rmsg.got_response, i+1)) 166 sleep( 1)166 sleep(500) 167 167 else: 168 168 log('Got delayed response %s'%uuid) … … 179 179 return True 180 180 181 def submit_payload(self, encryption, source, status, msg, perf, tag):181 def submit_payload(self, encryption, target, length, source, status, msg, perf, tag): 182 182 message = plugin_pb2.SubmitRequestMessage() 183 183 184 184 message.header.version = plugin_pb2.Common.VERSION_1 185 message.header.recipient_id = "test_rp"185 message.header.recipient_id = target 186 186 message.channel = 'nsca_test_outbox' 187 187 host = message.header.hosts.add() 188 host.address = "127.0.0.1:15667" 189 host.id = "test_rp" 190 enc = host.metadata.add() 191 enc.key = "encryption" 192 enc.value = encryption 193 enc = host.metadata.add() 194 enc.key = "password" 195 enc.value = 'pwd-%s'%encryption 188 host.id = target 189 if (target == 'valid'): 190 pass 191 else: 192 host.address = "127.0.0.1:15667" 193 enc = host.metadata.add() 194 enc.key = "encryption" 195 enc.value = encryption 196 enc = host.metadata.add() 197 enc.key = "password" 198 enc.value = 'pwd-%s'%encryption 199 enc = host.metadata.add() 200 enc.key = "payload length" 201 enc.value = '%d'%length 196 202 197 203 uid = str(uuid.uuid4()) … … 208 214 return result 209 215 210 def submit_via_exec(self, encryption, source, status, msg, perf, tag):216 def submit_via_exec(self, encryption, target, length, source, status, msg, perf, tag): 211 217 uid = str(uuid.uuid4()) 212 218 … … 216 222 '--result', '%d'%status, 217 223 '--message', '%s - %s'%(uid, msg), 218 '--encryption', encryption, 219 '--password', 'pwd-%s'%encryption, 220 '--address', '127.0.0.1:15667' 224 '--target', target, 221 225 ] 226 if (target == 'valid'): 227 pass 228 else: 229 args.extend([ 230 '--address', '127.0.0.1:15667', 231 '--encryption', encryption, 232 '--password', 'pwd-%s'%encryption, 233 '--payload-length', '%d'%length, 234 ]) 222 235 (result_code, result_message) = core.simple_exec('any', 'nsca_submit', args) 223 236 result = TestResult('Testing payload submission (via command line exec): %s'%tag) … … 232 245 return result 233 246 234 def test_one_crypto_full(self, encryption, state, key ):247 def test_one_crypto_full(self, encryption, state, key, target, length): 235 248 result = TestResult('Testing %s/%s'%(encryption, key)) 236 result.add(self.submit_payload(encryption, '%ssrc%s'%(key, key), state, '%smsg%s'%(key, key), '', '%s/%s'%(state, encryption)))237 result.add(self.submit_via_exec(encryption, '%ssrc%s'%(key, key), state, '%smsg%s'%(key, key), '', '%s/%s'%(state, encryption)))238 return result 239 240 def test_one_crypto(self, crypto ):249 result.add(self.submit_payload(encryption, target, length, '%ssrc%s'%(key, key), state, '%smsg%s'%(key, key), '', '%s/%s/%d/%s'%(state, encryption, length, target))) 250 result.add(self.submit_via_exec(encryption, target, length, '%ssrc%s'%(key, key), state, '%smsg%s'%(key, key), '', '%s/%s/%d/%s'%(state, encryption, length, target))) 251 return result 252 253 def test_one_crypto(self, crypto, length=512): 241 254 conf = Settings.get() 242 255 conf.set_string('/settings/NSCA/test_nsca_server', 'encryption', '%s'%crypto) 243 256 conf.set_string('/settings/NSCA/test_nsca_server', 'password', 'pwd-%s'%crypto) 257 conf.set_int('/settings/NSCA/test_nsca_server', 'payload length', length) 244 258 core.reload('test_nsca_server') 245 result = TestResult('Testing encryption algorith: %s'%crypto) 259 260 conf.set_string('/settings/NSCA/test_nsca_client/targets/default', 'address', 'nsca://127.0.0.1:35667') 261 conf.set_string('/settings/NSCA/test_nsca_client/targets/default', 'encryption', '%s'%crypto) 262 conf.set_string('/settings/NSCA/test_nsca_client/targets/default', 'password', 'default-%s'%crypto) 263 conf.set_int('/settings/NSCA/test_nsca_client/targets/default', 'payload length', length*3) 264 265 conf.set_string('/settings/NSCA/test_nsca_client/targets/invalid', 'address', 'nsca://127.0.0.1:25667') 266 conf.set_string('/settings/NSCA/test_nsca_client/targets/invalid', 'encryption', 'none') 267 conf.set_string('/settings/NSCA/test_nsca_client/targets/invalid', 'password', 'invalid-%s'%crypto) 268 conf.set_int('/settings/NSCA/test_nsca_client/targets/invalid', 'payload length', length*2) 269 270 conf.set_string('/settings/NSCA/test_nsca_client/targets/valid', 'address', 'nsca://127.0.0.1:15667') 271 conf.set_string('/settings/NSCA/test_nsca_client/targets/valid', 'encryption', '%s'%crypto) 272 conf.set_string('/settings/NSCA/test_nsca_client/targets/valid', 'password', 'pwd-%s'%crypto) 273 conf.set_int('/settings/NSCA/test_nsca_client/targets/valid', 'payload length', length) 274 core.reload('test_nsca_client') 275 276 277 278 result = TestResult('Testing: %s/%d'%(crypto, length)) 246 279 result.add_message(isOpen('localhost', 15667), 'Checking that port is open') 247 result.add(self.test_one_crypto_full(crypto, status.UNKNOWN, 'unknown')) 248 result.add(self.test_one_crypto_full(crypto, status.OK, 'ok')) 249 result.add(self.test_one_crypto_full(crypto, status.WARNING, 'warn')) 250 result.add(self.test_one_crypto_full(crypto, status.CRITICAL, 'crit')) 280 for target in ['valid', 'test_rp', 'invalid']: 281 result.add(self.test_one_crypto_full(crypto, status.UNKNOWN, 'unknown', target, length)) 282 result.add(self.test_one_crypto_full(crypto, status.OK, 'ok', target, length)) 283 result.add(self.test_one_crypto_full(crypto, status.WARNING, 'warn', target, length)) 284 result.add(self.test_one_crypto_full(crypto, status.CRITICAL, 'crit', target, length)) 251 285 return result 252 286 … … 255 289 cryptos = ["none", "xor", "des", "3des", "cast128", "xtea", "blowfish", "twofish", "rc2", "aes", "aes256", "aes192", "aes128", "serpent", "gost", "3way"] 256 290 for c in cryptos: 257 result.add_message(True, 'Testing crypto: %s'%c) 258 result.add(self.test_one_crypto(c)) 291 for l in [128, 512, 1024, 4096]: 292 result.add(self.test_one_crypto(c, l)) 293 #result.add(self.test_one_crypto(c)) 259 294 260 295 return result -
scripts/python/test_python.py
r441a022 r0f7b655 58 58 old_stress_count = self.stress_count 59 59 old_noop_count = self.noop_count 60 sleep(5 )60 sleep(5000) 61 61 result.add_message(True, 'Commands/second: %d/%d'%( (self.stress_count-old_stress_count)/5, (self.noop_count-old_noop_count)/5 ) ) 62 62 elapsed = (time() - start) -
scripts/python/test_stress.py
r6a30f44 r0f7b655 113 113 old_stress_count = self.results_count 114 114 old_noop_count = self.check_count 115 sleep(5 )115 sleep(5000) 116 116 result.add_message(True, 'Commands/second: %d/%d'%( (self.results_count-old_stress_count)/5, (self.check_count-old_noop_count)/5 ) ) 117 117 if (self.results_count*100/total_count) > last_major + 10: -
scripts/python/test_w32_system.py
rffa6a59 r0f7b655 57 57 log('Starting notepad...') 58 58 handle = subprocess.Popen('notepad.exe', shell=False) 59 sleep( 1)59 sleep(500) 60 60 pids.append(handle.pid) 61 61 for j in range(0,3):
Note: See TracChangeset
for help on using the changeset viewer.








