Changeset 5e12ba6 in nscp
- Timestamp:
- 09/17/10 14:06:48 (3 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- c015acc
- Parents:
- 7065334
- Files:
-
- 21 edited
-
include/nscapi/nscapi_plugin_wrapper.hpp (modified) (1 diff)
-
include/nscapi/settings.hpp (modified) (1 diff)
-
include/pdh/collectors.hpp (modified) (9 diffs)
-
include/pdh/counters.hpp (modified) (2 diffs)
-
include/pdh/query.hpp (modified) (4 diffs)
-
include/settings/macros.h (modified) (4 diffs)
-
modules/CheckEventLog/CheckEventLog.cpp (modified) (2 diffs)
-
modules/CheckEventLog/CheckEventLog.h (modified) (1 diff)
-
modules/CheckHelpers/CheckHelpers.cpp (modified) (1 diff)
-
modules/CheckHelpers/CheckHelpers.h (modified) (1 diff)
-
modules/CheckSystem/CheckSystem.cpp (modified) (6 diffs)
-
modules/CheckSystem/CheckSystem.h (modified) (2 diffs)
-
modules/CheckSystem/PDHCollector.cpp (modified) (9 diffs)
-
modules/CheckSystem/PDHCollector.h (modified) (3 diffs)
-
modules/FileLogger/FileLogger.cpp (modified) (3 diffs)
-
modules/FileLogger/FileLogger.h (modified) (2 diffs)
-
modules/NRPEServer/NRPEServer.h (modified) (1 diff)
-
modules/NSCAAgent/NSCAAgent.cpp (modified) (2 diffs)
-
modules/NSCAAgent/NSCAAgent.h (modified) (1 diff)
-
modules/Scheduler/Scheduler.cpp (modified) (1 diff)
-
modules/Scheduler/Scheduler.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
include/nscapi/nscapi_plugin_wrapper.hpp
r497b779 r5e12ba6 172 172 class simple_plugin { 173 173 public: 174 nscapi::core_wrapper* get_core() {174 inline nscapi::core_wrapper* get_core() { 175 175 return nscapi::plugin_singleton->get_core(); 176 176 } -
include/nscapi/settings.hpp
r291548e r5e12ba6 144 144 typed_key_fun<T, typed_bool_value<T> >* bool_fun_key(boost::function<void (T)> fun, T def) { 145 145 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); 146 151 return r; 147 152 } -
include/pdh/collectors.hpp
rf0e6036 r5e12ba6 113 113 }; 114 114 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 115 124 template <class TType, int TCollectionFormat, class TMutextHandler = PDHCounterNoMutex> 116 125 class StaticPDHCounterListener { … … 118 127 119 128 template <class TType, class TMutextHandler> 120 class StaticPDHCounterListener<TType, format_double, TMutextHandler> : public PDH ::PDHCounterListener {129 class StaticPDHCounterListener<TType, format_double, TMutextHandler> : public PDHCollector { 121 130 TType value_; 122 131 TMutextHandler mutex_; … … 146 155 return format_double; 147 156 } 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 } 148 170 private: 149 171 std::wstring get_name() const { … … 155 177 156 178 template <class TType, class TMutextHandler> 157 class StaticPDHCounterListener<TType, format_long, TMutextHandler> : public PDH ::PDHCounterListener {179 class StaticPDHCounterListener<TType, format_long, TMutextHandler> : public PDHCollector { 158 180 TType value_; 159 181 TMutextHandler mutex_; … … 181 203 DWORD getFormat() const { 182 204 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()); 183 217 } 184 218 private: … … 191 225 192 226 template <class TType, class TMutextHandler> 193 class StaticPDHCounterListener<TType, format_large, TMutextHandler> : public PDH ::PDHCounterListener {227 class StaticPDHCounterListener<TType, format_large, TMutextHandler> : public PDHCollector { 194 228 TMutextHandler mutex_; 195 229 TType value_; … … 217 251 DWORD getFormat() const { 218 252 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()); 219 265 } 220 266 private: … … 228 274 229 275 template <class TType, class TMutextHandler> 230 class RoundINTPDHBufferListenerImpl : public PDH ::PDHCounterListener {276 class RoundINTPDHBufferListenerImpl : public PDHCollector { 231 277 TMutextHandler mutex_; 232 278 unsigned int length; … … 313 359 return (ret/backItems); 314 360 } 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 } 315 373 inline unsigned int getLength() const { 316 374 return length; -
include/pdh/counters.hpp
rf0e6036 r5e12ba6 44 44 std::wstring name_; 45 45 PDH_FMT_COUNTERVALUE data_; 46 PDHCounterListener *listener_; 46 typedef boost::shared_ptr<PDHCounterListener> listener_ptr; 47 listener_ptr listener_; 47 48 48 49 public: 49 50 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){} 52 53 virtual ~PDHCounter(void) { 53 54 if (hCounter_ != NULL) … … 55 56 } 56 57 57 void setListener( PDHCounterListener *listener) {58 void setListener(listener_ptr listener) { 58 59 listener_ = listener; 59 60 } -
include/pdh/query.hpp
rf0e6036 r5e12ba6 31 31 class PDHQuery : public PDH::PDHImplSubscriber { 32 32 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; 34 36 CounterList counters_; 35 37 PDH::PDH_HQUERY hQuery_; … … 41 43 } 42 44 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)); 45 47 counters_.push_back(counter); 46 48 return counter; 47 49 } 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)); 50 52 counters_.push_back(counter); 51 53 return counter; … … 54 56 if (hQuery_) 55 57 close(); 56 for (CounterList::iterator it = counters_.begin(); it != counters_.end(); it++) {57 delete (*it);58 }59 58 counters_.clear(); 60 59 } … … 94 93 PDH::PDHFactory::get_impl()->remove_listener(this); 95 94 on_unload(); 96 for (CounterList::iterator it = counters_.begin(); it != counters_.end(); it++) {97 delete (*it);98 }99 95 counters_.clear(); 100 96 } -
include/settings/macros.h
r497b779 r5e12ba6 215 215 namespace event_log { 216 216 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)."); 218 218 219 219 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."); 221 221 222 222 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"); 224 224 225 225 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)."); 227 227 228 228 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."); 230 230 } 231 231 … … 300 300 DESCRIBE_SETTING_ADVANCED(PDH_CPU, "PDH COUNTER", "Counter to use for CPU load."); 301 301 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"); 319 319 320 320 DEFINE_SETTING_S(PDH_SUBSYSTEM, CHECK_SYSTEM_SECTION, "pdh_subsystem", "fast"); … … 325 325 } 326 326 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 336 327 namespace nsca { 337 328 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."); 339 330 340 331 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\")"); 342 333 343 334 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."); 345 336 346 337 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"); 348 339 349 340 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."); 351 342 352 343 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"); 354 345 355 346 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."); 357 348 358 349 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."); 360 351 361 352 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)"); 363 354 364 355 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", "???"); 366 357 367 358 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"); 369 360 370 361 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)"); 372 363 373 364 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"); 375 366 376 367 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."); 378 369 379 370 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."); 381 372 382 373 } … … 436 427 namespace log { 437 428 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."); 439 430 440 431 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."); 442 433 443 434 DEFINE_SETTING_S(ROOT, LOG_SECTION, "root", "auto"); 444 DESCRIBE_SETTING_ADVANCED(ROOT, "TODO", "TODO");435 //DESCRIBE_SETTING_ADVANCED(ROOT, "TODO", "TODO"); 445 436 446 437 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."); 448 439 449 440 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"); 451 442 452 443 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."); 454 445 } 455 446 } -
modules/CheckEventLog/CheckEventLog.cpp
r497b779 r5e12ba6 57 57 #include <parsers/ast.cpp> 58 58 59 namespace sh = nscapi::settings_helper; 60 61 62 bool CheckEventLog::loadModule() { 63 return false; 64 } 65 66 67 bool 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 } 149 bool CheckEventLog::unloadModule() { 150 return true; 151 } 152 153 bool CheckEventLog::hasCommandHandler() { 154 return true; 155 } 156 bool CheckEventLog::hasMessageHandler() { 157 return false; 158 } 59 159 namespace filter { 60 160 namespace where { … … 393 493 */ 394 494 } 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 471 495 472 496 std::wstring find_eventlog_name(std::wstring name) { -
modules/CheckEventLog/CheckEventLog.h
r497b779 r5e12ba6 27 27 28 28 29 class CheckEventLog : public nscapi::impl::SimpleCommand {29 class CheckEventLog : public nscapi::impl::SimpleCommand, nscapi::impl::simple_plugin { 30 30 private: 31 31 bool debug_; 32 32 std::wstring syntax_; 33 DWORDbuffer_length_;33 int buffer_length_; 34 34 bool lookup_names_; 35 35 -
modules/CheckHelpers/CheckHelpers.cpp
r497b779 r5e12ba6 38 38 bool CheckHelpers::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 39 39 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).")); 49 49 } catch (nscapi::nscapi_exception &e) { 50 50 NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); -
modules/CheckHelpers/CheckHelpers.h
r497b779 r5e12ba6 23 23 #include <strEx.h> 24 24 25 class CheckHelpers : public nscapi::impl::SimpleCommand {25 class CheckHelpers : public nscapi::impl::SimpleCommand, nscapi::impl::simple_plugin { 26 26 private: 27 27 -
modules/CheckSystem/CheckSystem.cpp
r497b779 r5e12ba6 32 32 #include <filter_framework.hpp> 33 33 #include <simple_registry.hpp> 34 35 #ifdef USE_BOOST36 34 #include <boost/regex.hpp> 37 #endif38 35 39 36 CheckSystem gCheckSystem; … … 50 47 CheckSystem::~CheckSystem() {} 51 48 49 namespace sh = nscapi::settings_helper; 50 52 51 /** 53 52 * Load (initiate) module. … … 66 65 67 66 bool 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; 71 68 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")); 80 129 } catch (nscapi::nscapi_exception &e) { 81 130 NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); … … 83 132 NSC_LOG_ERROR_STD(_T("Failed to register command.")); 84 133 } 134 135 if (mode == NSCAPI::normalStart) { 136 pdhThread.createThread(data); 137 } 138 85 139 return true; 86 140 } … … 583 637 std::wstring wantedMethod = NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_ENUMPROC_METHOD, C_SYSTEM_ENUMPROC_METHOD_DEFAULT); 584 638 */ 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 592 639 593 640 std::list<TNtServiceInfo> service_list_automatic = TNtServiceInfo::EnumServices(SERVICE_WIN32,SERVICE_INACTIVE|SERVICE_ACTIVE); … … 595 642 if (excludeList.find((*service).m_strServiceName) == excludeList.end()) { 596 643 tmpObject.data = (*service).m_strServiceName; 597 tmpObject.crit.state = lookups [(*service).m_dwStartType];644 tmpObject.crit.state = lookups_[(*service).m_dwStartType]; 598 645 list.push_back(tmpObject); 599 646 } -
modules/CheckSystem/CheckSystem.h
r497b779 r5e12ba6 28 28 NSC_WRAPPERS_CLI(); 29 29 30 class CheckSystem : public nscapi::impl::SimpleCommand {30 class CheckSystem : public nscapi::impl::SimpleCommand, public nscapi::impl::simple_plugin { 31 31 private: 32 32 CheckMemory memoryChecker; … … 42 42 rB() : code_(NSCAPI::returnUNKNOWN) {} 43 43 } returnBundle; 44 45 std::map<DWORD,std::wstring> lookups_; 46 44 47 45 48 public: -
modules/CheckSystem/PDHCollector.cpp
r294b37b r5e12ba6 23 23 24 24 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); 25 PDHCollector::PDHCollector() : hStopEvent_(NULL), data_(NULL) { 32 26 std::wstring subsystem = SETTINGS_GET_STRING(check_system::PDH_SUBSYSTEM); 33 27 if (subsystem == setting_keys::check_system::PDH_SUBSYSTEM_FAST) { … … 39 33 } 40 34 41 PDHCollector::~PDHCollector() 35 PDHCollector::~PDHCollector() 42 36 { 43 37 if (hStopEvent_) 44 38 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 42 boost::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 149 53 150 54 /** … … 168 72 return 0; 169 73 } 74 75 data_ = reinterpret_cast<system_counter_data*>(lpParameter); 76 170 77 PDH::PDHQuery pdh; 171 78 bool bInit = true; … … 176 83 NSC_LOG_ERROR_STD(_T("Failed to get mutex when trying to start thread... thread will now die...")); 177 84 bInit = false; 178 } else if (!loadCounter(pdh)){85 } else { 179 86 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); 186 103 try { 187 104 pdh.open(); … … 204 121 else { 205 122 try { 206 if (!dontCollect_) 207 pdh.gatherData(); 123 pdh.gatherData(); 208 124 } catch (const PDH::PDHException &e) { 209 125 if (first) { // If this is the first run an error will be thrown since the data is not yet available … … 213 129 errors.push_back(_T("Failed to query performance counters: ") + e.getError()); 214 130 } 131 } catch (...) { 132 errors.push_back(_T("Failed to query performance counters: ")); 215 133 } 216 134 } … … 219 137 NSC_LOG_ERROR_STD(*cit); 220 138 } 221 } while (((waitStatus = WaitForSingleObject(hStopEvent_, checkIntervall_*100)) == WAIT_TIMEOUT));139 } while (((waitStatus = WaitForSingleObject(hStopEvent_, data_->check_intervall*100)) == WAIT_TIMEOUT)); 222 140 } else { 223 141 NSC_LOG_ERROR_STD(_T("No performance counters were found we will not wait for the end instead...")); … … 247 165 } 248 166 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 249 181 250 182 /** … … 264 196 */ 265 197 int 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))); 274 206 } catch (PDHCollectors::PDHException &e) { 275 207 NSC_LOG_ERROR(_T("Failed to get CPU value: ") + e.getError()); -
modules/CheckSystem/PDHCollector.h
rb4110d8 r5e12ba6 24 24 #include <thread.h> 25 25 #include <MutexRW.h> 26 #include <boost/unordered_map.hpp> 27 #include <boost/shared_ptr.hpp> 26 28 27 29 /** … … 45 47 */ 46 48 class PDHCollector { 49 public: 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 47 99 private: 48 100 101 system_counter_data *data_; 49 102 MutexRW mutex_; 50 103 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_; 53 109 54 110 PDHCollectors::StaticPDHCounterListener<unsigned __int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> memCmtLim; … … 70 126 bool loadCounter(PDH::PDHQuery &pdh); 71 127 128 __int64 get_int_value(std::wstring counter); 129 72 130 73 131 private: -
modules/FileLogger/FileLogger.cpp
r497b779 r5e12ba6 25 25 #include <fstream> 26 26 #include <utils.h> 27 28 namespace sh = nscapi::settings_helper; 27 29 28 30 FileLogger gFileLogger; … … 68 70 std::string FileLogger::getFileName() { 69 71 if (file_.empty()) { 70 file_ = to_string( SETTINGS_GET_STRING(log::FILENAME));72 file_ = to_string(cfg_file_); 71 73 if (file_.empty()) 72 74 file_ = to_string(setting_keys::log::FILENAME_DEFAULT); 73 75 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_)); 75 77 std::string::size_type pos = root.find_last_not_of('\\'); 76 78 if (pos != std::wstring::npos) { … … 86 88 return false; 87 89 } 88 89 90 bool FileLogger::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 90 91 //_tzset(); 91 getFileName();92 93 92 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; 100 129 } catch (nscapi::nscapi_exception &e) { 101 130 NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 131 return false; 102 132 } catch (...) { 103 133 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 } 110 136 NSC_LOG_MESSAGE_STD(_T("Using logmask: ") + nscapi::logging::to_string(log_mask_)); 111 137 init_ = true; -
modules/FileLogger/FileLogger.h
r497b779 r5e12ba6 23 23 NSC_WRAPPERS_MAIN(); 24 24 25 class FileLogger {25 class FileLogger : public nscapi::impl::simple_plugin { 26 26 private: 27 27 std::string file_; … … 29 29 bool init_; 30 30 int log_mask_; 31 std::wstring cfg_file_; 32 std::wstring cfg_root_; 31 33 32 34 public: -
modules/NRPEServer/NRPEServer.h
r497b779 r5e12ba6 25 25 NSC_WRAPPERS_MAIN(); 26 26 27 class NRPEListener {27 class NRPEListener : public nscapi::impl::simple_plugin { 28 28 private: 29 29 typedef enum { -
modules/NSCAAgent/NSCAAgent.cpp
r497b779 r5e12ba6 31 31 NSCAAgent gNSCAAgent; 32 32 33 namespace sh = nscapi::settings_helper; 34 33 35 /** 34 36 * Default c-tor … … 49 51 return false; 50 52 } 51 53 /* 54 DEFINE_SETTING_S(REPORT_MODE, NSCA_SERVER_SECTION, "report", "all"); 55 DESCRIBE_SETTING(REPORT_MODE, "REPORT MODE", "What to report to the server (any of the following: all, critical, warning, unknown, ok)"); 56 */ 52 57 bool 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);76 58 77 59 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; 78 110 } catch (nscapi::nscapi_exception &e) { 79 111 NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 112 return false; 80 113 } catch (...) { 81 114 NSC_LOG_ERROR_STD(_T("Failed to register command.")); 115 return false; 82 116 } 83 84 85 117 return true; 86 118 } -
modules/NSCAAgent/NSCAAgent.h
r497b779 r5e12ba6 74 74 NSCAPI::nagiosReturn handleSimpleNotification(const std::wstring channel, const std::wstring command, NSCAPI::nagiosReturn code, std::wstring msg, std::wstring perf); 75 75 76 77 void set_delay(std::wstring key) { 78 time_delta_ = strEx::stol_as_time_sec(key, 1); 79 } 80 76 81 }; -
modules/Scheduler/Scheduler.cpp
r497b779 r5e12ba6 28 28 Scheduler gInstance; 29 29 30 namespace sh = nscapi::settings_helper; 31 30 32 bool Scheduler::loadModule() { 31 33 return false; 32 34 } 33 35 /* 36 37 namespace scheduler { 38 DEFINE_PATH(SECTION, SCHEDULER_SECTION); 39 DESCRIBE_SETTING(SECTION, "SCHEDULER SECTION", "Section for the Scheduler module."); 40 41 DEFINE_PATH(SCHEDULES_SECTION, SCHEDULER_SECTION_SCH); 42 DESCRIBE_SETTING(SCHEDULES_SECTION, "SCHEDULES SECTION", "Section for defining schedules for the Scheduler module."); 43 44 DEFINE_PATH(DEFAULT_SCHEDULE_SECTION, SCHEDULER_SECTION_DEF); 45 DESCRIBE_SETTING(DEFAULT_SCHEDULE_SECTION, "DEFAULT SCHEDULER SECTION", "Default settings for all scheduled commands"); 46 47 DEFINE_SETTING_I(THREADS, SCHEDULER_SECTION, "debug threads", 1); 48 DESCRIBE_SETTING_ADVANCED(THREADS, "THREADS", "Number of threads to use int he thread pool (increase if you have many scheduled items)"); 49 50 DEFINE_SETTING_S(INTERVAL, SCHEDULER_SECTION_FAKE, "interval", "5m"); 51 DESCRIBE_SETTING(INTERVAL, "SCHEDULE INTERVAL", "Time in seconds between each check"); 52 53 DEFINE_SETTING_S(COMMAND, SCHEDULER_SECTION_FAKE, "command", "check_ok"); 54 DESCRIBE_SETTING(COMMAND, "SCHEDULE COMMAND", "Command to run"); 55 56 DEFINE_SETTING_S(CHANNEL, SCHEDULER_SECTION_FAKE, "channel", "NSCA"); 57 DESCRIBE_SETTING(CHANNEL, "SCHEDULE CHANNEL", "Channel to send results on"); 58 59 DEFINE_SETTING_S(REPORT_MODE, SCHEDULER_SECTION_FAKE, "report", "all"); 60 DESCRIBE_SETTING(REPORT_MODE, "REPORT MODE", "What to report to the server (any of the following: all, critical, warning, unknown, ok)"); 61 62 DEFINE_SETTING_S(INTERVAL_D, SCHEDULER_SECTION_DEF, "interval", "5m"); 63 DESCRIBE_SETTING(INTERVAL_D, "SCHEDULE INTERVAL", "Time in seconds between each check"); 64 65 DEFINE_SETTING_S(COMMAND_D, SCHEDULER_SECTION_DEF, "command", "check_ok"); 66 DESCRIBE_SETTING(COMMAND_D, "SCHEDULE COMMAND", "Command to run"); 67 68 DEFINE_SETTING_S(CHANNEL_D, SCHEDULER_SECTION_DEF, "channel", "NSCA"); 69 DESCRIBE_SETTING(CHANNEL_D, "SCHEDULE CHANNEL", "Channel to send results on"); 70 71 DEFINE_SETTING_S(REPORT_MODE_D, SCHEDULER_SECTION_DEF, "report", "all"); 72 DESCRIBE_SETTING(REPORT_MODE_D, "REPORT MODE", "What to report to the server (any of the following: all, critical, warning, unknown, ok)"); 73 */ 34 74 bool 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 } 35 113 try { 36 114 SETTINGS_REG_PATH(scheduler::SECTION); -
modules/Scheduler/Scheduler.h
r497b779 r5e12ba6 26 26 27 27 28 class Scheduler : public scheduler::schedule_handler {28 class Scheduler : public scheduler::schedule_handler, public nscapi::impl::simple_plugin { 29 29 private: 30 30 scheduler::simple_scheduler scheduler_;
Note: See TracChangeset
for help on using the changeset viewer.








