Ignore:
Timestamp:
07/11/05 21:55:28 (8 years ago)
Author:
Michael Medin <michael@…>
Children:
237da21
Parents:
e93e741
Message:

changes all over manily in the checking code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/modules/CheckEventLog/CheckEventLog.cpp

    rf896cfb r24f7192  
    2828} 
    2929 
    30 std::string CheckEventLog::getModuleName() { 
    31   return "Event log Checker."; 
    32 } 
    33 NSCModuleWrapper::module_version CheckEventLog::getModuleVersion() { 
    34   NSCModuleWrapper::module_version version = {0, 0, 1 }; 
    35   return version; 
    36 } 
    37  
    3830bool CheckEventLog::hasCommandHandler() { 
    3931  return true; 
     
    4234  return false; 
    4335} 
     36 
    4437 
    4538 
     
    4942  EventLogRecord(EVENTLOGRECORD *pevlr) : pevlr_(pevlr) { 
    5043  } 
    51   inline DWORD timeGenerated() { 
     44  inline DWORD timeGenerated() const { 
    5245    return pevlr_->TimeGenerated; 
    5346  } 
    54   inline DWORD timeWritten() { 
     47  inline DWORD timeWritten() const { 
    5548    return pevlr_->TimeWritten; 
    5649  } 
    57   inline std::string eventSource() { 
     50  inline std::string eventSource() const { 
    5851    return reinterpret_cast<LPSTR>(reinterpret_cast<LPBYTE>(pevlr_) + sizeof(EVENTLOGRECORD)); 
    5952  } 
    6053 
    61   inline DWORD eventType() { 
     54  inline DWORD eventType() const { 
    6255    return pevlr_->EventType; 
    6356  } 
    64  
    65   std::string enumStrings() { 
     57/* 
     58  std::string userSID() const { 
     59    if (pevlr_->UserSidOffset == 0) 
     60      return ""; 
     61    PSID p = reinterpret_cast<PSID>(reinterpret_cast<LPBYTE>(pevlr_) + + pevlr_->UserSidOffset); 
     62    LPSTR user = new CHAR[1025]; 
     63    LPSTR domain = new CHAR[1025]; 
     64    DWORD userLen = 1024; 
     65    DWORD domainLen = 1024; 
     66    SID_NAME_USE sidName; 
     67    LookupAccountSid(NULL, p, user, &userLen, domain, &domainLen, &sidName); 
     68    user[userLen] = 0; 
     69    domain[domainLen] = 0; 
     70    return std::string(domain) + "\\" + std::string(user); 
     71  } 
     72  */ 
     73 
     74  std::string enumStrings() const { 
    6675    std::string ret; 
    6776    LPSTR p = reinterpret_cast<LPSTR>(reinterpret_cast<LPBYTE>(pevlr_) + pevlr_->StringOffset); 
     
    93102    if (sType == "auditFailure") 
    94103      return EVENTLOG_AUDIT_FAILURE; 
    95     return 0; 
     104    return strEx::stoi(sType); 
     105  } 
     106  static std::string translateType(DWORD dwType) { 
     107    if (dwType == EVENTLOG_ERROR_TYPE) 
     108      return "error"; 
     109    if (dwType == EVENTLOG_WARNING_TYPE) 
     110      return "warning"; 
     111    if (dwType == EVENTLOG_INFORMATION_TYPE) 
     112      return "info"; 
     113    if (dwType == EVENTLOG_AUDIT_SUCCESS) 
     114      return "auditSuccess"; 
     115    if (dwType == EVENTLOG_AUDIT_FAILURE) 
     116      return "auditFailure"; 
     117    return strEx::itos(dwType); 
    96118  } 
    97119 
     
    100122 
    101123struct searchQuery { 
    102   struct searchQueryBundle { 
    103124    struct searchQueryItem { 
    104       DWORD eventType_; 
    105       std::string eventSource_; 
    106       boost::regex eventSourceRegExp_; 
    107       bool notSetValue_; 
    108       DWORD writtenBeforeDelta_ ; 
    109       DWORD writtenAfterDelta_ ; 
    110       DWORD generatedBeforeDelta_; 
    111       DWORD generatedAfterDelta_; 
     125 
     126      typedef enum { 
     127        eventType,  
     128        eventSource,  
     129        timeWritten, 
     130        timeGenerated, 
     131        message, 
     132        none 
     133      } queryType; 
     134 
     135      typedef enum { out, in, undefined } filterType; 
     136 
     137      filterType filter_; 
     138      queryType queryType_; 
     139      DWORD dwValue_; 
    112140      boost::regex regexp_; 
    113  
    114       searchQueryItem(bool notSetValue)  
    115         : eventType_(0), notSetValue_(notSetValue),  
    116         writtenBeforeDelta_(0), writtenAfterDelta_(0) , 
    117         generatedBeforeDelta_(0), generatedAfterDelta_(0)  
     141       
     142 
     143      searchQueryItem()  
     144        : queryType_(none), dwValue_(0), filter_(out)  
    118145      {} 
     146      searchQueryItem(filterType filter, queryType type, std::string str)  
     147        : queryType_(type), dwValue_(0), filter_(filter) 
     148      { 
     149        switch (queryType_ ) { 
     150        case eventType: 
     151          dwValue_ = EventLogRecord::translateType(str); 
     152          break; 
     153 
     154        case timeGenerated: 
     155          dwValue_ = strEx::stoui_as_time(str)/1000; 
     156          break; 
     157 
     158        case eventSource: 
     159        case message: 
     160          try { 
     161            regexp_ = str; 
     162          } catch (const boost::bad_expression e) { 
     163            throw (std::string)"Invalid syntax in regular expression:" + str; 
     164          } 
     165          break; 
     166        } 
     167      } 
     168 
    119169      searchQueryItem& operator=(const searchQueryItem &other) { 
    120         eventType_ = other.eventType_; 
    121         eventSource_ = other.eventSource_; 
    122         notSetValue_ = other.notSetValue_; 
    123         writtenBeforeDelta_ = other.writtenBeforeDelta_; 
    124         writtenAfterDelta_ = other.writtenAfterDelta_; 
    125         generatedBeforeDelta_ = other.generatedBeforeDelta_; 
    126         generatedAfterDelta_ = other.generatedAfterDelta_; 
     170        queryType_ = other.queryType_; 
     171        dwValue_ = other.dwValue_; 
     172        filter_ = other.filter_; 
    127173        try { 
    128174          regexp_ = other.regexp_; 
     
    130176          throw (std::string)"Invalid syntax in regular expression:" + other.toString(); 
    131177        } 
    132         try { 
    133           eventSourceRegExp_ = other.eventSourceRegExp_; 
    134         } catch (const boost::bad_expression e) { 
    135           throw (std::string)"Invalid syntax in event source regular expression:" + other.toString(); 
    136         } 
    137178        return *this; 
    138179      } 
    139180 
    140       inline bool matchDateWritten(DWORD now, DWORD written) const { 
    141         if ((writtenAfterDelta_ == 0)&&(writtenBeforeDelta_ == 0)) 
    142           return notSetValue_; 
    143         bool ret = true; 
    144         if (writtenAfterDelta_ != 0) { 
    145           if (writtenAfterDelta_+written <= now) 
    146             ret = false; 
    147         } 
    148         if (writtenBeforeDelta_ != 0) { 
    149           if (writtenBeforeDelta_+written > now) 
    150             ret = false; 
    151         } 
    152         return ret; 
    153       } 
    154       inline bool matchDateGenerated(DWORD now, DWORD written) const { 
    155         if ((generatedAfterDelta_ == 0)&&(generatedBeforeDelta_ == 0)) 
    156           return notSetValue_; 
    157         bool ret = true; 
    158         if (generatedAfterDelta_ != 0) { 
    159           if (generatedAfterDelta_+written <= now) 
    160             ret = false; 
    161         } 
    162         if (generatedBeforeDelta_ != 0) { 
    163           if (generatedBeforeDelta_+written > now) 
    164             ret = false; 
    165         } 
    166         return ret; 
    167       } 
    168       inline bool matchType(DWORD eventType) const { 
    169         if (eventType_ == 0) 
    170           return notSetValue_; 
    171         return eventType_ & eventType; 
    172       } 
    173       inline bool matchSource(std::string eventSource) const { 
    174         if ((eventSource_.empty())&&eventSourceRegExp_.empty()) 
    175           return notSetValue_; 
    176         else if (eventSource_.empty()) 
    177           return boost::regex_match(eventSource, eventSourceRegExp_); 
    178         else if (eventSourceRegExp_.empty()) 
    179           return eventSource_ == eventSource; 
    180         return boost::regex_match(eventSource, eventSourceRegExp_) && (eventSource_ == eventSource); 
    181       } 
    182       inline bool matchRegexp(std::string msg) const { 
    183         if (regexp_.empty()) 
    184           return notSetValue_; 
    185         return boost::regex_match(msg, regexp_); 
    186       } 
     181      bool match(DWORD now, const EventLogRecord &record) const { 
     182        switch (queryType_) { 
     183        case eventType: 
     184          return record.eventType() & dwValue_; 
     185 
     186        case eventSource: 
     187          if (regexp_.empty()) 
     188            return false; 
     189          return boost::regex_match(record.eventSource(), regexp_); 
     190 
     191        case timeWritten: 
     192          return record.timeWritten() < (now-dwValue_); 
     193 
     194        case timeGenerated: 
     195          return record.timeGenerated() < (now-dwValue_); 
     196 
     197        case message: 
     198          if (regexp_.empty()) 
     199            return false; 
     200          return boost::regex_match(record.enumStrings(), regexp_); 
     201 
     202        default: 
     203          return false; 
     204        } 
     205      } 
     206      std::string queryType2String(queryType query) const { 
     207        switch (queryType_) { 
     208        case eventType: 
     209          return "eventType"; 
     210        case eventSource: 
     211          return "eventSource"; 
     212        case timeWritten: 
     213          return "timeWritten"; 
     214        case timeGenerated: 
     215          return "timeGenerated"; 
     216        case message: 
     217          return "message"; 
     218        default: 
     219          return "unknown"; 
     220        } 
     221 
     222      } 
     223 
    187224      std::string toString() const { 
    188225        std::stringstream ss; 
    189         ss << "    Regexp: " << regexp_ << std::endl; 
    190         ss << "    Event type: " << eventType_ << std::endl; 
    191         ss << "    Event source: " << eventSource_ << std::endl; 
    192         ss << "    Event source Regexp: " << eventSourceRegExp_ << std::endl; 
    193         ss << "    Written delta: " << writtenAfterDelta_ << " > " << writtenBeforeDelta_ << std::endl; 
    194         ss << "    Generated delta: " << generatedAfterDelta_ << " > " << generatedBeforeDelta_ << std::endl; 
     226        ss << " Type: " << queryType2String(queryType_) << " = " << dwValue_ << ", '" << regexp_ << "'"; 
    195227        return ss.str(); 
    196228      } 
    197229    }; 
    198     struct searchQueryItem require; 
    199     struct searchQueryItem exclude; 
    200     searchQueryBundle() : require(true), exclude(false) {} 
    201     std::string toString() { 
    202       return "  Required:\n" + require.toString()  + "\n  Exclude:\n" + exclude.toString(); 
     230 
     231 
     232 
     233  unsigned int truncate; 
     234  unsigned warning_count; 
     235  unsigned critical_count; 
     236  bool descriptions; 
     237  std::list<searchQueryItem> queries; 
     238 
     239  searchQuery() : truncate(0), descriptions(false), warning_count(0), critical_count(0) {} 
     240 
     241  std::string toString() { 
     242    std::string ret; 
     243    for (std::list<searchQuery::searchQueryItem>::const_iterator cit = queries.begin(); cit != queries.end(); ++cit ) { 
     244      ret += (*cit).toString(); 
    203245    } 
    204   }; 
    205  
    206   searchQueryBundle warn; 
    207   searchQueryBundle critical; 
    208   unsigned int truncate; 
    209   bool descriptions; 
    210   searchQuery() : truncate(0), descriptions(false) {} 
    211  
    212   std::string toString() { 
    213     return "Warn:\n" + warn.toString()  + "\nCritical:\n" + critical.toString(); 
     246    return ret; 
    214247  } 
    215248 
    216249}; 
    217250 
    218 void addToQueryItem(searchQuery::searchQueryBundle::searchQueryItem &item, std::string arg) { 
    219   std::pair<std::string,std::string> p = strEx::split(arg, "="); 
    220   if (p.first == "eventType") 
    221     item.eventType_ = EventLogRecord::appendType(item.eventType_, p.second); 
    222   else if (p.first == "eventSource") 
    223     item.eventSource_ = p.second; 
    224   else if (p.first == "eventSourceRegexp") { 
    225     try { 
    226       std::string s = p.second; 
    227       item.eventSourceRegExp_ = s; 
    228     } catch (const boost::bad_expression e) { 
    229       item.eventSourceRegExp_ = ""; 
    230       throw (std::string)"Invalid syntax in regular expression:" + p.second; 
    231     } 
    232   } 
    233   else if (p.first == "generatedBeforeDelta") 
    234     item.generatedBeforeDelta_ = strEx::stoi(p.second); 
    235   else if (p.first == "generatedAfterDelta") 
    236     item.generatedAfterDelta_ = strEx::stoi(p.second); 
    237   else if (p.first == "writtenBeforeDelta") 
    238     item.writtenBeforeDelta_ = strEx::stoi(p.second); 
    239   else if (p.first == "writtenAfterDelta") 
    240     item.writtenAfterDelta_ = strEx::stoi(p.second); 
    241   else if (p.first == "regexp") { 
    242     try { 
    243       item.regexp_ = p.second; 
    244     } catch (const boost::bad_expression e) { 
    245       item.regexp_ = ""; 
    246       throw (std::string)"Invalid syntax in regular expression:" + p.second; 
    247     } 
    248   } else 
    249     throw (std::string)"Invalid argument: " + p.first; 
    250    
    251 } 
    252 void addToQueryBundle(searchQuery::searchQueryBundle &bundle, std::string arg) { 
    253   std::pair<std::string,std::string> p = strEx::split(arg, "."); 
    254   if (p.first == "require") 
    255     addToQueryItem(bundle.require, p.second); 
    256   else if (p.first == "exclude") 
    257     addToQueryItem(bundle.exclude, p.second); 
    258   else 
    259     throw (std::string)"Invalid require/exclude: " + p.first; 
    260 } 
    261 void addToQuery(searchQuery &q, std::string arg) { 
    262   std::pair<std::string,std::string> p = strEx::split(arg, "."); 
    263   if (p.first == "warn") 
    264     addToQueryBundle(q.warn, p.second); 
    265   else if (p.first == "critical") 
    266     addToQueryBundle(q.critical, p.second); 
    267   else if (p.first == "all") { 
    268     addToQueryBundle(q.warn, p.second); 
    269     addToQueryBundle(q.critical, p.second); 
    270   } else { 
    271     std::pair<std::string,std::string> p = strEx::split(arg, "="); 
    272     if (p.first == "truncate") 
    273       q.truncate = strEx::stoi(p.second); 
    274     else if (p.first == "descriptions") 
    275       q.descriptions = true; 
    276     else 
    277       throw (std::string)"Invalid argument: " + arg; 
    278   } 
    279 } 
    280  
    281 void buildQury(searchQuery &query, std::list<std::string> args) { 
    282   for (std::list<std::string>::const_iterator it = args.begin(); it!=args.end(); it++) { 
    283     NSC_DEBUG_MSG_STD("Adding: " + *it); 
    284     addToQuery(query, *it); 
    285   } 
    286 } 
     251// checkEventLog file=application truncate=1024 descriptions filter=[out|in] 
     252//          warning-count=3 critical-count=10 
     253// filter type = warning AND generated > 1d 
     254// 
     255// match (type, "warning") && match(generated, "1d") 
     256//          filer-eventType=warning  
     257//          filer-eventSource= 
     258//          filer-date=4d 
     259// 
    287260// CheckEventLog 
    288261// request: CheckEventLog&<logfile>&<Query strings> 
     
    291264//          1 - Unknown 
    292265//          2 - Errors 
     266 
     267// ./nrpe-2.0/src/check_nrpe -H 192.168.167 -p 5666 -c checkEventLog -a file=system file=application filter-eventType=warning filter-generated=1d descriptions filter-eventSource=Cdrom filter-eventSource=NSClient warning-count=3 critical-count=7 filter=in truncate=512 
     268// 
    293269// Examples: 
    294270// CheckEventLog&Application&1&<type>&<query>&huffa... 
    295271// CheckEventLog&Application&warn.require.eventType=warning&critical.require.eventType=error&truncate=1024&descriptions&all.exclude.eventSourceRegexp=^(Win|Msi|NSClient\+\+|Userenv|ASP\.NET|LoadPerf|Outlook|Application E|NSClient).* 
    296272#define BUFFER_SIZE 1024*64 
    297  
    298273NSCAPI::nagiosReturn CheckEventLog::handleCommand(const strEx::blindstr command, const unsigned int argLen, char **char_args, std::string &message, std::string &perf) { 
    299274  if (command != "CheckEventLog") 
     
    301276  NSCAPI::nagiosReturn rCode = NSCAPI::returnOK; 
    302277  std::list<std::string> args = arrayBuffer::arrayBuffer2list(argLen, char_args); 
    303   if (args.size() < 2) { 
    304     message = "Missing argument"; 
    305     return NSCAPI::returnCRIT; 
    306   } 
    307  
    308   std::list<std::string>::iterator it = args.begin(); 
    309   for (;it != args.end();it++) { 
    310     NSC_DEBUG_MSG_STD("Arguments: " + (*it)); 
    311   } 
     278 
    312279  std::string ret; 
    313   bool critical = false; 
    314280  searchQuery query; 
    315   std::string logFile = args.front(); args.pop_front(); 
    316   try { 
    317     buildQury(query, args); 
    318   } catch (std::string s) { 
    319     message = s; 
    320     return NSCAPI::returnCRIT; 
    321   } 
    322   NSC_DEBUG_MSG_STD("Base query: " + query.toString()); 
    323  
    324   HANDLE hLog = OpenEventLog(NULL, logFile.c_str()); 
    325   if (hLog == NULL) { 
    326     message = "Could not open the Application event log."; 
     281  std::list<std::string> files; 
     282  searchQuery::searchQueryItem::filterType filter = searchQuery::searchQueryItem::out; 
     283 
     284  for (std::list<std::string>::const_iterator it = args.begin(); it!=args.end(); ++it) { 
     285    try { 
     286      if ((*it) == "descriptions") { 
     287        query.descriptions = true; 
     288      } else { 
     289        std::pair<std::string,std::string> p = strEx::split((*it), "="); 
     290        if (p.first == "truncate") { 
     291          query.truncate = strEx::stoi(p.second); 
     292        } else if (p.first == "file") { 
     293          files.push_back(p.second); 
     294        } else if (p.first == "filter") { 
     295          if (p.second == "in") 
     296            filter = searchQuery::searchQueryItem::in; 
     297          else 
     298            filter = searchQuery::searchQueryItem::out; 
     299        } else if (p.first == "warning-count") { 
     300          query.warning_count = strEx::stoi(p.second); 
     301        } else if (p.first == "critical-count") { 
     302          query.critical_count = strEx::stoi(p.second); 
     303 
     304        } else if (p.first == "filter-eventType") { 
     305          query.queries.push_back(searchQuery::searchQueryItem(filter, searchQuery::searchQueryItem::eventType, p.second)); 
     306        } else if (p.first == "filter-eventSource") { 
     307          query.queries.push_back(searchQuery::searchQueryItem(filter, searchQuery::searchQueryItem::eventSource, p.second)); 
     308        } else if (p.first == "filter-generated") { 
     309          query.queries.push_back(searchQuery::searchQueryItem(filter, searchQuery::searchQueryItem::timeGenerated, p.second)); 
     310        } else if (p.first == "filter-written") { 
     311          query.queries.push_back(searchQuery::searchQueryItem(filter, searchQuery::searchQueryItem::timeWritten, p.second)); 
     312        } else if (p.first == "filter-message") { 
     313          query.queries.push_back(searchQuery::searchQueryItem(filter, searchQuery::searchQueryItem::message, p.second)); 
     314        } 
     315      } 
     316    } catch (std::string s) { 
     317      if (message.empty()) 
     318        message += "UNKNOWN: "; 
     319      else 
     320        message += ", "; 
     321      message += s; 
     322    } 
     323  } 
     324  if (!message.empty()) { 
    327325    return NSCAPI::returnUNKNOWN; 
    328326  } 
    329327 
    330   DWORD dwThisRecord, dwRead, dwNeeded; 
    331   EVENTLOGRECORD *pevlr; 
    332   BYTE bBuffer[BUFFER_SIZE];  
    333  
    334   pevlr = reinterpret_cast<EVENTLOGRECORD*>(&bBuffer); 
    335  
    336   // get time now !!! 
    337   __time64_t ltime; 
    338   _time64(&ltime); 
    339   DWORD currentTime = ltime; 
    340  
    341   GetOldestEventLogRecord(hLog, &dwThisRecord); 
    342  
    343   while (ReadEventLog(hLog, EVENTLOG_FORWARDS_READ|EVENTLOG_SEQUENTIAL_READ, 
    344     0, pevlr, BUFFER_SIZE, &dwRead, &dwNeeded)) 
    345   { 
    346     while (dwRead > 0)  
    347     {  
    348       bool match = false; 
    349       bool c = false; 
    350       EventLogRecord record(pevlr); 
    351  
    352       if ( query.critical.require.matchType(record.eventType()) && 
    353         query.critical.require.matchSource(record.eventSource()) && 
    354         query.critical.require.matchDateGenerated(currentTime, record.timeGenerated()) && 
    355         query.critical.require.matchDateWritten(currentTime, record.timeWritten()) && 
    356         query.critical.require.matchRegexp(record.enumStrings()) 
    357         ) { 
    358           match = true; 
    359           c = true; 
    360         } 
    361       if ( query.critical.exclude.matchType(record.eventType()) || 
    362         query.critical.exclude.matchSource(record.eventSource()) || 
    363         query.critical.exclude.matchDateGenerated(currentTime, record.timeGenerated()) || 
    364         query.critical.exclude.matchDateWritten(currentTime, record.timeWritten()) || 
    365         query.critical.exclude.matchRegexp(record.enumStrings()) 
    366         ) { 
    367           match = false; 
    368           c = false; 
    369         } 
    370  
    371       if ( query.warn.require.matchType(record.eventType()) && 
    372         query.warn.require.matchSource(record.eventSource()) && 
    373         query.warn.require.matchDateGenerated(currentTime, record.timeGenerated()) && 
    374         query.warn.require.matchDateWritten(currentTime, record.timeWritten()) && 
    375         query.warn.require.matchRegexp(record.enumStrings()) 
    376         ) 
    377         match = true; 
    378       if ( query.warn.exclude.matchType(record.eventType()) || 
    379         query.warn.exclude.matchSource(record.eventSource()) || 
    380         query.warn.exclude.matchDateGenerated(currentTime, record.timeGenerated()) || 
    381         query.warn.exclude.matchDateWritten(currentTime, record.timeWritten()) || 
    382         query.warn.exclude.matchRegexp(record.enumStrings()) 
    383         ) 
    384         match = false; 
    385        
    386       if (match) { 
    387         if (c) 
    388           critical = true; 
    389         if (!ret.empty()) 
    390           ret += " - "; 
    391         ret += record.eventSource(); 
    392         if (query.descriptions) { 
    393           std::string s = record.enumStrings(); 
    394           if (!s.empty()) 
    395             ret += " [" + s + "]" ; 
    396         } 
    397       } 
    398       dwRead -= pevlr->Length;  
    399       pevlr = (EVENTLOGRECORD *)  
    400         ((LPBYTE) pevlr + pevlr->Length);  
     328  unsigned int hit_count = 0; 
     329 
     330  for (std::list<std::string>::const_iterator cit2 = files.begin(); cit2 != files.end(); ++cit2) { 
     331    HANDLE hLog = OpenEventLog(NULL, (*cit2).c_str()); 
     332    if (hLog == NULL) { 
     333      message = "Could not open the '" + (*cit2) + "' event log."; 
     334      return NSCAPI::returnUNKNOWN; 
     335    } 
     336 
     337    DWORD dwThisRecord, dwRead, dwNeeded; 
     338    EVENTLOGRECORD *pevlr; 
     339    BYTE bBuffer[BUFFER_SIZE];  
     340 
     341    pevlr = reinterpret_cast<EVENTLOGRECORD*>(&bBuffer); 
     342 
     343    __time64_t ltime; 
     344    _time64(&ltime); 
     345    DWORD currentTime = ltime; 
     346 
     347    GetOldestEventLogRecord(hLog, &dwThisRecord); 
     348 
     349    while (ReadEventLog(hLog, EVENTLOG_FORWARDS_READ|EVENTLOG_SEQUENTIAL_READ, 
     350      0, pevlr, BUFFER_SIZE, &dwRead, &dwNeeded)) 
     351    { 
     352      while (dwRead > 0)  
     353      {  
     354        bool match = false; 
     355        bool undefined = true; 
     356        searchQuery::searchQueryItem::filterType tFilter = searchQuery::searchQueryItem::out; 
     357        EventLogRecord record(pevlr); 
     358 
     359        for (std::list<searchQuery::searchQueryItem>::const_iterator cit3 = query.queries.begin(); cit3 != query.queries.end(); ++cit3 ) { 
     360          if ((*cit3).match(currentTime, record)) { 
     361            if ((*cit3).filter_ == searchQuery::searchQueryItem::in) 
     362              match = true; 
     363            else { 
     364              match = false; 
     365            } 
     366          } 
     367        } 
     368 
     369        if (match) { 
     370          if (!ret.empty()) 
     371            ret += ", "; 
     372          ret += record.eventSource(); 
     373          if (query.descriptions) { 
     374            ret += "(" + EventLogRecord::translateType(record.eventType()) + ")"; 
     375            ret += "[" + record.enumStrings() + "]"; 
     376          } 
     377          hit_count++; 
     378        } 
     379 
     380        dwRead -= pevlr->Length;  
     381        pevlr = (EVENTLOGRECORD *) ((LPBYTE) pevlr + pevlr->Length);  
     382      }  
     383 
     384      pevlr = (EVENTLOGRECORD *) &bBuffer;  
    401385    }  
    402386 
    403     pevlr = (EVENTLOGRECORD *) &bBuffer;  
    404   }  
    405  
    406   CloseEventLog(hLog); 
    407   if (critical) { 
    408     ret = "CRITICAL: " + ret; 
     387    CloseEventLog(hLog); 
     388  } 
     389 
     390  if ((query.critical_count > 0) && (hit_count > query.critical_count)) { 
     391    ret = "CRITICAL: " + strEx::itos(hit_count) + " > critical: " + ret; 
    409392    rCode = NSCAPI::returnCRIT; 
    410   } 
    411   else if (!ret.empty()) { 
    412     ret = "WARNING: " + ret; 
     393  } else if ((query.warning_count > 0) && (hit_count > query.warning_count)) { 
     394    ret = "WARNING: " + strEx::itos(hit_count) + " > warning: " + ret; 
    413395    rCode = NSCAPI::returnWARN; 
    414   } else  
    415     ret = "OK: No errors/warnings in event log."; 
     396  } else { 
     397    ret = "OK: " + strEx::itos(hit_count) + ": " + ret; 
     398  } 
    416399  if (query.truncate != 0) 
     400    ret = ret.substr(0, query.truncate); 
     401  if ((query.truncate > 0) && (ret.length() > query.truncate)) 
    417402    ret = ret.substr(0, query.truncate); 
    418403  message = ret; 
Note: See TracChangeset for help on using the changeset viewer.