Changeset a87ce04 in nscp
- Timestamp:
- 01/08/12 22:29:34 (17 months ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- 7354aa1
- Parents:
- 81a6048
- Files:
-
- 2 added
- 26 edited
-
changelog (modified) (1 diff)
-
include/EnumProcess.cpp (modified) (4 diffs)
-
include/client/command_line_parser.cpp (modified) (3 diffs)
-
include/client/command_line_parser.hpp (modified) (2 diffs)
-
include/nrpe/packet.hpp (modified) (1 diff)
-
include/nsca/nsca_packet.hpp (modified) (6 diffs)
-
include/nsca/nsca_socket.hpp (modified) (2 diffs)
-
include/nsca/server/connection.cpp (modified) (5 diffs)
-
include/nsca/server/parser.hpp (modified) (1 diff)
-
include/nscapi/functions.hpp (modified) (3 diffs)
-
include/nscapi/nscapi_core_wrapper.cpp (modified) (1 diff)
-
include/nscapi/nscapi_plugin_wrapper.hpp (modified) (1 diff)
-
modules/GraphiteClient/module.cmake (modified) (1 diff)
-
modules/NRPEClient/NRPEClient.cpp (modified) (6 diffs)
-
modules/NRPEClient/NRPEClient.h (modified) (3 diffs)
-
modules/NSCAClient/NSCAClient.cpp (modified) (2 diffs)
-
modules/NSCAClient/NSCAClient.h (modified) (1 diff)
-
modules/NSCPClient/NSCPClient.cpp (modified) (1 diff)
-
modules/PythonScript/script_wrapper.cpp (modified) (2 diffs)
-
modules/SMTPClient/SMTPClient.cpp (modified) (1 diff)
-
modules/SyslogClient/SyslogClient.cpp (modified) (1 diff)
-
scripts/python/badapp.py (added)
-
scripts/python/test_nrpe.py (added)
-
scripts/python/test_nsca.py (modified) (4 diffs)
-
service/NSClient++.cpp (modified) (2 diffs)
-
service/cli_parser.hpp (modified) (1 diff)
-
version.hpp (modified) (1 diff)
-
version.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
changelog
r330af36 ra87ce04 5 5 * Fixa dependonservice LanManWorkStation (old win) 6 6 * Fix RtlStringFromGUID problem on NT4 7 8 9 2012-01-08 MickeM 10 * Fixed some issues in the NRPE decoder 11 * Added support for forwarding queries (ie. xxx_forward) mainly usefull for python(?) scripts where we can now handconstruct messages for delivery 12 * Added NRPE unit tests (52 of them) 7 13 8 14 2011-12-08 MickeM -
include/EnumProcess.cpp
r81a6048 ra87ce04 292 292 typedef struct _PROCESS_BASIC_INFORMATION { 293 293 LONG ExitStatus; 294 PVOID PebBaseAddress;294 LPVOID PebBaseAddress; 295 295 ULONG_PTR AffinityMask; 296 296 LONG BasePriority; … … 299 299 } PROCESS_BASIC_INFORMATION, *PPROCESS_BASIC_INFORMATION; 300 300 301 302 301 typedef struct _UNICODE_STRING { 303 302 USHORT Length; … … 306 305 } UNICODE_STRING, *PUNICODE_STRING; 307 306 308 PVOID GetPebAddress(HANDLE ProcessHandle) {307 LPVOID GetPebAddress(HANDLE ProcessHandle) { 309 308 PFNtQueryInformationProcess NtQueryInformationProcess = (PFNtQueryInformationProcess)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtQueryInformationProcess"); 310 309 if (NtQueryInformationProcess == NULL) … … 315 314 } 316 315 316 317 typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); 318 LPFN_ISWOW64PROCESS fnIsWow64Process; 319 320 bool IsWow64(HANDLE hProcess, bool def = false) { 321 BOOL bIsWow64 = FALSE; 322 fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(GetModuleHandle(TEXT("kernel32")),"IsWow64Process"); 323 if(NULL != fnIsWow64Process) { 324 if (!fnIsWow64Process(hProcess,&bIsWow64)) 325 return def; 326 } 327 return bIsWow64?true:false; 328 } 329 317 330 std::wstring CEnumProcess::GetCommandLine(HANDLE hProcess) { 318 331 319 PVOID rtlUserProcParamsAddress;320 332 UNICODE_STRING commandLine; 321 PVOID pebAddress = GetPebAddress(hProcess);322 323 324 333 #ifdef _WIN64 325 if (!ReadProcessMemory(hProcess, (PCHAR)pebAddress + 0x20, &rtlUserProcParamsAddress, sizeof(PVOID), NULL)) 334 LPVOID pebAddress = GetPebAddress(hProcess); 335 LPVOID rtlUserProcParamsAddress; 336 if (!ReadProcessMemory(hProcess, (PCHAR)pebAddress + 0x20, &rtlUserProcParamsAddress, sizeof(LPVOID), NULL)) 326 337 throw process_enumeration_exception(_T("Could not read the address of ProcessParameters: ") + error::lookup::last_error()); 327 #else328 if (!ReadProcessMemory(hProcess, (PCHAR)pebAddress + 0x10, &rtlUserProcParamsAddress, sizeof(PVOID), NULL))329 throw process_enumeration_exception(_T("Could not read the address of ProcessParameters: ") + error::lookup::last_error());330 #endif331 332 #ifdef _WIN64333 338 if (!ReadProcessMemory(hProcess, (PCHAR)rtlUserProcParamsAddress + 0x70, &commandLine, sizeof(commandLine), NULL)) 334 339 throw process_enumeration_exception(_T("Could not read commandline: ") + error::lookup::last_error()); 335 340 #else 341 bool osIsWin64 = IsWow64(GetCurrentProcess()); 342 if (!IsWow64(hProcess, !osIsWin64)) 343 return _T(""); 344 LPVOID pebAddress = GetPebAddress(hProcess); 345 LPVOID rtlUserProcParamsAddress; 346 if (!ReadProcessMemory(hProcess, (PCHAR)pebAddress + 0x10, &rtlUserProcParamsAddress, sizeof(LPVOID), NULL)) 347 throw process_enumeration_exception(_T("Could not read the address of ProcessParameters: ") + error::lookup::last_error()); 336 348 if (!ReadProcessMemory(hProcess, (PCHAR)rtlUserProcParamsAddress + 0x40, &commandLine, sizeof(commandLine), NULL)) 337 349 throw process_enumeration_exception(_T("Could not read commandline: ") + error::lookup::last_error()); -
include/client/command_line_parser.cpp
rf33c12f ra87ce04 73 73 } 74 74 75 int client::command_line_parser::do_execute_command_as_query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result) {75 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) { 76 76 if (!config.validate()) 77 77 throw cli_exception("Invalid data: " + config.to_string()); … … 80 80 } else if (command == _T("query")) { 81 81 return do_query(config, command, arguments, result); 82 } else if (command == _T("forward")) { 83 return do_forward(config, request, result); 82 84 } else if (command == _T("exec")) { 83 85 int ret = do_exec(config, command, arguments, result); … … 155 157 modify_header(config, message.mutable_header(), config.data->recipient); 156 158 nscapi::functions::append_simple_query_request_payload(message.add_payload(), config.data->command, config.data->arguments); 157 std::string result; 158 return config.handler->query(config.data, message.mutable_header(), message.SerializeAsString(), result); 159 return config.handler->query(config.data, message.mutable_header(), message.SerializeAsString(), response); 160 } 161 162 int client::command_line_parser::do_forward(configuration &config, const std::string &request, std::string &response) { 163 /* 164 if (!config.data->target_id.empty()) { 165 if (!config.target_lookup) 166 throw cli_exception("No target interface given when looking for targets"); 167 config.data->recipient.import(config.target_lookup->lookup_target(config.data->target_id)); 168 } 169 */ 170 Plugin::QueryRequestMessage message; 171 message.ParseFromString(request); 172 return config.handler->query(config.data, message.mutable_header(), request, response); 159 173 } 160 174 -
include/client/command_line_parser.hpp
rf33c12f ra87ce04 138 138 139 139 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, 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 141 static int do_relay_submit(configuration &config, const std::string &request, std::string &response); 142 142 … … 159 159 || (command == _T("query")) 160 160 || (command == _T("exec")) 161 ||(command == _T("submit")); 161 || (command == _T("submit")) 162 || (command == _T("forward")); 162 163 } 163 164 164 165 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); 165 167 static int do_exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result); 166 168 static int do_submit(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result); -
include/nrpe/packet.hpp
r96c1461 ra87ce04 225 225 throw nrpe::nrpe_packet_exception(_T("Invalid checksum in NRPE packet: ") + strEx::ihextos(crc32_) + _T("!=") + strEx::ihextos(calculatedCRC32_)); 226 226 // Verify CRC32 end 227 result_ = swap_bytes::ntoh< u_int32_t>(p->result_code);227 result_ = swap_bytes::ntoh<int16_t>(p->result_code); 228 228 payload_ = strEx::string_to_wstring(std::string(p->buffer)); 229 229 } -
include/nsca/nsca_packet.hpp
rf7a074d ra87ce04 2 2 3 3 #include <boost/date_time.hpp> 4 #include <boost/lexical_cast.hpp>5 4 6 5 #include <types.hpp> … … 11 10 #include <utils.h> 12 11 12 namespace nstr = nscp::helpers; 13 13 namespace nsca { 14 14 //#define NSCA_MAX_PLUGINOUTPUT_LENGTH 512 … … 61 61 62 62 /* data packet containing service check results */ 63 class nsca_exception { 64 std::wstring msg_; 65 public: 66 nsca_exception(std::wstring msg) : msg_(msg) {} 67 std::wstring what() { return msg_;} 63 class nsca_exception : public std::exception { 64 std::string msg_; 65 public: 66 nsca_exception() {} 67 ~nsca_exception() throw () {} 68 nsca_exception(std::string msg) : msg_(msg) {} 69 const char* what() const throw () { return msg_.c_str(); } 68 70 }; 69 71 … … 134 136 std::string to_string() const { 135 137 return "service: " + service + ", " + 136 "code: " + boost::lexical_cast<std::string>(code) + ", " +137 "time: " + boost::lexical_cast<std::string>(time) + ", " +138 "code: " + nstr::to_string(code) + ", " + 139 "time: " + nstr::to_string(time) + ", " + 138 140 "result: " + result; 139 141 } … … 157 159 delete [] tmp; 158 160 if (crc32 != calculated_crc32) 159 throw nsca::nsca_exception( _T("Invalid crc: ") + strEx::itos(crc32) + _T(" != ") + strEx::itos(calculated_crc32));161 throw nsca::nsca_exception("Invalid crc: " + nstr::to_string(crc32) + " != " + nstr::to_string(calculated_crc32)); 160 162 } 161 163 … … 163 165 // FIXME: This is crap and needs rewriting. No std::string and beetter zero handling... 164 166 if (service.length() >= nsca::length::desc_length) 165 throw nsca::nsca_exception( _T("Description field to long"));167 throw nsca::nsca_exception("Description field to long: " + nstr::to_string(service.length()) + " > " + nstr::to_string(nsca::length::desc_length)); 166 168 if (host.length() >= nsca::length::host_length) 167 throw nsca::nsca_exception( _T("Host field to long"));169 throw nsca::nsca_exception("Host field to long: " + nstr::to_string(host.length()) + " > " + nstr::to_string(nsca::length::host_length)); 168 170 if (result.length() >= get_payload_length()) 169 throw nsca::nsca_exception( _T("Result field to long"));171 throw nsca::nsca_exception("Result field to long: " + nstr::to_string(result.length()) + " > " + nstr::to_string(get_payload_length())); 170 172 if (buffer.size() < get_packet_length()) 171 throw nsca::nsca_exception( _T("Buffer is to short"));173 throw nsca::nsca_exception("Buffer is to short: " + nstr::to_string(buffer.length()) + " > " + nstr::to_string(get_packet_length())); 172 174 173 175 nsca::data::data_packet *data = reinterpret_cast<nsca::data::data_packet*>(&*buffer.begin()); -
include/nsca/nsca_socket.hpp
r96c1461 ra87ce04 56 56 } 57 57 58 virtual void shutdown() { 59 NSC_DEBUG_MSG(_T("Ending socket (gracefully)")); 60 // Initiate graceful connection closure. 61 boost::system::error_code ignored_ec; 62 get_socket().lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec); 63 }; 64 58 65 virtual void send_nsca(const nsca::packet &packet, const boost::posix_time::seconds timeout) { 59 66 if (!get_socket().is_open()) { … … 64 71 packet.get_buffer(buffer); 65 72 crypt_inst.encrypt_buffer(buffer); 73 NSC_DEBUG_MSG(_T("Sending data: ") + strEx::itos(buffer.size())); 66 74 write_with_timeout(buffer, timeout); 67 75 } -
include/nsca/server/connection.cpp
r9b9be81 ra87ce04 37 37 nsca::iv_packet packet(iv); 38 38 buffers.push_back(buf(packet.get_buffer())); 39 handler_->log_debug(__FILE__, __LINE__, _T("Sending IV...")); 39 40 start_write_request(buffers, 30); 40 41 } … … 64 65 } 65 66 void connection::handle_write_response(const boost::system::error_code& e, std::size_t bytes_transferred) { 66 handler_->log_ error(__FILE__, __LINE__, _T("Wrote data (server): ") + strEx::itos(bytes_transferred));67 handler_->log_debug(__FILE__, __LINE__, _T("Wrote data (server): ") + strEx::itos(bytes_transferred)); 67 68 if (!e) 68 69 start_read_request(buffer_); … … 72 73 void connection::handle_read_request(const boost::system::error_code& e, std::size_t bytes_transferred) { 73 74 if (!e) { 75 handler_->log_debug(__FILE__, __LINE__, _T("Recieved data (server): ") + strEx::itos(bytes_transferred)); 74 76 bool result; 75 77 buffer_type::iterator begin = buffer_.begin(); … … 79 81 boost::tie(result, begin) = parser_.digest(begin, end); 80 82 if (begin == old_begin) { 81 handler_->log_error(__FILE__, __LINE__, _T(" Something strange happened..."));83 handler_->log_error(__FILE__, __LINE__, _T("Failed to digest data")); 82 84 return; 83 85 } … … 101 103 } 102 104 } else { 103 handler_->log_debug(__FILE__, __LINE__, _T("Failed to read request "));105 handler_->log_debug(__FILE__, __LINE__, _T("Failed to read request: ") + utf8::to_unicode(e.message()) + _T(" after ") + strEx::itos(parser_.size())); 104 106 } 105 107 } -
include/nsca/server/parser.hpp
r9b9be81 ra87ce04 42 42 packet_length_ = nsca::length::get_packet_length(length); 43 43 } 44 std::string::size_type size() { 45 return buffer_.size(); 46 } 44 47 }; 45 48 -
include/nscapi/functions.hpp
r330af36 ra87ce04 192 192 return net::parse(address, port); 193 193 } 194 static bool to_bool(std::string value ) {194 static bool to_bool(std::string value, bool def = false) { 195 195 if (value.empty()) 196 return false;197 if (value == "true" || value == "1" )196 return def; 197 if (value == "true" || value == "1" || value == "True") 198 198 return true; 199 199 return false; … … 210 210 211 211 inline int get_int_data(std::string key, int def = 0) { 212 return to_int(data[key]); 213 } 214 inline bool get_bool_data(std::string key, int def = 0) { 215 return to_bool(data[key]); 216 } 217 inline std::string get_string_data(std::string key) { 218 return data[key]; 212 return to_int(data[key], def); 213 } 214 inline bool get_bool_data(std::string key, bool def = false) { 215 return to_bool(data[key], def); 216 } 217 inline std::string get_string_data(std::string key, std::string def = "") { 218 data_map::iterator it = data.find(key); 219 if (it == data.end()) 220 return def; 221 return it->second; 219 222 } 220 223 inline bool has_data(std::string key) { … … 460 463 static int parse_simple_submit_request_payload(const Plugin::QueryResponseMessage::Response &payload, std::wstring &alias, std::wstring &message) { 461 464 alias = utf8::cvt<std::wstring>(payload.alias()); 465 if (alias.empty()) 466 alias = utf8::cvt<std::wstring>(payload.command()); 462 467 message = utf8::cvt<std::wstring>(payload.message()); 463 468 return gbp_to_nagios_status(payload.result()); -
include/nscapi/nscapi_core_wrapper.cpp
r96c1461 ra87ce04 189 189 if (!response.empty()) { 190 190 try { 191 nscapi::functions::parse_simple_query_response(response, msg, perf);191 return nscapi::functions::parse_simple_query_response(response, msg, perf); 192 192 } catch (std::exception &e) { 193 193 CORE_LOG_ERROR_STD(_T("Failed to extract return message: ") + utf8::cvt<std::wstring>(e.what())); -
include/nscapi/nscapi_plugin_wrapper.hpp
r330af36 ra87ce04 357 357 //return helpers::wrap_string(reply, response_buffer, response_buffer_len, retCode); 358 358 return retCode; 359 } catch (const std::exception &e) { 360 NSC_LOG_CRITICAL(_T("Exception in NSHandleNotification: ") + utf8::to_unicode(e.what())); 359 361 } catch (...) { 360 362 NSC_LOG_CRITICAL(_T("Unknown exception in: NSHandleNotification")); -
modules/GraphiteClient/module.cmake
r330af36 ra87ce04 1 SET (BUILD_MODULE 1)1 SET (BUILD_MODULE 0) 2 2 3 3 -
modules/NRPEClient/NRPEClient.cpp
rf33c12f ra87ce04 100 100 101 101 get_core()->registerSubmissionListener(get_id(), channel_); 102 102 register_command(_T("nrpe_query"), _T("Check remote NRPE host")); 103 register_command(_T("nrpe_submit"), _T("Submit (via query) remote NRPE host")); 104 register_command(_T("nrpe_forward"), _T("Forward query to remote NRPE host")); 105 register_command(_T("nrpe_exec"), _T("Execute (via query) remote NRPE host")); 106 register_command(_T("nrpe_help"), _T("Help on using NRPE Client")); 103 107 if (!targets.has_target(_T("default"))) { 104 108 add_target(_T("default"), _T("default")); … … 188 192 NSCAPI::nagiosReturn NRPEClient::handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &result) { 189 193 nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_query_request(char_command, request); 190 std::wstring cmd = client::command_line_parser::parse_command(data.command, _T(" syslog"));194 std::wstring cmd = client::command_line_parser::parse_command(data.command, _T("nrpe")); 191 195 client::configuration config; 192 196 setup(config); 193 if ( !client::command_line_parser::is_command(cmd))194 return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, re sult);197 if (client::command_line_parser::is_command(cmd)) 198 return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, request, result); 195 199 return commands.exec_simple(config, data.target, char_command, data.args, result); 196 200 } … … 262 266 nscapi::functions::destination_container recipient; 263 267 nscapi::functions::parse_destination(header, header.recipient_id(), recipient, true); 264 return connection_data(recipient );268 return connection_data(recipient, targets.find_target(_T("default"))); 265 269 } 266 270 … … 272 276 Plugin::QueryRequestMessage request_message; 273 277 request_message.ParseFromString(request); 274 connection_data con = parse_header(*header);278 connection_data con = this->instance->parse_header(*header); 275 279 276 280 Plugin::QueryResponseMessage response_message; … … 294 298 Plugin::SubmitRequestMessage request_message; 295 299 request_message.ParseFromString(request); 296 connection_data con = parse_header(*header);300 connection_data con = this->instance->parse_header(*header); 297 301 std::wstring channel = utf8::cvt<std::wstring>(request_message.channel()); 298 302 … … 316 320 Plugin::ExecuteRequestMessage request_message; 317 321 request_message.ParseFromString(request); 318 connection_data con = parse_header(*header);322 connection_data con = this->instance->parse_header(*header); 319 323 320 324 Plugin::ExecuteResponseMessage response_message; -
modules/NRPEClient/NRPEClient.h
rf33c12f ra87ce04 51 51 bool use_ssl; 52 52 53 connection_data(nscapi::functions::destination_container recipient ) {54 cert = recipient.get_string_data("certificate" );53 connection_data(nscapi::functions::destination_container recipient, nscapi::target_handler::optarget dt) { 54 cert = recipient.get_string_data("certificate", dt?utf8::cvt<std::string>(dt->options[_T("certificate")]):""); 55 55 timeout = recipient.get_int_data("timeout", 30); 56 56 buffer_length = recipient.get_int_data("payload length", 1024); … … 58 58 if (recipient.has_data("no ssl")) 59 59 use_ssl = !recipient.get_bool_data("no ssl"); 60 if (recipient.has_data("use ssl")) 61 use_ssl = recipient.get_bool_data("use ssl"); 60 62 61 63 net::url url = recipient.get_url(5666); … … 153 155 static nrpe::packet send_ssl(std::string cert, std::string host, std::string port, int timeout, nrpe::packet packet); 154 156 155 staticconnection_data parse_header(const ::Plugin::Common_Header &header);157 connection_data parse_header(const ::Plugin::Common_Header &header); 156 158 157 159 private: -
modules/NSCAClient/NSCAClient.cpp
rf33c12f ra87ce04 228 228 setup(config); 229 229 if (!client::command_line_parser::is_command(cmd)) 230 return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, re sult);230 return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, request, result); 231 231 return commands.exec_simple(config, data.target, char_command, data.args, result); 232 232 } … … 401 401 return NSCAPI::hasFailed; 402 402 } 403 NSC_DEBUG_MSG_STD(_T("Got IV sending data: ") + strEx::itos(packets.size()));403 NSC_DEBUG_MSG_STD(_T("Got IV sending packets: ") + strEx::itos(packets.size())); 404 404 BOOST_FOREACH(const nsca::packet &packet, packets) { 405 NSC_DEBUG_MSG_STD(_T("Sending : ") + utf8::cvt<std::wstring>(packet.to_string()));405 NSC_DEBUG_MSG_STD(_T("Sending (data): ") + utf8::cvt<std::wstring>(packet.to_string())); 406 406 socket.send_nsca(packet, boost::posix_time::seconds(data.timeout)); 407 407 } 408 socket.shutdown(); 408 409 return boost::make_tuple(NSCAPI::returnUNKNOWN, _T("")); 409 } catch ( nsca::nsca_encrypt::encryption_exception &e) {410 } catch (const nsca::nsca_encrypt::encryption_exception &e) { 410 411 NSC_LOG_ERROR_STD(_T("NSCA Error: ") + utf8::to_unicode(e.what())); 411 412 return boost::make_tuple(NSCAPI::returnUNKNOWN, _T("NSCA error: ") + utf8::to_unicode(e.what())); 412 } catch ( std::runtime_error &e) {413 } catch (const std::runtime_error &e) { 413 414 NSC_LOG_ERROR_STD(_T("Socket error: ") + utf8::to_unicode(e.what())); 414 415 return boost::make_tuple(NSCAPI::returnUNKNOWN, _T("Socket error: ") + utf8::to_unicode(e.what())); 415 } catch ( std::exception &e) {416 } catch (const std::exception &e) { 416 417 NSC_LOG_ERROR_STD(_T("Error: ") + utf8::to_unicode(e.what())); 417 418 return boost::make_tuple(NSCAPI::returnUNKNOWN, _T("Error: ") + utf8::to_unicode(e.what())); 418 419 } catch (...) { 420 NSC_LOG_ERROR_STD(_T("Unknown exception when sending NSCA data: ")); 419 421 return boost::make_tuple(NSCAPI::returnUNKNOWN, _T("Unknown error -- REPORT THIS!")); 420 422 } -
modules/NSCAClient/NSCAClient.h
rf33c12f ra87ce04 60 60 password = recipient.get_string_data("password"); 61 61 encryption = recipient.get_string_data("encryption"); 62 time_delta = strEx::stol_as_time_sec(recipient.get_string_data("time offset")); 62 std::string tmp = recipient.get_string_data("time offset"); 63 if (!tmp.empty()) 64 time_delta = strEx::stol_as_time_sec(recipient.get_string_data("time offset")); 65 else 66 time_delta = 0; 63 67 net::url url = recipient.get_url(5667); 64 68 host = url.host; -
modules/NSCPClient/NSCPClient.cpp
rf33c12f ra87ce04 199 199 setup(config); 200 200 if (!client::command_line_parser::is_command(cmd)) 201 return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, re sult);201 return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, request, result); 202 202 return commands.exec_simple(config, data.target, char_command, data.args, result); 203 203 } -
modules/PythonScript/script_wrapper.cpp
rf7a074d ra87ce04 265 265 l.append(utf8::cvt<std::string>(a)); 266 266 } 267 tuple ret = boost::python::call<tuple>(boost::python::object(it->second).ptr(), l);267 object ret = boost::python::call<object>(boost::python::object(it->second).ptr(), l); 268 268 if (ret.ptr() == Py_None) { 269 269 msg = _T("None"); … … 390 390 int ret_code = NSCAPI::returnIgnored; 391 391 try { 392 tuple ret = boost::python::call<tuple>(boost::python::object(it->second).ptr(), channel, request);392 object ret = boost::python::call<object>(boost::python::object(it->second).ptr(), channel, request); 393 393 if (ret.ptr() == Py_None) { 394 394 return NSCAPI::returnIgnored; -
modules/SMTPClient/SMTPClient.cpp
rf33c12f ra87ce04 181 181 setup(config); 182 182 if (!client::command_line_parser::is_command(cmd)) 183 return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, re sult);183 return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, request, result); 184 184 return commands.exec_simple(config, data.target, char_command, data.args, result); 185 185 } -
modules/SyslogClient/SyslogClient.cpp
rf33c12f ra87ce04 228 228 setup(config); 229 229 if (!client::command_line_parser::is_command(cmd)) 230 return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, re sult);230 return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, request, result); 231 231 return commands.exec_simple(config, data.target, char_command, data.args, result); 232 232 } -
scripts/python/test_nsca.py
rf7a074d ra87ce04 106 106 107 107 def inbox_handler_wrapped(self, channel, request): 108 log_error('DISCARD EDmessage on %s'%(channel))108 log_error('DISCARDING message on %s'%(channel)) 109 109 110 110 message = plugin_pb2.SubmitRequestMessage() 111 111 message.ParseFromString(request) 112 112 command = message.payload[0].command 113 #log('Got message %s on %s'%(command, channel))113 log('Got message %s on %s'%(command, channel)) 114 114 115 115 msg = self.get_response(command) 116 116 msg.got_response = True 117 117 self.set_response(msg) 118 return (False, '')118 return None 119 119 120 120 def teardown(self): … … 164 164 sleep(1) 165 165 if not found: 166 result.add_message(False, 'Failed to send message with uuid: %s using %s'%(uid, encryption), err) 167 return result 168 169 def test_one_full(self, encryption, state, key): 170 return self.submit_payload(encryption, '%ssrc%s'%(key, key), state, '%smsg%s'%(key, key), '') 171 172 def test_one(self, crypto): 166 return None 167 return result 168 169 def test_one_crypto_full(self, encryption, state, key): 170 r1 = self.submit_payload(encryption, '%ssrc%s'%(key, key), state, '%smsg%s'%(key, key), '') 171 if r1: 172 return r1 173 result = TestResult() 174 result.add_message(True, '*FAILED* to send message with %s (retrying)'%encryption) 175 r2 = self.submit_payload(encryption, '%ssrc%s'%(key, key), state, '%smsg%s'%(key, key), '') 176 if r2: 177 result.add(r2) 178 return result 179 result.add_message(False, 'Failed to send message with uuid: %s'%encryption) 180 return result 181 182 def test_one_crypto(self, crypto): 173 183 conf = Settings.get() 174 184 conf.set_string('/settings/NSCA/test_nsca_server', 'encryption', '%s'%crypto) … … 176 186 core.reload('test_nsca_server') 177 187 result = TestResult() 178 result.add(self.test_one_ full(crypto, status.UNKNOWN, 'unknown'))179 result.add(self.test_one_ full(crypto, status.OK, 'ok'))180 result.add(self.test_one_ full(crypto, status.WARNING, 'warn'))181 result.add(self.test_one_ full(crypto, status.CRITICAL, 'crit'))188 result.add(self.test_one_crypto_full(crypto, status.UNKNOWN, 'unknown')) 189 result.add(self.test_one_crypto_full(crypto, status.OK, 'ok')) 190 result.add(self.test_one_crypto_full(crypto, status.WARNING, 'warn')) 191 result.add(self.test_one_crypto_full(crypto, status.CRITICAL, 'crit')) 182 192 return result 183 193 … … 187 197 # Currently broken: "xor" 188 198 cryptos = ["des", "3des", "cast128", "xtea", "blowfish", "twofish", "rc2", "aes", "serpent", "gost", "none", "3way"] 189 #cryptos = ["none"]190 199 for c in cryptos: 191 200 result.add_message(True, 'Testing crypto: %s'%c) 192 result.add(self.test_one (c))201 result.add(self.test_one_crypto(c)) 193 202 194 203 return result -
service/NSClient++.cpp
rf085f9b ra87ce04 1207 1207 } 1208 1208 int query_helper(NSClientT::plugin_type plugin, std::wstring command, std::vector<std::wstring> arguments, std::string request, std::list<std::string> *responses) { 1209 std::string response; 1210 if (!plugin->hasCommandHandler()) 1211 return NSCAPI::returnIgnored; 1212 int ret = plugin->handleCommand(command.c_str(), request, response); 1213 if (ret != NSCAPI::returnIgnored && !response.empty()) 1214 responses->push_back(response); 1215 return ret; 1209 return NSCAPI::returnIgnored; 1210 // std::string response; 1211 // if (!plugin->hasCommandHandler()) 1212 // return NSCAPI::returnIgnored; 1213 // int ret = plugin->handleCommand(command.c_str(), request, response); 1214 // if (ret != NSCAPI::returnIgnored && !response.empty()) 1215 // responses->push_back(response); 1216 // return ret; 1216 1217 } 1217 1218 … … 1223 1224 int ret = load_and_run(module, boost::bind(&query_helper, _1, command, arguments, request, &responses), errors); 1224 1225 1225 BOOST_FOREACH(std::string &r, responses) { 1226 try { 1227 std::wstring msg, perf; 1228 nscapi::functions::parse_simple_query_response(r, msg, perf); 1229 resp.push_back(msg + _T("|") + perf); 1230 } catch (std::exception &e) { 1231 resp.push_back(_T("Failed to extract return message: ") + utf8::cvt<std::wstring>(e.what())); 1232 LOG_ERROR_CORE_STD(resp.back()); 1233 return NSCAPI::returnUNKNOWN; 1234 } 1226 nsclient::commands::plugin_type plugin = commands_.get(command); 1227 if (!plugin) { 1228 LOG_ERROR_CORE(_T("No handler for command: ") + command + _T(" avalible commands: ") + commands_.to_wstring()); 1229 return NSCAPI::returnUNKNOWN; 1230 } 1231 std::string response; 1232 NSCAPI::nagiosReturn c = plugin->handleCommand(command.c_str(), request, response); 1233 try { 1234 std::wstring msg, perf; 1235 nscapi::functions::parse_simple_query_response(response, msg, perf); 1236 resp.push_back(msg + _T("|") + perf); 1237 } catch (std::exception &e) { 1238 resp.push_back(_T("Failed to extract return message: ") + utf8::cvt<std::wstring>(e.what())); 1239 LOG_ERROR_CORE_STD(resp.back()); 1240 return NSCAPI::returnUNKNOWN; 1235 1241 } 1236 1242 BOOST_FOREACH(const std::wstring &e, errors) { -
service/cli_parser.hpp
r9c06054 ra87ce04 392 392 mainClient.log_info(__FILE__, __LINE__, _T("Mode: ") + strEx::itos(mode)); 393 393 mainClient.log_info(__FILE__, __LINE__, _T("Boot: ") + strEx::itos(boot)); 394 if (!module.empty() && boot) 395 mainClient.log_info(__FILE__, __LINE__, _T("Warning module and boot specified only THAT module will be loaded")); 394 396 std::wstring args; 395 397 BOOST_FOREACH(std::wstring s, arguments) -
version.hpp
r330af36 ra87ce04 1 1 #ifndef VERSION_HPP 2 2 #define VERSION_HPP 3 #define PRODUCTVER 0,4,0,11 34 #define STRPRODUCTVER "0,4,0,11 3"5 #define STRPRODUCTDATE "2011-12- 08"3 #define PRODUCTVER 0,4,0,118 4 #define STRPRODUCTVER "0,4,0,118" 5 #define STRPRODUCTDATE "2011-12-16" 6 6 #endif // VERSION_HPP -
version.txt
r330af36 ra87ce04 1 1 version=0.4.0 2 build=11 33 date=2011-12- 082 build=118 3 date=2011-12-16
Note: See TracChangeset
for help on using the changeset viewer.








