Changeset 5e12ba6 in nscp


Ignore:
Timestamp:
09/17/10 14:06:48 (3 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
c015acc
Parents:
7065334
Message:

Various minor changes (NOT BUILDING PROPERLY)

Files:
21 edited

Legend:

Unmodified
Added
Removed
  • include/nscapi/nscapi_plugin_wrapper.hpp

    r497b779 r5e12ba6  
    172172    class simple_plugin { 
    173173    public: 
    174       nscapi::core_wrapper* get_core() { 
     174      inline nscapi::core_wrapper* get_core() { 
    175175        return nscapi::plugin_singleton->get_core(); 
    176176      } 
  • include/nscapi/settings.hpp

    r291548e r5e12ba6  
    144144    typed_key_fun<T, typed_bool_value<T> >* bool_fun_key(boost::function<void (T)> fun, T def) { 
    145145      typed_key_fun<T, typed_bool_value<T> >* r = new typed_key_fun<T, typed_bool_value<T> >(fun, def); 
     146      return r; 
     147    } 
     148    template<class T> 
     149    typed_key_fun<T, typed_string_value<T> >* string_fun_key(boost::function<void (T)> fun, T def) { 
     150      typed_key_fun<T, typed_string_value<T> >* r = new typed_key_fun<T, typed_string_value<T> >(fun, def); 
    146151      return r; 
    147152    } 
  • include/pdh/collectors.hpp

    rf0e6036 r5e12ba6  
    113113  }; 
    114114 
     115  class PDHCollector : public PDH::PDHCounterListener{ 
     116  public: 
     117    virtual std::wstring get_string() = 0; 
     118    virtual double get_double() = 0; 
     119    virtual __int64 get_int64() = 0; 
     120    virtual double get_average(int backlog) = 0; 
     121  }; 
     122 
     123 
    115124  template <class TType, int TCollectionFormat, class TMutextHandler = PDHCounterNoMutex> 
    116125  class StaticPDHCounterListener { 
     
    118127 
    119128  template <class TType, class TMutextHandler> 
    120   class StaticPDHCounterListener<TType, format_double, TMutextHandler> : public PDH::PDHCounterListener { 
     129  class StaticPDHCounterListener<TType, format_double, TMutextHandler> : public PDHCollector { 
    121130    TType value_; 
    122131    TMutextHandler mutex_; 
     
    146155      return format_double; 
    147156    } 
     157  public: 
     158    inline std::wstring get_string() { 
     159      return to_wstring(getValue()); 
     160    } 
     161    inline double get_double() { 
     162      return static_cast<double>(getValue()); 
     163    } 
     164    __int64 get_int64() { 
     165      return getValue(); 
     166    } 
     167    inline double get_average(int backlog) { 
     168      return static_cast<double>(getValue()); 
     169    } 
    148170  private: 
    149171    std::wstring get_name() const { 
     
    155177 
    156178  template <class TType, class TMutextHandler> 
    157   class StaticPDHCounterListener<TType, format_long, TMutextHandler> : public PDH::PDHCounterListener { 
     179  class StaticPDHCounterListener<TType, format_long, TMutextHandler> : public PDHCollector { 
    158180    TType value_; 
    159181    TMutextHandler mutex_; 
     
    181203    DWORD getFormat() const { 
    182204      return format_long; 
     205    } 
     206    inline std::wstring get_string() { 
     207      return to_wstring(getValue()); 
     208    } 
     209    inline double get_double() { 
     210      return static_cast<double>(getValue()); 
     211    } 
     212    __int64 get_int64() { 
     213      return getValue(); 
     214    } 
     215    inline double get_average(int backlog) { 
     216      return static_cast<double>(getValue()); 
    183217    } 
    184218  private: 
     
    191225 
    192226  template <class TType, class TMutextHandler> 
    193   class StaticPDHCounterListener<TType, format_large, TMutextHandler> : public PDH::PDHCounterListener { 
     227  class StaticPDHCounterListener<TType, format_large, TMutextHandler> : public PDHCollector { 
    194228    TMutextHandler mutex_; 
    195229    TType value_; 
     
    217251    DWORD getFormat() const { 
    218252      return format_large; 
     253    } 
     254    inline std::wstring get_string() { 
     255      return to_wstring(getValue()); 
     256    } 
     257    inline double get_double() { 
     258      return static_cast<double>(getValue()); 
     259    } 
     260    __int64 get_int64() { 
     261      return getValue(); 
     262    } 
     263    inline double get_average(int backlog) { 
     264      return static_cast<double>(getValue()); 
    219265    } 
    220266  private: 
     
    228274 
    229275  template <class TType, class TMutextHandler> 
    230   class RoundINTPDHBufferListenerImpl : public PDH::PDHCounterListener { 
     276  class RoundINTPDHBufferListenerImpl : public PDHCollector { 
    231277    TMutextHandler mutex_; 
    232278    unsigned int length; 
     
    313359      return (ret/backItems); 
    314360    } 
     361    inline std::wstring get_string() { 
     362      return to_wstring(getAvrage(length-1)); 
     363    } 
     364    inline double get_double() { 
     365      return getAvrage(length-1); 
     366    } 
     367    __int64 get_int64() { 
     368      return static_cast<__int64>(getAvrage(length-1)); 
     369    } 
     370    inline double get_average(int backlog) { 
     371      return getAvrage(backlog); 
     372    } 
    315373    inline unsigned int getLength() const { 
    316374      return length; 
  • include/pdh/counters.hpp

    rf0e6036 r5e12ba6  
    4444    std::wstring name_; 
    4545    PDH_FMT_COUNTERVALUE data_; 
    46     PDHCounterListener *listener_; 
     46    typedef boost::shared_ptr<PDHCounterListener> listener_ptr; 
     47    listener_ptr listener_; 
    4748 
    4849  public: 
    4950 
    50     PDHCounter(std::wstring name, PDHCounterListener *listener) : name_(name), listener_(listener), hCounter_(NULL){} 
    51     PDHCounter(std::wstring name) : name_(name), listener_(NULL), hCounter_(NULL){} 
     51    PDHCounter(std::wstring name, listener_ptr listener) : name_(name), listener_(listener), hCounter_(NULL){} 
     52    PDHCounter(std::wstring name) : name_(name), hCounter_(NULL){} 
    5253    virtual ~PDHCounter(void) { 
    5354      if (hCounter_ != NULL) 
     
    5556    } 
    5657 
    57     void setListener(PDHCounterListener *listener) { 
     58    void setListener(listener_ptr listener) { 
    5859      listener_ = listener; 
    5960    } 
  • include/pdh/query.hpp

    rf0e6036 r5e12ba6  
    3131  class PDHQuery : public PDH::PDHImplSubscriber { 
    3232  private: 
    33     typedef std::list<PDHCounter*> CounterList; 
     33    typedef boost::shared_ptr<PDHCounter> counter_ptr; 
     34    typedef boost::shared_ptr<PDHCounterListener> listener_ptr; 
     35    typedef std::list<counter_ptr> CounterList; 
    3436    CounterList counters_; 
    3537    PDH::PDH_HQUERY hQuery_; 
     
    4143    } 
    4244 
    43     PDHCounter* addCounter(std::wstring name, PDHCounterListener *listener) { 
    44       PDHCounter *counter = new PDHCounter(name, listener); 
     45    counter_ptr addCounter(std::wstring name, listener_ptr) { 
     46      counter_ptr counter = counter_ptr(new PDHCounter(name, listener)); 
    4547      counters_.push_back(counter); 
    4648      return counter; 
    4749    } 
    48     PDHCounter* addCounter(std::wstring name) { 
    49       PDHCounter *counter = new PDHCounter(name); 
     50    counter_ptr addCounter(std::wstring name) { 
     51      counter_ptr counter = counter_ptr(new PDHCounter(name)); 
    5052      counters_.push_back(counter); 
    5153      return counter; 
     
    5456      if (hQuery_) 
    5557        close(); 
    56       for (CounterList::iterator it = counters_.begin(); it != counters_.end(); it++) { 
    57         delete (*it); 
    58       } 
    5958      counters_.clear(); 
    6059    } 
     
    9493      PDH::PDHFactory::get_impl()->remove_listener(this); 
    9594      on_unload(); 
    96       for (CounterList::iterator it = counters_.begin(); it != counters_.end(); it++) { 
    97         delete (*it); 
    98       } 
    9995      counters_.clear(); 
    10096    } 
  • include/settings/macros.h

    r497b779 r5e12ba6  
    215215  namespace event_log { 
    216216    DEFINE_PATH(SECTION, EVENT_LOG_SECTION); 
    217     DESCRIBE_SETTING(SECTION, "EVENT LOG SECTION", "Section for the EventLog Checker (CHeckEventLog.dll)."); 
     217    //DESCRIBE_SETTING(SECTION, "EVENT LOG SECTION", "Section for the EventLog Checker (CHeckEventLog.dll)."); 
    218218 
    219219    DEFINE_SETTING_B(DEBUG_KEY, EVENT_LOG_SECTION, "debug", false); 
    220     DESCRIBE_SETTING_ADVANCED(DEBUG_KEY, "DEBUG", "Log all \"hits\" and \"misses\" on the eventlog filter chain, useful for debugging eventlog checks but very very very noisy so you don't want to accidentally set this on a real machine."); 
     220    //DESCRIBE_SETTING_ADVANCED(DEBUG_KEY, "DEBUG", "Log all \"hits\" and \"misses\" on the eventlog filter chain, useful for debugging eventlog checks but very very very noisy so you don't want to accidentally set this on a real machine."); 
    221221 
    222222    DEFINE_SETTING_B(LOOKUP_NAMES, EVENT_LOG_SECTION, "lookup_names", false); 
    223     DESCRIBE_SETTING_ADVANCED(LOOKUP_NAMES, "TODO", "TODO"); 
     223    //DESCRIBE_SETTING_ADVANCED(LOOKUP_NAMES, "TODO", "TODO"); 
    224224 
    225225    DEFINE_SETTING_S(SYNTAX, EVENT_LOG_SECTION, "syntax", ""); 
    226     DESCRIBE_SETTING(SYNTAX, "SYNTAX", "Set this to use a specific syntax string for all commands (that don't specify one)."); 
     226    //DESCRIBE_SETTING(SYNTAX, "SYNTAX", "Set this to use a specific syntax string for all commands (that don't specify one)."); 
    227227 
    228228    DEFINE_SETTING_I(BUFFER_SIZE, EVENT_LOG_SECTION, "buffer_size", 65535); 
    229     DESCRIBE_SETTING(BUFFER_SIZE, "BUFFER SIZE", "The size of the bugfer to use when getting messages this affects the speed and maximum size of messages you can recieve."); 
     229    //DESCRIBE_SETTING(BUFFER_SIZE, "BUFFER SIZE", "The size of the bugfer to use when getting messages this affects the speed and maximum size of messages you can recieve."); 
    230230  } 
    231231 
     
    300300    DESCRIBE_SETTING_ADVANCED(PDH_CPU, "PDH COUNTER", "Counter to use for CPU load."); 
    301301 
    302     DEFINE_PATH(SERVICES_SECTION, CHECK_SYSTEM_SERVICES_SECTION); 
    303     DESCRIBE_SETTING_ADVANCED(SERVICES_SECTION, "SERVICE CHECKS", "Section to define service checks to use"); 
    304  
    305     DEFINE_SETTING_S(SVC_BOOT_START, CHECK_SYSTEM_SERVICES_SECTION, "SERVICE_BOOT_START", "ignored"); 
    306     DESCRIBE_SETTING_ADVANCED(SVC_BOOT_START, "SERVICE_BOOT_START SERVICE CHECK", "Set how to handle services set to SERVICE_BOOT_START state when checking all services"); 
    307  
    308     DEFINE_SETTING_S(SVC_SYSTEM_START, CHECK_SYSTEM_SERVICES_SECTION, "SERVICE_SYSTEM_START", "ignored"); 
    309     DESCRIBE_SETTING_ADVANCED(SVC_SYSTEM_START, "SERVICE_BOOT_START SERVICE CHECK", "Set how to handle services set to SERVICE_BOOT_START state when checking all services"); 
    310  
    311     DEFINE_SETTING_S(SVC_AUTO_START, CHECK_SYSTEM_SERVICES_SECTION, "SERVICE_AUTO_START", "started"); 
    312     DESCRIBE_SETTING_ADVANCED(SVC_AUTO_START, "SERVICE_BOOT_START SERVICE CHECK", "Set how to handle services set to SERVICE_BOOT_START state when checking all services"); 
    313  
    314     DEFINE_SETTING_S(SVC_DEMAND_START, CHECK_SYSTEM_SERVICES_SECTION, "SERVICE_DEMAND_START", "ignored"); 
    315     DESCRIBE_SETTING_ADVANCED(SVC_DEMAND_START, "SERVICE_BOOT_START SERVICE CHECK", "Set how to handle services set to SERVICE_BOOT_START state when checking all services"); 
    316  
    317     DEFINE_SETTING_S(SVC_DISABLED, CHECK_SYSTEM_SERVICES_SECTION, "SERVICE_DISABLED", "stopped"); 
    318     DESCRIBE_SETTING_ADVANCED(SVC_DISABLED, "SERVICE_BOOT_START SERVICE CHECK", "Set how to handle services set to SERVICE_BOOT_START state when checking all services"); 
     302    //DEFINE_PATH(SERVICES_SECTION, CHECK_SYSTEM_SERVICES_SECTION); 
     303    //DESCRIBE_SETTING_ADVANCED(SERVICES_SECTION, "SERVICE CHECKS", "Section to define service checks to use"); 
     304 
     305    //DEFINE_SETTING_S(SVC_BOOT_START, CHECK_SYSTEM_SERVICES_SECTION, "SERVICE_BOOT_START", "ignored"); 
     306    //DESCRIBE_SETTING_ADVANCED(SVC_BOOT_START, "SERVICE_BOOT_START SERVICE CHECK", "Set how to handle services set to SERVICE_BOOT_START state when checking all services"); 
     307 
     308    //DEFINE_SETTING_S(SVC_SYSTEM_START, CHECK_SYSTEM_SERVICES_SECTION, "SERVICE_SYSTEM_START", "ignored"); 
     309    //DESCRIBE_SETTING_ADVANCED(SVC_SYSTEM_START, "SERVICE_BOOT_START SERVICE CHECK", "Set how to handle services set to SERVICE_BOOT_START state when checking all services"); 
     310 
     311    //DEFINE_SETTING_S(SVC_AUTO_START, CHECK_SYSTEM_SERVICES_SECTION, "SERVICE_AUTO_START", "started"); 
     312    //DESCRIBE_SETTING_ADVANCED(SVC_AUTO_START, "SERVICE_BOOT_START SERVICE CHECK", "Set how to handle services set to SERVICE_BOOT_START state when checking all services"); 
     313 
     314    //DEFINE_SETTING_S(SVC_DEMAND_START, CHECK_SYSTEM_SERVICES_SECTION, "SERVICE_DEMAND_START", "ignored"); 
     315    //DESCRIBE_SETTING_ADVANCED(SVC_DEMAND_START, "SERVICE_BOOT_START SERVICE CHECK", "Set how to handle services set to SERVICE_BOOT_START state when checking all services"); 
     316 
     317    //DEFINE_SETTING_S(SVC_DISABLED, CHECK_SYSTEM_SERVICES_SECTION, "SERVICE_DISABLED", "stopped"); 
     318    //DESCRIBE_SETTING_ADVANCED(SVC_DISABLED, "SERVICE_BOOT_START SERVICE CHECK", "Set how to handle services set to SERVICE_BOOT_START state when checking all services"); 
    319319 
    320320    DEFINE_SETTING_S(PDH_SUBSYSTEM, CHECK_SYSTEM_SECTION, "pdh_subsystem", "fast"); 
     
    325325  } 
    326326 
    327   namespace check_disk { 
    328     DEFINE_PATH(SECTION, CHECK_DISK_SECTION); 
    329     DESCRIBE_SETTING(SECTION, "CHECK DISK SECTION", ""); 
    330  
    331     DEFINE_SETTING_B(SHOW_ERRORS, CHECK_DISK_SECTION, "show errors", false); 
    332     DESCRIBE_SETTING_ADVANCED(SHOW_ERRORS, "", "???"); 
    333      
    334   } 
    335  
    336327  namespace nsca { 
    337328    DEFINE_PATH(SECTION, NSCA_SECTION); 
    338     DESCRIBE_SETTING(SECTION, "NSCA SECTION", "Section for NSCA passive check module."); 
     329    //DESCRIBE_SETTING(SECTION, "NSCA SECTION", "Section for NSCA passive check module."); 
    339330 
    340331    DEFINE_SETTING_I(INTERVAL, NSCA_SECTION, "interval", 60); 
    341     DESCRIBE_SETTING(INTERVAL, "COMMAND TIMEOUT", "Time in seconds between each report back to the server (cant as of yet be set individually so this is for all \"checks\")"); 
     332    //DESCRIBE_SETTING(INTERVAL, "COMMAND TIMEOUT", "Time in seconds between each report back to the server (cant as of yet be set individually so this is for all \"checks\")"); 
    342333 
    343334    DEFINE_SETTING_S(HOSTNAME, NSCA_SECTION, "hostname", ""); 
    344     DESCRIBE_SETTING_ADVANCED(HOSTNAME, "LOCAL HOSTNAME", "The host name of this host if set to blank (default) the windows name of the computer will be used."); 
     335    //DESCRIBE_SETTING_ADVANCED(HOSTNAME, "LOCAL HOSTNAME", "The host name of this host if set to blank (default) the windows name of the computer will be used."); 
    345336 
    346337    DEFINE_PATH(SERVER_SECTION, NSCA_SERVER_SECTION); 
    347     DESCRIBE_SETTING(SERVER_SECTION, "NSCA SERVER SECTION", "Configure the NSCA server to report to"); 
     338    //DESCRIBE_SETTING(SERVER_SECTION, "NSCA SERVER SECTION", "Configure the NSCA server to report to"); 
    348339 
    349340    DEFINE_SETTING_S(SERVER_HOST, NSCA_SERVER_SECTION, "host", "unknown-host"); 
    350     DESCRIBE_SETTING(SERVER_HOST, "NSCA SERVER", "The NSCA/Nagios(?) server to report results to."); 
     341    //DESCRIBE_SETTING(SERVER_HOST, "NSCA SERVER", "The NSCA/Nagios(?) server to report results to."); 
    351342 
    352343    DEFINE_SETTING_I(SERVER_PORT, NSCA_SERVER_SECTION, "port", 5667); 
    353     DESCRIBE_SETTING(SERVER_PORT, "NSCA PORT", "The NSCA server port"); 
     344    //DESCRIBE_SETTING(SERVER_PORT, "NSCA PORT", "The NSCA server port"); 
    354345 
    355346    DEFINE_SETTING_I(ENCRYPTION, NSCA_SERVER_SECTION, "encryption method", 1); 
    356     DESCRIBE_SETTING(ENCRYPTION, "NSCA ENCRYPTION", "Number corresponding to the various encryption algorithms (see the wiki). Has to be the same as the server or it wont work at all."); 
     347    //DESCRIBE_SETTING(ENCRYPTION, "NSCA ENCRYPTION", "Number corresponding to the various encryption algorithms (see the wiki). Has to be the same as the server or it wont work at all."); 
    357348 
    358349    DEFINE_SETTING_S(PASSWORD, NSCA_SERVER_SECTION, "password", ""); 
    359     DESCRIBE_SETTING(PASSWORD, "NSCA PASSWORD", "The password to use. Again has to be the same as the server or it wont work at all."); 
     350    //DESCRIBE_SETTING(PASSWORD, "NSCA PASSWORD", "The password to use. Again has to be the same as the server or it wont work at all."); 
    360351 
    361352    DEFINE_SETTING_I(THREADS, NSCA_SECTION, "debug threads", 1); 
    362     DESCRIBE_SETTING_ADVANCED(THREADS, "DEBUG OPTION (THREADS)", "Number of threads to run, no reason to change this really (unless you want to stress test something)"); 
     353    //DESCRIBE_SETTING_ADVANCED(THREADS, "DEBUG OPTION (THREADS)", "Number of threads to run, no reason to change this really (unless you want to stress test something)"); 
    363354 
    364355    DEFINE_SETTING_B(CACHE_HOST, NSCA_SECTION, "cache hostname", false); 
    365     DESCRIBE_SETTING_ADVANCED(CACHE_HOST, "CACHE HOSTNAME", "???"); 
     356    //DESCRIBE_SETTING_ADVANCED(CACHE_HOST, "CACHE HOSTNAME", "???"); 
    366357 
    367358    DEFINE_PATH(CMD_SECTION, NSCA_CMD_SECTION); 
    368     DESCRIBE_SETTING(CMD_SECTION, "NSCA COMMAND SECTION", "Commands to check and report to the NSCA server"); 
     359    //DESCRIBE_SETTING(CMD_SECTION, "NSCA COMMAND SECTION", "Commands to check and report to the NSCA server"); 
    369360 
    370361    DEFINE_SETTING_S(REPORT_MODE, NSCA_SERVER_SECTION, "report", "all"); 
    371     DESCRIBE_SETTING(REPORT_MODE, "REPORT MODE", "What to report to the server (any of the following: all, critical, warning, unknown, ok)"); 
     362    //DESCRIBE_SETTING(REPORT_MODE, "REPORT MODE", "What to report to the server (any of the following: all, critical, warning, unknown, ok)"); 
    372363 
    373364    DEFINE_SETTING_S(TIME_DELTA_DEFAULT, NSCA_SECTION, "delay", "0"); 
    374     DESCRIBE_SETTING(TIME_DELTA_DEFAULT, "TODO", "TODO"); 
     365    //DESCRIBE_SETTING(TIME_DELTA_DEFAULT, "TODO", "TODO"); 
    375366 
    376367    DEFINE_SETTING_I(PAYLOAD_LENGTH, NSCA_SECTION, "payload length", 512); 
    377     DESCRIBE_SETTING_ADVANCED(PAYLOAD_LENGTH, "PAYLOAD LENGTH", "Length of payload to/from the NSCA agent. This is a hard specific value so you have to \"configure\" (read recompile) your NSCA server to use the same value for it to work."); 
     368    //DESCRIBE_SETTING_ADVANCED(PAYLOAD_LENGTH, "PAYLOAD LENGTH", "Length of payload to/from the NSCA agent. This is a hard specific value so you have to \"configure\" (read recompile) your NSCA server to use the same value for it to work."); 
    378369 
    379370    DEFINE_SETTING_I(READ_TIMEOUT, NSCA_SERVER_SECTION, GENERIC_KEY_SOCK_READ_TIMEOUT, 30); 
    380     DESCRIBE_SETTING(READ_TIMEOUT, "SOCKET TIMEOUT", "Timeout when reading packets on incoming sockets. If the data has not arrived withint this time we will bail out."); 
     371    //DESCRIBE_SETTING(READ_TIMEOUT, "SOCKET TIMEOUT", "Timeout when reading packets on incoming sockets. If the data has not arrived withint this time we will bail out."); 
    381372 
    382373  } 
     
    436427  namespace log { 
    437428    DEFINE_PATH(SECTION, LOG_SECTION); 
    438     DESCRIBE_SETTING_ADVANCED(SECTION, "LOG SECTION", "Configure loggning properties."); 
     429    //DESCRIBE_SETTING_ADVANCED(SECTION, "LOG SECTION", "Configure loggning properties."); 
    439430 
    440431    DEFINE_SETTING_S(FILENAME, LOG_SECTION, "file", "nsclient.log"); 
    441     DESCRIBE_SETTING_ADVANCED(FILENAME, "SYNTAX", "The file to write log data to. If no directory is used this is relative to the NSClient++ binary."); 
     432    //DESCRIBE_SETTING_ADVANCED(FILENAME, "SYNTAX", "The file to write log data to. If no directory is used this is relative to the NSClient++ binary."); 
    442433 
    443434    DEFINE_SETTING_S(ROOT, LOG_SECTION, "root", "auto"); 
    444     DESCRIBE_SETTING_ADVANCED(ROOT, "TODO", "TODO"); 
     435    //DESCRIBE_SETTING_ADVANCED(ROOT, "TODO", "TODO"); 
    445436 
    446437    DEFINE_SETTING_S(DATEMASK, LOG_SECTION, "date format", "%Y-%m-%d %H:%M:%S"); 
    447     DESCRIBE_SETTING_ADVANCED(DATEMASK, "DATEMASK", "The date format used when logging to a file."); 
     438    //DESCRIBE_SETTING_ADVANCED(DATEMASK, "DATEMASK", "The date format used when logging to a file."); 
    448439 
    449440    DEFINE_SETTING_S(LOG_MASK, LOG_SECTION, "log mask", "normal"); 
    450     DESCRIBE_SETTING_ADVANCED(LOG_MASK, "LOG MASK", "The log mask information, error, warning, critical, debug"); 
     441    //DESCRIBE_SETTING_ADVANCED(LOG_MASK, "LOG MASK", "The log mask information, error, warning, critical, debug"); 
    451442 
    452443    DEFINE_SETTING_B(DEBUG_LOG, LOG_SECTION, "debug", false); 
    453     DESCRIBE_SETTING_ADVANCED(DEBUG_LOG, "DEBUG LOGGING", "Enable debug logging can help track down errors and find problems but will impact overall perfoamnce negativly."); 
     444    //DESCRIBE_SETTING_ADVANCED(DEBUG_LOG, "DEBUG LOGGING", "Enable debug logging can help track down errors and find problems but will impact overall perfoamnce negativly."); 
    454445  } 
    455446} 
  • modules/CheckEventLog/CheckEventLog.cpp

    r497b779 r5e12ba6  
    5757#include <parsers/ast.cpp> 
    5858 
     59namespace sh = nscapi::settings_helper; 
     60 
     61 
     62bool CheckEventLog::loadModule() { 
     63  return false; 
     64} 
     65 
     66 
     67bool CheckEventLog::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
     68  try { 
     69    get_core()->registerCommand(_T("CheckEventLog"), _T("Check for errors in the event logger!")); 
     70 
     71    sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 
     72    settings.set_alias(_T("CheckEventlog"), alias); 
     73 
     74    settings.add_path_to_settings() 
     75      (_T("EVENT LOG SECTION"), _T("Section for the EventLog Checker (CHeckEventLog.dll).")) 
     76      ; 
     77 
     78    settings.add_key_to_settings() 
     79      (_T("debug"), sh::bool_key(&debug_, false), 
     80      _T("DEBUG"), _T("Log all \"hits\" and \"misses\" on the eventlog filter chain, useful for debugging eventlog checks but very very very noisy so you don't want to accidentally set this on a real machine.")) 
     81 
     82      (_T("lookup names"), sh::bool_key(&lookup_names_, false), 
     83      _T("LOOKUP NAMES"), _T("")) 
     84 
     85      (_T("syntax"), sh::wstring_key(&syntax_), 
     86      _T("SYNTAX"), _T("Set this to use a specific syntax string for all commands (that don't specify one).")) 
     87 
     88      (_T("buffer size"), sh::int_key(&buffer_length_, 128*1024), 
     89      _T("BUFFER_SIZE"), _T("The size of the buffer to use when getting messages this affects the speed and maximum size of messages you can recieve.")) 
     90      ; 
     91 
     92    settings.register_all(); 
     93    settings.notify(); 
     94 
     95  } catch (std::exception &e) { 
     96    NSC_LOG_ERROR_STD(_T("Exception caught: ") + to_wstring(e.what())); 
     97    return false; 
     98  } catch (nscapi::nscapi_exception &e) { 
     99    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
     100    return false; 
     101  } catch (...) { 
     102    NSC_LOG_ERROR_STD(_T("Failed to register command.")); 
     103    return false; 
     104  } 
     105  /* 
     106  parse(_T("321 = 123")); 
     107  parse(_T("123 = 123")); 
     108  parse(_T("id = 123")); 
     109  parse(_T("id = 321")); 
     110 
     111  parse(_T("id = '123'")); 
     112  parse(_T("id = '321'")); 
     113 
     114  parse(_T("id = convert(123)")); 
     115  parse(_T("id = convert(321)")); 
     116 
     117  parse(_T("id = 123 AND 123 = 123 AND id = 123x")); 
     118  parse(_T("id = 123 AND 123 = 321 OR 123 = 456 OR 123 = 123")); 
     119   
     120  parse(_T("foo")); 
     121  parse(_T("1")); 
     122  parse(_T("foo = ")); 
     123  parse(_T("foo = 1")); 
     124  parse(_T("'foo' = 1")); 
     125  parse(_T("foo = '1'")); 
     126  parse(_T("'hello'='world'")); 
     127 
     128  parse(_T("foo = bar")); 
     129  parse(_T("foo = bar AND bar = foo")); 
     130  parse(_T("foo = bar AND bar = 1")); 
     131  parse(_T("foo = bar AND bar = foo OR foo = bar")); 
     132  parse(_T("foo = bar AND bar = 1 OR foo = 1")); 
     133  parse(_T(" foo = bar AND ( test > 120 OR foo < 123) OR ugh IN (123, 456, 789)")); 
     134 
     135  parse(_T("aaa = 111 OR bbb = 222 OR ccc = 333")); 
     136  parse(_T("(aaa = 111) OR bbb = 222 OR ccc = 333")); 
     137  parse(_T("(aaa = 111 OR bbb = 222) OR ccc = 333")); 
     138  parse(_T("(aaa = 111 OR bbb = 222 OR ccc = 333)")); 
     139  parse(_T("aaa = 111 OR (bbb = 222 OR ccc = 333)")); 
     140  parse(_T("aaa = 111 OR bbb = 222 OR (ccc = 333)")); 
     141  parse(_T("ccc = -333")); 
     142  parse(_T("ccc = -333 AND ccc = to_date('AABBCC', 1234)")); 
     143  parse(_T("aaa = 111 OR bbb = 222 OR (ccc = -333)")); 
     144  parse(_T("ccc = -333 AND ccc = to_date('AABBCC', 1234) OR aaa = 123x")); 
     145  parse(_T("ccc = -333 AND ccc = to_date('AABBCC', 1234) OR aaa = 123x OR 123r = foo123")); 
     146*/ 
     147  return true; 
     148} 
     149bool CheckEventLog::unloadModule() { 
     150  return true; 
     151} 
     152 
     153bool CheckEventLog::hasCommandHandler() { 
     154  return true; 
     155} 
     156bool CheckEventLog::hasMessageHandler() { 
     157  return false; 
     158} 
    59159namespace filter { 
    60160  namespace where { 
     
    393493  */ 
    394494} 
    395 bool CheckEventLog::loadModule() { 
    396   return false; 
    397 } 
    398  
    399 bool CheckEventLog::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
    400   try { 
    401     SETTINGS_REG_PATH(event_log::SECTION); 
    402     SETTINGS_REG_KEY_B(event_log::DEBUG_KEY); 
    403     SETTINGS_REG_KEY_S(event_log::SYNTAX); 
    404  
    405     GET_CORE()->registerCommand(_T("CheckEventLog"), _T("Check for errors in the event logger!")); 
    406  
    407     debug_ = SETTINGS_GET_BOOL(event_log::DEBUG_KEY); 
    408     lookup_names_ = SETTINGS_GET_BOOL(event_log::LOOKUP_NAMES); 
    409     syntax_ = SETTINGS_GET_STRING(event_log::SYNTAX); 
    410     buffer_length_ = SETTINGS_GET_INT(event_log::BUFFER_SIZE); 
    411   } catch (nscapi::nscapi_exception &e) { 
    412     NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
    413   } catch (...) { 
    414     NSC_LOG_ERROR_STD(_T("Failed to register command.")); 
    415   } 
    416   /* 
    417   parse(_T("321 = 123")); 
    418   parse(_T("123 = 123")); 
    419   parse(_T("id = 123")); 
    420   parse(_T("id = 321")); 
    421  
    422   parse(_T("id = '123'")); 
    423   parse(_T("id = '321'")); 
    424  
    425   parse(_T("id = convert(123)")); 
    426   parse(_T("id = convert(321)")); 
    427  
    428   parse(_T("id = 123 AND 123 = 123 AND id = 123x")); 
    429   parse(_T("id = 123 AND 123 = 321 OR 123 = 456 OR 123 = 123")); 
    430    
    431   parse(_T("foo")); 
    432   parse(_T("1")); 
    433   parse(_T("foo = ")); 
    434   parse(_T("foo = 1")); 
    435   parse(_T("'foo' = 1")); 
    436   parse(_T("foo = '1'")); 
    437   parse(_T("'hello'='world'")); 
    438  
    439   parse(_T("foo = bar")); 
    440   parse(_T("foo = bar AND bar = foo")); 
    441   parse(_T("foo = bar AND bar = 1")); 
    442   parse(_T("foo = bar AND bar = foo OR foo = bar")); 
    443   parse(_T("foo = bar AND bar = 1 OR foo = 1")); 
    444   parse(_T(" foo = bar AND ( test > 120 OR foo < 123) OR ugh IN (123, 456, 789)")); 
    445  
    446   parse(_T("aaa = 111 OR bbb = 222 OR ccc = 333")); 
    447   parse(_T("(aaa = 111) OR bbb = 222 OR ccc = 333")); 
    448   parse(_T("(aaa = 111 OR bbb = 222) OR ccc = 333")); 
    449   parse(_T("(aaa = 111 OR bbb = 222 OR ccc = 333)")); 
    450   parse(_T("aaa = 111 OR (bbb = 222 OR ccc = 333)")); 
    451   parse(_T("aaa = 111 OR bbb = 222 OR (ccc = 333)")); 
    452   parse(_T("ccc = -333")); 
    453   parse(_T("ccc = -333 AND ccc = to_date('AABBCC', 1234)")); 
    454   parse(_T("aaa = 111 OR bbb = 222 OR (ccc = -333)")); 
    455   parse(_T("ccc = -333 AND ccc = to_date('AABBCC', 1234) OR aaa = 123x")); 
    456   parse(_T("ccc = -333 AND ccc = to_date('AABBCC', 1234) OR aaa = 123x OR 123r = foo123")); 
    457 */ 
    458   return true; 
    459 } 
    460 bool CheckEventLog::unloadModule() { 
    461   return true; 
    462 } 
    463  
    464 bool CheckEventLog::hasCommandHandler() { 
    465   return true; 
    466 } 
    467 bool CheckEventLog::hasMessageHandler() { 
    468   return false; 
    469 } 
    470  
    471495 
    472496std::wstring find_eventlog_name(std::wstring name) { 
  • modules/CheckEventLog/CheckEventLog.h

    r497b779 r5e12ba6  
    2727 
    2828 
    29 class CheckEventLog  : public nscapi::impl::SimpleCommand { 
     29class CheckEventLog  : public nscapi::impl::SimpleCommand, nscapi::impl::simple_plugin { 
    3030private: 
    3131  bool debug_; 
    3232  std::wstring syntax_; 
    33   DWORD buffer_length_; 
     33  int buffer_length_; 
    3434  bool lookup_names_; 
    3535 
  • modules/CheckHelpers/CheckHelpers.cpp

    r497b779 r5e12ba6  
    3838bool CheckHelpers::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
    3939  try { 
    40     GET_CORE()->registerCommand(_T("CheckAlwaysOK"), _T("Run another check and regardless of its return code return OK.")); 
    41     GET_CORE()->registerCommand(_T("CheckAlwaysCRITICAL"), _T("Run another check and regardless of its return code return CRIT.")); 
    42     GET_CORE()->registerCommand(_T("CheckAlwaysWARNING"), _T("Run another check and regardless of its return code return WARN.")); 
    43     GET_CORE()->registerCommand(_T("CheckMultiple"), _T("Run more then one check and return the worst state.")); 
    44     GET_CORE()->registerCommand(_T("CheckOK"), _T("Just return OK (anything passed along will be used as a message).")); 
    45     GET_CORE()->registerCommand(_T("check_ok"), _T("Just return OK (anything passed along will be used as a message).")); 
    46     GET_CORE()->registerCommand(_T("CheckWARNING"), _T("Just return WARN (anything passed along will be used as a message).")); 
    47     GET_CORE()->registerCommand(_T("CheckCRITICAL"), _T("Just return CRIT (anything passed along will be used as a message).")); 
    48     GET_CORE()->registerCommand(_T("CheckVersion"), _T("Just return the nagios version (along with OK status).")); 
     40    get_core()->registerCommand(_T("CheckAlwaysOK"), _T("Run another check and regardless of its return code return OK.")); 
     41    get_core()->registerCommand(_T("CheckAlwaysCRITICAL"), _T("Run another check and regardless of its return code return CRIT.")); 
     42    get_core()->registerCommand(_T("CheckAlwaysWARNING"), _T("Run another check and regardless of its return code return WARN.")); 
     43    get_core()->registerCommand(_T("CheckMultiple"), _T("Run more then one check and return the worst state.")); 
     44    get_core()->registerCommand(_T("CheckOK"), _T("Just return OK (anything passed along will be used as a message).")); 
     45    get_core()->registerCommand(_T("check_ok"), _T("Just return OK (anything passed along will be used as a message).")); 
     46    get_core()->registerCommand(_T("CheckWARNING"), _T("Just return WARN (anything passed along will be used as a message).")); 
     47    get_core()->registerCommand(_T("CheckCRITICAL"), _T("Just return CRIT (anything passed along will be used as a message).")); 
     48    get_core()->registerCommand(_T("CheckVersion"), _T("Just return the nagios version (along with OK status).")); 
    4949  } catch (nscapi::nscapi_exception &e) { 
    5050    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
  • modules/CheckHelpers/CheckHelpers.h

    r497b779 r5e12ba6  
    2323#include <strEx.h> 
    2424 
    25 class CheckHelpers : public nscapi::impl::SimpleCommand { 
     25class CheckHelpers : public nscapi::impl::SimpleCommand, nscapi::impl::simple_plugin { 
    2626private: 
    2727 
  • modules/CheckSystem/CheckSystem.cpp

    r497b779 r5e12ba6  
    3232#include <filter_framework.hpp> 
    3333#include <simple_registry.hpp> 
    34  
    35 #ifdef USE_BOOST 
    3634#include <boost/regex.hpp> 
    37 #endif 
    3835 
    3936CheckSystem gCheckSystem; 
     
    5047CheckSystem::~CheckSystem() {} 
    5148 
     49namespace sh = nscapi::settings_helper; 
     50 
    5251/** 
    5352 * Load (initiate) module. 
     
    6665 
    6766bool CheckSystem::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
    68   if (mode == NSCAPI::normalStart) { 
    69     pdhThread.createThread(); 
    70   } 
     67  PDHCollector::system_counter_data *data = new PDHCollector::system_counter_data; 
    7168  try { 
    72     GET_CORE()->registerCommand(_T("checkCPU"), _T("Check the CPU load of the computer.")); 
    73     GET_CORE()->registerCommand(_T("checkUpTime"), _T("Check the up-time of the computer.")); 
    74     GET_CORE()->registerCommand(_T("checkServiceState"), _T("Check the state of one or more of the computer services.")); 
    75     GET_CORE()->registerCommand(_T("checkProcState"), _T("Check the state of one or more of the processes running on the computer.")); 
    76     GET_CORE()->registerCommand(_T("checkMem"), _T("Check free/used memory on the system.")); 
    77     GET_CORE()->registerCommand(_T("checkCounter"), _T("Check a PDH counter.")); 
    78     GET_CORE()->registerCommand(_T("listCounterInstances"), _T("List all instances for a counter.")); 
    79     GET_CORE()->registerCommand(_T("checkSingleRegEntry"), _T("Check registry key")); 
     69    std::map<std::wstring,std::wstring> service_mappings; 
     70    bool default_counters; 
     71 
     72    sh::settings_registry settings(get_core()); 
     73    settings.set_alias(_T("check"), alias, _T("system/windows")); 
     74 
     75    settings.add_path_to_settings() 
     76      (_T("WINDOWS CHECK SYSTEM"), _T("Section for system checks and system settings")) 
     77 
     78      (_T("service mapping"), sh::wstring_map_path(&service_mappings) 
     79      , _T("SERVICE MAPPING SECTION"), _T("")) 
     80 
     81      (_T("pdh"), _T("PDH COUNTER INFORMATION"), _T("")) 
     82 
     83      //(_T("pdh/counter"), _T("PDH COUNTERS"), _T("")) 
     84 
     85      ; 
     86 
     87 
     88    settings.add_key_to_settings() 
     89      (_T("default"), sh::bool_key(&default_counters), 
     90      _T("HOSTNAME"), _T("The host name of this host if set to blank (default) the windows name of the computer will be used.")) 
     91//  
     92//      (_T("hostname cache"), sh::bool_key(&cacheNscaHost_), 
     93//      _T("CACHE HOSTNAME"), _T("")) 
     94//  
     95//      (_T("delay"), sh::string_fun_key<std::wstring>(boost::bind(&NSCAAgent::set_delay, this, _1), 0), 
     96//      _T("DELAY"), _T("")) 
     97//  
     98//      (_T("payload length"), sh::uint_key(&payload_length_, 512), 
     99//      _T("PAYLOAD LENGTH"), _T("The password to use. Again has to be the same as the server or it wont work at all.")) 
     100 
     101      ; 
     102 
     103 
     104    settings.register_all(); 
     105    settings.notify(); 
     106 
     107    lookups_[SERVICE_BOOT_START] = service_mappings[_T("BOOT_START")]; 
     108    lookups_[SERVICE_SYSTEM_START] = service_mappings[_T("SYSTEM_START")]; 
     109    lookups_[SERVICE_AUTO_START] = service_mappings[_T("AUTO_START")]; 
     110    lookups_[SERVICE_DEMAND_START] = service_mappings[_T("DEMAND_START")]; 
     111    lookups_[SERVICE_DISABLED] = service_mappings[_T("DISABLED")]; 
     112 
     113    typedef PDHCollector::system_counter_data::counter cnt; 
     114    if (default_counters) { 
     115      data->counters.push_back(cnt(_T("cpu load"), _T("\\238(_total)\\6"), cnt::type_int64, cnt::format_large, cnt::rrd)); 
     116      data->counters.push_back(cnt(_T("memory commit bytes"), _T("\\4\26"), cnt::type_int64, cnt::format_large, cnt::value)); 
     117      data->counters.push_back(cnt(_T("memory commit limit"), _T("\\4\\30"), cnt::type_int64, cnt::format_large, cnt::value)); 
     118      data->counters.push_back(cnt(_T("uptime"), _T("\\2\\674"), cnt::type_int64, cnt::format_large, cnt::value)); 
     119    } 
     120 
     121    get_core()->registerCommand(_T("checkCPU"), _T("Check the CPU load of the computer.")); 
     122    get_core()->registerCommand(_T("checkUpTime"), _T("Check the up-time of the computer.")); 
     123    get_core()->registerCommand(_T("checkServiceState"), _T("Check the state of one or more of the computer services.")); 
     124    get_core()->registerCommand(_T("checkProcState"), _T("Check the state of one or more of the processes running on the computer.")); 
     125    get_core()->registerCommand(_T("checkMem"), _T("Check free/used memory on the system.")); 
     126    get_core()->registerCommand(_T("checkCounter"), _T("Check a PDH counter.")); 
     127    get_core()->registerCommand(_T("listCounterInstances"), _T("List all instances for a counter.")); 
     128    get_core()->registerCommand(_T("checkSingleRegEntry"), _T("Check registry key")); 
    80129  } catch (nscapi::nscapi_exception &e) { 
    81130    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
     
    83132    NSC_LOG_ERROR_STD(_T("Failed to register command.")); 
    84133  } 
     134 
     135  if (mode == NSCAPI::normalStart) { 
     136    pdhThread.createThread(data); 
     137  } 
     138 
    85139  return true; 
    86140} 
     
    583637    std::wstring wantedMethod = NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_ENUMPROC_METHOD, C_SYSTEM_ENUMPROC_METHOD_DEFAULT); 
    584638    */ 
    585     std::map<DWORD,std::wstring> lookups; 
    586     lookups[SERVICE_BOOT_START] = SETTINGS_GET_STRING(check_system::SVC_BOOT_START); 
    587     lookups[SERVICE_SYSTEM_START] = SETTINGS_GET_STRING(check_system::SVC_SYSTEM_START); 
    588     lookups[SERVICE_AUTO_START] = SETTINGS_GET_STRING(check_system::SVC_AUTO_START); 
    589     lookups[SERVICE_DEMAND_START] = SETTINGS_GET_STRING(check_system::SVC_DEMAND_START); 
    590     lookups[SERVICE_DISABLED] = SETTINGS_GET_STRING(check_system::SVC_DISABLED); 
    591  
    592639 
    593640    std::list<TNtServiceInfo> service_list_automatic = TNtServiceInfo::EnumServices(SERVICE_WIN32,SERVICE_INACTIVE|SERVICE_ACTIVE);  
     
    595642      if (excludeList.find((*service).m_strServiceName) == excludeList.end()) { 
    596643        tmpObject.data = (*service).m_strServiceName; 
    597         tmpObject.crit.state = lookups[(*service).m_dwStartType];  
     644        tmpObject.crit.state = lookups_[(*service).m_dwStartType];  
    598645        list.push_back(tmpObject);  
    599646      } 
  • modules/CheckSystem/CheckSystem.h

    r497b779 r5e12ba6  
    2828NSC_WRAPPERS_CLI(); 
    2929 
    30 class CheckSystem : public nscapi::impl::SimpleCommand { 
     30class CheckSystem : public nscapi::impl::SimpleCommand, public nscapi::impl::simple_plugin { 
    3131private: 
    3232  CheckMemory memoryChecker; 
     
    4242    rB() : code_(NSCAPI::returnUNKNOWN) {} 
    4343  } returnBundle; 
     44 
     45  std::map<DWORD,std::wstring> lookups_; 
     46 
    4447 
    4548public: 
  • modules/CheckSystem/PDHCollector.cpp

    r294b37b r5e12ba6  
    2323 
    2424 
    25 PDHCollector::PDHCollector() : hStopEvent_(NULL) { 
    26   // TODO: Re add this? 
    27   //dontCollect_ = SETTINGS_GET_INT(check_system::) NSCModuleHelper::getSettingsInt(C_SYSTEM_SECTION_TITLE, C_SYSTEM_IGNORE_COLLECTION, C_SYSTEM_IGNORE_COLLECTION_DEFAULT)==1; 
    28   checkIntervall_ = SETTINGS_GET_INT(check_system::INTERVALL); 
    29   std::wstring s = SETTINGS_GET_STRING(check_system::BUFFER_SIZE); 
    30   unsigned int i = strEx::stoui_as_time(s, checkIntervall_*100); 
    31   cpu.resize(i/(checkIntervall_*100)+10); 
     25PDHCollector::PDHCollector() : hStopEvent_(NULL), data_(NULL) { 
    3226  std::wstring subsystem = SETTINGS_GET_STRING(check_system::PDH_SUBSYSTEM); 
    3327  if (subsystem == setting_keys::check_system::PDH_SUBSYSTEM_FAST) { 
     
    3933} 
    4034 
    41 PDHCollector::~PDHCollector()  
     35PDHCollector::~PDHCollector() 
    4236{ 
    4337  if (hStopEvent_) 
    4438    CloseHandle(hStopEvent_); 
    45 } 
    46  
    47 bool PDHCollector::loadCounter(PDH::PDHQuery &pdh) { 
    48   std::wstring method = SETTINGS_GET_STRING(check_system::CPU_METHOD); 
    49  
    50   if (method == setting_keys::check_system::CPU_METHOD_PDH_MANUAL) { 
    51     NSC_DEBUG_MSG_STD(_T("Autodetect disabled from nsc.ini via: ") + SETTINGS_MAKE_NAME(check_system::CPU_METHOD)); 
    52     return false; 
    53   } 
    54   std::wstring prefix; 
    55   std::wstring section = SETTINGS_GET_STRING(check_system::FORCE_LANGUAGE); 
    56   bool bUseIndex = false; 
    57  
    58   // Investigate environment and find out what to use 
    59   try { 
    60     OSVERSIONINFO osVer = systemInfo::getOSVersion(); 
    61     if (!systemInfo::isNTBased(osVer)) { 
    62       NSC_LOG_ERROR_STD(_T("Detected Windows 3.x or Windows 9x, PDH will be disabled.")); 
    63       NSC_LOG_ERROR_STD(_T("To manual set performance counters you need to first setup ") + SETTINGS_MAKE_NAME(check_system::CPU_METHOD) + _T(", and then you also need to configure the various counter.")); 
    64       return false; 
    65     } 
    66  
    67     LANGID langId = -1; 
    68     if (systemInfo::isBelowNT4(osVer)) { 
    69       NSC_DEBUG_MSG_STD(_T("Autodetected NT4, using NT4 PDH counters.")); 
    70       prefix = _T("NT4"); 
    71       bUseIndex = false; 
    72       langId = systemInfo::GetSystemDefaultLangID(); 
    73     } else if (systemInfo::isAboveW2K(osVer)) { 
    74       NSC_DEBUG_MSG_STD(_T("Autodetected w2k or later, using w2k PDH counters.")); 
    75       bUseIndex = true; 
    76       prefix = _T("W2K"); 
    77       langId = systemInfo::GetSystemDefaultUILanguage(); 
    78     } else { 
    79       NSC_LOG_ERROR_STD(_T("Unknown OS detected, PDH will be disabled.")); 
    80       NSC_LOG_ERROR_STD(_T("To manual set performance counters you need to first set ") + SETTINGS_MAKE_NAME(check_system::CPU_METHOD) + _T(" in the config file, and then you also need to configure the various counter.")); 
    81       return false; 
    82     } 
    83  
    84     if (!section.empty()) { 
    85       NSC_DEBUG_MSG_STD(_T("Overriding language with: ") + section); 
    86     } else { 
    87       section = _T("0000") + strEx::ihextos(langId); 
    88       section = _T("0x") + section.substr(section.length()-4); 
    89     } 
    90     if (bUseIndex&&(method==setting_keys::check_system::CPU_METHOD_PDH_NO_INDEX)) { 
    91       NSC_DEBUG_MSG_STD(_T("We wanted to use index but were forced not to use them due to: ") + SETTINGS_MAKE_NAME(check_system::CPU_METHOD)); 
    92       bUseIndex = false; 
    93     } 
    94   } catch (const systemInfo::SystemInfoException &e) { 
    95     NSC_LOG_ERROR_STD(_T("To manual set performance counters you need to first set ") + SETTINGS_MAKE_NAME(check_system::CPU_METHOD) + _T(" in the config file, and then you also need to configure the various counter.")); 
    96     NSC_LOG_ERROR_STD(_T("The Error: ") + e.getError()); 
    97     return false; 
    98   } catch (...) { 
    99     NSC_LOG_ERROR_STD(_T("To manual set performance counters you need to first set ") + SETTINGS_MAKE_NAME(check_system::CPU_METHOD) + _T(" in the config file, and then you also need to configure the various counter.")); 
    100     NSC_LOG_ERROR_STD(_T("The Error: UNKNOWN_EXCEPTION")); 
    101     return false; 
    102   } 
    103  
    104   // Open counters via .defs file or index. 
    105   try { 
    106     std::wstring proc; 
    107     std::wstring uptime; 
    108     std::wstring memCl; 
    109     std::wstring memCb; 
    110     if (bUseIndex) { 
    111       NSC_DEBUG_MSG_STD(_T("Using index to retrive counternames")); 
    112       proc = _T("\\") + PDH::PDHResolver::lookupIndex(238) + _T("(_total)\\") + PDH::PDHResolver::lookupIndex(6); 
    113       uptime = _T("\\") + PDH::PDHResolver::lookupIndex(2) + _T("\\") + PDH::PDHResolver::lookupIndex(674); 
    114       memCl = _T("\\") + PDH::PDHResolver::lookupIndex(4) + _T("\\") + PDH::PDHResolver::lookupIndex(30); 
    115       memCb = _T("\\") + PDH::PDHResolver::lookupIndex(4) + _T("\\") + PDH::PDHResolver::lookupIndex(26); 
    116     } else { 
    117       NSC_LOG_ERROR_STD(_T("You need to manually configure performance counters!")); 
    118       /* 
    119       Settings::SettingsCore settings; 
    120       settings.setFile(NSCModuleHelper::getBasePath(),  _T("counters.defs"), true); 
    121       NSC_DEBUG_MSG_STD(_T("Detected language: ") + settings.getString(section, _T("Description"), _T("Not found")) + _T(" (") + section + _T(")")); 
    122       if (settings.getString(section, _T("Description"), _T("_NOT_FOUND")) == _T("_NOT_FOUND")) { 
    123         NSC_LOG_ERROR_STD(_T("Detected language: ") + section + _T(" but it could not be found in: counters.defs")); 
    124         NSC_LOG_ERROR_STD(_T("You need to manually configure performance counters!")); 
    125         return false; 
    126       } 
    127       NSC_DEBUG_MSG_STD(_T("Attempting to get localized PDH values from the .defs file")); 
    128       proc = settings.getString(section, prefix + _T("_") + C_SYSTEM_CPU, C_SYSTEM_MEM_CPU_DEFAULT); 
    129       uptime = settings.getString(section, prefix + _T("_") + C_SYSTEM_UPTIME, C_SYSTEM_UPTIME_DEFAULT); 
    130       memCl = settings.getString(section, prefix + _T("_") + C_SYSTEM_MEM_PAGE_LIMIT, C_SYSTEM_MEM_PAGE_LIMIT_DEFAULT); 
    131       memCb = settings.getString(section, prefix + _T("_") + C_SYSTEM_MEM_PAGE, C_SYSTEM_MEM_PAGE_DEFAULT); 
    132       */ 
    133     } 
    134     NSC_DEBUG_MSG_STD(_T("Found countername: CPU:    ") + proc); 
    135     NSC_DEBUG_MSG_STD(_T("Found countername: UPTIME: ") + uptime); 
    136     NSC_DEBUG_MSG_STD(_T("Found countername: MCL:    ") + memCl); 
    137     NSC_DEBUG_MSG_STD(_T("Found countername: MCB:    ") + memCb); 
    138     pdh.addCounter(proc, &cpu); 
    139     pdh.addCounter(uptime, &upTime); 
    140     pdh.addCounter(memCl, &memCmtLim); 
    141     pdh.addCounter(memCb, &memCmt); 
    142     pdh.open(); 
    143   } catch (const PDH::PDHException &e) { 
    144     NSC_LOG_ERROR_STD(_T("Failed to open performance counters: ") + e.getError()); 
    145     return false; 
    146   } 
    147   return true; 
    148 } 
     39  delete data_; 
     40} 
     41 
     42boost::shared_ptr<PDHCollectors::PDHCollector> PDHCollector::system_counter_data::counter::get_counter(int check_intervall) { 
     43  if (data_type == type_uint64 && data_format == format_large && collection_strategy == value) { 
     44    return boost::shared_ptr<PDHCollectors::PDHCollector>(new PDHCollectors::StaticPDHCounterListener<unsigned __int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex>); 
     45  } else if (data_type == type_int64 && data_format == format_large && collection_strategy == value) { 
     46    return boost::shared_ptr<PDHCollectors::PDHCollector>(new PDHCollectors::StaticPDHCounterListener<__int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex>); 
     47  } else if (data_type == type_int64 && data_format == format_large && collection_strategy == rrd) { 
     48    return boost::shared_ptr<PDHCollectors::PDHCollector>(new PDHCollectors::RoundINTPDHBufferListener<__int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex>(get_length(check_intervall))); 
     49  } 
     50  return boost::shared_ptr<PDHCollectors::PDHCollector>(); 
     51} 
     52 
    14953 
    15054/** 
     
    16872    return 0; 
    16973  } 
     74 
     75  data_ = reinterpret_cast<system_counter_data*>(lpParameter); 
     76 
    17077  PDH::PDHQuery pdh; 
    17178  bool bInit = true; 
     
    17683      NSC_LOG_ERROR_STD(_T("Failed to get mutex when trying to start thread... thread will now die...")); 
    17784      bInit = false; 
    178     } else if (!loadCounter(pdh)) { 
     85    } else { 
    17986      pdh.removeAllCounters(); 
    180       NSC_DEBUG_MSG_STD(_T("We aparently failed to load counters trying to use default (English) counters or those configured in nsc.ini")); 
    181       SetThreadLocale(MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT)); 
    182       pdh.addCounter(SETTINGS_GET_STRING(check_system::PDH_MEM_CMT_LIM), &memCmtLim); 
    183       pdh.addCounter(SETTINGS_GET_STRING(check_system::PDH_MEM_CMT_BYT), &memCmt); 
    184       pdh.addCounter(SETTINGS_GET_STRING(check_system::PDH_SYSUP), &upTime); 
    185       pdh.addCounter(SETTINGS_GET_STRING(check_system::PDH_CPU), &cpu); 
     87      NSC_DEBUG_MSG_STD(_T("Loading counters...")); 
     88      BOOST_FOREACH(system_counter_data::counter c, data_->counters) { 
     89        NSC_DEBUG_MSG_STD(_T("Loading counter: ") + c.alias + _T(" = ") + c.path); 
     90        collector_ptr collector = c.get_counter(data_->check_intervall); 
     91        if (collector) { 
     92          counters_[c.alias] = collector; 
     93          pdh.addCounter(c.path, collector); 
     94        } else { 
     95          NSC_LOG_ERROR_STD(_T("Failed to load counter: ") + c.alias + _T(" = ") + c.path); 
     96        } 
     97      } 
     98      //SetThreadLocale(MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT)); 
     99//      pdh.addCounter(SETTINGS_GET_STRING(check_system::PDH_MEM_CMT_LIM), &memCmtLim); 
     100//      pdh.addCounter(SETTINGS_GET_STRING(check_system::PDH_MEM_CMT_BYT), &memCmt); 
     101//      pdh.addCounter(SETTINGS_GET_STRING(check_system::PDH_SYSUP), &upTime); 
     102//      pdh.addCounter(SETTINGS_GET_STRING(check_system::PDH_CPU), &cpu); 
    186103      try { 
    187104        pdh.open(); 
     
    204121        else { 
    205122          try { 
    206             if (!dontCollect_) 
    207               pdh.gatherData(); 
     123            pdh.gatherData(); 
    208124          } catch (const PDH::PDHException &e) { 
    209125            if (first) {  // If this is the first run an error will be thrown since the data is not yet available 
     
    213129              errors.push_back(_T("Failed to query performance counters: ") + e.getError()); 
    214130            } 
     131          } catch (...) { 
     132            errors.push_back(_T("Failed to query performance counters: ")); 
    215133          } 
    216134        }  
     
    219137        NSC_LOG_ERROR_STD(*cit); 
    220138      } 
    221     } while (((waitStatus = WaitForSingleObject(hStopEvent_, checkIntervall_*100)) == WAIT_TIMEOUT)); 
     139    } while (((waitStatus = WaitForSingleObject(hStopEvent_, data_->check_intervall*100)) == WAIT_TIMEOUT)); 
    222140  } else { 
    223141    NSC_LOG_ERROR_STD(_T("No performance counters were found we will not wait for the end instead...")); 
     
    247165} 
    248166 
     167__int64 PDHCollector::get_int_value(std::wstring counter) { 
     168  ReadLock lock(&mutex_, true, 5000); 
     169  if (!lock.IsLocked())  { 
     170    NSC_LOG_ERROR(_T("Failed to get Mutex for: ") + counter); 
     171    return 0; 
     172  } 
     173 
     174  counter_map::iterator it = counters_.find(counter); 
     175  if (it == counters_.end()) 
     176    return 0; 
     177  collector_ptr ptr = (*it).second; 
     178  return ptr->get_int64(); 
     179} 
     180 
    249181 
    250182/** 
     
    264196*/ 
    265197int PDHCollector::getCPUAvrage(std::wstring time) { 
    266   unsigned int mseconds = strEx::stoui_as_time(time, checkIntervall_*100); 
    267   ReadLock lock(&mutex_, true, 5000); 
    268   if (!lock.IsLocked()) { 
    269     NSC_LOG_ERROR(_T("Failed to get Mutex!")); 
    270     return -1; 
    271   } 
    272   try { 
    273     return static_cast<int>(cpu.getAvrage(mseconds / (checkIntervall_*100))); 
     198  unsigned int mseconds = strEx::stoui_as_time(time, 100); 
     199  ReadLock lock(&mutex_, true, 5000); 
     200  if (!lock.IsLocked()) { 
     201    NSC_LOG_ERROR(_T("Failed to get Mutex!")); 
     202    return -1; 
     203  } 
     204  try { 
     205    return static_cast<int>(cpu.getAvrage(mseconds / (100))); 
    274206  } catch (PDHCollectors::PDHException &e) { 
    275207    NSC_LOG_ERROR(_T("Failed to get CPU value: ") + e.getError()); 
  • modules/CheckSystem/PDHCollector.h

    rb4110d8 r5e12ba6  
    2424#include <thread.h> 
    2525#include <MutexRW.h> 
     26#include <boost/unordered_map.hpp> 
     27#include <boost/shared_ptr.hpp> 
    2628 
    2729/** 
     
    4547 */ 
    4648class PDHCollector { 
     49public: 
     50 
     51  struct system_counter_data { 
     52 
     53    struct counter { 
     54      typedef enum data_type_struct { 
     55        type_int64, type_uint64 
     56      }; 
     57      typedef enum data_format_struct { 
     58        format_large 
     59      }; 
     60      typedef enum collection_strategy_struct { 
     61        rrd, value 
     62      }; 
     63 
     64      counter(std::wstring alias, std::wstring path, data_type_struct data_type, data_format_struct data_format, collection_strategy_struct collection_strategy) 
     65        : alias(alias) 
     66        , path(path) 
     67        , data_type(data_type) 
     68        , data_format(data_format) 
     69        , collection_strategy(collection_strategy) 
     70      {} 
     71      data_type_struct data_type; 
     72      data_format_struct data_format; 
     73      std::wstring alias; 
     74      std::wstring path; 
     75      collection_strategy_struct collection_strategy; 
     76      std::wstring buffer_size; 
     77 
     78      boost::shared_ptr<PDHCollectors::PDHCollector> get_counter(int check_intervall); 
     79 
     80      int get_length(int check_intervall) { 
     81        unsigned int i = strEx::stoui_as_time(buffer_size, check_intervall*100); 
     82        if (check_intervall == 0) 
     83          return 100; // TODO fix this! 
     84        return i/(check_intervall*100)+10; 
     85      } 
     86 
     87      //      PDHCollectors::StaticPDHCounterListener<unsigned __int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> memCmtLim; 
     88      //      PDHCollectors::StaticPDHCounterListener<unsigned __int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> memCmt; 
     89      //      PDHCollectors::StaticPDHCounterListener<__int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> upTime; 
     90      //      PDHCollectors::RoundINTPDHBufferListener<__int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> cpu; 
     91 
     92    }; 
     93 
     94    int check_intervall; 
     95 
     96    std::list<counter> counters; 
     97  }; 
     98 
    4799private: 
    48100 
     101  system_counter_data *data_; 
    49102  MutexRW mutex_; 
    50103  HANDLE hStopEvent_; 
    51   int checkIntervall_; 
    52   bool dontCollect_; 
     104  typedef boost::shared_ptr<PDHCollectors::PDHCollector> collector_ptr; 
     105  typedef boost::unordered_map<std::wstring,collector_ptr > counter_map; 
     106  counter_map counters_; 
     107//  int checkIntervall_; 
     108//  bool dontCollect_; 
    53109 
    54110  PDHCollectors::StaticPDHCounterListener<unsigned __int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> memCmtLim; 
     
    70126  bool loadCounter(PDH::PDHQuery &pdh); 
    71127 
     128  __int64 get_int_value(std::wstring counter); 
     129 
    72130 
    73131private: 
  • modules/FileLogger/FileLogger.cpp

    r497b779 r5e12ba6  
    2525#include <fstream> 
    2626#include <utils.h> 
     27 
     28namespace sh = nscapi::settings_helper; 
    2729 
    2830FileLogger gFileLogger; 
     
    6870std::string FileLogger::getFileName() { 
    6971  if (file_.empty()) { 
    70     file_ = to_string(SETTINGS_GET_STRING(log::FILENAME)); 
     72    file_ = to_string(cfg_file_); 
    7173    if (file_.empty()) 
    7274      file_ = to_string(setting_keys::log::FILENAME_DEFAULT); 
    7375    if (file_.find("\\") == std::wstring::npos) { 
    74       std::string root = to_string(getFolder(SETTINGS_GET_STRING(log::ROOT))); 
     76      std::string root = to_string(getFolder(cfg_root_)); 
    7577      std::string::size_type pos = root.find_last_not_of('\\'); 
    7678      if (pos != std::wstring::npos) { 
     
    8688  return false; 
    8789} 
    88  
    8990bool FileLogger::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
    9091  //_tzset(); 
    91   getFileName(); 
    92  
    9392  try { 
    94     SETTINGS_REG_PATH(log::SECTION); 
    95  
    96     SETTINGS_REG_KEY_S(log::FILENAME); 
    97     SETTINGS_REG_KEY_S(log::DATEMASK); 
    98     SETTINGS_REG_KEY_S(log::LOG_MASK); 
    99  
     93    std::wstring log_mask, file, root; 
     94 
     95    sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 
     96    settings.set_alias(_T("log"), alias); 
     97 
     98    settings.add_path_to_settings() 
     99      (_T("LOG SECTION"), _T("Configure loggning properties.")) 
     100      ; 
     101 
     102    settings.add_key_to_settings() 
     103      //(_T("debug"), sh::bool_key(&debug_, false), 
     104      //_T("DEBUG LOGGING"), _T("Enable debug logging can help track down errors and find problems but will impact overall performance negativly.")) 
     105 
     106      (_T("log mask"), sh::wstring_key(&log_mask, false), 
     107      _T("LOG MASK"), _T("The log mask information, error, warning, critical, debug")) 
     108 
     109      (_T("root"), sh::wstring_key(&cfg_root_, _T("auto")), 
     110      _T("ROOT"), _T("Set this to use a specific syntax string for all commands (that don't specify one).")) 
     111 
     112      (_T("file name"), sh::wstring_key(&cfg_file_), 
     113      _T("FILENAME"), _T("The file to write log data to. If no directory is used this is relative to the NSClient++ binary.")) 
     114 
     115      (_T("date format"), sh::string_key(&format_, "%Y-%m-%d %H:%M:%S"), 
     116      _T("DATEMASK"), _T("The size of the buffer to use when getting messages this affects the speed and maximum size of messages you can recieve.")) 
     117      ; 
     118 
     119    settings.register_all(); 
     120    settings.notify(); 
     121 
     122    log_mask_ = nscapi::logging::parse(log_mask); 
     123 
     124    getFileName(); 
     125 
     126  } catch (std::exception &e) { 
     127    NSC_LOG_ERROR_STD(_T("Exception caught: ") + to_wstring(e.what())); 
     128    return false; 
    100129  } catch (nscapi::nscapi_exception &e) { 
    101130    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
     131    return false; 
    102132  } catch (...) { 
    103133    NSC_LOG_ERROR_STD(_T("Failed to register command.")); 
    104   } 
    105  
    106  
    107   format_ = to_string(SETTINGS_GET_STRING(log::DATEMASK)); 
    108   std::wstring log_mask = SETTINGS_GET_STRING(log::LOG_MASK); 
    109   log_mask_ = nscapi::logging::parse(log_mask); 
     134    return false; 
     135  } 
    110136  NSC_LOG_MESSAGE_STD(_T("Using logmask: ") + nscapi::logging::to_string(log_mask_)); 
    111137  init_ = true; 
  • modules/FileLogger/FileLogger.h

    r497b779 r5e12ba6  
    2323NSC_WRAPPERS_MAIN(); 
    2424 
    25 class FileLogger { 
     25class FileLogger : public nscapi::impl::simple_plugin { 
    2626private: 
    2727  std::string file_; 
     
    2929  bool init_; 
    3030  int log_mask_; 
     31  std::wstring cfg_file_; 
     32  std::wstring cfg_root_; 
    3133 
    3234public: 
  • modules/NRPEServer/NRPEServer.h

    r497b779 r5e12ba6  
    2525NSC_WRAPPERS_MAIN(); 
    2626 
    27 class NRPEListener { 
     27class NRPEListener : public nscapi::impl::simple_plugin { 
    2828private: 
    2929  typedef enum { 
  • modules/NSCAAgent/NSCAAgent.cpp

    r497b779 r5e12ba6  
    3131NSCAAgent gNSCAAgent; 
    3232 
     33namespace sh = nscapi::settings_helper; 
     34 
    3335/** 
    3436 * Default c-tor 
     
    4951  return false; 
    5052} 
    51  
     53/* 
     54DEFINE_SETTING_S(REPORT_MODE, NSCA_SERVER_SECTION, "report", "all"); 
     55DESCRIBE_SETTING(REPORT_MODE, "REPORT MODE", "What to report to the server (any of the following: all, critical, warning, unknown, ok)"); 
     56*/ 
    5257bool NSCAAgent::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
    53   try { 
    54  
    55     SETTINGS_REG_PATH(nsca::SECTION); 
    56     SETTINGS_REG_PATH(nsca::SERVER_SECTION); 
    57     SETTINGS_REG_PATH(nsca::CMD_SECTION); 
    58  
    59     SETTINGS_REG_KEY_S(nsca::HOSTNAME); 
    60     SETTINGS_REG_KEY_S(nsca::SERVER_HOST); 
    61     SETTINGS_REG_KEY_I(nsca::SERVER_PORT); 
    62     SETTINGS_REG_KEY_I(nsca::ENCRYPTION); 
    63     SETTINGS_REG_KEY_S(nsca::PASSWORD); 
    64     SETTINGS_REG_KEY_B(nsca::CACHE_HOST); 
    65  
    66     hostname_ = to_string(SETTINGS_GET_STRING(nsca::HOSTNAME)); 
    67     nscahost_ = SETTINGS_GET_STRING(nsca::SERVER_HOST); 
    68     nscaport_ = SETTINGS_GET_INT(nsca::SERVER_PORT); 
    69  
    70     encryption_method_ = SETTINGS_GET_INT(nsca::ENCRYPTION); 
    71     password_ = strEx::wstring_to_string(SETTINGS_GET_STRING(nsca::PASSWORD)); 
    72     cacheNscaHost_ = SETTINGS_GET_INT(nsca::CACHE_HOST); 
    73     timeout_ = SETTINGS_GET_INT(nsca::READ_TIMEOUT); 
    74     payload_length_ = SETTINGS_GET_INT(nsca::PAYLOAD_LENGTH); 
    75     time_delta_ = strEx::stol_as_time_sec(SETTINGS_GET_STRING(nsca::TIME_DELTA_DEFAULT), 1); 
    7658 
    7759 
     60  try { 
     61    sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 
     62    settings.set_alias(_T("NSCA"), alias, _T("agent")); 
     63 
     64    settings.add_path_to_settings() 
     65      (_T("NSCA AGENT SECTION"), _T("Section for NSCA passive check module.")) 
     66      ; 
     67 
     68    settings.add_key_to_settings() 
     69      (_T("hostname"), sh::string_key(&hostname_), 
     70      _T("HOSTNAME"), _T("The host name of this host if set to blank (default) the windows name of the computer will be used.")) 
     71 
     72      (_T("hostname cache"), sh::bool_key(&cacheNscaHost_), 
     73      _T("CACHE HOSTNAME"), _T("")) 
     74 
     75      (_T("delay"), sh::string_fun_key<std::wstring>(boost::bind(&NSCAAgent::set_delay, this, _1), 0), 
     76      _T("DELAY"), _T("")) 
     77 
     78      (_T("payload length"), sh::uint_key(&payload_length_, 512), 
     79      _T("PAYLOAD LENGTH"), _T("The password to use. Again has to be the same as the server or it wont work at all.")) 
     80 
     81      ; 
     82 
     83    settings.add_path_to_settings(_T("server")) 
     84      (_T("NSCA SERVER"), _T("Configure the NSCA server to report to.")) 
     85      ; 
     86 
     87    settings.add_key_to_settings(_T("server")) 
     88      (_T("host"), sh::wstring_key(&nscahost_), 
     89      _T("NSCA HOST"), _T("The NSCA server to report results to.")) 
     90 
     91      (_T("port"), sh::uint_key(&nscaport_, 5666), 
     92      _T("NSCA PORT"), _T("The NSCA server port")) 
     93 
     94      (_T("encryption method"), sh::int_key(&encryption_method_), 
     95      _T("ENCRYPTION METHOD"), _T("Number corresponding to the various encryption algorithms (see the wiki). Has to be the same as the server or it wont work at all.")) 
     96 
     97      (_T("password"), sh::string_key(&password_), 
     98      _T("PASSWORD"), _T("The password to use. Again has to be the same as the server or it wont work at all.")) 
     99 
     100      (_T("timeout"), sh::uint_key(&timeout_, 30), 
     101      _T("SOCKET TIMEOUT"), _T("Timeout when reading packets on incoming sockets. If the data has not arrived withint this time we will bail out.")) 
     102      ; 
     103 
     104    settings.register_all(); 
     105    settings.notify(); 
     106 
     107  } catch (std::exception &e) { 
     108    NSC_LOG_ERROR_STD(_T("Exception caught: ") + to_wstring(e.what())); 
     109    return false; 
    78110  } catch (nscapi::nscapi_exception &e) { 
    79111    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
     112    return false; 
    80113  } catch (...) { 
    81114    NSC_LOG_ERROR_STD(_T("Failed to register command.")); 
     115    return false; 
    82116  } 
    83  
    84  
    85117  return true; 
    86118} 
  • modules/NSCAAgent/NSCAAgent.h

    r497b779 r5e12ba6  
    7474  NSCAPI::nagiosReturn handleSimpleNotification(const std::wstring channel, const std::wstring command, NSCAPI::nagiosReturn code, std::wstring msg, std::wstring perf); 
    7575 
     76 
     77  void set_delay(std::wstring key) { 
     78    time_delta_ = strEx::stol_as_time_sec(key, 1); 
     79  } 
     80 
    7681}; 
  • modules/Scheduler/Scheduler.cpp

    r497b779 r5e12ba6  
    2828Scheduler gInstance; 
    2929 
     30namespace sh = nscapi::settings_helper; 
     31 
    3032bool Scheduler::loadModule() { 
    3133  return false; 
    3234} 
    33  
     35/* 
     36 
     37namespace scheduler { 
     38DEFINE_PATH(SECTION, SCHEDULER_SECTION); 
     39DESCRIBE_SETTING(SECTION, "SCHEDULER SECTION", "Section for the Scheduler module."); 
     40 
     41DEFINE_PATH(SCHEDULES_SECTION, SCHEDULER_SECTION_SCH); 
     42DESCRIBE_SETTING(SCHEDULES_SECTION, "SCHEDULES SECTION", "Section for defining schedules for the Scheduler module."); 
     43 
     44DEFINE_PATH(DEFAULT_SCHEDULE_SECTION, SCHEDULER_SECTION_DEF); 
     45DESCRIBE_SETTING(DEFAULT_SCHEDULE_SECTION, "DEFAULT SCHEDULER SECTION", "Default settings for all scheduled commands"); 
     46 
     47DEFINE_SETTING_I(THREADS, SCHEDULER_SECTION, "debug threads", 1); 
     48DESCRIBE_SETTING_ADVANCED(THREADS, "THREADS", "Number of threads to use int he thread pool (increase if you have many scheduled items)"); 
     49 
     50DEFINE_SETTING_S(INTERVAL, SCHEDULER_SECTION_FAKE, "interval", "5m"); 
     51DESCRIBE_SETTING(INTERVAL, "SCHEDULE INTERVAL", "Time in seconds between each check"); 
     52 
     53DEFINE_SETTING_S(COMMAND, SCHEDULER_SECTION_FAKE, "command", "check_ok"); 
     54DESCRIBE_SETTING(COMMAND, "SCHEDULE COMMAND", "Command to run"); 
     55 
     56DEFINE_SETTING_S(CHANNEL, SCHEDULER_SECTION_FAKE, "channel", "NSCA"); 
     57DESCRIBE_SETTING(CHANNEL, "SCHEDULE CHANNEL", "Channel to send results on"); 
     58 
     59DEFINE_SETTING_S(REPORT_MODE, SCHEDULER_SECTION_FAKE, "report", "all"); 
     60DESCRIBE_SETTING(REPORT_MODE, "REPORT MODE", "What to report to the server (any of the following: all, critical, warning, unknown, ok)"); 
     61 
     62DEFINE_SETTING_S(INTERVAL_D, SCHEDULER_SECTION_DEF, "interval", "5m"); 
     63DESCRIBE_SETTING(INTERVAL_D, "SCHEDULE INTERVAL", "Time in seconds between each check"); 
     64 
     65DEFINE_SETTING_S(COMMAND_D, SCHEDULER_SECTION_DEF, "command", "check_ok"); 
     66DESCRIBE_SETTING(COMMAND_D, "SCHEDULE COMMAND", "Command to run"); 
     67 
     68DEFINE_SETTING_S(CHANNEL_D, SCHEDULER_SECTION_DEF, "channel", "NSCA"); 
     69DESCRIBE_SETTING(CHANNEL_D, "SCHEDULE CHANNEL", "Channel to send results on"); 
     70 
     71DEFINE_SETTING_S(REPORT_MODE_D, SCHEDULER_SECTION_DEF, "report", "all"); 
     72DESCRIBE_SETTING(REPORT_MODE_D, "REPORT MODE", "What to report to the server (any of the following: all, critical, warning, unknown, ok)"); 
     73*/ 
    3474bool Scheduler::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
     75 
     76  try { 
     77    get_core()->registerCommand(_T("CheckEventLog"), _T("Check for errors in the event logger!")); 
     78 
     79    sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 
     80    settings.set_alias(_T("scheduler"), alias); 
     81 
     82    settings.add_path_to_settings() 
     83      (_T("SCHEDULER SECTION"), _T("Section for the Scheduler module.")) 
     84      ; 
     85 
     86//    settings.add_key_to_settings() 
     87//      (_T("debug"), sh::bool_key(&debug_, false), 
     88//      _T("DEBUG"), _T("Log all \"hits\" and \"misses\" on the eventlog filter chain, useful for debugging eventlog checks but very very very noisy so you don't want to accidentally set this on a real machine.")) 
     89//  
     90//      (_T("lookup names"), sh::bool_key(&lookup_names_, false), 
     91//      _T("LOOKUP NAMES"), _T("")) 
     92//  
     93//      (_T("syntax"), sh::wstring_key(&syntax_), 
     94//      _T("SYNTAX"), _T("Set this to use a specific syntax string for all commands (that don't specify one).")) 
     95//  
     96//      (_T("buffer size"), sh::int_key(&buffer_length_, 128*1024), 
     97//      _T("BUFFER_SIZE"), _T("The size of the buffer to use when getting messages this affects the speed and maximum size of messages you can recieve.")) 
     98//      ; 
     99 
     100    settings.register_all(); 
     101    settings.notify(); 
     102 
     103  } catch (std::exception &e) { 
     104    NSC_LOG_ERROR_STD(_T("Exception caught: ") + to_wstring(e.what())); 
     105    return false; 
     106  } catch (nscapi::nscapi_exception &e) { 
     107    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
     108    return false; 
     109  } catch (...) { 
     110    NSC_LOG_ERROR_STD(_T("Failed to register command.")); 
     111    return false; 
     112  } 
    35113  try { 
    36114    SETTINGS_REG_PATH(scheduler::SECTION); 
  • modules/Scheduler/Scheduler.h

    r497b779 r5e12ba6  
    2626 
    2727 
    28 class Scheduler : public scheduler::schedule_handler { 
     28class Scheduler : public scheduler::schedule_handler, public nscapi::impl::simple_plugin { 
    2929private: 
    3030  scheduler::simple_scheduler scheduler_; 
Note: See TracChangeset for help on using the changeset viewer.