Changeset dd02c15 in nscp


Ignore:
Timestamp:
03/20/08 17:13:36 (5 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
b7ed6ac
Parents:
5aebda1
Message:
  • Fixed service check: check_nt -v SERVICESTATE -l CheckAll? so it works as advertised (#150)
    • Fixed issue with check_nt MEMUSE/CPULOAD/UPTIME if something is "broken" they will now return an error instead of "0". (#134) Added option debug_skip_data_collection to simulate this (just for kicks)
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • AutoBuild.h

    r5aebda1 rdd02c15  
    33// change the FALSE to TRUE for autoincrement of build number 
    44#define INCREMENT_VERSION TRUE 
    5 #define FILEVER        0,3,1,15 
    6 #define PRODUCTVER     0,3,1,15 
    7 #define STRFILEVER     _T("0.3.1.15") 
    8 #define STRPRODUCTVER  _T("0.3.1.15") 
    9 #define STRPRODUCTDATE  _T("2008-03-18") 
     5#define FILEVER        0,3,1,18 
     6#define PRODUCTVER     0,3,1,18 
     7#define STRFILEVER     _T("0.3.1.18") 
     8#define STRPRODUCTVER  _T("0.3.1.18") 
     9#define STRPRODUCTDATE  _T("2008-03-20") 
    1010#endif // AUTOBUILD_H 
  • changelog

    r5aebda1 rdd02c15  
    22 * Process times and similar ? 
    33 * Fix configuration GUI (low priority) 
    4  * Fix installer (after configuration UI) 
    54 * Add API for rehashing the daemon (or implement it the API is there but does nothing) 
    65 * Improved socket performance (would be nice if we could be used as a "hub") 
     
    87 
    982007-03-20 
    10  + Added host-lookupos for NSCA server 
     9 + Added host-lookupos for NSCA server (#149) 
    1110 + Added option (cache_hostname=1|0) to cache the NSCA host name (Ie. only lookup once) 
     11 * Fixed service check: check_nt -v SERVICESTATE -l CheckAll so it works as advertised (#150) 
     12 * Fixed issue with check_nt MEMUSE/CPULOAD/UPTIME if something is "broken" they will now return an error instead of "0". (#134) 
     13   Added option debug_skip_data_collection to simulate this (just for kicks) 
    1214 
    13152007-03-18 
  • include/PDHCollectors.h

    r394f7a1 rdd02c15  
    116116    TType value_; 
    117117    TMutextHandler mutex_; 
    118   public: 
    119     StaticPDHCounterListener() : value_(0) {} 
     118    bool hasValue_; 
     119    std::wstring lastError_; 
     120  public: 
     121    StaticPDHCounterListener() : value_(0), hasValue_(false) {} 
    120122    virtual void collect(const PDH::PDHCounter &counter) { 
    121123      PDHCounterMutexHandler mutex(&mutex_); 
     
    123125        return; 
    124126      value_ = counter.getDoubleValue(); 
     127      hasValue_ = true; 
    125128    } 
    126129    void attach(const PDH::PDHCounter &counter){} 
     
    129132      PDHCounterMutexHandler mutex(&mutex_); 
    130133      if (!mutex.hasLock()) 
    131         return -1; 
     134        throw PDHException(_T("Could not get mutex")); 
     135      if (!hasValue_) 
     136        throw PDHException(_T("No value has been collected yet")); 
    132137      return value_; 
    133138    } 
     
    141146    TType value_; 
    142147    TMutextHandler mutex_; 
    143   public: 
    144     StaticPDHCounterListener() : value_(0) {} 
     148    bool hasValue_; 
     149  public: 
     150    StaticPDHCounterListener() : value_(0), hasValue_(false) {} 
    145151    virtual void collect(const PDH::PDHCounter &counter) { 
    146152      PDHCounterMutexHandler mutex(&mutex_); 
     
    148154        return; 
    149155      value_ = counter.getIntValue(); 
     156      hasValue_ = true; 
    150157    } 
    151158    void attach(const PDH::PDHCounter &counter){} 
     
    154161      PDHCounterMutexHandler mutex(&mutex_); 
    155162      if (!mutex.hasLock()) 
    156         return -1; 
     163        throw PDHException(_T("Could not get mutex")); 
     164      if (!hasValue_) 
     165        throw PDHException(_T("No value has been collected yet")); 
    157166      return value_; 
    158167    } 
     
    166175    TMutextHandler mutex_; 
    167176    TType value_; 
    168   public: 
    169     StaticPDHCounterListener() : value_(0) {} 
     177    bool hasValue_; 
     178  public: 
     179    StaticPDHCounterListener() : value_(0), hasValue_(false) {} 
    170180    virtual void collect(const PDH::PDHCounter &counter) { 
    171181      PDHCounterMutexHandler mutex(&mutex_); 
     
    173183        return; 
    174184      value_ = counter.getInt64Value(); 
     185      hasValue_ = true; 
    175186    } 
    176187    void attach(const PDH::PDHCounter &counter){} 
     
    179190      PDHCounterMutexHandler mutex(&mutex_); 
    180191      if (!mutex.hasLock()) 
    181         return -1; 
     192        throw PDHException(_T("Could not get mutex")); 
     193      if (!hasValue_) 
     194        throw PDHException(_T("No value has been collected yet")); 
    182195      return value_; 
    183196    } 
     
    194207    TType *buffer; 
    195208    unsigned int current; 
    196   public: 
    197     RoundINTPDHBufferListenerImpl() : buffer(NULL), length(0), current(0) {} 
    198     RoundINTPDHBufferListenerImpl(int length_) : length(length_), current(0) { 
     209    bool hasValue_; 
     210  public: 
     211    RoundINTPDHBufferListenerImpl() : buffer(NULL), length(0), current(0), hasValue_(false) {} 
     212    RoundINTPDHBufferListenerImpl(int length_) : length(length_), current(0), hasValue_(false) { 
    199213      PDHCounterMutexHandler mutex(mutex_); 
    200214      if (!mutex.hasLock()) 
     
    245259      if (current >= length) 
    246260        return; 
     261      hasValue_ = true; 
    247262      buffer[current++] = value; 
    248263      if (current >= length) 
     
    253268      if (!mutex.hasLock(true)) 
    254269        throw PDHException(_T("Failed to get mutex :(")); 
     270      if (!hasValue_) 
     271        throw PDHException(_T("No value has been collected yet")); 
    255272      if ((backItems == 0) || (backItems >= length)) 
    256         return -1; 
     273        throw PDHException(_T("Strange error buffer pointers are f*cked up")); 
    257274      double ret = 0; 
    258275      if (current >= backItems) { 
  • include/config.h

    r5aebda1 rdd02c15  
    134134#define C_SYSTEM_NO_INDEX _T("dont_use_pdh_index") 
    135135#define C_SYSTEM_NO_INDEX_DEFAULT 0 
     136#define C_SYSTEM_IGNORE_COLLECTION _T("debug_skip_data_collection") 
     137#define C_SYSTEM_IGNORE_COLLECTION_DEFAULT 0 
    136138 
    137139#define C_SYSTEM_MEM_PAGE_LIMIT _T("MemoryCommitLimit") 
  • modules/CheckSystem/CheckSystem.cpp

    r394f7a1 rdd02c15  
    456456  } 
    457457  unsigned long long value = pObject->getUptime(); 
     458  if (value == -1) { 
     459    msg = _T("ERROR: Could not get value"); 
     460    return NSCAPI::returnUNKNOWN; 
     461  } 
    458462  if (bNSClient) { 
    459463    msg = strEx::itos(value); 
     
    474478 
    475479 
     480inline int get_state(DWORD state) { 
     481  if (state == SERVICE_RUNNING) 
     482    return checkHolders::state_started; 
     483  else if (state == SERVICE_STOPPED) 
     484    return checkHolders::state_stopped; 
     485  return checkHolders::state_none; 
     486} 
    476487 
    477488/** 
     
    571582      } catch (NTServiceException e) { 
    572583        if (!msg.empty()) msg += _T(" - "); 
    573         msg += (*it).data + _T(": Unknown"); 
     584        msg += (*it).data + _T(": Error"); 
    574585        NSCHelper::escalteReturnCodeToWARN(returnCode); 
    575586        continue; 
    576587      } 
    577       if ((info.m_dwCurrentState == SERVICE_RUNNING) && (*it).showAll()) { 
    578         if (!msg.empty()) msg += _T(" - "); 
    579         msg += (*it).data + _T(": Started"); 
    580       } else if (info.m_dwCurrentState == SERVICE_RUNNING) { 
    581       } else if (info.m_dwCurrentState == SERVICE_STOPPED) { 
    582         if (!msg.empty()) msg += _T(" - "); 
    583         msg += (*it).data + _T(": Stopped"); 
    584         NSCHelper::escalteReturnCodeToCRIT(returnCode); 
    585       } else { 
    586         if (!msg.empty()) msg += _T(" - "); 
    587         msg += (*it).data + _T(": Unknown"); 
    588         NSCHelper::escalteReturnCodeToWARN(returnCode); 
     588      if ((*it).crit.state.hasBounds()) { 
     589        bool ok = (*it).crit.state.check(get_state(info.m_dwCurrentState)); 
     590        if (!ok || (*it).showAll()) { 
     591          if (info.m_dwCurrentState == SERVICE_RUNNING) { 
     592            if (!msg.empty()) msg += _T(" - "); 
     593            msg += (*it).data + _T(": Started"); 
     594          } else if (info.m_dwCurrentState == SERVICE_STOPPED) { 
     595            if (!msg.empty()) msg += _T(" - "); 
     596            msg += (*it).data + _T(": Stopped"); 
     597          } else { 
     598            if (!msg.empty()) msg += _T(" - "); 
     599            msg += (*it).data + _T(": Unknown"); 
     600          } 
     601          if (!ok)  
     602            NSCHelper::escalteReturnCodeToCRIT(returnCode); 
     603        } 
    589604      } 
    590605    } else { 
     
    678693      } 
    679694      dataPaged.value = pObject->getMemCommit(); 
     695      if (dataPaged.value == -1) { 
     696        msg = _T("ERROR: Failed to get PDH value."); 
     697        return NSCAPI::returnUNKNOWN; 
     698      } 
    680699      dataPaged.total = pObject->getMemCommitLimit(); 
     700      if (dataPaged.total == -1) { 
     701        msg = _T("ERROR: Failed to get PDH value."); 
     702        return NSCAPI::returnUNKNOWN; 
     703      } 
    681704    } else if (firstMem) { 
    682705      try { 
  • modules/CheckSystem/PDHCollector.cpp

    r394f7a1 rdd02c15  
    2525 
    2626PDHCollector::PDHCollector() : hStopEvent_(NULL) { 
     27  dontCollect_ = NSCModuleHelper::getSettingsInt(C_SYSTEM_SECTION_TITLE, C_SYSTEM_IGNORE_COLLECTION, C_SYSTEM_IGNORE_COLLECTION_DEFAULT)==1; 
    2728  checkIntervall_ = NSCModuleHelper::getSettingsInt(C_SYSTEM_SECTION_TITLE, C_SYSTEM_CHECK_RESOLUTION, C_SYSTEM_CHECK_RESOLUTION_DEFAULT); 
    2829  std::wstring s = NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_CPU_BUFFER_TIME, C_SYSTEM_CPU_BUFFER_TIME_DEFAULT); 
     
    192193        else { 
    193194          try { 
    194             pdh.gatherData(); 
     195            if (!dontCollect_) 
     196              pdh.gatherData(); 
    195197          } catch (const PDH::PDHException &e) { 
    196             if (first) {  // If this is the first run an error will be thrown since the data is not yet avalible 
     198            if (first) {  // If this is the first run an error will be thrown since the data is not yet available 
    197199              // This is "ok" but perhaps another solution would be better, but this works :) 
    198200              first = false; 
     
    260262    return static_cast<int>(cpu.getAvrage(mseconds / (checkIntervall_*100))); 
    261263  } catch (PDHCollectors::PDHException &e) { 
    262     NSC_LOG_ERROR(_T("Failed to get (sub) Mutex!")); 
     264    NSC_LOG_ERROR(_T("Failed to get CPU value: ") + e.getError()); 
     265    return -1; 
     266  } catch (...) { 
     267    NSC_LOG_ERROR(_T("Failed to get CPU value")); 
    263268    return -1; 
    264269  } 
     
    276281    return -1; 
    277282  } 
    278   return upTime.getValue(); 
     283  try { 
     284    return upTime.getValue(); 
     285  } catch (PDHCollectors::PDHException &e) { 
     286    NSC_LOG_ERROR(_T("Failed to get UPTIME value: ") + e.getError()); 
     287    return -1; 
     288  } catch (...) { 
     289    NSC_LOG_ERROR(_T("Failed to get UPTIME value")); 
     290    return -1; 
     291  } 
    279292} 
    280293/** 
     
    288301    return -1; 
    289302  } 
    290   return memCmtLim.getValue(); 
     303  try { 
     304    return memCmtLim.getValue(); 
     305  } catch (PDHCollectors::PDHException &e) { 
     306    NSC_LOG_ERROR(_T("Failed to get MEM_CMT_LIMIT value: ") + e.getError()); 
     307    return -1; 
     308  } catch (...) { 
     309    NSC_LOG_ERROR(_T("Failed to get MEM_CMT_LIMIT value")); 
     310    return -1; 
     311  } 
    291312} 
    292313/** 
     
    301322    return -1; 
    302323  } 
    303   return memCmt.getValue(); 
    304 } 
     324  try { 
     325    return memCmt.getValue(); 
     326  } catch (PDHCollectors::PDHException &e) { 
     327    NSC_LOG_ERROR(_T("Failed to get MEM_CMT value: ") + e.getError()); 
     328    return -1; 
     329  } catch (...) { 
     330    NSC_LOG_ERROR(_T("Failed to get MEM_CMT value")); 
     331    return -1; 
     332  } 
     333} 
  • modules/CheckSystem/PDHCollector.h

    r394f7a1 rdd02c15  
    5050  HANDLE hStopEvent_; 
    5151  int checkIntervall_; 
     52  bool dontCollect_; 
    5253 
    5354  PDHCollectors::StaticPDHCounterListener<unsigned __int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> memCmtLim; 
Note: See TracChangeset for help on using the changeset viewer.