Changeset bf6e9b4 in nscp


Ignore:
Timestamp:
02/02/08 13:54:12 (5 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
52215d7
Parents:
5ac88c0a
Message:

2008-02-02 MickeM

  • Might have fixed the "missing eventlog messages" problem.
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • AutoBuild.h

    r3f69109 rbf6e9b4  
    33// change the FALSE to TRUE for autoincrement of build number 
    44#define INCREMENT_VERSION TRUE 
    5 #define FILEVER        0,3,0,12 
    6 #define PRODUCTVER     0,3,0,12 
    7 #define STRFILEVER     _T("0.3.0.12") 
    8 #define STRPRODUCTVER  _T("0.3.0.12") 
    9 #define STRPRODUCTDATE  _T("2007-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") 
    1010#endif // AUTOBUILD_H 
  • changelog

    r5ac88c0a rbf6e9b4  
    66 * Add API for rehashing the daemon (or implement it the API is there but does nothing) 
    77 
     82008-02-02 MickeM 
     9 * Might have fixed the "missing eventlog messages" problem. 
     10 
    8112008-01-27 MickeM 
    912 * Fixed a memory-leak in format_time 
     
    1215   For this to work you need to have the descriptions flag set 
    1316   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. 
    1419 
    15202007-12-16 MickeM 
     
    1823 
    19242007-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)) 
    2126 
    22272007-12-10 MickeM 
  • include/error.hpp

    r5ac88c0a rbf6e9b4  
    3434      LPVOID lpMsgBuf; 
    3535      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      } 
    3639      unsigned long dwRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_HMODULE|FORMAT_MESSAGE_ARGUMENT_ARRAY,hevt, 
    3740        dwError,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR)&lpMsgBuf,0,reinterpret_cast<va_list*>(arguments)); 
     
    5053    public: 
    5154      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        } 
    5259        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, 
    5561          dwError,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR)&lpMsgBuf,0,reinterpret_cast<va_list*>(arguments)); 
    5662        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(")"); 
    5969        } 
    6070        std::wstring str = reinterpret_cast<TCHAR*>(lpMsgBuf); 
    6171        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); 
    6388        return str; 
    6489      } 
  • modules/CheckEventLog/CheckEventLog.cpp

    r5ac88c0a rbf6e9b4  
    2828#include <utils.h> 
    2929#include <error.hpp> 
     30#include <map> 
    3031 
    3132CheckEventLog gCheckEventLog; 
     
    5657  return false; 
    5758} 
    58  
    5959 
    6060 
     
    225225      p += len+1; 
    226226    } 
    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    } 
    228259    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     } 
    233260    return ret; 
    234261  } 
     
    274301  } 
    275302}; 
     303/* 
     304return (pevlr_->EventID&0xffff); 
     305} 
     306inline DWORD severity() const { 
     307return (pevlr_->EventID>>30); 
     308*/ 
     309class uniq_eventlog_record { 
     310  DWORD ID; 
     311  WORD type; 
     312  WORD category; 
     313public: 
     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}; 
     322typedef std::map<uniq_eventlog_record,bool> uniq_eventlog_map; 
    276323 
    277324 
     
    332379  bool bFilterNew = false; 
    333380  bool bShowDescriptions = false; 
     381  bool unique = false; 
    334382  unsigned int truncate = 0; 
    335383  std::wstring syntax; 
     
    338386  const int filter_normal = 3; 
    339387  const int filter_compat = 3; 
    340   NSC_DEBUG_MSG_STD(_T("000") + message) ; 
    341388 
    342389  try { 
     
    344391      MAP_OPTIONS_NUMERIC_ALL(query, _T("")) 
    345392      MAP_OPTIONS_STR2INT(_T("truncate"), truncate) 
     393      MAP_OPTIONS_BOOL_TRUE(_T("unique"), unique) 
    346394      MAP_OPTIONS_BOOL_TRUE(_T("descriptions"), bShowDescriptions) 
    347395      MAP_OPTIONS_PUSH(_T("file"), files) 
     
    402450      return NSCAPI::returnUNKNOWN; 
    403451    } 
     452    uniq_eventlog_map uniq_records; 
    404453 
    405454    //DWORD dwThisRecord; 
     
    464513          match = true; 
    465514        } 
     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        } 
    466524 
    467525        if (match) { 
Note: See TracChangeset for help on using the changeset viewer.