Changeset b24c97f in nscp


Ignore:
Timestamp:
11/10/11 00:04:50 (19 months ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
d48afa1
Parents:
40fca56
Message:
  • Added initial SyslogClient module to allow syuslog forwarding (of passive checks ish) Still requires template support and configuration options (mainly PoC right now).
Files:
7 added
7 edited

Legend:

Unmodified
Added
Removed
  • changelog

    r40fca56 rb24c97f  
    77 
    882011-11-09 MickeM 
     9 * Added initial SyslogClient module to allow syuslog forwarding (of passive checks ish) 
     10   Still requires template support and configuration options (mainly PoC right now). 
    911 * Added initial SMTPClient to allow sending messages via SMTP. 
    1012   Still requires template support and configuration options (mainly PoC right now). 
     
    128712892005-02-14 MickeM 
    12881290 * Initial SourceForge release 
    1289  
    1290   
  • include/client/command_line_parser.hpp

    r98113da rb24c97f  
    114114    static std::list<std::string> simple_submit(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments); 
    115115 
     116    static std::wstring parse_command(std::wstring command, std::wstring prefix) { 
     117      std::wstring cmd = command; 
     118      if (command.length() > prefix.length()) { 
     119        if (command.substr(0,prefix.length()) == prefix) 
     120          cmd = command.substr(prefix.length()); 
     121        else if (command.substr(command.length()-prefix.length()) == prefix) 
     122          cmd = command.substr(0, command.length()-prefix.length()); 
     123        if (cmd[0] == L'_') 
     124          cmd = cmd.substr(1); 
     125        if (cmd[cmd.length()-1] == L'_') 
     126          cmd = cmd.substr(0, cmd.length()-1); 
     127      } 
     128      return cmd; 
     129    } 
     130 
    116131    static int query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &msg, std::wstring &perf); 
    117132    //static std::list<std::string> submit(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments); 
  • include/net/net.hpp

    ra629015 rb24c97f  
    1010    std::string query; 
    1111    unsigned int port; 
     12    std::string get_port() { 
     13      std::stringstream ss; 
     14      ss << port; 
     15      return ss.str(); 
     16    } 
    1217    std::string to_string() { 
    1318      std::stringstream ss; 
  • include/settings/settings_ini.hpp

    rfb7e36a rb24c97f  
    160160      get_core()->get_logger()->debug(__FILE__, __LINE__, std::wstring(_T("Get sections for: ")) + path); 
    161161      CSimpleIni::TNamesDepend lst; 
     162      std::wstring::size_type path_len = path.length(); 
    162163      ini.GetAllSections(lst); 
    163164      if (path.empty()) { 
     
    172173        } 
    173174      } else { 
    174         for (CSimpleIni::TNamesDepend::const_iterator cit = lst.begin(); cit != lst.end(); ++cit) { 
    175           std::wstring mapped = (*cit).pItem; 
    176           std::wstring::size_type mapped_len = mapped.length(); 
    177           std::wstring::size_type path_len = path.length(); 
    178           if (mapped_len > path_len+1 && mapped.substr(0,path_len) == path) { 
    179             std::wstring::size_type pos = mapped.find(L'/', path_len+1); 
     175        BOOST_FOREACH(const CSimpleIni::Entry e, lst) { 
     176          std::wstring key = e.pItem; 
     177          get_core()->get_logger()->debug(__FILE__, __LINE__, std::wstring(_T("  + ")) + key); 
     178          if (key.length() > path_len+1 && key.substr(0,path_len) == path) { 
     179            get_core()->get_logger()->debug(__FILE__, __LINE__, std::wstring(_T("  + >> ")) + key); 
     180            std::wstring::size_type pos = key.find(L'/', path_len+1); 
    180181            if (pos == std::wstring::npos) 
    181               mapped = mapped.substr(path_len+1); 
     182              key = key.substr(path_len+1); 
    182183            else 
    183               mapped = mapped.substr(path_len+1, pos-path_len-1); 
    184             list.push_back(mapped); 
     184              key = key.substr(path_len+1, pos-path_len-1); 
     185            list.push_back(key); 
    185186          } 
    186187        } 
  • modules/SMTPClient/SMTPClient.cpp

    r40fca56 rb24c97f  
    6161  try { 
    6262    sh::settings_registry settings(get_settings_proxy()); 
    63     settings.set_alias(_T("NSCA"), alias, _T("client")); 
     63    settings.set_alias(_T("SMTP"), alias, _T("client")); 
    6464    target_path = settings.alias().get_settings_path(_T("targets")); 
    6565 
     
    124124 
    125125std::wstring SMTPClient::setup(client::configuration &config, const std::wstring &command) { 
    126   clp_handler_impl *handler = new clp_handler_impl(this, payload_length_, time_delta_); 
     126  clp_handler_impl *handler = new clp_handler_impl(this); 
    127127  add_local_options(config.local, handler->local_data); 
    128   std::wstring cmd = command; 
    129   if (command.length() > 5 && command.substr(0,5) == _T("nsca_")) 
    130     cmd = command.substr(5); 
    131   if (command.length() > 5 && command.substr(command.length()-5) == _T("_nsca")) 
    132     cmd = command.substr(0, command.length()-5); 
     128  std::wstring cmd = client::command_line_parser::parse_command(command, _T("smtp")); 
    133129  config.handler = client::configuration::handler_type(handler); 
    134130  return cmd; 
    135131} 
    136  
    137132 
    138133NSCAPI::nagiosReturn SMTPClient::handleCommand(const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf) { 
     
    159154NSCAPI::nagiosReturn SMTPClient::handleRAWNotification(const wchar_t* channel, std::string request, std::string &response) { 
    160155  try { 
    161  
    162156    client::configuration config; 
    163157    net::wurl url; 
    164158    url.protocol = _T("smtp"); 
    165  
    166159    nscapi::target_handler::optarget target = targets.find_target(_T("default")); 
    167160    if (target) { 
     
    183176    } 
    184177    return NSCAPI::isSuccess; 
    185   } catch (nsca::nsca_encrypt::encryption_exception &e) { 
    186     NSC_LOG_ERROR_STD(_T("Failed to encrypt data: ") + str::to_wstring(e.what())); 
    187     return NSCAPI::hasFailed; 
    188178  } catch (std::exception &e) { 
    189179    NSC_LOG_ERROR_STD(_T("Failed to send data: ") + utf8::cvt<std::wstring>(e.what())); 
     
    194184  } 
    195185} 
    196 NSCAPI::nagiosReturn SMTPClient::send(sender_information &data, const std::list<nsca::packet> packets) { 
    197   try { 
    198     // TODO Add email sending here 
    199     return NSCAPI::isSuccess; 
    200   } catch (nsca::nsca_encrypt::encryption_exception &e) { 
    201     NSC_LOG_ERROR_STD(_T("Failed to encrypt data: ") + str::to_wstring(e.what())); 
    202     return NSCAPI::hasFailed; 
    203   } catch (std::exception &e) { 
    204     NSC_LOG_ERROR_STD(_T("Failed to send data: ") + utf8::cvt<std::wstring>(e.what())); 
    205     return NSCAPI::hasFailed; 
    206   } catch (...) { 
    207     NSC_LOG_ERROR_STD(_T("Failed to send data: UNKNOWN")); 
    208     return NSCAPI::hasFailed; 
    209   } 
    210 } 
    211  
    212186 
    213187////////////////////////////////////////////////////////////////////////// 
    214188// Parser implementations 
    215189int SMTPClient::clp_handler_impl::query(client::configuration::data_type data, std::string request, std::string &reply) { 
    216   NSC_LOG_ERROR_STD(_T("NSCA does not support query patterns")); 
     190  NSC_LOG_ERROR_STD(_T("SMTP does not support query patterns")); 
    217191  return NSCAPI::hasFailed; 
    218192} 
     193int SMTPClient::clp_handler_impl::exec(client::configuration::data_type data, std::string request, std::string &reply) { 
     194  NSC_LOG_ERROR_STD(_T("SMTP does not support exec patterns")); 
     195  return NSCAPI::hasFailed; 
     196} 
     197 
    219198int SMTPClient::clp_handler_impl::submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &response) { 
    220199  try { 
     
    222201    Plugin::SubmitRequestMessage message; 
    223202    message.ParseFromString(request); 
    224     std::list<nsca::packet> list; 
    225     int iii = message.payload_size(); 
    226203 
    227204    std::wstring alias, command, msg, perf; 
     
    248225  } 
    249226} 
    250 int SMTPClient::clp_handler_impl::exec(client::configuration::data_type data, std::string request, std::string &reply) { 
    251   NSC_LOG_ERROR_STD(_T("NSCA does not support exec patterns")); 
    252   return NSCAPI::hasFailed; 
    253 } 
    254  
    255  
    256227 
    257228NSC_WRAP_DLL(); 
  • modules/SMTPClient/SMTPClient.def

    r40fca56 rb24c97f  
    1 LIBRARY NSCAAgent 
     1LIBRARY SMTPClient 
    22 
    33EXPORTS 
  • modules/SMTPClient/SMTPClient.h

    r40fca56 rb24c97f  
    3434 
    3535  std::string hostname_; 
    36   unsigned int payload_length_; 
    37   unsigned int timeout_; 
    3836  std::wstring channel_; 
    39   int time_delta_; 
    4037  nscapi::target_handler targets; 
    4138  std::wstring target_path; 
    4239 
    43  
    44   struct sender_information { 
    45     sender_information(nscapi::functions::destination_container &src) : timeout(10) { 
    46       net::url u = src.get_url(25); 
    47       host = u.host; 
    48       port = u.port; 
    49       //password = src.data["password"]; 
    50       //encryption = src.data["encryption"]; 
    51     } 
    52     std::string password; 
    53     std::string encryption; 
    54     std::string host; 
    55     unsigned int timeout; 
    56     int port; 
    57   }; 
    5840  struct connection_data : public client::nscp_cli_data {}; 
    5941  struct clp_handler_impl : public client::clp_handler { 
    6042 
    6143    SMTPClient *instance; 
    62     clp_handler_impl(SMTPClient *instance, unsigned int payload_length, int time_delta) : instance(instance) {} 
     44    clp_handler_impl(SMTPClient *instance) : instance(instance) {} 
    6345    connection_data local_data; 
    6446 
     
    10082  int commandLineExec(const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result); 
    10183 
    102   NSCAPI::nagiosReturn send(sender_information &data, const std::list<nsca::packet> packets); 
    103  
    104  
    10584  std::wstring setup(client::configuration &config, const std::wstring &command); 
    10685  void add_local_options(boost::program_options::options_description &desc, connection_data &command_data); 
Note: See TracChangeset for help on using the changeset viewer.