Changeset 1bfe6f0 in nscp for include/NSCHelper.cpp
- Timestamp:
- 01/17/10 12:29:46 (3 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- 6822839
- Parents:
- cc2efd6
- File:
-
- 1 edited
-
include/NSCHelper.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
include/NSCHelper.cpp
r79e734f r1bfe6f0 83 83 84 84 85 #define REPORT_ERROR 0x01 86 #define REPORT_WARNING 0x02 87 #define REPORT_UNKNOWN 0x04 88 #define REPORT_OK 0x08 89 90 unsigned int NSCHelper::report::parse(std::wstring str) { 91 unsigned int report = 0; 92 strEx::splitList lst = strEx::splitEx(str, _T(",")); 93 for (strEx::splitList::const_iterator key = lst.begin(); key != lst.end(); ++key) { 94 if (*key == _T("all")) { 95 report |= REPORT_ERROR|REPORT_OK|REPORT_UNKNOWN|REPORT_WARNING; 96 } else if (*key == _T("error") || *key == _T("err") || *key == _T("critical") || *key == _T("crit")) { 97 report |= REPORT_ERROR; 98 } else if (*key == _T("warning") || *key == _T("warn")) { 99 report |= REPORT_WARNING; 100 } else if (*key == _T("unknown")) { 101 report |= REPORT_UNKNOWN; 102 } else if (*key == _T("ok")) { 103 report |= REPORT_OK; 104 } 105 } 106 return report; 107 } 108 bool NSCHelper::report::matches(unsigned int report, NSCAPI::nagiosReturn code) { 109 return ( 110 (code == NSCAPI::returnOK && (report&REPORT_OK)==REPORT_OK) || 111 (code == NSCAPI::returnCRIT && ((report&REPORT_ERROR)==REPORT_ERROR) ) || 112 (code == NSCAPI::returnWARN && ((report&REPORT_WARNING)==REPORT_WARNING) ) || 113 (code == NSCAPI::returnUNKNOWN && ((report&REPORT_UNKNOWN)==REPORT_UNKNOWN) ) || 114 ( (code != NSCAPI::returnOK) && (code != NSCAPI::returnCRIT) && (code != NSCAPI::returnWARN) && (code != NSCAPI::returnUNKNOWN) ) 115 ); 116 } 117 std::wstring NSCHelper::report::to_string(unsigned int report) { 118 std::wstring ret; 119 if ((report&REPORT_OK)!=0) { 120 if (!ret.empty()) ret += _T(","); 121 ret += _T("ok"); 122 } 123 if ((report&REPORT_WARNING)!=0) { 124 if (!ret.empty()) ret += _T(","); 125 ret += _T("warning"); 126 } 127 if ((report&REPORT_ERROR)!=0) { 128 if (!ret.empty()) ret += _T(","); 129 ret += _T("critical"); 130 } 131 if ((report&REPORT_UNKNOWN)!=0) { 132 if (!ret.empty()) ret += _T(","); 133 ret += _T("unknown"); 134 } 135 return ret; 136 } 137 138 85 139 /** 86 140 * Translate a message type into a human readable string. … … 151 205 lpNSAPIExit fNSAPIExit = NULL; 152 206 lpNSAPIInject fNSAPIInject = NULL; 207 lpNSAPINotify fNSAPINotify = NULL; 153 208 lpNSAPICheckLogMessages fNSAPICheckLogMessages = NULL; 154 209 lpNSAPIEncrypt fNSAPIEncrypt = NULL; … … 225 280 return fNSAPIInject(command, argLen, argument, returnMessageBuffer, returnMessageBufferLen, returnPerfBuffer, returnPerfBufferLen); 226 281 } 282 283 NSCAPI::errorReturn NSCModuleHelper::NotifyChannel(std::wstring channel, std::wstring command, NSCAPI::nagiosReturn code, std::wstring message, std::wstring perf) { 284 if (!fNSAPINotify) 285 throw NSCMHExcpetion(_T("NSCore has not been initiated...")); 286 return fNSAPINotify(channel.c_str(), command.c_str(), code, message.c_str(), perf.c_str()); 287 } 288 227 289 /** 228 290 * Inject a request command in the core (this will then be sent to the plug-in stack for processing) … … 734 796 //NSCModuleHelper::fNSAPIExit = (NSCModuleHelper::lpNSAPIExit)f(_T("NSAPIExit")); 735 797 NSCModuleHelper::fNSAPIInject = (NSCModuleHelper::lpNSAPIInject)f(_T("NSAPIInject")); 798 NSCModuleHelper::fNSAPINotify = (NSCModuleHelper::lpNSAPINotify)f(_T("NSAPINotify")); 736 799 NSCModuleHelper::fNSAPIGetBasePath = (NSCModuleHelper::lpNSAPIGetBasePath)f(_T("NSAPIGetBasePath")); 737 800 NSCModuleHelper::fNSAPICheckLogMessages = (NSCModuleHelper::lpNSAPICheckLogMessages)f(_T("NSAPICheckLogMessages"));
Note: See TracChangeset
for help on using the changeset viewer.








