Changeset bf6e9b4 in nscp
- Timestamp:
- 02/02/08 13:54:12 (5 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- 52215d7
- Parents:
- 5ac88c0a
- Files:
-
- 4 edited
-
AutoBuild.h (modified) (1 diff)
-
changelog (modified) (3 diffs)
-
include/error.hpp (modified) (2 diffs)
-
modules/CheckEventLog/CheckEventLog.cpp (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
AutoBuild.h
r3f69109 rbf6e9b4 3 3 // change the FALSE to TRUE for autoincrement of build number 4 4 #define INCREMENT_VERSION TRUE 5 #define FILEVER 0,3,0, 126 #define PRODUCTVER 0,3,0, 127 #define STRFILEVER _T("0.3.0. 12")8 #define STRPRODUCTVER _T("0.3.0. 12")9 #define STRPRODUCTDATE _T("200 7-12-11")5 #define FILEVER 0,3,0,24 6 #define PRODUCTVER 0,3,0,24 7 #define STRFILEVER _T("0.3.0.24") 8 #define STRPRODUCTVER _T("0.3.0.24") 9 #define STRPRODUCTDATE _T("2008-02-02") 10 10 #endif // AUTOBUILD_H -
changelog
r5ac88c0a rbf6e9b4 6 6 * Add API for rehashing the daemon (or implement it the API is there but does nothing) 7 7 8 2008-02-02 MickeM 9 * Might have fixed the "missing eventlog messages" problem. 10 8 11 2008-01-27 MickeM 9 12 * Fixed a memory-leak in format_time … … 12 15 For this to work you need to have the descriptions flag set 13 16 In short: /nrpe -H 192.168.0.147 -c checkEventLog -a truncate=1024 "syntax=%generated%: %message%" descriptions=true file=System MaxWarn=1 MaxCrit=1 filter+eventType==error filter+generated=\<12h filter=new filter=all filter=in 17 + Added option "unique" to CheckEventLog If this is present only unique errors will be returned. 18 The uniqueness is defined by event-log, event-source, event-id and event-category. 14 19 15 20 2007-12-16 MickeM … … 18 23 19 24 2007-12-11 MickeM 20 + Added support for index-lookups of PDH counters (hopefully *all* local problems are now fixed (yeah right))25 + Added support for index-lookups of PDH counters (hopefully *all* locale problems are now fixed (yeah right)) 21 26 22 27 2007-12-10 MickeM -
include/error.hpp
r5ac88c0a rbf6e9b4 34 34 LPVOID lpMsgBuf; 35 35 HMODULE hevt = LoadLibraryEx(module.c_str(), NULL, DONT_RESOLVE_DLL_REFERENCES); 36 if (hevt == NULL) { 37 return _T("failed to load: ") + module + _T("( reson: ") + strEx::itos(GetLastError()) + _T(")"); 38 } 36 39 unsigned long dwRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_HMODULE|FORMAT_MESSAGE_ARGUMENT_ARRAY,hevt, 37 40 dwError,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR)&lpMsgBuf,0,reinterpret_cast<va_list*>(arguments)); … … 50 53 public: 51 54 static std::wstring from_module(std::wstring module, unsigned long dwError, DWORD *arguments) { 55 HMODULE hDLL = LoadLibraryEx(module.c_str(), NULL, DONT_RESOLVE_DLL_REFERENCES); 56 if (hDLL == NULL) { 57 return _T("failed to load: ") + module + _T("( reson: ") + strEx::itos(GetLastError()) + _T(")"); 58 } 52 59 LPVOID lpMsgBuf; 53 HMODULE hevt = LoadLibraryEx(module.c_str(), NULL, DONT_RESOLVE_DLL_REFERENCES); 54 unsigned long dwRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_HMODULE|FORMAT_MESSAGE_ARGUMENT_ARRAY,hevt, 60 unsigned long dwRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_HMODULE|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_ARGUMENT_ARRAY,hDLL, 55 61 dwError,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR)&lpMsgBuf,0,reinterpret_cast<va_list*>(arguments)); 56 62 if (dwRet == 0) { 57 FreeLibrary(hevt); 58 return _T("failed to lookup error code: ") + strEx::itos(dwError) + _T(" from DLL: ") + module + _T("( reson: ") + strEx::itos(GetLastError()) + _T(")"); 63 FreeLibrary(hDLL); 64 DWORD err = GetLastError(); 65 if (err == 317) { 66 return _T(""); 67 } 68 return _T("failed to lookup error code: ") + strEx::itos(dwError) + _T(" from DLL: ") + module + _T("( reson: ") + strEx::itos(err) + _T(")"); 59 69 } 60 70 std::wstring str = reinterpret_cast<TCHAR*>(lpMsgBuf); 61 71 LocalFree(lpMsgBuf); 62 FreeLibrary(hevt); 72 FreeLibrary(hDLL); 73 return str; 74 } 75 static std::wstring from_system(unsigned long dwError, DWORD *arguments) { 76 LPVOID lpMsgBuf; 77 unsigned long dwRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_ARGUMENT_ARRAY,NULL, 78 dwError,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR)&lpMsgBuf,0,reinterpret_cast<va_list*>(arguments)); 79 if (dwRet == 0) { 80 DWORD err = GetLastError(); 81 if (err == 317) { 82 return _T(""); 83 } 84 return _T("failed to lookup error code: ") + strEx::itos(dwError) + _T(" from system ( reson: ") + strEx::itos(err) + _T(")"); 85 } 86 std::wstring str = reinterpret_cast<TCHAR*>(lpMsgBuf); 87 LocalFree(lpMsgBuf); 63 88 return str; 64 89 } -
modules/CheckEventLog/CheckEventLog.cpp
r5ac88c0a rbf6e9b4 28 28 #include <utils.h> 29 29 #include <error.hpp> 30 #include <map> 30 31 31 32 CheckEventLog gCheckEventLog; … … 56 57 return false; 57 58 } 58 59 59 60 60 … … 225 225 p += len+1; 226 226 } 227 std::wstring ret = error::format::message::from_module(get_dll(), eventID(), dwArgs); 227 228 /* 229 TCHAR **_sz = (TCHAR**)GlobalAlloc(GPTR, (pevlr_->NumStrings)*sizeof(TCHAR *)); 230 register UINT z; 231 TCHAR* p = reinterpret_cast<TCHAR*>(reinterpret_cast<LPBYTE>(pevlr_) + pevlr_->StringOffset); 232 for(unsigned int z = 0; z < pevlr_->NumStrings; z++) { 233 DWORD len = wcslen(p); 234 _sz[z] = (TCHAR *)GlobalAlloc(GPTR, (len+1) * sizeof(TCHAR)); 235 wcscpy_s(_sz[z], len, p); 236 p += len+1; 237 } 238 */ 239 std::wstring ret; 240 strEx::splitList dlls = strEx::splitEx(get_dll(), _T(";")); 241 for (strEx::splitList::const_iterator cit = dlls.begin(); cit != dlls.end(); ++cit) { 242 //std::wstring msg = error::format::message::from_module((*cit), eventID(), _sz); 243 std::wstring msg = error::format::message::from_module((*cit), eventID(), dwArgs); 244 if (msg.empty()) { 245 msg = error::format::message::from_module((*cit), pevlr_->EventID, dwArgs); 246 } 247 strEx::replace(msg, _T("\n"), _T(" ")); 248 strEx::replace(msg, _T("\t"), _T(" ")); 249 std::string::size_type pos = msg.find_last_not_of(_T("\n\t ")); 250 if (pos != std::string::npos) { 251 msg = msg.substr(0,pos); 252 } 253 if (!msg.empty()) { 254 if (!ret.empty()) 255 ret += _T(", "); 256 ret += msg; 257 } 258 } 228 259 delete [] dwArgs; 229 std::string::size_type pos = ret.find_last_not_of(_T("\n\t\m"));230 if (pos != std::string::npos) {231 ret = ret.substr(0,pos-1);232 }233 260 return ret; 234 261 } … … 274 301 } 275 302 }; 303 /* 304 return (pevlr_->EventID&0xffff); 305 } 306 inline DWORD severity() const { 307 return (pevlr_->EventID>>30); 308 */ 309 class uniq_eventlog_record { 310 DWORD ID; 311 WORD type; 312 WORD category; 313 public: 314 uniq_eventlog_record(EVENTLOGRECORD *pevlr) : ID(pevlr->EventID&0xffff), type(pevlr->EventType), category(pevlr->EventCategory) {} 315 bool operator< (const uniq_eventlog_record &other) const { 316 return (ID < other.ID) || ((ID==other.ID)&&(type < other.type)) || (ID==other.ID&&type==other.type)&&(category < other.category); 317 } 318 std::wstring to_string() const { 319 return _T("id=") + strEx::itos(ID) + _T("type=") + strEx::itos(type) + _T("category=") + strEx::itos(category); 320 } 321 }; 322 typedef std::map<uniq_eventlog_record,bool> uniq_eventlog_map; 276 323 277 324 … … 332 379 bool bFilterNew = false; 333 380 bool bShowDescriptions = false; 381 bool unique = false; 334 382 unsigned int truncate = 0; 335 383 std::wstring syntax; … … 338 386 const int filter_normal = 3; 339 387 const int filter_compat = 3; 340 NSC_DEBUG_MSG_STD(_T("000") + message) ;341 388 342 389 try { … … 344 391 MAP_OPTIONS_NUMERIC_ALL(query, _T("")) 345 392 MAP_OPTIONS_STR2INT(_T("truncate"), truncate) 393 MAP_OPTIONS_BOOL_TRUE(_T("unique"), unique) 346 394 MAP_OPTIONS_BOOL_TRUE(_T("descriptions"), bShowDescriptions) 347 395 MAP_OPTIONS_PUSH(_T("file"), files) … … 402 450 return NSCAPI::returnUNKNOWN; 403 451 } 452 uniq_eventlog_map uniq_records; 404 453 405 454 //DWORD dwThisRecord; … … 464 513 match = true; 465 514 } 515 if (match&&unique) { 516 uniq_eventlog_record record = pevlr; 517 uniq_eventlog_map::const_iterator cit = uniq_records.find(record); 518 if (cit != uniq_records.end()) { 519 match = false; 520 } 521 else 522 uniq_records[record] = true; 523 } 466 524 467 525 if (match) {
Note: See TracChangeset
for help on using the changeset viewer.








