Changeset c015acc in nscp
- Timestamp:
- 10/10/10 14:27:13 (3 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- f7663c9
- Parents:
- 5e12ba6
- Files:
-
- 22 edited
-
include/dll/impl_unix.hpp (modified) (2 diffs)
-
include/dll/impl_w32.hpp (modified) (2 diffs)
-
include/nscapi/settings.hpp (modified) (3 diffs)
-
include/pdh/collectors.hpp (modified) (1 diff)
-
include/pdh/query.hpp (modified) (1 diff)
-
include/settings/macros.h (modified) (1 diff)
-
modules/CheckEventLog/CheckEventLog.cpp (modified) (1 diff)
-
modules/CheckEventLog/CheckEventLog.def (modified) (1 diff)
-
modules/CheckExternalScripts/CheckExternalScripts.cpp (modified) (2 diffs)
-
modules/CheckSystem/CheckSystem.cpp (modified) (6 diffs)
-
modules/FileLogger/FileLogger.cpp (modified) (1 diff)
-
modules/NRPEServer/NRPEServer.cpp (modified) (1 diff)
-
modules/NSCAAgent/NSCAAgent.cpp (modified) (2 diffs)
-
modules/Scheduler/Scheduler.cpp (modified) (3 diffs)
-
modules/Scheduler/Scheduler.h (modified) (1 diff)
-
modules/Scheduler/simple_scheduler.hpp (modified) (1 diff)
-
service/NSCPlugin.cpp (modified) (1 diff)
-
service/NSCPlugin.h (modified) (2 diffs)
-
service/NSClient++.cpp (modified) (4 diffs)
-
service/commands.hpp (modified) (1 diff)
-
service/core_api.cpp (modified) (2 diffs)
-
service/settings_client.hpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
include/dll/impl_unix.hpp
r01a278b rc015acc 29 29 } 30 30 } 31 boost::filesystem::wpath fix_module_name( boost::filesystem::wpath module_ ) { 32 boost::filesystem::wpath mod = module_ / get_extension(); 31 static boost::filesystem::wpath fix_module_name( boost::filesystem::wpath module ) { 32 if (boost::filesystem::is_regular(module)) 33 return module; 34 boost::filesystem::wpath mod = module / get_extension(); 33 35 if (boost::filesystem::is_regular(mod)) 34 36 return mod; 35 return module _;37 return module; 36 38 } 37 39 static std::wstring get_extension() { … … 96 98 97 99 bool is_loaded() const { return handle_!=NULL; } 98 std::wstring get_file() const { return module_.string(); } 100 boost::filesystem::wpath get_file() const { return module_; } 101 std::wstring get_filename() const { return module_.leaf(); } 102 std::wstring get_module_name() { 103 std::wstring ext = get_extension(); 104 int l = ext.length(); 105 std::wstring fn = get_filename(); 106 if ((fn.length() > l) && (fn.substr(fn.size()-l) == ext)) 107 return fn.substr(0, fn.size()-l); 108 return fn; 109 } 99 110 }; 100 111 } -
include/dll/impl_w32.hpp
rd05c3f0 rc015acc 16 16 } 17 17 } 18 boost::filesystem::wpath fix_module_name( boost::filesystem::wpath module_ ) { 19 boost::filesystem::wpath mod = module_ / std::wstring(_T(".dll")); 18 static boost::filesystem::wpath fix_module_name( boost::filesystem::wpath module ) { 19 if (boost::filesystem::is_regular(module)) 20 return module; 21 boost::filesystem::wpath mod = module / std::wstring(_T(".dll")); 20 22 if (boost::filesystem::is_regular(mod)) 21 23 return mod; 22 std::wstring tmp = module_.file_string() + _T(".dll"); 23 mod = tmp; 24 if (boost::filesystem::is_regular(mod)) 25 return mod; 26 return module_; 24 return module; 27 25 } 28 26 … … 52 50 } 53 51 bool is_loaded() const { return handle_ != NULL; } 54 std::wstring get_file() const { return module_.file_string(); } 52 boost::filesystem::wpath get_file() const { return module_; } 53 std::wstring get_filename() const { return module_.leaf(); } 54 std::wstring get_module_name() { 55 std::wstring ext = _T(".dll"); 56 int l = ext.length(); 57 std::wstring fn = get_filename(); 58 if ((fn.length() > l) && (fn.substr(fn.size()-l) == ext)) 59 return fn.substr(0, fn.size()-l); 60 return fn; 61 } 55 62 }; 56 63 } -
include/nscapi/settings.hpp
r5e12ba6 rc015acc 364 364 }; 365 365 366 367 class path_extension { 368 public: 369 path_extension(settings_registry * owner, std::wstring path) : owner_(owner), path_(path) {} 370 371 settings_keys_easy_init add_key_to_path(std::wstring path) { 372 return settings_keys_easy_init(get_path(path), owner_); 373 } 374 settings_keys_easy_init add_key() { 375 return settings_keys_easy_init(path_, owner_); 376 } 377 settings_paths_easy_init add_path(std::wstring path = _T("")) { 378 return settings_paths_easy_init(get_path(path), owner_); 379 } 380 inline std::wstring get_path(std::wstring path) { 381 if (!path.empty()) 382 return path_ + _T("/") + path; 383 return path_; 384 } 385 386 private: 387 std::wstring path_; 388 settings_registry * owner_; 389 }; 390 class alias_extension { 391 public: 392 alias_extension(settings_registry * owner, std::wstring alias) : owner_(owner), alias_(alias) {} 393 394 settings_keys_easy_init add_key_to_path(std::wstring path) { 395 return settings_keys_easy_init(get_path(path), owner_); 396 } 397 settings_paths_easy_init add_path(std::wstring path) { 398 return settings_paths_easy_init(get_path(path), owner_); 399 } 400 inline std::wstring get_path(std::wstring path) { 401 if (path.empty()) 402 return _T("/") + alias_; 403 return path + _T("/") + alias_; 404 } 405 406 407 settings_keys_easy_init add_key_to_settings(std::wstring path = _T("")) { 408 return settings_keys_easy_init(get_settings_path(path), owner_); 409 } 410 settings_paths_easy_init add_path_to_settings(std::wstring path = _T("")) { 411 return settings_paths_easy_init(get_settings_path(path), owner_); 412 } 413 inline std::wstring get_settings_path(std::wstring path) { 414 if (path.empty()) 415 return _T("/settings/") + alias_; 416 return _T("/settings/") + alias_ + _T("/") + path; 417 } 418 419 static std::wstring get_alias(std::wstring cur, std::wstring def) { 420 if (cur.empty()) 421 return def; 422 else 423 return cur; 424 } 425 static std::wstring get_alias(std::wstring prefix, std::wstring cur, std::wstring def) { 426 if (!prefix.empty()) 427 prefix += _T("/"); 428 if (cur.empty()) 429 return prefix + def; 430 else 431 return prefix + cur; 432 } 433 void set_alias(std::wstring cur, std::wstring def) { 434 alias_ = get_alias(cur, def); 435 } 436 void set_alias(std::wstring prefix, std::wstring cur, std::wstring def) { 437 alias_ = get_alias(prefix, cur, def); 438 } 439 440 private: 441 std::wstring alias_; 442 settings_registry * owner_; 443 }; 444 366 445 class settings_registry { 367 446 typedef std::list<boost::shared_ptr<key_info> > key_list; … … 386 465 return settings_keys_easy_init(path, this); 387 466 } 388 settings_keys_easy_init add_key_to_path_w_alias(std::wstring path) {389 return settings_keys_easy_init(path + _T("/") + alias_, this);390 }391 settings_keys_easy_init add_key_to_settings(std::wstring path = _T("")) {392 if (path.empty())393 return settings_keys_easy_init(_T("/settings/") + alias_, this);394 return settings_keys_easy_init(_T("/settings/") + alias_ + _T("/") + path, this);395 }396 467 settings_paths_easy_init add_path() { 397 468 return settings_paths_easy_init(this); 398 469 } 399 settings_paths_easy_init add_path_w_alias(std::wstring path) { 400 return settings_paths_easy_init(path + _T("/") + alias_, this); 401 } 402 settings_paths_easy_init add_path_to_settings(std::wstring path = _T("")) { 403 if (path.empty()) 404 return settings_paths_easy_init(_T("/settings/") + alias_, this); 405 return settings_paths_easy_init(_T("/settings/") + alias_ + _T("/") + path, this); 406 } 470 407 471 void set_alias(std::wstring cur, std::wstring def) { 408 if (cur.empty()) 409 alias_ = def; 410 else 411 alias_ = cur; 472 alias_ = alias_extension::get_alias(cur, def); 412 473 } 413 474 void set_alias(std::wstring prefix, std::wstring cur, std::wstring def) { 414 if (!prefix.empty()) 415 prefix += _T("/"); 416 if (cur.empty()) 417 alias_ = prefix + def; 418 else 419 alias_ = prefix + cur; 420 } 475 alias_ = alias_extension::get_alias(prefix, cur, def); 476 } 477 alias_extension alias() { 478 return alias_extension(this, alias_); 479 } 480 alias_extension alias(std::wstring alias) { 481 return alias_extension(this, alias); 482 } 483 alias_extension alias(std::wstring cur, std::wstring def) { 484 return alias_extension(this, alias_extension::get_alias(cur, def)); 485 } 486 alias_extension alias(std::wstring prefix, std::wstring cur, std::wstring def) { 487 return alias_extension(this, alias_extension::get_alias(prefix, cur, def)); 488 } 489 490 path_extension path(std::wstring path) { 491 return path_extension(this, path); 492 } 493 421 494 422 495 void register_all() { … … 450 523 } 451 524 }; 525 // class simple_alias_settings_registry : public settings_registry { 526 // private: 527 // std::wstring alias_; 528 // 529 // public: 530 // simple_alias_settings_registry(nscapi::core_wrapper* core) : settings_registry(core) {} 531 // 532 // settings_keys_easy_init add_key_to_path_w_alias(std::wstring path) { 533 // return settings_keys_easy_init(path + _T("/") + alias_, this); 534 // } 535 // settings_keys_easy_init add_key_to_settings(std::wstring path = _T("")) { 536 // return settings_keys_easy_init(get_settings_path(path), this); 537 // } 538 // settings_paths_easy_init add_path_w_alias(std::wstring path) { 539 // return settings_paths_easy_init(path + _T("/") + alias_, this); 540 // } 541 // settings_paths_easy_init add_path_to_settings(std::wstring path = _T("")) { 542 // if (path.empty()) 543 // return settings_paths_easy_init(_T("/settings/") + alias_, this); 544 // return settings_paths_easy_init(_T("/settings/") + alias_ + _T("/") + path, this); 545 // } 546 // static std::wstring get_settings_path(std::wstring alias, std::wstring path) { 547 // if (path.empty()) 548 // return _T("/settings/") + alias; 549 // return _T("/settings/") + alias + _T("/") + path; 550 // } 551 // std::wstring get_settings_path(std::wstring path) { 552 // if (path.empty()) 553 // return _T("/settings/") + alias_; 554 // return _T("/settings/") + alias_ + _T("/") + path; 555 // } 556 // void set_alias(std::wstring cur, std::wstring def) { 557 // if (cur.empty()) 558 // alias_ = def; 559 // else 560 // alias_ = cur; 561 // } 562 // void set_alias(std::wstring prefix, std::wstring cur, std::wstring def) { 563 // if (!prefix.empty()) 564 // prefix += _T("/"); 565 // if (cur.empty()) 566 // alias_ = prefix + def; 567 // else 568 // alias_ = prefix + cur; 569 // } 570 // 571 // }; 452 572 } 453 573 } -
include/pdh/collectors.hpp
r5e12ba6 rc015acc 284 284 RoundINTPDHBufferListenerImpl() : buffer(NULL), length(0), current(0), hasValue_(false) {} 285 285 RoundINTPDHBufferListenerImpl(int length_) : length(length_), current(0), hasValue_(false) { 286 PDHCounterMutexHandler mutex( mutex_);287 if (!mutex.hasLock()) 288 return; 289 buffer = new int[length];286 PDHCounterMutexHandler mutex(&mutex_); 287 if (!mutex.hasLock()) 288 return; 289 buffer = new TType[length]; 290 290 for (unsigned int i=0; i<length;i++) 291 291 buffer[i] = 0; -
include/pdh/query.hpp
r5e12ba6 rc015acc 43 43 } 44 44 45 counter_ptr addCounter(std::wstring name, listener_ptr ) {45 counter_ptr addCounter(std::wstring name, listener_ptr listener) { 46 46 counter_ptr counter = counter_ptr(new PDHCounter(name, listener)); 47 47 counters_.push_back(counter); -
include/settings/macros.h
r5e12ba6 rc015acc 375 375 namespace scheduler { 376 376 DEFINE_PATH(SECTION, SCHEDULER_SECTION); 377 DESCRIBE_SETTING(SECTION, "SCHEDULER SECTION", "Section for the Scheduler module.");377 //DESCRIBE_SETTING(SECTION, "SCHEDULER SECTION", "Section for the Scheduler module."); 378 378 379 379 DEFINE_PATH(SCHEDULES_SECTION, SCHEDULER_SECTION_SCH); 380 DESCRIBE_SETTING(SCHEDULES_SECTION, "SCHEDULES SECTION", "Section for defining schedules for the Scheduler module.");380 //DESCRIBE_SETTING(SCHEDULES_SECTION, "SCHEDULES SECTION", "Section for defining schedules for the Scheduler module."); 381 381 382 382 DEFINE_PATH(DEFAULT_SCHEDULE_SECTION, SCHEDULER_SECTION_DEF); 383 DESCRIBE_SETTING(DEFAULT_SCHEDULE_SECTION, "DEFAULT SCHEDULER SECTION", "Default settings for all scheduled commands");383 //DESCRIBE_SETTING(DEFAULT_SCHEDULE_SECTION, "DEFAULT SCHEDULER SECTION", "Default settings for all scheduled commands"); 384 384 385 385 DEFINE_SETTING_I(THREADS, SCHEDULER_SECTION, "debug threads", 1); 386 DESCRIBE_SETTING_ADVANCED(THREADS, "THREADS", "Number of threads to use int he thread pool (increase if you have many scheduled items)");386 //DESCRIBE_SETTING_ADVANCED(THREADS, "THREADS", "Number of threads to use int he thread pool (increase if you have many scheduled items)"); 387 387 388 388 DEFINE_SETTING_S(INTERVAL, SCHEDULER_SECTION_FAKE, "interval", "5m"); 389 DESCRIBE_SETTING(INTERVAL, "SCHEDULE INTERVAL", "Time in seconds between each check");389 //DESCRIBE_SETTING(INTERVAL, "SCHEDULE INTERVAL", "Time in seconds between each check"); 390 390 391 391 DEFINE_SETTING_S(COMMAND, SCHEDULER_SECTION_FAKE, "command", "check_ok"); 392 DESCRIBE_SETTING(COMMAND, "SCHEDULE COMMAND", "Command to run");392 //DESCRIBE_SETTING(COMMAND, "SCHEDULE COMMAND", "Command to run"); 393 393 394 394 DEFINE_SETTING_S(CHANNEL, SCHEDULER_SECTION_FAKE, "channel", "NSCA"); 395 DESCRIBE_SETTING(CHANNEL, "SCHEDULE CHANNEL", "Channel to send results on");395 //DESCRIBE_SETTING(CHANNEL, "SCHEDULE CHANNEL", "Channel to send results on"); 396 396 397 397 DEFINE_SETTING_S(REPORT_MODE, SCHEDULER_SECTION_FAKE, "report", "all"); 398 DESCRIBE_SETTING(REPORT_MODE, "REPORT MODE", "What to report to the server (any of the following: all, critical, warning, unknown, ok)");398 //DESCRIBE_SETTING(REPORT_MODE, "REPORT MODE", "What to report to the server (any of the following: all, critical, warning, unknown, ok)"); 399 399 400 400 DEFINE_SETTING_S(INTERVAL_D, SCHEDULER_SECTION_DEF, "interval", "5m"); 401 DESCRIBE_SETTING(INTERVAL_D, "SCHEDULE INTERVAL", "Time in seconds between each check");401 //DESCRIBE_SETTING(INTERVAL_D, "SCHEDULE INTERVAL", "Time in seconds between each check"); 402 402 403 403 DEFINE_SETTING_S(COMMAND_D, SCHEDULER_SECTION_DEF, "command", "check_ok"); 404 DESCRIBE_SETTING(COMMAND_D, "SCHEDULE COMMAND", "Command to run");404 //DESCRIBE_SETTING(COMMAND_D, "SCHEDULE COMMAND", "Command to run"); 405 405 406 406 DEFINE_SETTING_S(CHANNEL_D, SCHEDULER_SECTION_DEF, "channel", "NSCA"); 407 DESCRIBE_SETTING(CHANNEL_D, "SCHEDULE CHANNEL", "Channel to send results on");407 //DESCRIBE_SETTING(CHANNEL_D, "SCHEDULE CHANNEL", "Channel to send results on"); 408 408 409 409 DEFINE_SETTING_S(REPORT_MODE_D, SCHEDULER_SECTION_DEF, "report", "all"); 410 DESCRIBE_SETTING(REPORT_MODE_D, "REPORT MODE", "What to report to the server (any of the following: all, critical, warning, unknown, ok)");410 //DESCRIBE_SETTING(REPORT_MODE_D, "REPORT MODE", "What to report to the server (any of the following: all, critical, warning, unknown, ok)"); 411 411 412 412 } -
modules/CheckEventLog/CheckEventLog.cpp
r5e12ba6 rc015acc 72 72 settings.set_alias(_T("CheckEventlog"), alias); 73 73 74 settings.a dd_path_to_settings()74 settings.alias().add_path_to_settings() 75 75 (_T("EVENT LOG SECTION"), _T("Section for the EventLog Checker (CHeckEventLog.dll).")) 76 76 ; 77 77 78 settings.a dd_key_to_settings()78 settings.alias().add_key_to_settings() 79 79 (_T("debug"), sh::bool_key(&debug_, false), 80 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.")) -
modules/CheckEventLog/CheckEventLog.def
r291548e rc015acc 13 13 NSUnloadModule 14 14 NSGetModuleDescription 15 NSDeleteBuffer -
modules/CheckExternalScripts/CheckExternalScripts.cpp
r497b779 rc015acc 76 76 settings.set_alias(alias, _T("external scripts")); 77 77 78 settings.a dd_path_to_settings()78 settings.alias().add_path_to_settings() 79 79 (_T("EXTERNAL SCRIPT SECTION"), _T("Section for external scripts configuration options (CheckExternalScripts).")) 80 80 … … 92 92 ; 93 93 94 settings.a dd_key_to_settings()94 settings.alias().add_key_to_settings() 95 95 (_T("timeout"), sh::uint_key(&timeout, 60), 96 96 _T("COMMAND TIMEOUT"), _T("The maximum time in seconds that a command can execute. (if more then this execution will be aborted). NOTICE this only affects external commands not internal ones.")) -
modules/CheckSystem/CheckSystem.cpp
r5e12ba6 rc015acc 73 73 settings.set_alias(_T("check"), alias, _T("system/windows")); 74 74 75 settings.a dd_path_to_settings()75 settings.alias().add_path_to_settings() 76 76 (_T("WINDOWS CHECK SYSTEM"), _T("Section for system checks and system settings")) 77 77 … … 86 86 87 87 88 settings.a dd_key_to_settings()88 settings.alias().add_key_to_settings() 89 89 (_T("default"), sh::bool_key(&default_counters), 90 90 _T("HOSTNAME"), _T("The host name of this host if set to blank (default) the windows name of the computer will be used.")) … … 197 197 } 198 198 if (bStatus) { 199 PDH::PDHCounter *pCounter = NULL; 199 200 //typedef boost::shared_ptr<PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> > cnt_type; 201 typedef boost::shared_ptr<PDH::PDHCounter> counter_ptr; 202 //typedef boost::shared_ptr<PDH::PDHCounterListener> cnt_type; 203 counter_ptr pCounter; 204 //PDH::PDHCounter *pCounter = NULL; 200 205 PDH::PDHQuery pdh; 201 206 try { 202 PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> cDouble; 203 pCounter = pdh.addCounter(counter, &cDouble); 207 //pCounter.reset(new PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE>); 208 //PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> cDouble; 209 pdh.addCounter(counter); 204 210 pdh.open(); 205 211 … … 279 285 try { 280 286 PDH::PDHQuery pdh; 281 PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> cDouble;282 pdh.addCounter(counter , &cDouble);287 //PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> cDouble; 288 pdh.addCounter(counter); 283 289 pdh.open(); 284 290 pdh.gatherData(); … … 1127 1133 } 1128 1134 PDH::PDHQuery pdh; 1129 PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> cDouble; 1130 pdh.addCounter(counter.data, &cDouble); 1135 typedef boost::shared_ptr<PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> > ptr_lsnr_type; 1136 ptr_lsnr_type cDouble(new PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE>()); 1137 //boost::shared_ptr<PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> > cDouble; 1138 pdh.addCounter(counter.data, cDouble); 1131 1139 pdh.open(); 1132 1140 if (bCheckAverages) { … … 1136 1144 pdh.gatherData(); 1137 1145 pdh.close(); 1138 double value = cDouble .getValue();1146 double value = cDouble->getValue(); 1139 1147 if (bNSClient) { 1140 1148 if (!msg.empty()) -
modules/FileLogger/FileLogger.cpp
r5e12ba6 rc015acc 96 96 settings.set_alias(_T("log"), alias); 97 97 98 settings.a dd_path_to_settings()98 settings.alias().add_path_to_settings() 99 99 (_T("LOG SECTION"), _T("Configure loggning properties.")) 100 100 ; 101 101 102 settings.a dd_key_to_settings()102 settings.alias().add_key_to_settings() 103 103 //(_T("debug"), sh::bool_key(&debug_, false), 104 104 //_T("DEBUG LOGGING"), _T("Enable debug logging can help track down errors and find problems but will impact overall performance negativly.")) -
modules/NRPEServer/NRPEServer.cpp
r291548e rc015acc 62 62 settings.set_alias(_T("NRPE"), alias, _T("server")); 63 63 64 settings.a dd_path_to_settings()64 settings.alias().add_path_to_settings() 65 65 (_T("NRPE SERVER SECTION"), _T("Section for NRPE (NRPEListener.dll) (check_nrpe) protocol options.")) 66 66 ; 67 67 68 settings.a dd_key_to_settings()68 settings.alias().add_key_to_settings() 69 69 (_T("port"), sh::uint_key(&info_.port, 5666), 70 70 _T("PORT NUMBER"), _T("Port to use for NRPE.")) -
modules/NSCAAgent/NSCAAgent.cpp
r5e12ba6 rc015acc 62 62 settings.set_alias(_T("NSCA"), alias, _T("agent")); 63 63 64 settings.a dd_path_to_settings()64 settings.alias().add_path_to_settings() 65 65 (_T("NSCA AGENT SECTION"), _T("Section for NSCA passive check module.")) 66 66 ; 67 67 68 settings.a dd_key_to_settings()68 settings.alias().add_key_to_settings() 69 69 (_T("hostname"), sh::string_key(&hostname_), 70 70 _T("HOSTNAME"), _T("The host name of this host if set to blank (default) the windows name of the computer will be used.")) … … 81 81 ; 82 82 83 settings.a dd_path_to_settings(_T("server"))83 settings.alias().add_path_to_settings(_T("server")) 84 84 (_T("NSCA SERVER"), _T("Configure the NSCA server to report to.")) 85 85 ; 86 86 87 settings.a dd_key_to_settings(_T("server"))87 settings.alias().add_key_to_settings(_T("server")) 88 88 (_T("host"), sh::wstring_key(&nscahost_), 89 89 _T("NSCA HOST"), _T("The NSCA server to report results to.")) -
modules/Scheduler/Scheduler.cpp
r5e12ba6 rc015acc 33 33 return false; 34 34 } 35 /*36 35 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 */74 36 bool Scheduler::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 75 37 76 38 try { 77 get_core()->registerCommand(_T("CheckEventLog"), _T("Check for errors in the event logger!"));78 39 40 typedef std::map<std::wstring,std::wstring> schedule_map; 41 schedule_map schedules; 79 42 sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 80 43 settings.set_alias(_T("scheduler"), alias); 81 44 82 settings.a dd_path_to_settings()45 settings.alias().add_path_to_settings() 83 46 (_T("SCHEDULER SECTION"), _T("Section for the Scheduler module.")) 47 84 48 ; 85 49 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 //;50 settings.alias().add_key_to_settings() 51 (_T("threads"), sh::int_fun_key<unsigned int>(boost::bind(&scheduler::simple_scheduler::set_threads, &scheduler_, _1), 1), 52 _T("THREAD COUNT"), _T("Number of threads to use.")) 53 ; 54 55 scheduler::target def = read_schedule(settings.alias().get_settings_path(_T("default")), _T("Default schedule")); 56 57 std::wstring sch_path = settings.alias().get_settings_path(_T("schedules")); 58 59 settings.alias().add_path_to_settings() 60 (_T("schedules"), sh::fun_values_path(boost::bind(&Scheduler::add_schedule, this, sch_path, _1, _2, def)), 61 _T("SCHEDULER SECTION"), _T("Section for the Scheduler module.")) 62 ; 99 63 100 64 settings.register_all(); … … 112 76 } 113 77 try { 114 SETTINGS_REG_PATH(scheduler::SECTION);115 SETTINGS_REG_PATH(scheduler::DEFAULT_SCHEDULE_SECTION);116 SETTINGS_REG_PATH(scheduler::SCHEDULES_SECTION);117 118 SETTINGS_REG_KEY_S(scheduler::INTERVAL_D);119 SETTINGS_REG_KEY_S(scheduler::COMMAND_D);120 SETTINGS_REG_KEY_S(scheduler::CHANNEL_D);121 SETTINGS_REG_KEY_S(scheduler::REPORT_MODE_D);122 123 SETTINGS_REG_KEY_I(scheduler::THREADS);124 } catch (nscapi::nscapi_exception &e) {125 NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_);126 } catch (...) {127 NSC_LOG_ERROR_STD(_T("Failed to register command."));128 }129 130 131 try {132 133 scheduler_.set_threads(SETTINGS_GET_INT(scheduler::THREADS));134 78 NSC_DEBUG_MSG_STD(_T("Thread count: ") + to_wstring(scheduler_.get_threads())); 135 136 79 if (mode == NSCAPI::normalStart) { 137 80 scheduler_.set_handler(this); 138 81 scheduler_.start(); 139 }140 141 bool found = false;142 scheduler::target def = read_defaut_schedule(setting_keys::scheduler::DEFAULT_SCHEDULE_SECTION_PATH);143 std::list<std::wstring> items = GET_CORE()->getSettingsSection(setting_keys::scheduler::SCHEDULES_SECTION_PATH);144 145 for (std::list<std::wstring>::const_iterator cit = items.begin(); cit != items.end(); ++cit) {146 found = true;147 add_schedule(*cit, GET_CORE()->getSettingsString(setting_keys::scheduler::SCHEDULES_SECTION_PATH, *cit, _T("")), def);148 }149 150 if (!found) {151 NSC_DEBUG_MSG_STD(_T("No scheduled commands found!"));152 SETTINGS_REG_KEY_S(scheduler::INTERVAL);153 SETTINGS_REG_KEY_S(scheduler::COMMAND);154 SETTINGS_REG_KEY_S(scheduler::CHANNEL);155 SETTINGS_REG_KEY_S(scheduler::REPORT_MODE);156 157 82 } 158 83 } catch (nscapi::nscapi_exception &e) { … … 166 91 } 167 92 168 scheduler::target Scheduler::read_defaut_schedule(std::wstring path) { 93 scheduler::target Scheduler::read_schedule(std::wstring path, std::wstring schedule_name, scheduler::target *def) { 94 169 95 scheduler::target item; 170 item.channel = GET_CORE()->getSettingsString(path, setting_keys::scheduler::CHANNEL_D, setting_keys::scheduler::CHANNEL_D_DEFAULT); 171 item.command = GET_CORE()->getSettingsString(path, setting_keys::scheduler::COMMAND_D, setting_keys::scheduler::COMMAND_D_DEFAULT); 172 std::wstring report = GET_CORE()->getSettingsString(path, setting_keys::scheduler::REPORT_MODE_D, setting_keys::scheduler::REPORT_MODE_D_DEFAULT); 96 std::wstring report, duration; 97 98 sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 99 100 settings.path(path).add_path() 101 (_T("SCHEDULE DEFENITION"), _T("Schedule defenition for: ") + schedule_name) 102 ; 103 104 settings.path(path).add_key() 105 (_T("channel"), sh::wstring_key(&item.channel, def==NULL?_T("NSCA"):def->channel), 106 _T("SCHEDULE CHANNEL"), _T("Channel to send results on")) 107 108 (_T("command"), sh::wstring_key(&item.command, def==NULL?_T("check_ok"):def->command), 109 _T("SCHEDULE COMMAND"), _T("Command to execute")) 110 111 (_T("report"), sh::wstring_key(&report, def==NULL?_T("all"):nscapi::report::to_string(def->report)), 112 _T("REPORT MODE"), _T("What to report to the server (any of the following: all, critical, warning, unknown, ok)")) 113 114 // TODO: get the proper default value here! 115 (_T("interval"), sh::wstring_key(&duration, _T("5s")), 116 _T("SCHEDULE INTERAVAL"), _T("Time in seconds between each check")) 117 118 ; 119 120 settings.register_all(); 121 settings.notify(); 122 173 123 item.report = nscapi::report::parse(report); 174 std::wstring duration = GET_CORE()->getSettingsString(path, setting_keys::scheduler::INTERVAL_D, setting_keys::scheduler::INTERVAL_D_DEFAULT);175 124 item.duration = boost::posix_time::seconds(strEx::stoui_as_time_sec(duration, 1)); 176 125 return item; 177 126 } 178 void Scheduler::add_schedule(std::wstring alias, std::wstring command, scheduler::target def) { 179 scheduler::target item; 180 std::wstring detail_path = setting_keys::scheduler::SCHEDULES_SECTION_PATH + _T("/") + alias; 181 item.alias = alias; 182 item.command = command; 183 item.channel = GET_CORE()->getSettingsString(detail_path, setting_keys::scheduler::CHANNEL, def.channel); 184 item.command = GET_CORE()->getSettingsString(detail_path, setting_keys::scheduler::COMMAND, item.command); 185 127 void Scheduler::add_schedule(std::wstring path, std::wstring alias, std::wstring command, scheduler::target def) { 128 def.alias = alias; 129 def.command = command; 130 scheduler::target item = read_schedule(path + _T("/") + alias, alias, &def); 186 131 strEx::parse_command(item.command, item.command, item.arguments); 187 188 std::wstring report = GET_CORE()->getSettingsString(detail_path, setting_keys::scheduler::REPORT_MODE, nscapi::report::to_string(def.report));189 item.report = nscapi::report::parse(report);190 std::wstring duration = GET_CORE()->getSettingsString(detail_path, setting_keys::scheduler::INTERVAL, to_wstring(def.duration.total_seconds()) + _T("s"));191 item.duration = boost::posix_time::seconds(strEx::stoui_as_time_sec(duration, 1));192 132 scheduler_.add_task(item); 193 133 } -
modules/Scheduler/Scheduler.h
r5e12ba6 rc015acc 40 40 41 41 42 void add_schedule(std::wstring alias, std::wstring command, scheduler::target def);43 scheduler::target read_ defaut_schedule(std::wstring path);42 void add_schedule(std::wstring path, std::wstring alias, std::wstring command, scheduler::target def); 43 scheduler::target read_schedule(std::wstring path, std::wstring comment, scheduler::target *def = NULL); 44 44 void handle_schedule(scheduler::target item); 45 45 void on_error(std::wstring error); -
modules/Scheduler/simple_scheduler.hpp
rc0d7e82 rc015acc 122 122 }; 123 123 124 class simple_scheduler {124 class simple_scheduler : public boost::noncopyable { 125 125 private: 126 126 typedef std::map<int,target> target_list_type; -
service/NSCPlugin.cpp
rc146f89 rc015acc 435 435 } 436 436 437 bool NSCPlugin::is_duplicate( boost::filesystem::wpath file, std::wstring alias ) { 438 if (alias.empty()) 439 return module_.get_file() == dll::dll::fix_module_name(file); 440 return module_.get_file() == dll::dll::fix_module_name(file) || alias == alias_; 441 } -
service/NSCPlugin.h
r7065334 rc015acc 61 61 */ 62 62 NSPluginException(dll::dll &module, std::wstring error) : error_(error) { 63 file_ = getModule(module.get_file());63 file_ = module.get_module_name(); 64 64 } 65 std::wstring getModule(std::wstring file) { 66 if (file.empty()) 67 return _T(""); 68 std::wstring ret = file; 69 std::wstring::size_type pos = ret.find_last_of(_T("\\")); 70 if (pos != std::wstring::npos && ++pos < ret.length()) { 71 ret = ret.substr(pos); 72 } 73 return ret; 65 std::wstring what() { 66 return error_ + _T(" in file: ") + file_; 74 67 } 75 68 … … 154 147 void showTray(); 155 148 void hideTray(); 149 bool is_duplicate( boost::filesystem::wpath file, std::wstring alias ); 156 150 157 151 std::wstring getFilename() { 158 std::wstring file = module_.get_file(); 159 if (file.empty()) 160 return _T(""); 161 std::wstring::size_type pos = file.find_last_of(_T("\\")); 162 if (pos != std::wstring::npos && ++pos < file.length()) { 163 return file.substr(pos); 164 } 165 return file; 152 return module_.get_filename(); 166 153 } 167 154 std::wstring getModule() { 168 std::wstring file = getFilename();169 std::wstring::size_type pos = file.find_last_of(_T("."));170 if (pos != std::wstring::npos) {171 file = file.substr(0, pos);172 }173 pos = file.find_last_of(_T("/\\"));174 if (pos != std::wstring::npos) {175 file = file.substr(pos);176 }177 155 #ifndef WIN32 156 std::wstring file = module_.get_module_name(); 178 157 if (file.substr(0,3) == _T("lib")) 179 158 file = file.substr(3); 159 return file; 160 #else 161 return module_.get_module_name(); 180 162 #endif 181 return file;182 163 } 183 164 static std::wstring get_plugin_file(std::wstring key) { -
service/NSClient++.cpp
rb4db89d rc015acc 488 488 } 489 489 490 NSClientT::plugin_info_list NSClientT::get_all_plugins() {491 boost::filesystem::wpath pluginPath = expand_path(_T("${module-path}"));492 plugin_alias_list_type plugins = find_all_plugins(false);493 plugin_info_list ret;494 std::pair<std::wstring,std::wstring> v;495 496 BOOST_FOREACH(v, plugins) {497 plugin_info_type info;498 info.dll = v.second;499 try {500 LOG_DEBUG_STD(_T("Attempting to fake load: ") + v.second + _T(" as ") + v.first);501 NSCPlugin plugin(next_plugin_id_++, pluginPath / v.second, v.first);502 plugin.load_dll();503 plugin.load_plugin(NSCAPI::dontStart);504 info.name = plugin.getName();505 info.description = plugin.getDescription();506 plugin.unload();507 } catch (NSPluginException e) {508 LOG_CRITICAL_STD(_T("Error loading: ") + e.file_ + _T(" root cause: ") + e.error_);509 } catch (...) {510 LOG_CRITICAL_STD(_T("Unknown Error loading: ") + info.dll);511 }512 ret.push_back(info);513 }514 return ret;515 }490 // NSClientT::plugin_info_list NSClientT::get_all_plugins() { 491 // boost::filesystem::wpath pluginPath = expand_path(_T("${module-path}")); 492 // plugin_alias_list_type plugins = find_all_plugins(false); 493 // plugin_info_list ret; 494 // std::pair<std::wstring,std::wstring> v; 495 // 496 // BOOST_FOREACH(v, plugins) { 497 // plugin_info_type info; 498 // info.dll = v.second; 499 // try { 500 // LOG_DEBUG_STD(_T("Attempting to fake load: ") + v.second + _T(" as ") + v.first); 501 // NSCPlugin plugin(next_plugin_id_++, pluginPath / v.second, v.first); 502 // plugin.load_dll(); 503 // plugin.load_plugin(NSCAPI::dontStart); 504 // info.name = plugin.getName(); 505 // info.description = plugin.getDescription(); 506 // plugin.unload(); 507 // } catch (NSPluginException e) { 508 // LOG_CRITICAL_STD(_T("Error loading: ") + e.file_ + _T(" root cause: ") + e.error_); 509 // } catch (...) { 510 // LOG_CRITICAL_STD(_T("Unknown Error loading: ") + info.dll); 511 // } 512 // ret.push_back(info); 513 // } 514 // return ret; 515 // } 516 516 517 517 … … 528 528 529 529 BOOST_FOREACH(v, plugins) { 530 std::wstring desc;531 std::wstring name = v.second;532 530 try { 533 NSCPlugin plugin(next_plugin_id_++, pluginPath / v.second, v.first); 534 name = plugin.getModule(); 535 plugin.load_dll(); 536 plugin.load_plugin(mode); 537 desc = plugin.getName() + _T(" - "); 538 desc += plugin.getDescription(); 539 plugin.unload(); 540 } catch (NSPluginException e) { 541 desc += _T("unknown module"); 542 LOG_CRITICAL_STD(_T("Error loading: ") + e.file_ + _T(" root cause: ") + e.error_); 531 addPlugin(pluginPath / v.second, v.second); 532 } catch (NSPluginException &e) { 533 LOG_CRITICAL_STD(_T("Failed to register plugin: ") + e.what()); 543 534 } catch (...) { 544 desc += _T("unknown module"); 545 LOG_CRITICAL_STD(_T("Unknown Error loading: ") + name); 546 } 547 try { 548 if (v.first.empty() && !settings_manager::get_settings()->has_key(MAIN_MODULES_SECTION, v.second)) 549 settings_manager::get_core()->register_key(MAIN_MODULES_SECTION, name, settings::settings_core::key_string, desc, desc, _T("disabled"), false); 550 } catch (...) { 551 LOG_CRITICAL_STD(_T("Failed to register plugin key: ") + name); 552 } 535 LOG_CRITICAL_STD(_T("Failed to register plugin key: ") + v.second); 536 } 537 // std::wstring desc; 538 // std::wstring name = v.second; 539 // try { 540 // NSCPlugin plugin(next_plugin_id_++, pluginPath / v.second, v.first); 541 // name = plugin.getModule(); 542 // plugin.load_dll(); 543 // plugin.load_plugin(mode); 544 // desc = plugin.getName() + _T(" - "); 545 // desc += plugin.getDescription(); 546 // plugin.unload(); 547 // } catch (NSPluginException e) { 548 // desc += _T("unknown module"); 549 // LOG_CRITICAL_STD(_T("Error loading: ") + e.file_ + _T(" root cause: ") + e.error_); 550 // } catch (...) { 551 // desc += _T("unknown module"); 552 // LOG_CRITICAL_STD(_T("Unknown Error loading: ") + name); 553 // } 554 // try { 555 // if (v.first.empty() && !settings_manager::get_settings()->has_key(MAIN_MODULES_SECTION, v.second)) 556 // settings_manager::get_core()->register_key(MAIN_MODULES_SECTION, name, settings::settings_core::key_string, desc, desc, _T("disabled"), false); 557 // } catch (...) { 558 // LOG_CRITICAL_STD(_T("Failed to register plugin key: ") + name); 559 // } 553 560 } 554 561 } … … 847 854 try { 848 855 plugin_type plugin = addPlugin(getBasePath() / boost::filesystem::wpath(_T("modules")) / boost::filesystem::wpath(module), _T("")); 849 LOG_DEBUG_STD(_T("Loading plugin: ") + plugin->getName() + _T("...")); 850 plugin->load_plugin(NSCAPI::dontStart); 851 return plugin->commandLineExec(argLen, args); 856 if (plugin) { 857 LOG_DEBUG_STD(_T("Loading plugin: ") + plugin->getName() + _T("...")); 858 plugin->load_plugin(NSCAPI::dontStart); 859 return plugin->commandLineExec(argLen, args); 860 } else { 861 LOG_ERROR_CORE_STD(_T("Failed to load: ") + std::wstring(module) + _T(" available modules are: ") + moduleList); 862 return 1; 863 } 852 864 } catch (NSPluginException e) { 853 865 LOG_MESSAGE_STD(_T("Module (") + e.file_ + _T(") was not found: ") + e.error_); … … 974 986 return plugin; 975 987 } 988 989 BOOST_FOREACH(plugin_type plug, plugins_) { 990 if (plug->is_duplicate(file, alias)) { 991 plugin.reset(); 992 return plug; 993 } 994 } 995 996 976 997 plugins_.insert(plugins_.end(), plugin); 977 998 commands_.add_plugin(plugin); -
service/commands.hpp
r294b37b rc015acc 92 92 std::wstring lc = make_key(cmd); 93 93 if (!have_plugin(plugin_id)) 94 throw command_exception("Failed to find plugin: " + ::to_string(plugin_id) + " : " + unsafe_get_all_plugin_ids());94 throw command_exception("Failed to find plugin: " + ::to_string(plugin_id) + " {" + unsafe_get_all_plugin_ids() + "}"); 95 95 descriptions_[lc] = desc; 96 96 commands_[lc] = plugins_[plugin_id]; -
service/core_api.cpp
r291548e rc015acc 342 342 } 343 343 NSCAPI::errorReturn NSAPIGetPluginList(int *len, NSCAPI::plugin_info *list[]) { 344 NSClientT::plugin_info_list plugList= mainClient.get_all_plugins();345 *len = plugList.size();344 // NSClientT::plugin_info_list plugList= mainClient.get_all_plugins(); 345 *len = 0; //plugList.size(); 346 346 347 347 *list = new NSCAPI::plugin_info[*len+1]; 348 /* 348 349 int i=0; 349 350 for(NSClientT::plugin_info_list::const_iterator cit = plugList.begin(); cit != plugList.end(); ++cit,i++) { … … 353 354 (*list)[i].description = copyString((*cit).description); 354 355 } 356 */ 355 357 return NSCAPI::isSuccess; 356 358 } -
service/settings_client.hpp
r2a1411e rc015acc 112 112 } catch (settings::settings_exception e) { 113 113 error_msg(_T("Failed to initialize settings: ") + e.getError()); 114 } catch (NSPluginException &e) { 115 error_msg(_T("Failed to load plugins: ") + to_wstring(e.what())); 114 116 } catch (std::exception &e) { 115 117 error_msg(_T("Failed to initialize settings: ") + to_wstring(e.what()));
Note: See TracChangeset
for help on using the changeset viewer.








