Changeset 8013c0c in nscp
- Timestamp:
- 01/23/12 07:41:06 (17 months ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- 6a30f44
- Parents:
- 28f6a64
- Files:
-
- 37 edited
-
changelog (modified) (1 diff)
-
helpers/settings_manager/settings_manager_impl.cpp (modified) (1 diff)
-
include/NSCAPI.h (modified) (2 diffs)
-
include/nscapi/functions.hpp (modified) (2 diffs)
-
include/nscapi/macros.hpp (modified) (1 diff)
-
include/nscapi/nscapi_core_wrapper.cpp (modified) (7 diffs)
-
include/nscapi/nscapi_core_wrapper.hpp (modified) (4 diffs)
-
include/nscapi/nscapi_helper.cpp (modified) (2 diffs)
-
include/nscapi/nscapi_helper.hpp (modified) (1 diff)
-
include/nscapi/nscapi_plugin_wrapper.cpp (modified) (1 diff)
-
include/nscapi/settings_proxy.hpp (modified) (1 diff)
-
include/settings/client/settings_client.cpp (modified) (1 diff)
-
include/settings/client/settings_client.hpp (modified) (9 diffs)
-
include/settings/settings_core.hpp (modified) (3 diffs)
-
modules/CheckNSCP/CheckNSCP.cpp (modified) (1 diff)
-
modules/CheckSystem/PDHCollector.cpp (modified) (2 diffs)
-
modules/DistributedServer/handler_impl.hpp (modified) (1 diff)
-
modules/FileLogger/FileLogger.cpp (modified) (1 diff)
-
modules/LUAScript/script_wrapper.hpp (modified) (1 diff)
-
modules/NRPEServer/handler_impl.hpp (modified) (1 diff)
-
modules/NSCAClient/NSCAClient.cpp (modified) (4 diffs)
-
modules/NSCAServer/handler_impl.hpp (modified) (1 diff)
-
modules/NSCPServer/handler_impl.hpp (modified) (1 diff)
-
modules/NSClientServer/handler_impl.hpp (modified) (1 diff)
-
modules/Scheduler/simple_scheduler.cpp (modified) (1 diff)
-
scripts/python/lib/test_helper.py (modified) (10 diffs)
-
service/CMakeLists.txt (modified) (1 diff)
-
service/NSClient++.cpp (modified) (3 diffs)
-
service/NSClient++.h (modified) (4 diffs)
-
service/cli_parser.hpp (modified) (11 diffs)
-
service/core_api.cpp (modified) (3 diffs)
-
service/core_api.h (modified) (1 diff)
-
service/logger.hpp (modified) (1 diff)
-
service/settings_logger_impl.cpp (modified) (4 diffs)
-
service/simple_client.hpp (modified) (2 diffs)
-
version.hpp (modified) (1 diff)
-
version.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
changelog
rb175d61 r8013c0c 5 5 * Fixa dependonservice LanManWorkStation (old win) 6 6 * Fix RtlStringFromGUID problem on NT4 7 8 2012-01-22 MickeM 9 * Fixed so NSCAClient parses address correctly 10 * setings exception is now derived from exception meaning it will show up more with details (instead of unknown) 11 * Added API for handling log level (replaces older debug flag) 12 * Added options for settings debug level 13 * Changed to --settings is a global argument (meaning you canuse it in any mode) 14 * Added arguments parsing to test: so you can use global arguments such as --log and --settings. 15 * Removed memory leak in settings parsing interface 7 16 8 17 2012-01-20 MickeM -
helpers/settings_manager/settings_manager_impl.cpp
r89838be r8013c0c 24 24 inline NSCSettingsImpl* internal_get() { 25 25 if (settings_impl == NULL) 26 throw "Settings has not been initiated!";26 throw settings::settings_exception(_T("Settings has not been initiated!")); 27 27 return settings_impl; 28 28 } -
include/NSCAPI.h
rf7a074d r8013c0c 96 96 97 97 // Various message Types 98 const int log = 1; // Log message 99 const int error = -1; // Error (non critical) 100 const int critical = -10; // Critical error 101 const int warning = 2; // Warning 102 const int debug = 10; // Debug message 103 104 typedef int messageTypes; // Message type 98 namespace log_level { 99 typedef int level; 100 const int critical = 1; // Critical error 101 const int error = 10; // Error 102 const int warning = 50; // Warning <<< Default for command line interface 103 const int log = 100; // Log message <<< Default for service 104 const int info = 150; // information 105 const int debug = 500; // Debug messages <<< Default for test 106 const int trace = 1000; // Trace messages 107 } 108 109 typedef log_level::level messageTypes; // Message type 105 110 106 111 struct plugin_info { … … 175 180 typedef NSCAPI::errorReturn (*lpNSAPIRegisterRoutingListener)(unsigned int plugin_id, const wchar_t* channel); 176 181 typedef NSCAPI::errorReturn (*lpNSAPIReload)(const wchar_t* module); 182 typedef NSCAPI::log_level::level (*lpNSAPIGetLoglevel)(); 177 183 178 184 } -
include/nscapi/functions.hpp
rba63b95 r8013c0c 118 118 119 119 static Plugin::LogEntry::Entry::Level log_to_gpb(NSCAPI::messageTypes ret) { 120 if (ret == NSCAPI:: critical)120 if (ret == NSCAPI::log_level::critical) 121 121 return Plugin::LogEntry_Entry_Level_LOG_CRITICAL; 122 if (ret == NSCAPI:: debug)122 if (ret == NSCAPI::log_level::debug) 123 123 return Plugin::LogEntry_Entry_Level_LOG_DEBUG; 124 if (ret == NSCAPI:: error)124 if (ret == NSCAPI::log_level::error) 125 125 return Plugin::LogEntry_Entry_Level_LOG_ERROR; 126 if (ret == NSCAPI::log )126 if (ret == NSCAPI::log_level::log) 127 127 return Plugin::LogEntry_Entry_Level_LOG_INFO; 128 if (ret == NSCAPI::warning) 128 if (ret == NSCAPI::log_level::info) 129 return Plugin::LogEntry_Entry_Level_LOG_INFO; 130 if (ret == NSCAPI::log_level::warning) 129 131 return Plugin::LogEntry_Entry_Level_LOG_WARNING; 130 132 return Plugin::LogEntry_Entry_Level_LOG_ERROR; … … 132 134 static NSCAPI::messageTypes gpb_to_log(Plugin::LogEntry::Entry::Level ret) { 133 135 if (ret == Plugin::LogEntry_Entry_Level_LOG_CRITICAL) 134 return NSCAPI:: critical;136 return NSCAPI::log_level::critical; 135 137 if (ret == Plugin::LogEntry_Entry_Level_LOG_DEBUG) 136 return NSCAPI:: debug;138 return NSCAPI::log_level::debug; 137 139 if (ret == Plugin::LogEntry_Entry_Level_LOG_ERROR) 138 return NSCAPI:: error;140 return NSCAPI::log_level::error; 139 141 if (ret == Plugin::LogEntry_Entry_Level_LOG_INFO) 140 return NSCAPI::log ;142 return NSCAPI::log_level::info; 141 143 if (ret == Plugin::LogEntry_Entry_Level_LOG_WARNING) 142 return NSCAPI:: warning;143 return NSCAPI:: error;144 return NSCAPI::log_level::warning; 145 return NSCAPI::log_level::error; 144 146 } 145 147 -
include/nscapi/macros.hpp
r40fca56 r8013c0c 35 35 // Logging calls for the core wrapper 36 36 37 #define NSC_LOG_ERROR_STD(msg) NSC_LOG_ERROR(((std::wstring)msg).c_str())38 #define NSC_LOG_ERROR(msg) NSC_ANY_MSG(msg,NSCAPI::error)37 #define NSC_LOG_ERROR_STD(msg) if (GET_CORE()->should_log(NSCAPI::log_level::error)) { NSC_ANY_MSG((std::wstring)msg, NSCAPI::log_level::error); } 38 #define NSC_LOG_ERROR(msg) if (GET_CORE()->should_log(NSCAPI::log_level::error)) { NSC_ANY_MSG(msg, NSCAPI::log_level::error); } 39 39 40 #define NSC_LOG_CRITICAL_STD(msg) NSC_LOG_CRITICAL(((std::wstring)msg).c_str())41 #define NSC_LOG_CRITICAL(msg) NSC_ANY_MSG(msg,NSCAPI::critical)40 #define NSC_LOG_CRITICAL_STD(msg) if (GET_CORE()->should_log(NSCAPI::log_level::critical)) { NSC_ANY_MSG((std::wstring)msg, NSCAPI::log_level::critical); } 41 #define NSC_LOG_CRITICAL(msg) if (GET_CORE()->should_log(NSCAPI::log_level::critical)) { NSC_ANY_MSG(msg, NSCAPI::log_level::critical); } 42 42 43 #define NSC_LOG_MESSAGE_STD(msg) NSC_LOG_MESSAGE(((std::wstring)msg).c_str())44 #define NSC_LOG_MESSAGE(msg) NSC_ANY_MSG(msg,NSCAPI::log)43 #define NSC_LOG_MESSAGE_STD(msg) if (GET_CORE()->should_log(NSCAPI::log_level::info)) { NSC_ANY_MSG((std::wstring)msg, NSCAPI::log_level::info); } 44 #define NSC_LOG_MESSAGE(msg) if (GET_CORE()->should_log(NSCAPI::log_level::info)) { NSC_ANY_MSG(msg, NSCAPI::log_level::info); } 45 45 46 #define NSC_DEBUG_MSG_STD(msg) NSC_DEBUG_MSG((std::wstring)msg)47 #define NSC_DEBUG_MSG(msg) NSC_ANY_MSG(msg,NSCAPI::debug)46 #define NSC_DEBUG_MSG_STD(msg) if (GET_CORE()->should_log(NSCAPI::log_level::debug)) { NSC_ANY_MSG((std::wstring)msg, NSCAPI::log_level::debug); } 47 #define NSC_DEBUG_MSG(msg) if (GET_CORE()->should_log(NSCAPI::log_level::debug)) { NSC_ANY_MSG(msg, NSCAPI::log_level::debug); } 48 48 49 49 #define NSC_ANY_MSG(msg, type) GET_CORE()->log(type, __FILE__, __LINE__, msg) 50 /*51 #define NSC_LOG_ERROR_STD(msg)52 #define NSC_LOG_ERROR(msg)53 54 #define NSC_LOG_CRITICAL_STD(msg)55 #define NSC_LOG_CRITICAL(msg)56 57 #define NSC_LOG_MESSAGE_STD(msg)58 #define NSC_LOG_MESSAGE(msg)59 60 #define NSC_DEBUG_MSG_STD(msg)61 #define NSC_DEBUG_MSG(msg)62 63 #define NSC_ANY_MSG(msg, type)64 */65 50 66 51 ////////////////////////////////////////////////////////////////////////// -
include/nscapi/nscapi_core_wrapper.cpp
ra87ce04 r8013c0c 35 35 using namespace nscp::helpers; 36 36 37 #define CORE_LOG_ERROR_STD(msg) CORE_LOG_ERROR(((std::wstring)msg).c_str()) 38 #define CORE_LOG_ERROR(msg) CORE_ANY_MSG(msg,NSCAPI::error) 39 40 #define CORE_LOG_CRITICAL_STD(msg) CORE_LOG_CRITICAL(((std::wstring)msg).c_str()) 41 #define CORE_LOG_CRITICAL(msg) CORE_ANY_MSG(msg,NSCAPI::critical) 42 43 #define CORE_LOG_MESSAGE_STD(msg) CORE_LOG_MESSAGE(((std::wstring)msg).c_str()) 44 #define CORE_LOG_MESSAGE(msg) CORE_ANY_MSG(msg,NSCAPI::log) 45 46 #define CORE_DEBUG_MSG_STD(msg) CORE_DEBUG_MSG((std::wstring)msg) 47 #define CORE_DEBUG_MSG(msg) CORE_ANY_MSG(msg,NSCAPI::debug) 48 49 #define CORE_ANY_MSG(msg, type) log(type, __FILE__, __LINE__, msg) 37 38 #define CORE_LOG_ERROR_STD(msg) if (should_log(NSCAPI::log_level::error)) { log(NSCAPI::log_level::error, __FILE__, __LINE__, (std::wstring)msg); } 39 #define CORE_LOG_ERROR(msg) if (should_log(NSCAPI::log_level::error)) { log(NSCAPI::log_level::error, __FILE__, __LINE__, msg); } 40 41 //#define CORE_LOG_CRITICAL_STD(msg) if (matches(NSCAPI::critical)) { CORE_ANY_MSG(NSCAPI::critical, __FILE__, __LINE__, (std::wstring)msg) } 42 //#define CORE_LOG_CRITICAL(msg) if (matches(NSCAPI::critical)) { CORE_ANY_MSG(NSCAPI::critical, __FILE__, __LINE__, msg) } 43 44 //#define CORE_LOG_MESSAGE_STD(msg) if (matches(NSCAPI::info)) { CORE_ANY_MSG(NSCAPI::info, __FILE__, __LINE__, (std::wstring)msg) } 45 //#define CORE_LOG_MESSAGE(msg) if (matches(NSCAPI::info)) { CORE_ANY_MSG(NSCAPI::info, __FILE__, __LINE__, msg) } 46 47 //#define CORE_DEBUG_MSG_STD(msg) if (matches(NSCAPI::debug)) { CORE_ANY_MSG(NSCAPI::debug, __FILE__, __LINE__, (std::wstring)msg) } 48 //#define CORE_DEBUG_MSG(msg) if (matches(NSCAPI::debug)) { CORE_ANY_MSG(NSCAPI::debug, __FILE__, __LINE__, msg) } 49 50 //#define CORE_ANY_MSG(msg, type) log(type, __FILE__, __LINE__, msg) 50 51 51 52 … … 53 54 // Callbacks into the core 54 55 ////////////////////////////////////////////////////////////////////////// 56 57 bool nscapi::core_wrapper::should_log(NSCAPI::nagiosReturn msgType) { 58 enum log_status {unknown, set }; 59 static NSCAPI::log_level::level level = NSCAPI::log_level::log; 60 static log_status status = unknown; 61 if (status == unknown) { 62 level = get_loglevel(); 63 status = set; 64 } 65 return nscapi::logging::matches(level, msgType); 66 } 67 55 68 56 69 /** … … 63 76 * @throws nscapi::nscapi_exception When core pointer set is unavailable. 64 77 */ 65 void nscapi::core_wrapper::log(int msgType, std::string file, int line, std::wstring logMessage) { 66 if (fNSAPIMessage) { 67 if ((msgType == NSCAPI::debug) && (!logDebug())) 68 return; 69 std::string str; 70 try { 71 Plugin::LogEntry message; 72 Plugin::LogEntry::Entry *msg = message.add_entry(); 73 msg->set_level(nscapi::functions::log_to_gpb(msgType)); 74 msg->set_file(file); 75 msg->set_line(line); 76 msg->set_message(utf8::cvt<std::string>(logMessage)); 77 if (!message.SerializeToString(&str)) { 78 std::cout << "Failed to generate message"; 79 } 80 return fNSAPIMessage(str.c_str(), str.size()); 81 } catch (...) { 82 std::wcout << _T("Failed to generate message: "); 78 void nscapi::core_wrapper::log(NSCAPI::nagiosReturn msgType, std::string file, int line, std::wstring logMessage) { 79 if (!should_log(msgType)) 80 return; 81 if (!fNSAPIMessage) { 82 std::wcout << _T("*** *** *** NSCore not loaded, dumping log: ") << to_wstring(file) << _T(":") << line << _T(": ") << std::endl << logMessage << std::endl; 83 return; 84 } 85 std::string str; 86 try { 87 Plugin::LogEntry message; 88 Plugin::LogEntry::Entry *msg = message.add_entry(); 89 msg->set_level(nscapi::functions::log_to_gpb(msgType)); 90 msg->set_file(file); 91 msg->set_line(line); 92 msg->set_message(utf8::cvt<std::string>(logMessage)); 93 if (!message.SerializeToString(&str)) { 94 std::wcout << _T("Failed to generate message: SERIALIZATION ERROR"); 83 95 } 84 // return fNSAPIMessage(to_string(logMessage).c_str(), logMessage.size()); 85 } 86 else 87 std::wcout << _T("*** *** *** NSCore not loaded, dumping log: ") << to_wstring(file) << _T(":") << line << _T(": ") << std::endl << logMessage << std::endl; 88 } 89 void nscapi::core_wrapper::log(int msgType, std::string file, int line, std::string message) { 90 if ((msgType == NSCAPI::debug) && (!logDebug())) 96 return fNSAPIMessage(str.c_str(), str.size()); 97 } catch (const std::exception &e) { 98 std::wcout << _T("Failed to generate message: ") << utf8::to_unicode(e.what()); 99 } catch (...) { 100 std::wcout << _T("Failed to generate message: UNKNOWN"); 101 } 102 } 103 void nscapi::core_wrapper::log(NSCAPI::nagiosReturn msgType, std::string file, int line, std::string message) { 104 if (!should_log(msgType)) 91 105 return; 92 106 log(msgType, file, line, utf8::cvt<std::wstring>(message)); 93 107 } 108 109 NSCAPI::log_level::level nscapi::core_wrapper::get_loglevel() { 110 if (!fNSAPIGetLoglevel) { 111 return NSCAPI::log_level::debug; 112 } 113 return fNSAPIGetLoglevel(); 114 } 115 94 116 95 117 /** … … 237 259 switch (retC) { 238 260 case NSCAPI::returnIgnored: 239 CORE_LOG_ MESSAGE_STD(_T("No handler for command '") + command + _T("'."));261 CORE_LOG_ERROR_STD(_T("No handler for command '") + command + _T("'.")); 240 262 break; 241 263 case NSCAPI::returnOK: … … 273 295 switch (retC) { 274 296 case NSCAPI::returnIgnored: 275 CORE_LOG_ MESSAGE_STD(_T("No handler for command '") + command + _T("'."));297 CORE_LOG_ERROR_STD(_T("No handler for command '") + command + _T("'.")); 276 298 break; 277 299 case NSCAPI::returnOK: … … 475 497 } 476 498 477 478 bool nscapi::core_wrapper::logDebug() {479 enum status {unknown, debug, nodebug };480 static status d = unknown;481 if (d == unknown) {482 if (checkLogMessages(debug)== NSCAPI::istrue)483 d = debug;484 else485 d = nodebug;486 }487 return (d == debug);488 }489 499 490 500 std::wstring nscapi::core_wrapper::Encrypt(std::wstring str, unsigned int algorithm) { … … 698 708 fNSAPIRegisterSubmissionListener = (nscapi::core_api::lpNSAPIRegisterSubmissionListener)f(_T("NSAPIRegisterSubmissionListener")); 699 709 fNSAPIRegisterRoutingListener = (nscapi::core_api::lpNSAPIRegisterRoutingListener)f(_T("NSAPIRegisterRoutingListener")); 710 fNSAPIGetLoglevel = (nscapi::core_api::lpNSAPIGetLoglevel)f(_T("NSAPIGetLoglevel")); 700 711 701 712 return true; -
include/nscapi/nscapi_core_wrapper.hpp
r40fca56 r8013c0c 73 73 nscapi::core_api::lpNSAPIRegisterSubmissionListener fNSAPIRegisterSubmissionListener; 74 74 nscapi::core_api::lpNSAPIRegisterRoutingListener fNSAPIRegisterRoutingListener; 75 nscapi::core_api::lpNSAPIGetLoglevel fNSAPIGetLoglevel; 75 76 76 77 public: … … 118 119 , fNSAPISettingsSave(NULL) 119 120 , fNSAPIExpandPath(NULL) 121 , fNSAPIGetLoglevel(NULL) 120 122 {} 121 123 … … 133 135 void settings_save(); 134 136 135 void log(int msgType, std::string file, int line, std::wstring message); 136 void log(int msgType, std::string file, int line, std::string message); 137 void log(NSCAPI::nagiosReturn msgType, std::string file, int line, std::wstring message); 138 void log(NSCAPI::nagiosReturn msgType, std::string file, int line, std::string message); 139 bool should_log(NSCAPI::nagiosReturn msgType); 140 NSCAPI::log_level::level get_loglevel(); 137 141 void DestroyBuffer(char**buffer); 138 142 NSCAPI::nagiosReturn query(const wchar_t* command, const char *request, const unsigned int request_len, char **response, unsigned int *response_len); … … 153 157 void Exit(void); 154 158 std::wstring getBasePath(); 155 bool logDebug();156 159 bool checkLogMessages(int type); 157 160 std::wstring Encrypt(std::wstring str, unsigned int algorithm = NSCAPI::encryption_xor); -
include/nscapi/nscapi_helper.cpp
r54ac968 r8013c0c 85 85 } 86 86 87 #define LOG_CRIT 0x10 88 #define LOG_ERROR 0x08 89 #define LOG_WARNING 0x04 90 #define LOG_MSG 0x02 91 #define LOG_DEBUG 0x01 92 93 unsigned int nscapi::logging::parse(std::wstring str) { 94 unsigned int report = 0; 87 #define PARSE_LOGLEVEL_BEGIN() if (false) {} 88 #define PARSE_LOGLEVEL(key_str, value) else if (*key == _T(key_str) && level < value) { level = value; } 89 #define PARSE_LOGLEVEL_END() 90 91 NSCAPI::log_level::level nscapi::logging::parse(std::wstring str) { 92 unsigned int level = 0; 95 93 strEx::splitList lst = strEx::splitEx(str, _T(",")); 96 97 94 for (strEx::splitList::const_iterator key = lst.begin(); key != lst.end(); ++key) { 98 if (*key == _T("all")) { 99 report |= LOG_MSG|LOG_ERROR|LOG_CRIT|LOG_WARNING|LOG_DEBUG; 100 } else if (*key == _T("normal")) { 101 report |= LOG_MSG|LOG_ERROR|LOG_CRIT|LOG_WARNING; 102 } else if (*key == _T("log") || *key == _T("message") || *key == _T("info") || *key == _T("INFO")) { 103 report |= LOG_MSG; 104 } else if (*key == _T("error") || *key == _T("ERROR")) { 105 report |= LOG_ERROR; 106 } else if (*key == _T("critical") || *key == _T("CRITICAL")) { 107 report |= LOG_CRIT; 108 } else if (*key == _T("warning") || *key == _T("WARN")) { 109 report |= LOG_WARNING; 110 } else if (*key == _T("debug") || *key == _T("DEBUG")) { 111 report |= LOG_DEBUG; 112 } 113 } 114 return report; 115 } 116 bool nscapi::logging::matches(unsigned int report, NSCAPI::nagiosReturn code) { 117 return ( 118 (code == NSCAPI::critical && ((report&LOG_CRIT)==LOG_CRIT) ) || 119 (code == NSCAPI::error && ((report&LOG_ERROR)==LOG_ERROR) ) || 120 (code == NSCAPI::warning && ((report&LOG_WARNING)==LOG_WARNING) ) || 121 (code == NSCAPI::log && ((report&LOG_MSG)==LOG_MSG) ) || 122 (code == NSCAPI::debug && ((report&LOG_DEBUG)==LOG_DEBUG) ) || 123 ( (code != NSCAPI::critical) && (code != NSCAPI::error) && (code != NSCAPI::warning) && (code != NSCAPI::log) && (code != NSCAPI::debug) ) 124 ); 125 } 126 127 std::wstring nscapi::logging::to_string(unsigned int report) { 128 std::wstring ret; 129 if ((report&LOG_CRIT)!=0) { 130 if (!ret.empty()) ret += _T(","); 131 ret += _T("critical"); 132 } 133 if ((report&LOG_ERROR)!=0) { 134 if (!ret.empty()) ret += _T(","); 135 ret += _T("error"); 136 } 137 if ((report&LOG_WARNING)!=0) { 138 if (!ret.empty()) ret += _T(","); 139 ret += _T("warning"); 140 } 141 if ((report&LOG_MSG)!=0) { 142 if (!ret.empty()) ret += _T(","); 143 ret += _T("message"); 144 } 145 if ((report&LOG_DEBUG)!=0) { 146 if (!ret.empty()) ret += _T(","); 147 ret += _T("debug"); 148 } 149 return ret; 95 PARSE_LOGLEVEL_BEGIN() 96 PARSE_LOGLEVEL("all", NSCAPI::log_level::trace) 97 PARSE_LOGLEVEL("normal", NSCAPI::log_level::info) 98 PARSE_LOGLEVEL("service", NSCAPI::log_level::log) 99 PARSE_LOGLEVEL("log", NSCAPI::log_level::log) 100 PARSE_LOGLEVEL("message", NSCAPI::log_level::info) 101 PARSE_LOGLEVEL("error", NSCAPI::log_level::error) 102 PARSE_LOGLEVEL("critical", NSCAPI::log_level::critical) 103 PARSE_LOGLEVEL("debug", NSCAPI::log_level::debug) 104 PARSE_LOGLEVEL("trace", NSCAPI::log_level::trace) 105 PARSE_LOGLEVEL("info", NSCAPI::log_level::info) 106 PARSE_LOGLEVEL("warning", NSCAPI::log_level::warning) 107 PARSE_LOGLEVEL_END() 108 } 109 return level; 110 } 111 bool nscapi::logging::matches(NSCAPI::log_level::level level, NSCAPI::nagiosReturn code) { 112 return code <= level; 113 } 114 115 #define RENDER_LOGLEVEL_BEGIN() 116 #define RENDER_LOGLEVEL(key_str, value) if (level == value) { return _T(key_str); } 117 #define RENDER_LOGLEVEL_END() 118 119 std::wstring nscapi::logging::to_string(NSCAPI::log_level::level level) { 120 RENDER_LOGLEVEL_BEGIN() 121 RENDER_LOGLEVEL("all", NSCAPI::log_level::trace) 122 RENDER_LOGLEVEL("normal", NSCAPI::log_level::info) 123 RENDER_LOGLEVEL("log", NSCAPI::log_level::log) 124 RENDER_LOGLEVEL("message", NSCAPI::log_level::info) 125 RENDER_LOGLEVEL("error", NSCAPI::log_level::error) 126 RENDER_LOGLEVEL("critical", NSCAPI::log_level::critical) 127 RENDER_LOGLEVEL("debug", NSCAPI::log_level::debug) 128 RENDER_LOGLEVEL("trace", NSCAPI::log_level::trace) 129 RENDER_LOGLEVEL("info", NSCAPI::log_level::info) 130 RENDER_LOGLEVEL("warning", NSCAPI::log_level::warning) 131 RENDER_LOGLEVEL_END() 132 return strEx::itos(level); 150 133 } 151 134 … … 198 181 std::wstring nscapi::plugin_helper::translateMessageType(NSCAPI::messageTypes msgType) { 199 182 switch (msgType) { 200 case NSCAPI:: error:183 case NSCAPI::log_level::error: 201 184 return _T("error"); 202 case NSCAPI:: critical:185 case NSCAPI::log_level::critical: 203 186 return _T("critical"); 204 case NSCAPI:: warning:187 case NSCAPI::log_level::warning: 205 188 return _T("warning"); 206 case NSCAPI::log :189 case NSCAPI::log_level::log: 207 190 return _T("message"); 208 case NSCAPI:: debug:191 case NSCAPI::log_level::debug: 209 192 return _T("debug"); 210 193 } -
include/nscapi/nscapi_helper.hpp
rd66ccee r8013c0c 48 48 } 49 49 namespace logging { 50 unsigned intparse(std::wstring str);51 bool matches( unsigned int report, NSCAPI::nagiosReturn code);52 std::wstring to_string( unsigned int report);50 NSCAPI::log_level::level parse(std::wstring str); 51 bool matches(NSCAPI::log_level::level level, NSCAPI::nagiosReturn code); 52 std::wstring to_string(NSCAPI::log_level::level level); 53 53 } 54 54 }; -
include/nscapi/nscapi_plugin_wrapper.cpp
rba63b95 r8013c0c 119 119 nscapi::functions::create_simple_submit_response(channel, command, ret, _T(""), response); 120 120 } catch (std::exception &e) { 121 nscapi::plugin_singleton->get_core()->log(NSCAPI:: error, __FILE__, __LINE__, utf8::cvt<std::wstring>("Failed to parse data from: " + strEx::strip_hex(request) + ": " + e.what()));121 nscapi::plugin_singleton->get_core()->log(NSCAPI::log_level::error, __FILE__, __LINE__, utf8::cvt<std::wstring>("Failed to parse data from: " + strEx::strip_hex(request) + ": " + e.what())); 122 122 } catch (...) { 123 nscapi::plugin_singleton->get_core()->log(NSCAPI:: error, __FILE__, __LINE__, utf8::cvt<std::wstring>("Failed to parse data from: " + strEx::strip_hex(request)));123 nscapi::plugin_singleton->get_core()->log(NSCAPI::log_level::error, __FILE__, __LINE__, utf8::cvt<std::wstring>("Failed to parse data from: " + strEx::strip_hex(request))); 124 124 } 125 125 return NSCAPI::returnIgnored; -
include/nscapi/settings_proxy.hpp
r40fca56 r8013c0c 52 52 53 53 virtual void err(std::string file, int line, std::wstring message) { 54 core_->log(NSCAPI:: error, file, line, message);54 core_->log(NSCAPI::log_level::error, file, line, message); 55 55 } 56 56 virtual void warn(std::string file, int line, std::wstring message) { 57 core_->log(NSCAPI:: warning, file, line, message);57 core_->log(NSCAPI::log_level::warning, file, line, message); 58 58 } 59 59 virtual void info(std::string file, int line, std::wstring message) { 60 core_->log(NSCAPI::log , file, line, message);60 core_->log(NSCAPI::log_level::log, file, line, message); 61 61 } 62 62 virtual void debug(std::string file, int line, std::wstring message) { 63 core_->log(NSCAPI:: debug, file, line, message);63 core_->log(NSCAPI::log_level::debug, file, line, message); 64 64 } 65 65 }; -
include/settings/client/settings_client.cpp
rf7a074d r8013c0c 11 11 } 12 12 */ 13 wstring_key_type*wstring_key(std::wstring *val, std::wstring def) {14 wstring_key_type* r = new wstring_key_type(val, def);13 boost::shared_ptr<wstring_key_type> wstring_key(std::wstring *val, std::wstring def) { 14 boost::shared_ptr<wstring_key_type> r(new wstring_key_type(val, def)); 15 15 return r; 16 16 } 17 wpath_key_type*wpath_key(std::wstring *val, std::wstring def) {18 wpath_key_type* r = new wpath_key_type(val, def);17 boost::shared_ptr<wpath_key_type> wpath_key(std::wstring *val, std::wstring def) { 18 boost::shared_ptr<wpath_key_type> r(new wpath_key_type(val, def)); 19 19 return r; 20 20 } 21 string_key_type*string_key(std::string *val, std::string def) {22 string_key_type* r = new string_key_type(val, def);21 boost::shared_ptr<string_key_type> string_key(std::string *val, std::string def) { 22 boost::shared_ptr<string_key_type> r(new string_key_type(val, def)); 23 23 return r; 24 24 } 25 int_key_type*int_key(int *val, int def) {26 int_key_type* r = new int_key_type(val, def);25 boost::shared_ptr<int_key_type> int_key(int *val, int def) { 26 boost::shared_ptr<int_key_type> r(new int_key_type(val, def)); 27 27 return r; 28 28 } 29 uint_key_type*uint_key(unsigned int *val, unsigned int def) {30 uint_key_type* r = new uint_key_type(val, def);29 boost::shared_ptr<uint_key_type> uint_key(unsigned int *val, unsigned int def) { 30 boost::shared_ptr<uint_key_type> r(new uint_key_type(val, def)); 31 31 return r; 32 32 } 33 boo l_key_type*bool_key(bool *val, bool def) {34 boo l_key_type* r = new bool_key_type(val, def);33 boost::shared_ptr<bool_key_type> bool_key(bool *val, bool def) { 34 boost::shared_ptr<bool_key_type> r(new bool_key_type(val, def)); 35 35 return r; 36 36 } 37 37 38 38 39 typed_path_fun*fun_path(boost::function<void (std::wstring)> fun) {40 typed_path_fun* r = new typed_path_fun(fun);39 boost::shared_ptr<typed_path_fun> fun_path(boost::function<void (std::wstring)> fun) { 40 boost::shared_ptr<typed_path_fun> r(new typed_path_fun(fun)); 41 41 return r; 42 42 } 43 typed_path_fun_value*fun_values_path(boost::function<void (std::wstring,std::wstring)> fun) {44 typed_path_fun_value* r = new typed_path_fun_value(fun);43 boost::shared_ptr<typed_path_fun_value> fun_values_path(boost::function<void (std::wstring,std::wstring)> fun) { 44 boost::shared_ptr<typed_path_fun_value> r(new typed_path_fun_value(fun)); 45 45 return r; 46 46 } 47 typed_path_map<>*wstring_map_path(std::map<std::wstring,std::wstring> *val) {48 typed_path_map<>* r = new typed_path_map<>(val);47 boost::shared_ptr<typed_path_map<> > wstring_map_path(std::map<std::wstring,std::wstring> *val) { 48 boost::shared_ptr<typed_path_map<> > r(new typed_path_map<>(val)); 49 49 return r; 50 50 } 51 typed_path_list*wstring_list_path(std::list<std::wstring> *val) {52 typed_path_list* r = new typed_path_list(val);51 boost::shared_ptr<typed_path_list> wstring_list_path(std::list<std::wstring> *val) { 52 boost::shared_ptr<typed_path_list> r(new typed_path_list(val)); 53 53 return r; 54 54 } -
include/settings/client/settings_client.hpp
rf7a074d r8013c0c 167 167 168 168 template<typename T> 169 typed_key_entry_in_vector<std::wstring, T, typed_string_value<std::wstring> >*wstring_vector_key(T *val, typename T::key_type key, std::wstring def) {170 typed_key_entry_in_vector<std::wstring, T, typed_string_value<std::wstring> >* r = new typed_key_entry_in_vector<std::wstring, T, typed_string_value<std::wstring> >(val, key, def);169 boost::shared_ptr<typed_key_entry_in_vector<std::wstring, T, typed_string_value<std::wstring> > > wstring_vector_key(T *val, typename T::key_type key, std::wstring def) { 170 boost::shared_ptr<typed_key_entry_in_vector<std::wstring, T, typed_string_value<std::wstring> > > r(new typed_key_entry_in_vector<std::wstring, T, typed_string_value<std::wstring> >(val, key, def)); 171 171 return r; 172 172 } … … 183 183 typed_key_entry_in_vector<std::wstring, T, typed_string_value<std::wstring> >* wstring_vector_key(T *val, typename T::key_type key, std::wstring def); 184 184 */ 185 wstring_key_type*wstring_key(std::wstring *val, std::wstring def = _T(""));186 string_key_type*string_key(std::string *val, std::string def = "");187 int_key_type*int_key(int *val, int def = 0);188 uint_key_type*uint_key(unsigned int *val, unsigned int def = 0);189 boo l_key_type*bool_key(bool *val, bool def = false);190 wpath_key_type*wpath_key(std::wstring *val, std::wstring def = _T(""));191 192 template<class T> 193 typed_key_fun<T, typed_int_value<T> >*int_fun_key(boost::function<void (T)> fun, T def) {194 typed_key_fun<T, typed_int_value<T> >* r = new typed_key_fun<T, typed_int_value<T> >(fun, def);185 boost::shared_ptr<wstring_key_type> wstring_key(std::wstring *val, std::wstring def = _T("")); 186 boost::shared_ptr<string_key_type> string_key(std::string *val, std::string def = ""); 187 boost::shared_ptr<int_key_type> int_key(int *val, int def = 0); 188 boost::shared_ptr<uint_key_type> uint_key(unsigned int *val, unsigned int def = 0); 189 boost::shared_ptr<bool_key_type> bool_key(bool *val, bool def = false); 190 boost::shared_ptr<wpath_key_type> wpath_key(std::wstring *val, std::wstring def = _T("")); 191 192 template<class T> 193 boost::shared_ptr<typed_key_fun<T, typed_int_value<T> > > int_fun_key(boost::function<void (T)> fun, T def) { 194 boost::shared_ptr<typed_key_fun<T, typed_int_value<T> > > r(new typed_key_fun<T, typed_int_value<T> >(fun, def)); 195 195 return r; 196 196 } 197 197 template<class T> 198 typed_key_fun<T, typed_bool_value<T> >*bool_fun_key(boost::function<void (T)> fun, T def) {199 typed_key_fun<T, typed_bool_value<T> >* r = new typed_key_fun<T, typed_bool_value<T> >(fun, def);198 boost::shared_ptr<typed_key_fun<T, typed_bool_value<T> > > bool_fun_key(boost::function<void (T)> fun, T def) { 199 boost::shared_ptr<typed_key_fun<T, typed_bool_value<T> > > r(new typed_key_fun<T, typed_bool_value<T> >(fun, def)); 200 200 return r; 201 201 } 202 202 template<class T> 203 typed_key_fun<T, typed_string_value<T> >*string_fun_key(boost::function<void (T)> fun, T def) {204 typed_key_fun<T, typed_string_value<T> >* r = new typed_key_fun<T, typed_string_value<T> >(fun, def);203 boost::shared_ptr<typed_key_fun<T, typed_string_value<T> > > string_fun_key(boost::function<void (T)> fun, T def) { 204 boost::shared_ptr<typed_key_fun<T, typed_string_value<T> > > r(new typed_key_fun<T, typed_string_value<T> >(fun, def)); 205 205 return r; 206 206 } … … 285 285 286 286 287 typed_path_fun*fun_path(boost::function<void (std::wstring)> fun);288 typed_path_fun_value*fun_values_path(boost::function<void (std::wstring,std::wstring)> fun);289 typed_path_map<>*wstring_map_path(std::map<std::wstring,std::wstring> *val);290 typed_path_list*wstring_list_path(std::list<std::wstring> *val);287 boost::shared_ptr<typed_path_fun> fun_path(boost::function<void (std::wstring)> fun); 288 boost::shared_ptr<typed_path_fun_value> fun_values_path(boost::function<void (std::wstring,std::wstring)> fun); 289 boost::shared_ptr<typed_path_map<> > wstring_map_path(std::map<std::wstring,std::wstring> *val); 290 boost::shared_ptr<typed_path_list> wstring_list_path(std::list<std::wstring> *val); 291 291 292 292 struct description_container { … … 328 328 description_container description; 329 329 330 key_info(std::wstring path_, std::wstring key_name_, key_interface*key, description_container description_)330 key_info(std::wstring path_, std::wstring key_name_, boost::shared_ptr<key_interface> key, description_container description_) 331 331 : path(path_) 332 332 , key_name(key_name_) … … 359 359 360 360 path_info(std::wstring path_name, description_container description_) : path_name(path_name), description(description_) {} 361 path_info(std::wstring path_name, path_interface*path, description_container description_) : path_name(path_name), path(path), description(description_) {}361 path_info(std::wstring path_name, boost::shared_ptr<path_interface> path, description_container description_) : path_name(path_name), path(path), description(description_) {} 362 362 363 363 path_info(const path_info& obj) : path_name(obj.path_name), description(obj.description), path(obj.path) {} … … 377 377 settings_paths_easy_init(std::wstring path, settings_registry* owner) : path_(path), owner(owner) {} 378 378 379 settings_paths_easy_init& operator()( path_interface *value, std::wstring title, std::wstring description) {379 settings_paths_easy_init& operator()(boost::shared_ptr<path_interface> value, std::wstring title, std::wstring description) { 380 380 boost::shared_ptr<path_info> d(new path_info(path_, value, description_container(title, description))); 381 381 add(d); … … 394 394 return *this; 395 395 } 396 settings_paths_easy_init& operator()(std::wstring path, path_interface *value, std::wstring title, std::wstring description) {396 settings_paths_easy_init& operator()(std::wstring path, boost::shared_ptr<path_interface> value, std::wstring title, std::wstring description) { 397 397 if (!path_.empty()) 398 398 path = path_ + _T("/") + path; … … 415 415 settings_keys_easy_init(std::wstring path, std::wstring parent, settings_registry* owner_) : owner(owner_), path_(path), parent_(parent) {} 416 416 417 settings_keys_easy_init& operator()(std::wstring path, std::wstring key_name, key_interface *value, std::wstring title, std::wstring description) {417 settings_keys_easy_init& operator()(std::wstring path, std::wstring key_name, boost::shared_ptr<key_interface> value, std::wstring title, std::wstring description) { 418 418 boost::shared_ptr<key_info> d(new key_info(path, key_name, value, description_container(title, description))); 419 419 if (!parent_.empty()) … … 423 423 } 424 424 425 settings_keys_easy_init& operator()(std::wstring key_name, key_interface*value, std::wstring title, std::wstring description) {425 settings_keys_easy_init& operator()(std::wstring key_name, boost::shared_ptr<key_interface> value, std::wstring title, std::wstring description) { 426 426 boost::shared_ptr<key_info> d(new key_info(path_, key_name, value, description_container(title, description))); 427 427 if (!parent_.empty()) -
include/settings/settings_core.hpp
rfb7e36a r8013c0c 36 36 37 37 38 class settings_exception {39 std:: wstring error_;38 class settings_exception : std::exception { 39 std::string error_; 40 40 public: 41 41 ////////////////////////////////////////////////////////////////////////// … … 44 44 /// 45 45 /// @author mickem 46 settings_exception(std::wstring error) : error_(error) {} 46 settings_exception(std::wstring error) : error_(utf8::cvt<std::string>(error)) {} 47 settings_exception(std::string error) : error_(utf8::cvt<std::string>(error)) {} 48 ~settings_exception() throw() {} 47 49 48 50 ////////////////////////////////////////////////////////////////////////// … … 51 53 /// 52 54 /// @author mickem 53 std::wstring getError() const { return error_; } 54 std::wstring getMessage() const { return error_; } 55 std::wstring getError() const { return wwhat(); } 56 std::wstring getMessage() const { return wwhat(); } 57 const char* what() const throw() { 58 return error_.c_str(); 59 } 60 const std::wstring wwhat() const throw() { 61 return utf8::to_unicode(error_); 62 } 55 63 }; 56 64 class KeyNotFoundException : public settings_exception { -
modules/CheckNSCP/CheckNSCP.cpp
ra78a985 r8013c0c 76 76 } 77 77 void CheckNSCP::handleMessage(int msgType, const std::string file, int line, std::string message) { 78 if (msgType != NSCAPI::error||msgType != NSCAPI::critical)78 if (msgType > NSCAPI::log_level::error) 79 79 return; 80 80 std::string err = render(msgType, file, line, message); -
modules/CheckSystem/PDHCollector.cpp
r7ec3dd1 r8013c0c 123 123 { 124 124 ReadLock lock(&mutex_, true, 5000); 125 if (!lock.IsLocked()) 125 if (!lock.IsLocked()) { 126 126 NSC_LOG_ERROR(_T("Failed to get Mutex!")); 127 else {127 } else { 128 128 try { 129 129 pdh.gatherData(); … … 204 204 */ 205 205 void PDHCollector::exitThread(void) { 206 if (hStopEvent_ == NULL) 206 if (hStopEvent_ == NULL) { 207 207 NSC_LOG_ERROR(_T("Stop event is not created!")); 208 else if (!SetEvent(hStopEvent_)) {208 } else if (!SetEvent(hStopEvent_)) { 209 209 NSC_LOG_ERROR_STD(_T("SetStopEvent failed")); 210 210 } -
modules/DistributedServer/handler_impl.hpp
r40fca56 r8013c0c 36 36 37 37 void log_debug(std::string file, int line, std::wstring msg) { 38 GET_CORE()->log(NSCAPI::debug, file, line, msg); 38 if (GET_CORE()->should_log(NSCAPI::log_level::debug)) { 39 GET_CORE()->log(NSCAPI::log_level::debug, file, line, msg); 40 } 39 41 } 40 42 void log_error(std::string file, int line, std::wstring msg) { 41 GET_CORE()->log(NSCAPI::error, file, line, msg); 43 if (GET_CORE()->should_log(NSCAPI::log_level::error)) { 44 GET_CORE()->log(NSCAPI::log_level::error, file, line, msg); 45 } 42 46 } 43 47 }; -
modules/FileLogger/FileLogger.cpp
ra78a985 r8013c0c 166 166 init_ = true; 167 167 std::string hello = "Starting to log for: " + utf8::cvt<std::string>(GET_CORE()->getApplicationName()) + " - " + utf8::cvt<std::string>(GET_CORE()->getApplicationVersionString()); 168 handleMessage(NSCAPI::log , __FILE__, __LINE__, hello);169 handleMessage(NSCAPI::log , __FILE__, __LINE__, "Log path is: " + file_);168 handleMessage(NSCAPI::log_level::log, __FILE__, __LINE__, hello); 169 handleMessage(NSCAPI::log_level::log, __FILE__, __LINE__, "Log path is: " + file_); 170 170 return true; 171 171 } -
modules/LUAScript/script_wrapper.hpp
r40fca56 r8013c0c 261 261 } 262 262 static int info (lua_State *L) { 263 return log_any(L, NSCAPI::log );263 return log_any(L, NSCAPI::log_level::info); 264 264 } 265 265 static int error (lua_State *L) { 266 return log_any(L, NSCAPI:: error);266 return log_any(L, NSCAPI::log_level::error); 267 267 } 268 268 static int log_any(lua_State *L, int mode) { -
modules/NRPEServer/handler_impl.hpp
r40fca56 r8013c0c 39 39 40 40 void log_debug(std::string file, int line, std::wstring msg) { 41 GET_CORE()->log(NSCAPI::debug, file, line, msg); 41 if (GET_CORE()->should_log(NSCAPI::log_level::debug)) { 42 GET_CORE()->log(NSCAPI::log_level::debug, file, line, msg); 43 } 42 44 } 43 45 void log_error(std::string file, int line, std::wstring msg) { 44 GET_CORE()->log(NSCAPI::error, file, line, msg); 46 if (GET_CORE()->should_log(NSCAPI::log_level::error)) { 47 GET_CORE()->log(NSCAPI::log_level::error, file, line, msg); 48 } 45 49 } 46 50 }; -
modules/NSCAClient/NSCAClient.cpp
rba63b95 r8013c0c 125 125 if (hostname_ == "auto") { 126 126 hostname_ = boost::asio::ip::host_name(); 127 128 127 } 129 128 … … 134 133 nscapi::target_handler::optarget t = targets.find_target(_T("default")); 135 134 if (t) { 136 if (!t->has_option("encryption")) 137 t->options[_T("encryption")] = encryption; 138 if (!t->has_option("timeout")) 139 t->options[_T("timeout")] = strEx::itos(timeout); 140 if (!t->has_option("payload length")) 141 t->options[_T("payload length")] = strEx::itos(payload_length); 142 if (!t->has_option("time offset")) 143 t->options[_T("time offset")] = utf8::cvt<std::wstring>(delay); 144 if (!t->has_option("password")) 145 t->options[_T("password")] = password; 146 if (!t->address.empty()) 147 t->address = _T("nsca://") + nscahost + _T(":") + strEx::itos(nscaport); 148 targets.add(*t); 135 nscapi::target_handler::target target = *t; 136 if (!target.has_option("encryption")) 137 target.options[_T("encryption")] = encryption; 138 if (!target.has_option("timeout")) 139 target.options[_T("timeout")] = strEx::itos(timeout); 140 if (!target.has_option("payload length")) 141 target.options[_T("payload length")] = strEx::itos(payload_length); 142 if (!target.has_option("time offset")) 143 target.options[_T("time offset")] = utf8::cvt<std::wstring>(delay); 144 if (!target.has_option("password")) 145 target.options[_T("password")] = password; 146 if (target.address.empty()) 147 target.address = _T("nsca://") + nscahost + _T(":") + strEx::itos(nscaport); 148 targets.add(target); 149 149 } else { 150 150 NSC_LOG_ERROR(_T("Default target not found!")); … … 170 170 std::wstring name; 171 171 try { 172 nsca::nsca_encrypt::any_encryption *core = nsca::nsca_encrypt::get_encryption_core(i);172 boost::shared_ptr<nsca::nsca_encrypt::any_encryption> core(nsca::nsca_encrypt::get_encryption_core(i)); 173 173 if (core == NULL) 174 174 name = _T("Broken<NULL>"); … … 292 292 if (opt) { 293 293 nscapi::target_handler::target t = *opt; 294 url.host = t.host; 295 if (t.has_option("port")) { 296 try { 297 url.port = strEx::stoi(t.options[_T("port")]); 298 } catch (...) {} 294 if (t.address.empty()) { 295 if (t.host.empty()) 296 url.host = t.host; 297 if (t.has_option("port")) { 298 try { 299 url.port = strEx::stoi(t.options[_T("port")]); 300 } catch (...) {} 301 } 302 } else { 303 url = net::parse(t.address); 299 304 } 300 305 std::string keys[] = {"encryption", "timeout", "payload length", "password", "time offset"}; -
modules/NSCAServer/handler_impl.hpp
r40fca56 r8013c0c 54 54 55 55 void log_debug(std::string file, int line, std::wstring msg) { 56 GET_CORE()->log(NSCAPI::debug, file, line, msg); 56 if (GET_CORE()->should_log(NSCAPI::log_level::debug)) { 57 GET_CORE()->log(NSCAPI::log_level::debug, file, line, msg); 58 } 57 59 } 58 60 void log_error(std::string file, int line, std::wstring msg) { 59 GET_CORE()->log(NSCAPI::error, file, line, msg); 61 if (GET_CORE()->should_log(NSCAPI::log_level::error)) { 62 GET_CORE()->log(NSCAPI::log_level::error, file, line, msg); 63 } 60 64 } 61 65 }; -
modules/NSCPServer/handler_impl.hpp
r40fca56 r8013c0c 36 36 37 37 void log_debug(std::string file, int line, std::wstring msg) { 38 GET_CORE()->log(NSCAPI::debug, file, line, msg); 38 if (GET_CORE()->should_log(NSCAPI::log_level::debug)) { 39 GET_CORE()->log(NSCAPI::log_level::debug, file, line, msg); 40 } 39 41 } 40 42 void log_error(std::string file, int line, std::wstring msg) { 41 GET_CORE()->log(NSCAPI::error, file, line, msg); 43 if (GET_CORE()->should_log(NSCAPI::log_level::error)) { 44 GET_CORE()->log(NSCAPI::log_level::error, file, line, msg); 45 } 42 46 } 43 47 }; -
modules/NSClientServer/handler_impl.hpp
r40fca56 r8013c0c 31 31 32 32 void log_debug(std::string file, int line, std::wstring msg) { 33 GET_CORE()->log(NSCAPI::debug, file, line, msg); 33 if (GET_CORE()->should_log(NSCAPI::log_level::debug)) { 34 GET_CORE()->log(NSCAPI::log_level::debug, file, line, msg); 35 } 34 36 } 35 37 void log_error(std::string file, int line, std::wstring msg) { 36 GET_CORE()->log(NSCAPI::error, file, line, msg); 38 if (GET_CORE()->should_log(NSCAPI::log_level::error)) { 39 GET_CORE()->log(NSCAPI::log_level::error, file, line, msg); 40 } 37 41 } 38 42 -
modules/Scheduler/simple_scheduler.cpp
r9c06054 r8013c0c 67 67 log_error(_T("NOONE IS HANDLING scheduled item ") + to_wstring((*instance).schedule_id) + _T(" ") + to_wstring(off.total_seconds()) + _T(" seconds to late from thread ") + to_wstring(id)); 68 68 } 69 } else {70 log_error(_T("Nothing is scheduled to run"));69 // } else { 70 // log_error(_T("Nothing is scheduled to run")); 71 71 } 72 72 -
scripts/python/lib/test_helper.py
r441a022 r8013c0c 1 from NSCP import Settings, Registry, Core, log, log_ error, status1 from NSCP import Settings, Registry, Core, log, log_debug, log_error, status 2 2 import os 3 3 import inspect … … 33 33 global test_manager 34 34 if not test_manager: 35 log('=== Creating new Test manager ===')36 35 test_manager = TestManager(plugin_id, plugin_alias, script_alias) 37 36 … … 43 42 44 43 reg.simple_function('py_unittest', run_tests, 'Run python unit test suite') 45 else:46 log('=== Reusing existing testmanager ===')47 44 48 45 return test_manager … … 82 79 def setup_singleton(klass, src = None): 83 80 klass.getInstance = SingletonHelper(klass) 84 log('Setting path: %s'%src)85 81 if not src: 86 82 cf = inspect.currentframe() … … 90 86 src = bf.f_code.co_filename 91 87 klass.__source__ = src 92 log('==>%s'%src)93 88 94 89 class BasicTest(object): … … 118 113 conf = Settings.get() 119 114 conf.set_string('/modules', 'pytest', 'PythonScript') 120 log('==> %s'%self.__source__)121 115 fn = os.path.basename(self.__source__) 122 116 (sn, ext) = os.path.splitext(fn) … … 152 146 def log(self, prefix = '', indent = 0): 153 147 if self.status: 154 log ('%s%s%s'%(prefix, ''.rjust(indent, ' '), self))148 log_debug('%s%s%s'%(prefix, ''.rjust(indent, ' '), self)) 155 149 else: 156 150 log_error('%s%s%s'%(prefix, ''.rjust(indent, ' '), self)) … … 189 183 start = '%s%s'%(prefix, ''.rjust(indent, ' ')) 190 184 if self.status: 191 log ('%s%s'%(start, self))185 log_debug('%s%s'%(start, self)) 192 186 else: 193 187 log_error('%s%s'%(start, self)) … … 199 193 200 194 def count(self): 201 total_count = 1195 total_count = 0 202 196 ok_count = 0 203 if self.status:204 ok_count = 1197 #if self.status: 198 # ok_count = 1 205 199 206 200 for c in self.children: … … 278 272 def return_nagios(self): 279 273 (total, ok) = self.count() 280 log (' | Test result log (only summary will be returned to query)')274 log_debug(' | Test result log (only summary will be returned to query)') 281 275 self.log(' | ') 282 276 if total == ok: -
service/CMakeLists.txt
r7515d00 r8013c0c 102 102 # SET_TARGET_PROPERTIES(${TARGET} PROPERTIES LINK_FLAGS "/MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\" /SUBSYSTEM:WINDOWS") 103 103 #ENDIF(WIN32) 104 #INSTALL(TARGETS ${TARGET} RUNTIME DESTINATION .) 105 106 #INSTALL(CODE "SET(PDB_FULL_PATH ${BUILD_TARGET_EXE_PATH}/${TARGET}.pdb)") 107 #INSTALL(CODE "FILE(INSTALL DESTINATION \${CMAKE_INSTALL_PREFIX} TYPE EXECUTABLE FILES \${PDB_FULL_PATH})") 104 INSTALL(TARGETS ${TARGET} RUNTIME DESTINATION .) 105 INSTALL(CODE "SET(PDB_FULL_PATH ${BUILD_TARGET_EXE_PATH}/${TARGET}.pdb)") 106 INSTALL(CODE "FILE(INSTALL DESTINATION \${CMAKE_INSTALL_PREFIX} TYPE EXECUTABLE FILES \${PDB_FULL_PATH})") 108 107 109 108 SOURCE_GROUP("NSCP API" REGULAR_EXPRESSION .*include/nscapi/.*) -
service/NSClient++.cpp
r441a022 r8013c0c 73 73 } 74 74 75 #define LOG_CRITICAL_CORE(msg) { std::string s = nsclient::logger_helper::create_error(__FILE__, __LINE__, msg); mainClient.reportMessage(s); }75 #define LOG_CRITICAL_CORE(msg) if (mainClient.should_log(NSCAPI::log_level::critical)) { std::string s = nsclient::logger_helper::create_error(__FILE__, __LINE__, msg); mainClient.reportMessage(s); } 76 76 #define LOG_CRITICAL_CORE_STD(msg) LOG_CRITICAL_CORE(std::wstring(msg)) 77 #define LOG_ERROR_CORE(msg) { std::string s = nsclient::logger_helper::create_error(__FILE__, __LINE__, msg); mainClient.reportMessage(s); }77 #define LOG_ERROR_CORE(msg) if (mainClient.should_log(NSCAPI::log_level::error)) { std::string s = nsclient::logger_helper::create_error(__FILE__, __LINE__, msg); mainClient.reportMessage(s); } 78 78 #define LOG_ERROR_CORE_STD(msg) LOG_ERROR_CORE(std::wstring(msg)) 79 #define LOG_INFO_CORE(msg) { std::string s = nsclient::logger_helper::create_info(__FILE__, __LINE__, msg); mainClient.reportMessage(s); }79 #define LOG_INFO_CORE(msg) if (mainClient.should_log(NSCAPI::log_level::info)) { std::string s = nsclient::logger_helper::create_info(__FILE__, __LINE__, msg); mainClient.reportMessage(s); } 80 80 #define LOG_INFO_CORE_STD(msg) LOG_INFO_CORE(std::wstring(msg)) 81 #define LOG_DEBUG_CORE(msg) { if (mainClient.logDebug()) { std::string s = nsclient::logger_helper::create_debug(__FILE__, __LINE__, msg); mainClient.reportMessage(s); }}81 #define LOG_DEBUG_CORE(msg) if (mainClient.should_log(NSCAPI::log_level::debug)) { std::string s = nsclient::logger_helper::create_debug(__FILE__, __LINE__, msg); mainClient.reportMessage(s); } 82 82 #define LOG_DEBUG_CORE_STD(msg) LOG_DEBUG_CORE(std::wstring(msg)) 83 #define LOG_TRACE_CORE(msg) if (mainClient.should_log(NSCAPI::log_level::trace)) { std::string s = nsclient::logger_helper::create_debug(__FILE__, __LINE__, msg); mainClient.reportMessage(s); } 84 #define LOG_TRACE_CORE_STD(msg) LOG_DEBUG_CORE(std::wstring(msg)) 83 85 84 86 /** … … 1111 1113 NSCAPI::nagiosReturn NSClientT::injectRAW(const wchar_t* raw_command, std::string &request, std::string &response) { 1112 1114 std::wstring cmd = nsclient::commands::make_key(raw_command); 1113 if (logDebug()) { 1114 LOG_DEBUG_CORE_STD(_T("Injecting: ") + cmd + _T("...")); 1115 } 1115 LOG_DEBUG_CORE_STD(_T("Injecting: ") + cmd + _T("...")); 1116 1116 /*if (shared_client_.get() != NULL && shared_client_->hasMaster()) { 1117 1117 try { … … 1431 1431 } 1432 1432 1433 bool NSClientT::logDebug() {1434 if ( debug_ == log_state_unknown) {1435 debug_ = log_state_looking;1433 NSCAPI::log_level::level NSClientT::get_loglevel() { 1434 if (log_status_ == log_state_unknown) { 1435 log_status_ = log_state_looking; 1436 1436 try { 1437 if (settings_manager::get_settings_no_wait()->get_bool(_T("log"), _T("debug"), false) == 1) 1438 debug_ = log_state_debug; 1439 else 1440 debug_ = log_state_nodebug; 1437 if (settings_manager::get_settings_no_wait()->get_bool(_T("log"), _T("debug"), false) == 1) { 1438 log_level_ = nscapi::logging::parse(_T("debug")); 1439 log_status_ = log_state_set; 1440 } else { 1441 std::wstring level = settings_manager::get_settings_no_wait()->get_string(_T("log"), _T("level"), _T("service")); 1442 log_level_ = nscapi::logging::parse(level); 1443 log_status_ = log_state_set; 1444 } 1441 1445 } catch (settings::settings_exception e) { 1442 debug_ = log_state_unknown; 1443 return false; 1444 } 1445 } else if (debug_ == log_state_looking) 1446 return false; 1447 return (debug_ == log_state_debug); 1446 log_status_ = log_state_unknown; 1447 } 1448 } 1449 return log_level_; 1450 } 1451 1452 bool NSClientT::should_log(NSCAPI::nagiosReturn level) { 1453 return nscapi::logging::matches(get_loglevel(), level); 1454 } 1455 void NSClientT::set_loglevel(std::wstring level) { 1456 log_status_ = log_state_set; 1457 NSCAPI::log_level::level new_log_level = nscapi::logging::parse(level); 1458 if (new_log_level != log_level_) { 1459 //update_log_level() TODO 1460 log_level_ = new_log_level; 1461 } 1448 1462 } 1449 1463 -
service/NSClient++.h
r89838be r8013c0c 24 24 #include <com_helpers.hpp> 25 25 #endif 26 26 27 27 28 #include <types.hpp> … … 97 98 //boost::shared_mutex m_mutexRWcmdDescriptions; 98 99 //cmdMap cmdDescriptions_; 99 enum log_status {log_state_unknown, log_state_looking, log_state_debug, log_state_nodebug }; 100 log_status debug_; 100 enum log_status {log_state_unknown, log_state_looking, log_state_set }; 101 log_status log_status_; 102 NSCAPI::log_level::level log_level_; 101 103 std::wstring context_; 102 104 #ifdef WIN32 … … 119 121 typedef std::multimap<std::wstring,std::wstring> plugin_alias_list_type; 120 122 // c-tor, d-tor 121 NSClientT(void) : debug_(log_state_unknown), enable_shared_session_(false), commands_(this), channels_(this), routers_(this), next_plugin_id_(0), service_name_(DEFAULT_SERVICE_NAME) {123 NSClientT(void) : log_status_(log_state_unknown), log_level_(NSCAPI::log_level::log), enable_shared_session_(false), commands_(this), channels_(this), routers_(this), next_plugin_id_(0), service_name_(DEFAULT_SERVICE_NAME) { 122 124 logger_master_.start_slave(); 123 125 } 124 126 virtual ~NSClientT(void) {} 125 void enableDebug(bool debug = true) { 126 if (debug) 127 debug_ = log_state_debug; 128 else 129 debug_ = log_state_nodebug; 130 } 127 NSCAPI::log_level::level get_loglevel(); 128 void set_loglevel(std::wstring level); 131 129 132 130 // Service helper functions … … 213 211 void startTrayIcon(DWORD dwSessionId); 214 212 215 bool logDebug();213 bool should_log(NSCAPI::nagiosReturn level); 216 214 void listPlugins(); 217 215 plugin_info_list get_all_plugins(); -
service/cli_parser.hpp
r441a022 r8013c0c 15 15 po::options_description common; 16 16 17 bool debug;18 17 bool help; 19 18 bool version; 19 std::wstring log_level; 20 std::wstring settings_store; 20 21 21 22 public: … … 27 28 , service("Service Options") 28 29 , client("Client Options") 29 , debug(false)30 30 , help(false) 31 31 , version(false) … … 37 37 ("client-help", "Produce help message for the various settings related client") 38 38 ("test-help", "Produce help message for the various settings related client") 39 39 /* 40 40 ("settings", "Enter settings mode and handle settings related commands") 41 41 ("service", "Enter service mode and handle service related commands") 42 42 ("client", "Enter client mode and handle client related commands") 43 43 ("test", "Start test and debug mode") 44 */ 44 45 ("version", po::bool_switch(&version), "Show version information") 45 46 ; 46 47 common.add_options() 48 ("settings", po::value<std::wstring>(&settings_store), "Override (temporarily) settings subsystem to use") 47 49 ("help", po::bool_switch(&help), "produce help message") 48 ("debug", po::bool_switch(&debug), "Show debug information") 50 ("debug", "Set log level to debug (and show debug information)") 51 ("log", po::value<std::wstring>(&log_level), "The log level to use") 49 52 ("version", po::bool_switch(&version), "Show version information") 50 53 ; 51 54 52 55 settings.add_options() 53 ("settings", po::value<std::wstring>(), "Override (temporarily) settings subsystem to use")54 56 ("migrate-to", po::value<std::wstring>(), "Migrate (copy) settings from current store to target store") 55 57 ("migrate-from", po::value<std::wstring>(), "Migrate (copy) settings from current store to target store") … … 80 82 ("query,q", po::value<std::wstring>(), "Run a query with a given name") 81 83 ("submit,s", po::value<std::wstring>(), "Name of query to ask") 82 ("settings", po::value<std::wstring>(), "Override (temporarily) settings subsystem to use")83 84 ("module,M", po::value<std::wstring>(), "Name of module to load (if not specified all modules in ini file will be loaded)") 84 85 ("argument,a", po::wvalue<std::vector<std::wstring> >(), "List of arguments (gets -- prefixed automatically)") … … 90 91 bool process_common_options(std::string context, po::options_description &desc) { 91 92 core_->set_console_log(); 92 if ( debug) {93 core_-> enableDebug(true);94 core_->log_debug(__FILE__, __LINE__, _T("Enabling debug mode"));95 }93 if (!log_level.empty()) 94 core_->set_loglevel(log_level); 95 if (!settings_store.empty()) 96 core_->set_settings_context(settings_store); 96 97 97 98 if (help) { … … 184 185 185 186 core_->set_console_log(); 186 core_->enableDebug(true); 187 188 // if (argc > 2 && wcscasecmp( _T("server"), argv[2] ) == 0 ) { 189 // server = true; 190 // } 191 // std::wcout << "Launching test mode - " << (server?_T("server mode"):_T("client mode")) << std::endl; 192 // LOG_MESSAGE_STD(_T("Booting: ") SZSERVICEDISPLAYNAME ); 193 nsclient::simple_client client(core_); 194 client.start(); 195 return 0; 187 core_->set_loglevel(_T("debug")); 188 189 190 try { 191 po::options_description all("Allowed options (settings)"); 192 all.add(common).add(settings); 193 194 po::variables_map vm; 195 po::store(po::parse_command_line(argc, argv, all), vm); 196 po::notify(vm); 197 198 if (process_common_options("settings", all)) 199 return 1; 200 201 nsclient::simple_client client(core_); 202 client.start(); 203 return 0; 204 } catch(std::exception & e) { 205 mainClient.log_error(__FILE__, __LINE__, std::string("Unable to parse command line (settings): ") + e.what()); 206 return 1; 207 } 196 208 } 197 209 … … 287 299 mainClient.log_info(__FILE__, __LINE__, _T("TODO retrieve name from service here")); 288 300 } 289 if ( debug) {301 if (mainClient.should_log(NSCAPI::log_level::debug)) { 290 302 mainClient.log_info(__FILE__, __LINE__, _T("Service name: ") + name); 291 303 mainClient.log_info(__FILE__, __LINE__, _T("Service description: ") + desc); … … 294 306 if (vm.count("run")) { 295 307 try { 296 mainClient.enableDebug(true);297 308 mainClient.start_and_wait(name); 298 309 } catch (...) { … … 395 406 } 396 407 397 if ( debug) {408 if (mainClient.should_log(NSCAPI::log_level::debug)) { 398 409 mainClient.log_info(__FILE__, __LINE__, _T("Module: ") + module); 399 410 mainClient.log_info(__FILE__, __LINE__, _T("Command: ") + command); … … 407 418 mainClient.log_info(__FILE__, __LINE__, _T("Arguments: ") + args); 408 419 } 409 if (vm.count("settings"))410 core_->set_settings_context(vm["settings"].as<std::wstring>());411 420 412 421 core_->boot_init(); … … 453 462 } 454 463 return ret; 455 } catch( std::exception & e) {464 } catch(const std::exception & e) { 456 465 std::wcerr << _T("Client: Unable to parse command line: ") << utf8::to_unicode(e.what()) << std::endl; 457 466 return 1; -
service/core_api.cpp
r40fca56 r8013c0c 169 169 170 170 NSCAPI::boolReturn NSAPICheckLogMessages(int messageType) { 171 if (mainClient.logDebug()) 172 return NSCAPI::istrue; 173 return NSCAPI::isfalse; 171 return mainClient.should_log(messageType); 174 172 } 175 173 … … 513 511 if (wcscasecmp(buffer, _T("NSAPIReload")) == 0) 514 512 return reinterpret_cast<LPVOID>(&NSAPIReload); 513 if (wcscasecmp(buffer, _T("NSAPIGetLoglevel")) == 0) 514 return reinterpret_cast<LPVOID>(&NSAPIGetLoglevel); 515 515 516 516 LOG_ERROR_STD(_T("Function not found: ") + buffer); … … 541 541 delete [] *buffer; 542 542 } 543 544 NSCAPI::log_level::level NSAPIGetLoglevel() { 545 return mainClient.get_loglevel(); 546 } -
service/core_api.h
rf7a074d r8013c0c 67 67 NSCAPI::errorReturn NSAPIRegisterRoutingListener(unsigned int plugin_id, const wchar_t* channel); 68 68 NSCAPI::errorReturn NSAPIReload(const wchar_t*); 69 NSCAPI::log_level::level NSAPIGetLoglevel(); -
service/logger.hpp
r330af36 r8013c0c 151 151 int code = nscapi::functions::gpb_to_log(l); 152 152 switch (code) { 153 case NSCAPI:: critical:153 case NSCAPI::log_level::critical: 154 154 return _T("c"); 155 case NSCAPI:: warning:155 case NSCAPI::log_level::warning: 156 156 return _T("w"); 157 case NSCAPI:: error:157 case NSCAPI::log_level::error: 158 158 return _T("e"); 159 case NSCAPI::log :159 case NSCAPI::log_level::log: 160 160 return _T("l"); 161 case NSCAPI:: debug:161 case NSCAPI::log_level::debug: 162 162 return _T("d"); 163 163 default: -
service/settings_logger_impl.cpp
r58f0e80 r8013c0c 11 11 /// @author mickem 12 12 void settings_logger::err(std::string file, int line, std::wstring message) { 13 if (!mainClient.should_log(NSCAPI::log_level::error)) 14 return; 13 15 std::string s = nsclient::logger_helper::create_error(file.c_str(), line, message.c_str()); 14 16 mainClient.reportMessage(s); … … 23 25 /// @author mickem 24 26 void settings_logger::warn(std::string file, int line, std::wstring message) { 27 if (!mainClient.should_log(NSCAPI::log_level::warning)) 28 return; 25 29 std::string s = nsclient::logger_helper::create_warning(file.c_str(), line, message.c_str()); 26 30 mainClient.reportMessage(s); … … 35 39 /// @author mickem 36 40 void settings_logger::info(std::string file, int line, std::wstring message) { 41 if (!mainClient.should_log(NSCAPI::log_level::info)) 42 return; 37 43 std::string s = nsclient::logger_helper::create_info(file.c_str(), line, message.c_str()); 38 44 mainClient.reportMessage(s); … … 47 53 /// @author mickem 48 54 void settings_logger::debug(std::string file, int line, std::wstring message) { 49 if (!mainClient. logDebug())55 if (!mainClient.should_log(NSCAPI::log_level::debug)) 50 56 return; 51 57 std::string s = nsclient::logger_helper::create_debug(file.c_str(), line, message.c_str()); -
service/simple_client.hpp
r89838be r8013c0c 14 14 } 15 15 void start() { 16 core_->enableDebug(true);17 16 if (!core_->boot_init()) { 18 17 core_->log_error(__FILE__, __LINE__, _T("Service failed to init")); … … 58 57 for (std::list<std::wstring>::const_iterator cit = lst.begin(); cit!=lst.end();++cit) 59 58 log(_T("| ") + *cit + _T(": ") + core_->describeCommand(*cit)); 60 } else if (s == _T("debug off")) { 61 log(_T("Setting debug log off...")); 62 core_->enableDebug(false); 63 } else if (s == _T("debug on")) { 64 log(_T("Setting debug log on...")); 65 core_->enableDebug(true); 59 } else if (s.size() > 4 && s.substr(0,3) == _T("log")) { 60 log(_T("Setting log to: ") + s.substr(4)); 61 core_->set_loglevel(s.substr(4)); 66 62 } else if (s == _T("reattach")) { 67 63 log(_T("Reattaching to session 0")); -
version.hpp
rf19371a r8013c0c 1 1 #ifndef VERSION_HPP 2 2 #define VERSION_HPP 3 #define PRODUCTVER 0,4,0,12 64 #define STRPRODUCTVER "0,4,0,12 6"5 #define STRPRODUCTDATE "2012-01-2 0"3 #define PRODUCTVER 0,4,0,129 4 #define STRPRODUCTVER "0,4,0,129" 5 #define STRPRODUCTDATE "2012-01-21" 6 6 #endif // VERSION_HPP -
version.txt
rf19371a r8013c0c 1 1 version=0.4.0 2 build=12 63 date=2012-01-2 02 build=129 3 date=2012-01-21
Note: See TracChangeset
for help on using the changeset viewer.








