Changeset 822454f in nscp


Ignore:
Timestamp:
03/20/12 23:34:15 (14 months ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
83c2453
Parents:
74e060a
Message:
  • Fixed alias/service name for real-time event log filters
  • Added smtp/syslog and graphite clients to installer
  • Fixed so eventlog wont crash on invalid messages
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • changelog

    r74e060a r822454f  
    44 * Fixa dependonservice LanManWorkStation (old win) 
    55 * Fix RtlStringFromGUID problem on NT4 
     6 
     72012-03-20 MickeM 
     8 * Fixed alias/service name for real-time event log filters 
     9 * Added smtp/syslog and graphite clients to installer 
     10 * Fixed so eventlog wont crahs on invalid messages 
    611 
    7122012-03-19 MickeM 
  • helpers/installers/installer/Product.wxs

    r74e060a r822454f  
    140140            <Component Id="PythonScript" Guid="8820A304-C696-4393-A72F-$(var.Postfix.GUID)" Win64="$(var.Win64)"> 
    141141              <File Id="PythonScript" Name="PythonScript.dll" DiskId="1" Source="$(var.Source)/modules/PythonScript.dll" Vital="no" /> 
     142            </Component> 
     143            <Component Id="ExtraClients" Guid="8820A304-C696-4393-A72F-$(var.Postfix.GUID)" Win64="$(var.Win64)"> 
     144              <File Id="GraphiteClient" Name="GraphiteClient.dll" DiskId="1" Source="$(var.Source)/modules/GraphiteClient.dll" Vital="no" /> 
     145              <File Id="SMTPClient" Name="SMTPClient.dll" DiskId="1" Source="$(var.Source)/modules/SMTPClient.dll" Vital="no" /> 
     146              <File Id="SyslogClient" Name="SyslogClient.dll" DiskId="1" Source="$(var.Source)/modules/SyslogClient.dll" Vital="no" /> 
    142147            </Component> 
    143148            <Component Id="Plugins" Guid="9B490E67-5472-4266-96DC-$(var.Postfix.GUID)" Win64="$(var.Win64)"> 
     
    270275          <ComponentRef Id="NSCA" /> 
    271276        </Feature> 
     277        <Feature Id="ExtraClientPlugin" Title="Various client plugins" Description="Plugins to connect to various sytems such as syslog, graphite and smtp" Level="1" Absent="disallow"> 
     278          <ComponentRef Id="ExtraClients" /> 
     279        </Feature> 
    272280        <Feature Id="NSCPPlugin" Title="NSCP plugin (experimental)" Description="Plugin to submit passive results to an NSCP server" Level="1" Absent="disallow"> 
    273281          <ComponentRef Id="NSCP" /> 
  • helpers/installers/ui/SelectConfigurationDlg.wxs

    rc88cf98 r822454f  
    1919          <Condition Action="disable"><![CDATA[CONFIGURATION_TYPE <> "ini://${exe-path}/nsclient.ini"]]></Condition> 
    2020        </Control> 
    21         <Control Id="userWriteConfig" Type="CheckBox" X="60"  Y="88" Width="260" Height="20" Property="USER_WRITABLE_CONFIG" Text="Allow Everyone to write config file" CheckBoxValue="1"> 
     21        <Control Id="userWriteConfig" Type="CheckBox" X="60"  Y="88" Width="260" Height="20" Property="USER_WRITABLE_CONFIG" Text="Allow all users to write config file" CheckBoxValue="1"> 
    2222          <Condition Action="enable">CONFIGURATION_TYPE = "ini://${exe-path}/nsclient.ini" AND INSTALL_SAMPLE_CONFIG</Condition> 
    2323          <Condition Action="disable"><![CDATA[CONFIGURATION_TYPE <> "ini://${exe-path}/nsclient.ini" OR NOT INSTALL_SAMPLE_CONFIG]]></Condition> 
  • modules/CheckEventLog/CheckEventLog.cpp

    r74e060a r822454f  
    147147} 
    148148 
    149 void real_time_thread::process_no_events() { 
     149void real_time_thread::process_no_events(std::wstring alias) { 
    150150  std::wstring response; 
    151   if (!nscapi::core_helper::submit_simple_message(info.target, info.alias, NSCAPI::returnCRIT, info.ok_msg, info.perf_msg, response)) { 
     151  if (alias.empty()) 
     152    alias = info.alias; 
     153  if (!nscapi::core_helper::submit_simple_message(info.target, alias, NSCAPI::returnCRIT, info.ok_msg, info.perf_msg, response)) { 
    152154    NSC_LOG_ERROR(_T("Failed to submit evenhtlog result: ") + response); 
    153155  } 
    154156} 
    155157 
    156 void real_time_thread::process_record(const EventLogRecord &record) { 
     158void real_time_thread::process_record(std::wstring alias, const EventLogRecord &record) { 
    157159  std::wstring response; 
    158160  std::wstring message = record.render(true, info.syntax, DATE_FORMAT, info.dwLang); 
    159   if (!nscapi::core_helper::submit_simple_message(info.target, info.alias, NSCAPI::returnCRIT, message, info.perf_msg, response)) { 
     161  if (alias.empty()) 
     162    alias = info.alias; 
     163  if (!nscapi::core_helper::submit_simple_message(info.target, alias, NSCAPI::returnCRIT, message, info.perf_msg, response)) { 
    160164    NSC_LOG_ERROR(_T("Failed to submit evenhtlog result: ") + response); 
    161165  } 
     
    199203 
    200204  std::list<eventlog_filter::filter_engine> filters; 
    201   BOOST_FOREACH(std::wstring filter, filters_) { 
     205  BOOST_FOREACH(const filter_container &filter, filters_) { 
    202206    eventlog_filter::filter_argument fargs = eventlog_filter::factories::create_argument(info.syntax, DATE_FORMAT); 
    203     fargs->filter = filter; 
    204     fargs->debug = true; 
     207    fargs->filter = filter.filter; 
     208    fargs->debug = debug_; 
     209    fargs->alias = filter.alias; 
    205210    eventlog_filter::filter_engine engine = eventlog_filter::factories::create_engine(fargs); 
    206211 
    207212    if (!engine) { 
    208       NSC_LOG_ERROR_STD(_T("Invalid filter: ") + filter); 
     213      NSC_LOG_ERROR_STD(_T("Invalid filter: ") + filter.filter); 
    209214      continue; 
    210215    } 
    211216 
    212217    if (!engine->boot()) { 
    213       NSC_LOG_ERROR_STD(_T("Error booting filter: ") + filter); 
     218      NSC_LOG_ERROR_STD(_T("Error booting filter: ") + filter.filter); 
    214219      continue; 
    215220    } 
     
    253258    DWORD dwWaitReason = WaitForMultipleObjects(list.size()+1, handles, FALSE, dwWaitTime==0?INFINITE:dwWaitTime); 
    254259    if (dwWaitReason == WAIT_TIMEOUT) { 
    255       process_no_events(); 
     260      BOOST_FOREACH(eventlog_filter::filter_engine engine, filters) { 
     261        process_no_events(engine->data->alias); 
     262      } 
    256263    } else if (dwWaitReason == WAIT_OBJECT_0) { 
    257264      delete [] handles; 
     
    277284        BOOST_FOREACH(eventlog_filter::filter_engine engine, filters) { 
    278285          if (engine->match(arg)) { 
    279             process_record(elr); 
     286            process_record(engine->data->alias, elr); 
    280287            matched = true; 
    281288          } 
     
    320327 
    321328void real_time_thread::add_realtime_filter(std::wstring key, std::wstring query) { 
    322   if (!key.empty() && query.empty()) 
    323     filters_.push_back(key); 
    324   else 
    325     filters_.push_back(query); 
     329  filter_container c; 
     330  if (!key.empty() && query.empty()) { 
     331    c.filter = key; 
     332    filters_.push_back(c); 
     333  } else { 
     334    c.alias = key; 
     335    c.filter = query; 
     336    filters_.push_back(c); 
     337  } 
    326338} 
    327339 
     
    374386 
    375387      (_T("maximum age"), sh::string_fun_key<std::wstring>(boost::bind(&real_time_thread::set_max_age, &thread_, _1), _T("5m")), 
    376       _T("MAGIMUM AGE"), _T("How long befor reporting \"ok\" (if this is set to off no ok will be reported only errors)")) 
     388      _T("MAGIMUM AGE"), _T("How long before reporting \"ok\" (if this is set to off no ok will be reported only errors)")) 
    377389 
    378390      (_T("filter"), sh::string_fun_key<std::wstring>(boost::bind(&real_time_thread::set_filter, &thread_, _1), _T("")), 
     
    394406      _T("ENABLE ACTIVE MONITORING"), _T("This will store all matches so you can use real-time filters from active monitoring (use CheckEventlogCache).")) 
    395407 
     408      (_T("ok message"), sh::wstring_key(&thread_.info.ok_msg, _T("eventlog found no records")), 
     409      _T("OK MESSAGE"), _T("This is the message sent periodically whenever no error is discovered.")) 
     410 
     411      (_T("alias"), sh::wstring_key(&thread_.info.alias, _T("eventlog")), 
     412      _T("ALIAS"), _T("The alias to use for this event (in NSCA this constitutes the service name).")) 
    396413      ; 
    397414 
  • modules/CheckEventLog/CheckEventLog.h

    r74e060a r822454f  
    3737    std::wstring syntax; 
    3838    std::wstring ok_msg; 
    39     std::wstring perf_msg; 
    40     bool perf; 
     39    std::wstring perf_msg; // 
     40    //bool perf; 
    4141    DWORD dwLang; 
    4242 
     43  }; 
     44 
     45  struct filter_container { 
     46    std::wstring filter; 
     47    std::wstring alias; 
    4348  }; 
    4449 
     
    4954  unsigned long long max_age_; 
    5055  //std::wstring syntax_; 
    51   std::list<std::wstring> filters_; 
     56  std::list<filter_container> filters_; 
    5257  boost::shared_ptr<boost::thread> thread_; 
    5358  HANDLE stop_event_; 
     
    9499  void thread_proc(); 
    95100//  void process_events(eventlog_filter::filter_engine engine, eventlog_wrapper &eventlog); 
    96   void process_no_events(); 
    97   void process_record(const EventLogRecord &record); 
     101  void process_no_events(std::wstring alias); 
     102  void process_record(std::wstring alias, const EventLogRecord &record); 
    98103  void debug_miss(const EventLogRecord &record); 
    99104//  void process_event(eventlog_filter::filter_engine engine, const EVENTLOGRECORD* record); 
  • modules/CheckEventLog/eventlog_record.hpp

    r74e060a r822454f  
    188188  }; 
    189189 
    190   boost::tuple<DWORD,std::wstring> wrapped_format(HMODULE hDLL, DWORD dwLang, DWORD id, tchar_array &buffer) const { 
     190  boost::tuple<DWORD,std::wstring> safe_format(HMODULE hDLL, DWORD dwLang) const { 
    191191    LPVOID lpMsgBuf; 
    192192    unsigned long dwRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_HMODULE|FORMAT_MESSAGE_ARGUMENT_ARRAY|FORMAT_MESSAGE_IGNORE_INSERTS,hDLL, 
    193       id,dwLang,(LPTSTR)&lpMsgBuf,0,reinterpret_cast<va_list*>(buffer.get_buffer_unsafe())); 
     193      pevlr_->EventID,dwLang,(LPTSTR)&lpMsgBuf,0,NULL); 
    194194    if (dwRet == 0) { 
    195195      return boost::tuple<DWORD,std::wstring>(GetLastError(), _T("")); 
    196196    } 
    197     LocalFree(lpMsgBuf); 
    198     dwRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_HMODULE|FORMAT_MESSAGE_ARGUMENT_ARRAY,hDLL, 
    199       id,dwLang,(LPTSTR)&lpMsgBuf,0,reinterpret_cast<va_list*>(buffer.get_buffer_unsafe())); 
    200     if (dwRet == 0) 
    201       return boost::make_tuple(GetLastError(), _T("")); 
    202197    std::wstring msg = reinterpret_cast<wchar_t*>(lpMsgBuf); 
    203198    LocalFree(lpMsgBuf); 
     199    const TCHAR* p = reinterpret_cast<const TCHAR*>(reinterpret_cast<const BYTE*>(pevlr_) + pevlr_->StringOffset); 
     200    for (unsigned int i = 0;i<pevlr_->NumStrings;i++) { 
     201      strEx::replace(msg, _T("%")+strEx::itos(i+1), std::wstring(p)); 
     202      unsigned int len = wcslen(p); 
     203      p = &(p[len+1]); 
     204    } 
    204205    return boost::make_tuple(0, msg); 
    205206  } 
    206207  std::wstring render_message(DWORD dwLang = 0) const { 
    207208    std::vector<std::wstring> args; 
    208     const TCHAR* p = reinterpret_cast<const TCHAR*>(reinterpret_cast<const BYTE*>(pevlr_) + pevlr_->StringOffset); 
    209  
    210     tchar_array buffer(pevlr_->NumStrings+10); 
    211     for (unsigned int i = 0;i<pevlr_->NumStrings;i++) { 
    212       unsigned int len = buffer.set(i, p); 
    213       p = &(p[len+1]); 
    214     } 
    215     for (unsigned int i = pevlr_->NumStrings;i<pevlr_->NumStrings+10;i++) { 
    216       unsigned int len = buffer.set(i, _T("")); 
    217     } 
    218209    std::wstring ret; 
    219210    strEx::splitList dlls = strEx::splitEx(get_dll(), _T(";")); 
     
    229220        if (dwLang == 0) 
    230221          dwLang = MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT); 
    231         boost::tuple<DWORD,std::wstring> formated_data = wrapped_format(hDLL, dwLang, pevlr_->EventID, buffer); 
     222        boost::tuple<DWORD,std::wstring> formated_data = safe_format(hDLL, dwLang); 
    232223        if (formated_data.get<0>() != 0) { 
    233224          FreeLibrary(hDLL); 
  • modules/CheckEventLog/filter.hpp

    r74e060a r822454f  
    140140    bool bShowDescriptions; 
    141141    unsigned long long now; 
     142    std::wstring alias; 
    142143 
    143144    data_arguments(parent_type::error_type error, std::wstring syntax, std::wstring datesyntax, bool debug = false) : where_filter::argument_interface(error, syntax, datesyntax) 
  • version.hpp

    r74e060a r822454f  
    11#ifndef VERSION_HPP 
    22#define VERSION_HPP 
    3 #define PRODUCTVER     0,4,0,145 
    4 #define STRPRODUCTVER  "0,4,0,145" 
    5 #define STRPRODUCTDATE "2012-03-18" 
     3#define PRODUCTVER     0,4,0,147 
     4#define STRPRODUCTVER  "0,4,0,147" 
     5#define STRPRODUCTDATE "2012-03-20" 
    66#endif // VERSION_HPP 
  • version.txt

    r74e060a r822454f  
    11version=0.4.0 
    2 build=145 
    3 date=2012-03-18 
     2build=147 
     3date=2012-03-20 
Note: See TracChangeset for help on using the changeset viewer.