Changeset a87ce04 in nscp


Ignore:
Timestamp:
01/08/12 22:29:34 (17 months ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
7354aa1
Parents:
81a6048
Message:
  • Fixed some issues in the NRPE decoder
  • Added support for forwarding queries (ie. xxx_forward) mainly usefull for python(?) scripts where we can now handconstruct messages for delivery
  • Added NRPE unit tests (52 of them)
  • Fixed process enumeration API for 64/32 bit
Files:
2 added
26 edited

Legend:

Unmodified
Added
Removed
  • changelog

    r330af36 ra87ce04  
    55 * Fixa dependonservice LanManWorkStation (old win) 
    66 * Fix RtlStringFromGUID problem on NT4 
     7 
     8 
     92012-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) 
    713 
    8142011-12-08 MickeM 
  • include/EnumProcess.cpp

    r81a6048 ra87ce04  
    292292typedef struct _PROCESS_BASIC_INFORMATION { 
    293293  LONG ExitStatus; 
    294   PVOID PebBaseAddress; 
     294  LPVOID PebBaseAddress; 
    295295  ULONG_PTR AffinityMask; 
    296296  LONG BasePriority; 
     
    299299} PROCESS_BASIC_INFORMATION, *PPROCESS_BASIC_INFORMATION; 
    300300 
    301  
    302301typedef struct _UNICODE_STRING { 
    303302  USHORT Length; 
     
    306305} UNICODE_STRING, *PUNICODE_STRING; 
    307306 
    308 PVOID GetPebAddress(HANDLE ProcessHandle) { 
     307LPVOID GetPebAddress(HANDLE ProcessHandle) { 
    309308  PFNtQueryInformationProcess NtQueryInformationProcess = (PFNtQueryInformationProcess)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtQueryInformationProcess"); 
    310309  if (NtQueryInformationProcess == NULL) 
     
    315314} 
    316315 
     316 
     317typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); 
     318LPFN_ISWOW64PROCESS fnIsWow64Process; 
     319 
     320bool 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 
    317330std::wstring CEnumProcess::GetCommandLine(HANDLE hProcess) { 
    318331 
    319   PVOID rtlUserProcParamsAddress; 
    320332  UNICODE_STRING commandLine; 
    321   PVOID pebAddress = GetPebAddress(hProcess); 
    322  
    323  
    324333#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)) 
    326337    throw process_enumeration_exception(_T("Could not read the address of ProcessParameters: ") + error::lookup::last_error()); 
    327 #else 
    328   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 #endif 
    331  
    332 #ifdef _WIN64 
    333338  if (!ReadProcessMemory(hProcess, (PCHAR)rtlUserProcParamsAddress + 0x70, &commandLine, sizeof(commandLine), NULL)) 
    334339    throw process_enumeration_exception(_T("Could not read commandline: ") + error::lookup::last_error()); 
    335340#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()); 
    336348  if (!ReadProcessMemory(hProcess, (PCHAR)rtlUserProcParamsAddress + 0x40, &commandLine, sizeof(commandLine), NULL)) 
    337349    throw process_enumeration_exception(_T("Could not read commandline: ") + error::lookup::last_error()); 
  • include/client/command_line_parser.cpp

    rf33c12f ra87ce04  
    7373} 
    7474 
    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) { 
     75int 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) { 
    7676  if (!config.validate()) 
    7777    throw cli_exception("Invalid data: " + config.to_string()); 
     
    8080  } else if (command == _T("query")) { 
    8181    return do_query(config, command, arguments, result); 
     82  } else if (command == _T("forward")) { 
     83    return do_forward(config, request, result); 
    8284  } else if (command == _T("exec")) { 
    8385    int ret = do_exec(config, command, arguments, result); 
     
    155157  modify_header(config, message.mutable_header(), config.data->recipient); 
    156158  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 
     162int 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); 
    159173} 
    160174 
  • include/client/command_line_parser.hpp

    rf33c12f ra87ce04  
    138138 
    139139    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); 
    141141    static int do_relay_submit(configuration &config, const std::string &request, std::string &response); 
    142142 
     
    159159        || (command == _T("query")) 
    160160        || (command == _T("exec")) 
    161         ||(command == _T("submit")); 
     161        || (command == _T("submit")) 
     162        || (command == _T("forward")); 
    162163    } 
    163164 
    164165    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); 
    165167    static int do_exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result); 
    166168    static int do_submit(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result); 
  • include/nrpe/packet.hpp

    r96c1461 ra87ce04  
    225225        throw nrpe::nrpe_packet_exception(_T("Invalid checksum in NRPE packet: ") + strEx::ihextos(crc32_) + _T("!=") + strEx::ihextos(calculatedCRC32_)); 
    226226      // Verify CRC32 end 
    227       result_ = swap_bytes::ntoh<u_int32_t>(p->result_code); 
     227      result_ = swap_bytes::ntoh<int16_t>(p->result_code); 
    228228      payload_ = strEx::string_to_wstring(std::string(p->buffer)); 
    229229    } 
  • include/nsca/nsca_packet.hpp

    rf7a074d ra87ce04  
    22 
    33#include <boost/date_time.hpp> 
    4 #include <boost/lexical_cast.hpp> 
    54 
    65#include <types.hpp> 
     
    1110#include <utils.h> 
    1211 
     12namespace nstr = nscp::helpers; 
    1313namespace nsca { 
    1414//#define NSCA_MAX_PLUGINOUTPUT_LENGTH  512 
     
    6161 
    6262  /* 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(); } 
    6870  }; 
    6971 
     
    134136    std::string to_string() const { 
    135137      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) + ", " +  
    138140        "result: " + result; 
    139141    } 
     
    157159      delete [] tmp; 
    158160      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)); 
    160162    } 
    161163 
     
    163165      // FIXME: This is crap and needs rewriting. No std::string and beetter zero handling... 
    164166      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)); 
    166168      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)); 
    168170      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())); 
    170172      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())); 
    172174 
    173175      nsca::data::data_packet *data = reinterpret_cast<nsca::data::data_packet*>(&*buffer.begin()); 
  • include/nsca/nsca_socket.hpp

    r96c1461 ra87ce04  
    5656    } 
    5757 
     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 
    5865    virtual void send_nsca(const nsca::packet &packet, const boost::posix_time::seconds timeout) { 
    5966      if (!get_socket().is_open()) { 
     
    6471      packet.get_buffer(buffer); 
    6572      crypt_inst.encrypt_buffer(buffer); 
     73      NSC_DEBUG_MSG(_T("Sending data: ") + strEx::itos(buffer.size())); 
    6674      write_with_timeout(buffer, timeout); 
    6775    } 
  • include/nsca/server/connection.cpp

    r9b9be81 ra87ce04  
    3737      nsca::iv_packet packet(iv); 
    3838      buffers.push_back(buf(packet.get_buffer())); 
     39      handler_->log_debug(__FILE__, __LINE__, _T("Sending IV...")); 
    3940      start_write_request(buffers, 30); 
    4041    } 
     
    6465    } 
    6566    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)); 
    6768      if (!e) 
    6869        start_read_request(buffer_); 
     
    7273    void connection::handle_read_request(const boost::system::error_code& e, std::size_t bytes_transferred) { 
    7374      if (!e) { 
     75        handler_->log_debug(__FILE__, __LINE__, _T("Recieved data (server): ") + strEx::itos(bytes_transferred)); 
    7476        bool result; 
    7577        buffer_type::iterator begin = buffer_.begin(); 
     
    7981          boost::tie(result, begin) = parser_.digest(begin, end); 
    8082          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")); 
    8284            return; 
    8385          } 
     
    101103        } 
    102104      } 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())); 
    104106      } 
    105107    } 
  • include/nsca/server/parser.hpp

    r9b9be81 ra87ce04  
    4242        packet_length_ = nsca::length::get_packet_length(length); 
    4343      } 
     44      std::string::size_type size() { 
     45        return buffer_.size(); 
     46      } 
    4447    }; 
    4548 
  • include/nscapi/functions.hpp

    r330af36 ra87ce04  
    192192        return net::parse(address, port); 
    193193      } 
    194       static bool to_bool(std::string value) { 
     194      static bool to_bool(std::string value, bool def = false) { 
    195195        if (value.empty()) 
    196           return false; 
    197         if (value == "true" || value == "1") 
     196          return def; 
     197        if (value == "true" || value == "1" || value == "True") 
    198198          return true; 
    199199        return false; 
     
    210210 
    211211      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; 
    219222      } 
    220223      inline bool has_data(std::string key) { 
     
    460463    static int parse_simple_submit_request_payload(const Plugin::QueryResponseMessage::Response &payload, std::wstring &alias, std::wstring &message) { 
    461464      alias = utf8::cvt<std::wstring>(payload.alias()); 
     465      if (alias.empty()) 
     466        alias = utf8::cvt<std::wstring>(payload.command()); 
    462467      message = utf8::cvt<std::wstring>(payload.message()); 
    463468      return gbp_to_nagios_status(payload.result()); 
  • include/nscapi/nscapi_core_wrapper.cpp

    r96c1461 ra87ce04  
    189189  if (!response.empty()) { 
    190190    try { 
    191       nscapi::functions::parse_simple_query_response(response, msg, perf); 
     191      return nscapi::functions::parse_simple_query_response(response, msg, perf); 
    192192    } catch (std::exception &e) { 
    193193      CORE_LOG_ERROR_STD(_T("Failed to extract return message: ") + utf8::cvt<std::wstring>(e.what())); 
  • include/nscapi/nscapi_plugin_wrapper.hpp

    r330af36 ra87ce04  
    357357        //return helpers::wrap_string(reply, response_buffer, response_buffer_len, retCode); 
    358358        return retCode; 
     359      } catch (const std::exception &e) {  
     360        NSC_LOG_CRITICAL(_T("Exception in NSHandleNotification: ") + utf8::to_unicode(e.what()));  
    359361      } catch (...) {  
    360362        NSC_LOG_CRITICAL(_T("Unknown exception in: NSHandleNotification"));  
  • modules/GraphiteClient/module.cmake

    r330af36 ra87ce04  
    1 SET (BUILD_MODULE 1) 
     1SET (BUILD_MODULE 0) 
    22 
    33 
  • modules/NRPEClient/NRPEClient.cpp

    rf33c12f ra87ce04  
    100100 
    101101    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")); 
    103107    if (!targets.has_target(_T("default"))) { 
    104108      add_target(_T("default"), _T("default")); 
     
    188192NSCAPI::nagiosReturn NRPEClient::handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &result) { 
    189193  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")); 
    191195  client::configuration config; 
    192196  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, result); 
     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); 
    195199  return commands.exec_simple(config, data.target, char_command, data.args, result); 
    196200} 
     
    262266  nscapi::functions::destination_container recipient; 
    263267  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"))); 
    265269} 
    266270 
     
    272276  Plugin::QueryRequestMessage request_message; 
    273277  request_message.ParseFromString(request); 
    274   connection_data con = parse_header(*header); 
     278  connection_data con = this->instance->parse_header(*header); 
    275279 
    276280  Plugin::QueryResponseMessage response_message; 
     
    294298  Plugin::SubmitRequestMessage request_message; 
    295299  request_message.ParseFromString(request); 
    296   connection_data con = parse_header(*header); 
     300  connection_data con = this->instance->parse_header(*header); 
    297301  std::wstring channel = utf8::cvt<std::wstring>(request_message.channel()); 
    298302   
     
    316320  Plugin::ExecuteRequestMessage request_message; 
    317321  request_message.ParseFromString(request); 
    318   connection_data con = parse_header(*header); 
     322  connection_data con = this->instance->parse_header(*header); 
    319323 
    320324  Plugin::ExecuteResponseMessage response_message; 
  • modules/NRPEClient/NRPEClient.h

    rf33c12f ra87ce04  
    5151    bool use_ssl; 
    5252 
    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")]):""); 
    5555      timeout = recipient.get_int_data("timeout", 30); 
    5656      buffer_length = recipient.get_int_data("payload length", 1024); 
     
    5858      if (recipient.has_data("no ssl")) 
    5959        use_ssl = !recipient.get_bool_data("no ssl"); 
     60      if (recipient.has_data("use ssl")) 
     61        use_ssl = recipient.get_bool_data("use ssl"); 
    6062 
    6163      net::url url = recipient.get_url(5666); 
     
    153155  static nrpe::packet send_ssl(std::string cert, std::string host, std::string port, int timeout, nrpe::packet packet); 
    154156 
    155   static connection_data parse_header(const ::Plugin::Common_Header &header); 
     157  connection_data parse_header(const ::Plugin::Common_Header &header); 
    156158 
    157159private: 
  • modules/NSCAClient/NSCAClient.cpp

    rf33c12f ra87ce04  
    228228  setup(config); 
    229229  if (!client::command_line_parser::is_command(cmd)) 
    230     return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, result); 
     230    return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, request, result); 
    231231  return commands.exec_simple(config, data.target, char_command, data.args, result); 
    232232} 
     
    401401      return NSCAPI::hasFailed; 
    402402    } 
    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())); 
    404404    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())); 
    406406      socket.send_nsca(packet, boost::posix_time::seconds(data.timeout)); 
    407407    } 
     408    socket.shutdown(); 
    408409    return boost::make_tuple(NSCAPI::returnUNKNOWN, _T("")); 
    409   } catch (nsca::nsca_encrypt::encryption_exception &e) { 
     410  } catch (const nsca::nsca_encrypt::encryption_exception &e) { 
    410411    NSC_LOG_ERROR_STD(_T("NSCA Error: ") + utf8::to_unicode(e.what())); 
    411412    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) { 
    413414    NSC_LOG_ERROR_STD(_T("Socket error: ") + utf8::to_unicode(e.what())); 
    414415    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) { 
    416417    NSC_LOG_ERROR_STD(_T("Error: ") + utf8::to_unicode(e.what())); 
    417418    return boost::make_tuple(NSCAPI::returnUNKNOWN, _T("Error: ") + utf8::to_unicode(e.what())); 
    418419  } catch (...) { 
     420    NSC_LOG_ERROR_STD(_T("Unknown exception when sending NSCA data: ")); 
    419421    return boost::make_tuple(NSCAPI::returnUNKNOWN, _T("Unknown error -- REPORT THIS!")); 
    420422  } 
  • modules/NSCAClient/NSCAClient.h

    rf33c12f ra87ce04  
    6060      password = recipient.get_string_data("password"); 
    6161      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; 
    6367      net::url url = recipient.get_url(5667); 
    6468      host = url.host; 
  • modules/NSCPClient/NSCPClient.cpp

    rf33c12f ra87ce04  
    199199  setup(config); 
    200200  if (!client::command_line_parser::is_command(cmd)) 
    201     return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, result); 
     201    return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, request, result); 
    202202  return commands.exec_simple(config, data.target, char_command, data.args, result); 
    203203} 
  • modules/PythonScript/script_wrapper.cpp

    rf7a074d ra87ce04  
    265265          l.append(utf8::cvt<std::string>(a)); 
    266266        } 
    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); 
    268268        if (ret.ptr() == Py_None) { 
    269269          msg = _T("None"); 
     
    390390      int ret_code = NSCAPI::returnIgnored; 
    391391      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); 
    393393        if (ret.ptr() == Py_None) { 
    394394          return NSCAPI::returnIgnored; 
  • modules/SMTPClient/SMTPClient.cpp

    rf33c12f ra87ce04  
    181181  setup(config); 
    182182  if (!client::command_line_parser::is_command(cmd)) 
    183     return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, result); 
     183    return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, request, result); 
    184184  return commands.exec_simple(config, data.target, char_command, data.args, result); 
    185185} 
  • modules/SyslogClient/SyslogClient.cpp

    rf33c12f ra87ce04  
    228228  setup(config); 
    229229  if (!client::command_line_parser::is_command(cmd)) 
    230     return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, result); 
     230    return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, request, result); 
    231231  return commands.exec_simple(config, data.target, char_command, data.args, result); 
    232232} 
  • scripts/python/test_nsca.py

    rf7a074d ra87ce04  
    106106 
    107107  def inbox_handler_wrapped(self, channel, request): 
    108     log_error('DISCARDED message on %s'%(channel)) 
     108    log_error('DISCARDING message on %s'%(channel)) 
    109109     
    110110    message = plugin_pb2.SubmitRequestMessage() 
    111111    message.ParseFromString(request) 
    112112    command = message.payload[0].command 
    113     #log('Got message %s on %s'%(command, channel)) 
     113    log('Got message %s on %s'%(command, channel)) 
    114114     
    115115    msg = self.get_response(command) 
    116116    msg.got_response = True 
    117117    self.set_response(msg) 
    118     return (False, '') 
     118    return None 
    119119     
    120120  def teardown(self): 
     
    164164        sleep(1) 
    165165    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): 
    173183    conf = Settings.get() 
    174184    conf.set_string('/settings/NSCA/test_nsca_server', 'encryption', '%s'%crypto) 
     
    176186    core.reload('test_nsca_server') 
    177187    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')) 
    182192    return result 
    183193 
     
    187197    # Currently broken: "xor" 
    188198    cryptos = ["des", "3des", "cast128", "xtea", "blowfish", "twofish", "rc2", "aes", "serpent", "gost", "none", "3way"] 
    189     #cryptos = ["none"] 
    190199    for c in cryptos: 
    191200      result.add_message(True, 'Testing crypto: %s'%c) 
    192       result.add(self.test_one(c)) 
     201      result.add(self.test_one_crypto(c)) 
    193202     
    194203    return result 
  • service/NSClient++.cpp

    rf085f9b ra87ce04  
    12071207} 
    12081208int 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; 
    12161217} 
    12171218 
     
    12231224  int ret = load_and_run(module, boost::bind(&query_helper, _1, command, arguments, request, &responses), errors); 
    12241225 
    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; 
    12351241  } 
    12361242  BOOST_FOREACH(const std::wstring &e, errors) { 
  • service/cli_parser.hpp

    r9c06054 ra87ce04  
    392392        mainClient.log_info(__FILE__, __LINE__, _T("Mode: ") + strEx::itos(mode)); 
    393393        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")); 
    394396        std::wstring args; 
    395397        BOOST_FOREACH(std::wstring s, arguments) 
  • version.hpp

    r330af36 ra87ce04  
    11#ifndef VERSION_HPP 
    22#define VERSION_HPP 
    3 #define PRODUCTVER     0,4,0,113 
    4 #define STRPRODUCTVER  "0,4,0,113" 
    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" 
    66#endif // VERSION_HPP 
  • version.txt

    r330af36 ra87ce04  
    11version=0.4.0 
    2 build=113 
    3 date=2011-12-08 
     2build=118 
     3date=2011-12-16 
Note: See TracChangeset for help on using the changeset viewer.