Changeset e93e741 in nscp


Ignore:
Timestamp:
05/29/05 20:58:08 (8 years ago)
Author:
Michael Medin <michael@…>
Children:
24f7192
Parents:
7da80b5
Message:
  • Fixed PROCSTATE and SERVICESTATE return state. + Added support for individual size in CheckDriveSize and CheckFileSize (size has to be specified before a drive/path)
  • Fixed performance data for drives (and possibly other places)
Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/changelog

    r7da80b5 re93e741  
     12005-05-29 MickeM 
     2 * Fixed PROCSTATE and SERVICESTATE return state. 
     3 + Added support for individual size in CheckDriveSize and CheckFileSize (size has to be specified before a drive/path) 
     4 * Fixed performance data for drives (and possibly other places) 
     5 
    162005-05-23 MickeM 
    27 + Added obfuscated password support 
  • trunk/docs/CheckDisk/index.html

    r7da80b5 re93e741  
    3333  <h2>CheckFileSize</h2> 
    3434  <p>This check does a recursive size calculation of the directory (or file) specified.  
    35   A request has one or more options described in the table below. </p> 
     35  A request has one or more options described in the table below. The order  
     36  only matter in that the size has to be specified before the File option  
     37  this becous you can change the size for each drive by specifying multiple  
     38  Size options.</p> 
    3639  <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" id="table5"> 
    3740    <tr> 
     
    127130      </div> 
    128131      </li> 
     132      <li> 
     133      <p><b>Sample of using individual size for multiple files.:</b></p> 
     134      <p><code>CheckFileSize MaxWarn=2G MaxCrit=4G File=c:\\pagefile.sys MaxWarn=1K MaxCrit=512 File=c:\\boot.ini</code></p> 
     135      <p><code>OK all file sizes are within bounds.</code></p> 
     136      <div class="config"> 
     137        <p>define command { </p> 
     138        <p>&nbsp;&nbsp;&nbsp; command_name CheckMyFiles </p> 
     139        <p>&nbsp;&nbsp;&nbsp; command_line check_nrpe -H $HOSTADDRESS$ -p  
     140        5666 -c CheckFileSize -a MaxWarn=2G MaxCrit=4G File=c:\\pagefile.sys MaxWarn=1K MaxCrit=512 File=c:\\boot.ini</p> 
     141        <p>}</p> 
     142        <p>&nbsp;&nbsp;&nbsp; check_command CheckMyFiles</p> 
     143      </div> 
     144      </li> 
    129145    </ul> 
    130146  </div> 
    131147  <h2>CheckDriveSize</h2> 
     148  <p>This check verifies the size of various drives specified on the command  
     149  line.  
     150  A request has one or more options described in the table below. The order  
     151  only matter in that the size has to be specified before the Drive option  
     152  this becous you can change the size for each drive by specifying multiple  
     153  Size options.</p> 
    132154  <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" id="table6"> 
    133155    <tr> 
  • trunk/include/PDHCollectors.h

    r7da80b5 re93e741  
    44 
    55namespace PDHCollectors { 
    6   class StaticPDHCounterListenerInt : public PDH::PDHCounterListener { 
    7     __int64 value_; 
     6  template <class TType = __int64, DWORD TCollectionFormat = PDH_FMT_LARGE> 
     7  class StaticPDHCounterListener : public PDH::PDHCounterListener { 
     8    TType value_; 
    89  public: 
    910    virtual void collect(const PDH::PDHCounter &counter) { 
    10       setValue(counter.getInt64Value()); 
     11      switch (TCollectionFormat) { 
     12        case PDH_FMT_LARGE: 
     13          setValue(counter.getInt64Value()); 
     14          break; 
     15        case PDH_FMT_DOUBLE: 
     16          setValue(counter.getDoubleValue()); 
     17          break; 
     18        default: 
     19          return; 
     20      } 
    1121    } 
    1222    void attach(const PDH::PDHCounter &counter){} 
    1323    void detach(const PDH::PDHCounter &counter){} 
    14     void setValue(__int64 value) { 
     24    void setValue(TType value) { 
    1525      value_ = value; 
    1626    } 
    17     __int64 getValue() const { 
     27    TType getValue() const { 
    1828      return value_; 
    1929    } 
    20   }; 
    21   class StaticPDHCounterListenerDouble : public PDH::PDHCounterListener { 
    22     double value_; 
    23   public: 
    24     virtual void collect(const PDH::PDHCounter &counter) { 
    25       setValue(counter.getDoubleValue()); 
    26     } 
    27     void attach(const PDH::PDHCounter &counter){} 
    28     void detach(const PDH::PDHCounter &counter){} 
    29     void setValue(double value) { 
    30       value_ = value; 
    31     } 
    32     double getValue() const { 
    33       return value_; 
     30    DWORD getFormat() const { 
     31      return TCollectionFormat; 
    3432    } 
    3533  }; 
    3634 
    37  
     35  template <class TType = __int64, DWORD TCollectionFormat = PDH_FMT_LARGE> 
    3836  class RoundINTPDHBufferListener : public PDH::PDHCounterListener { 
    3937    unsigned int length; 
    40     int *buffer; 
     38    TType *buffer; 
    4139    unsigned int current; 
    4240  public: 
     
    6462      length = newLength; 
    6563 
    66       buffer = new int[length]; 
     64      buffer = new TType[length]; 
    6765      for (unsigned int i=0; i<length;i++) 
    6866        buffer[i] = 0; 
     
    7068    } 
    7169    virtual void collect(const PDH::PDHCounter &counter) { 
    72       pushValue(static_cast<int>(counter.getInt64Value())); 
     70      switch (TCollectionFormat) { 
     71        case PDH_FMT_LONG: 
     72          pushValue(counter.getInt64Value()); 
     73          break; 
     74        case PDH_FMT_DOUBLE: 
     75          pushValue(counter.getInt64Value()); 
     76          break; 
     77        default: 
     78          return; 
     79      } 
    7380    } 
    7481    void attach(const PDH::PDHCounter &counter){} 
    7582    void detach(const PDH::PDHCounter &counter){} 
    76     void pushValue(int value) { 
     83    void pushValue(TType value) { 
    7784      if (buffer == NULL) 
    7885        return; 
     
    8390        current = 0; 
    8491    } 
    85     int getAvrage(unsigned int backItems) const { 
     92    TType getAvrage(unsigned int backItems) const { 
    8693      if ((backItems == 0) || (backItems >= length)) 
    8794        return -1; 
     
    98105          ret += buffer[i]; 
    99106      } 
    100       return static_cast<int>(ret/backItems); 
     107      return (ret/backItems); 
    101108    } 
    102109    inline unsigned int getLength() const { 
    103110      return length; 
    104111    } 
     112    DWORD getFormat() const { 
     113      return TCollectionFormat; 
     114    } 
    105115  }; 
    106116 
  • trunk/include/PDHCounter.h

    r7da80b5 re93e741  
    2323    virtual void attach(const PDHCounter &counter) = 0; 
    2424    virtual void detach(const PDHCounter &counter) = 0; 
     25    virtual DWORD getFormat() const = 0; 
    2526  }; 
    2627 
     
    7273        return; 
    7374      PDH_STATUS status; 
    74       if ((status = PdhGetFormattedCounterValue(hCounter_, PDH_FMT_LARGE , NULL, &data_)) != ERROR_SUCCESS) 
     75      if (!listener_) 
     76        return; 
     77      if ((status = PdhGetFormattedCounterValue(hCounter_, listener_->getFormat(), NULL, &data_)) != ERROR_SUCCESS) 
    7578        throw PDHException("PdhGetFormattedCounterValue failed", status); 
    76       if (listener_) 
    77         listener_->collect(*this); 
     79      listener_->collect(*this); 
    7880    } 
    7981    double getDoubleValue() const { 
  • trunk/include/strEx.h

    rf896cfb re93e741  
    4040  } 
    4141  inline std::string itos(unsigned long i) { 
     42    std::stringstream ss; 
     43    ss << i; 
     44    return ss.str(); 
     45  } 
     46  inline std::string itos(double i) { 
    4247    std::stringstream ss; 
    4348    ss << i; 
  • trunk/include/utils.h

    rf896cfb re93e741  
    2222      return strEx::itos(value) + "%"; 
    2323    } 
     24    static std::string print_unformated(TType value) { 
     25      return strEx::itos(value); 
     26    } 
    2427  }; 
    2528 
     
    3437    } 
    3538    static std::string print(TType value) { 
     39      return strEx::itos(value); 
     40    } 
     41    static std::string print_unformated(TType value) { 
    3642      return strEx::itos(value); 
    3743    } 
     
    5460 
    5561    Size() : bHasBounds_(false), value_(0) {}; 
     62 
     63    Size(const Size & other) { 
     64      bHasBounds_ = other.bHasBounds_; 
     65      value_ = other.value_; 
     66    } 
     67 
    5668    void set(std::string s) { 
    5769      value_ = THandler::parse(s); 
     
    101113 
    102114    SizePercentage() : type_(none), value_(0) {}; 
     115 
     116    SizePercentage(const SizePercentage &other) { 
     117      type_ = other.type_; 
     118      value_ = other.value_; 
     119    }; 
    103120    void set(std::string s) { 
    104121      std::string::size_type p = s.find_first_of('%'); 
     
    159176    typedef SizeMaxMin<TType, THandler, THolder> TMyType; 
    160177 
     178    SizeMaxMin() {} 
     179    SizeMaxMin(const SizeMaxMin &other) { 
     180      max = other.max; 
     181      min = other.min; 
     182    } 
     183 
    161184    std::string printPerfData() 
    162185    { 
    163186      if (max.hasBounds()) { 
    164         return THandler::print(max.value_) + ";"; 
     187        return THandler::print_unformated(max.value_) + ";"; 
    165188      } else if (min.hasBounds()) { 
    166         return THandler::print(min.value_) + ";"; 
     189        return THandler::print_unformated(min.value_) + ";"; 
    167190      } 
    168191      return "0;"; 
     
    180203    THolder min; 
    181204    typedef SizeMaxMinPercentage<TType, THandler, THolder> TMyType; 
     205 
     206    SizeMaxMinPercentage() {} 
     207    SizeMaxMinPercentage(const SizeMaxMinPercentage &other) { 
     208      max = other.max; 
     209      min = other.min; 
     210    } 
    182211 
    183212    bool isPercentage() { 
     
    207236        if (max.hasBounds()) { 
    208237          if (max.isPercentage()) { 
    209             return THandler::print((max.value_*total)/100) + ";"; 
    210           } else { 
    211             return THandler::print(max.value_) + ";"; 
     238            return THandler::print_unformated((max.value_*total)/100) + ";"; 
     239          } else { 
     240            return THandler::print_unformated(max.value_) + ";"; 
    212241          } 
    213242        } else if (min.hasBounds()) { 
    214243          if (min.isPercentage()) { 
    215             return THandler::print((min.value_*total)/100) + ";"; 
    216           } else { 
    217             return THandler::print(min.value_) + ";"; 
     244            return THandler::print_unformated((min.value_*total)/100) + ";"; 
     245          } else { 
     246            return THandler::print_unformated(min.value_) + ";"; 
    218247          } 
    219248        } 
     
    236265 
    237266  }; 
    238 /* 
    239   template <typename TType = drive_size, class THandler = drive_size_handler<>, class THolder = SizeMaxMinPercentage<> >  
    240   class PerformancePrinterPercentage { 
    241   public: 
    242     static std::string printPerf(std::string name, TType value, TType total, THolder &warn, THolder &crit) 
    243     { 
    244       std::string s; 
    245       bool percentage = crit.isPercentage()  || warn.isPercentage(); 
    246       if (percentage) 
    247         s += name + "=" + strEx::itos(value*100/total)+ "% "; 
    248       else 
    249         s+= name + "=" + strEx::itos(value) + ";"; 
    250       s += warn.printPerfData(percentage, value, total); 
    251       s += crit.printPerfData(percentage, value, total); 
    252       s += " "; 
    253       return s; 
    254     } 
    255   }; 
    256   template <typename TType = drive_size, class THandler = drive_size_handler<>, class THolder = SizeMaxMin<> >  
    257   class PerformancePrinter { 
    258   public: 
    259     static std::string printPerf(std::string name, TType value, THolder &warn, THolder &crit) 
    260     { 
    261       return name + "=" + strEx::itos(value) + ";" + warn.printPerfData() + crit.printPerfData(); 
    262     } 
    263   }; 
    264 */ 
    265267} 
    266268void generate_crc32_table(void); 
  • trunk/modules/CheckDisk/CheckDisk.cpp

    r7da80b5 re93e741  
    8383} 
    8484 
    85  
    86 #define MY_FILTER_UNKNOWN     0 
    87 #define MY_FILTER_NO_ROOT_DIR 1 
    88 #define MY_FILTER_REMOVABLE   2 
    89 #define MY_FILTER_FIXED       4 
    90 #define MY_FILTER_REMOTE      8 
    91 #define MY_FILTER_CDROM       16 
    92 #define MY_FILTER_RAMDISK     32 
     85struct DriveConatiner { 
     86  checkHolders::SizeMaxMinPercentage<> warn_; 
     87  checkHolders::SizeMaxMinPercentage<> crit_; 
     88  std::string drive_; 
     89  DriveConatiner(std::string drive, checkHolders::SizeMaxMinPercentage<> warn, checkHolders::SizeMaxMinPercentage<> crit)  
     90    : drive_(drive), warn_(warn), crit_(crit)  
     91  {} 
     92}; 
    9393 
    9494NSCAPI::nagiosReturn CheckDisk::CheckDriveSize(const unsigned int argLen, char **char_args, std::string &message, std::string &perf) { 
     
    111111  bool bFilterFixed = false; 
    112112  bool bFilterCDROM = false; 
    113   std::list<std::string> drives; 
     113  std::list<DriveConatiner> drives; 
    114114 
    115115  std::list<std::string>::const_iterator cit; 
     
    118118    std::pair<std::string,std::string> p = strEx::split(arg,"="); 
    119119    if (p.first == "Drive") { 
    120       drives.push_back(p.second); 
     120      drives.push_back(DriveConatiner(p.second, warn, crit)); 
    121121    } else if (p.first == "MaxWarn") { 
    122122      warn.max.set(p.second); 
     
    145145      bCheckAll = true; 
    146146    } else { 
    147       drives.push_back(p.first); 
     147      drives.push_back(DriveConatiner(p.first, warn, crit)); 
    148148    } 
    149149  } 
     
    158158        UINT drvType = GetDriveType(drv.c_str()); 
    159159        if ((!bFilter)&&(drvType == DRIVE_FIXED)) { 
    160           drives.push_back(drv); 
     160          drives.push_back(DriveConatiner(drv, warn, crit)); 
    161161        } else if ((bFilter)&&(bFilterFixed)&&(drvType==DRIVE_FIXED)) { 
    162           drives.push_back(drv); 
     162          drives.push_back(DriveConatiner(drv, warn, crit)); 
    163163        } else if ((bFilter)&&(bFilterCDROM)&&(drvType==DRIVE_CDROM)) { 
    164           drives.push_back(drv); 
     164          drives.push_back(DriveConatiner(drv, warn, crit)); 
    165165        } else if ((bFilter)&&(bFilterRemote)&&(drvType==DRIVE_REMOTE)) { 
    166           drives.push_back(drv); 
     166          drives.push_back(DriveConatiner(drv, warn, crit)); 
    167167        } else if ((bFilter)&&(bFilterRemovable)&&(drvType==DRIVE_REMOVABLE)) { 
    168           drives.push_back(drv); 
     168          drives.push_back(DriveConatiner(drv, warn, crit)); 
    169169        } 
    170170      } 
     
    174174  } 
    175175 
    176   for (std::list<std::string>::iterator it = drives.begin();it!=drives.end();it++) { 
    177     std::string drive = (*it); 
    178     if (drive.length() == 1) 
    179       drive += ":"; 
    180     UINT drvType = GetDriveType(drive.c_str()); 
     176  for (std::list<DriveConatiner>::iterator it = drives.begin();it!=drives.end();it++) { 
     177    DriveConatiner drive = (*it); 
     178    if (drive.drive_.length() == 1) 
     179      drive.drive_ += ":"; 
     180    UINT drvType = GetDriveType(drive.drive_.c_str()); 
    181181 
    182182    if ((!bFilter)&&(drvType != DRIVE_FIXED)) { 
    183       message = "UNKNOWN: Drive is not a fixed drive: " + drive + " (it is a: " + strEx::itos(drvType) + ")"; 
     183      message = "UNKNOWN: Drive is not a fixed drive: " + drive.drive_ + " (it is a: " + strEx::itos(drvType) + ")"; 
    184184      return NSCAPI::returnUNKNOWN; 
    185185    } else if ((bFilter)&&(!bFilterFixed)&&(drvType==DRIVE_FIXED)) { 
    186       message = "UNKNOWN: Drive does not match the current filter: " + drive + " (it is a: " + strEx::itos(drvType) + ")"; 
     186      message = "UNKNOWN: Drive does not match the current filter: " + drive.drive_ + " (it is a: " + strEx::itos(drvType) + ")"; 
    187187      return NSCAPI::returnUNKNOWN; 
    188188    } else if ((bFilter)&&(!bFilterCDROM)&&(drvType==DRIVE_CDROM)) { 
    189       message = "UNKNOWN: Drive does not match the current filter: " + drive + " (it is a: " + strEx::itos(drvType) + ")"; 
     189      message = "UNKNOWN: Drive does not match the current filter: " + drive.drive_ + " (it is a: " + strEx::itos(drvType) + ")"; 
    190190      return NSCAPI::returnUNKNOWN; 
    191191    } else if ((bFilter)&&(!bFilterRemote)&&(drvType==DRIVE_REMOTE)) { 
    192       message = "UNKNOWN: Drive does not match the current filter: " + drive + " (it is a: " + strEx::itos(drvType) + ")"; 
     192      message = "UNKNOWN: Drive does not match the current filter: " + drive.drive_ + " (it is a: " + strEx::itos(drvType) + ")"; 
    193193      return NSCAPI::returnUNKNOWN; 
    194194    } else if ((bFilter)&&(!bFilterRemovable)&&(drvType==DRIVE_REMOVABLE)) { 
    195       message = "UNKNOWN: Drive does not match the current filter: " + drive + " (it is a: " + strEx::itos(drvType) + ")"; 
     195      message = "UNKNOWN: Drive does not match the current filter: " + drive.drive_ + " (it is a: " + strEx::itos(drvType) + ")"; 
    196196      return NSCAPI::returnUNKNOWN; 
    197197    } 
     
    200200    ULARGE_INTEGER totalNumberOfBytes; 
    201201    ULARGE_INTEGER totalNumberOfFreeBytes; 
    202     if (!GetDiskFreeSpaceEx(drive.c_str(), &freeBytesAvailableToCaller, &totalNumberOfBytes, &totalNumberOfFreeBytes)) { 
    203       message = "UNKNOWN: Could not get free space for: " + drive; 
     202    if (!GetDiskFreeSpaceEx(drive.drive_.c_str(), &freeBytesAvailableToCaller, &totalNumberOfBytes, &totalNumberOfFreeBytes)) { 
     203      message = "UNKNOWN: Could not get free space for: " + drive.drive_; 
    204204      return NSCAPI::returnUNKNOWN; 
    205205    } 
     
    216216      checkHolders::drive_size usedSpace = totalNumberOfBytes.QuadPart-totalNumberOfFreeBytes.QuadPart; 
    217217      checkHolders::drive_size totalSpace = totalNumberOfBytes.QuadPart; 
    218       if (crit.max.hasBounds() && crit.max.checkMAX(usedSpace, totalSpace)) { 
    219         tStr += crit.max.prettyPrint(drive, usedSpace, totalSpace) + " > critical"; 
     218      if (drive.crit_.max.hasBounds() && drive.crit_.max.checkMAX(usedSpace, totalSpace)) { 
     219        tStr += drive.crit_.max.prettyPrint(drive.drive_, usedSpace, totalSpace) + " > critical"; 
    220220        NSCHelper::escalteReturnCodeToCRIT(returnCode); 
    221       } else if (crit.min.hasBounds() && crit.min.checkMIN(usedSpace, totalSpace)) { 
    222         tStr = crit.min.prettyPrint(drive, usedSpace, totalSpace) + " < critical"; 
     221      } else if (drive.crit_.min.hasBounds() && drive.crit_.min.checkMIN(usedSpace, totalSpace)) { 
     222        tStr = drive.crit_.min.prettyPrint(drive.drive_, usedSpace, totalSpace) + " < critical"; 
    223223        NSCHelper::escalteReturnCodeToCRIT(returnCode); 
    224       } else if (warn.max.hasBounds() && warn.max.checkMAX(usedSpace, totalSpace)) { 
    225         tStr = warn.max.prettyPrint(drive, usedSpace, totalSpace) + " > warning"; 
     224      } else if (drive.warn_.max.hasBounds() && drive.warn_.max.checkMAX(usedSpace, totalSpace)) { 
     225        tStr = drive.warn_.max.prettyPrint(drive.drive_, usedSpace, totalSpace) + " > warning"; 
    226226        NSCHelper::escalteReturnCodeToWARN(returnCode); 
    227       } else if (warn.min.hasBounds() && warn.min.checkMIN(usedSpace, totalSpace)) { 
    228         tStr = warn.min.prettyPrint(drive, usedSpace, totalSpace) + " < warning"; 
     227      } else if (drive.warn_.min.hasBounds() && drive.warn_.min.checkMIN(usedSpace, totalSpace)) { 
     228        tStr = drive.warn_.min.prettyPrint(drive.drive_, usedSpace, totalSpace) + " < warning"; 
    229229        NSCHelper::escalteReturnCodeToWARN(returnCode); 
    230230      } else if (bShowAll) { 
    231         tStr = drive + ": " + strEx::itos_as_BKMG(usedSpace); 
    232       } 
    233       perf += checkHolders::SizeMaxMinPercentage<>::printPerf(drive, usedSpace, totalSpace, warn, crit); 
     231        tStr = drive.drive_ + ": " + strEx::itos_as_BKMG(usedSpace); 
     232      } 
     233      perf += checkHolders::SizeMaxMinPercentage<>::printPerf(drive.drive_, usedSpace, totalSpace, drive.warn_, drive.crit_); 
    234234      if (!message.empty() && !tStr.empty()) 
    235235        message += ", "; 
     
    245245} 
    246246 
     247struct PathConatiner { 
     248  checkHolders::SizeMaxMin<> warn_; 
     249  checkHolders::SizeMaxMin<> crit_; 
     250  std::string drive_; 
     251  std::string alias_; 
     252  PathConatiner(std::string drive, checkHolders::SizeMaxMin<> warn, checkHolders::SizeMaxMin<> crit)  
     253    : drive_(drive), warn_(warn), crit_(crit)  
     254  {} 
     255  PathConatiner(std::string drive, std::string alias, checkHolders::SizeMaxMin<> warn, checkHolders::SizeMaxMin<> crit)  
     256    : drive_(drive), alias_(alias), warn_(warn), crit_(crit)  
     257  {} 
     258  std::string getPath() { 
     259    return drive_; 
     260  } 
     261  std::string getName() { 
     262    if (alias_.empty()) 
     263      return drive_; 
     264    return alias_; 
     265  } 
     266}; 
     267 
    247268NSCAPI::nagiosReturn CheckDisk::CheckFileSize(const unsigned int argLen, char **char_args, std::string &message, std::string &perf) { 
    248   // CheckFileSize 
    249   // request: CheckFileSize <option> <option>... 
    250   // <option>     MaxWarn=<size gmkb> 
    251   //          MaxCrit=<size gmkb> 
    252   //          MinWarn=<size gmkb> 
    253   //          MinCrit=<size gmkb> 
    254   //          ShowAll 
    255   //          File=<path> 
    256   //          File:<shortname>=<path> 
    257   // 
    258   // Return: <return state>&<return string>... 
    259   // <return state> 0 - No errors 
    260   //          1 - Unknown 
    261   //          2 - Errors 
    262   // <size gmkb> is a size with a possible modifier letter (such as G for gigabyte, M for Megabyte, K for kilobyte etc) 
    263   // Examples: 
    264   // <return string>  <directory> <size gmkb> ... |<shortname>=<size>:<warn>:<crit> 
    265   // test: CheckFileSize ShowAll MaxWarn=1024M MaxCrit=4096M File:WIN=c:\WINDOWS\*.* 
    266   //       CheckFileSize 
    267   // 
    268   // check_nscp -H <ip> -p <port> -s <passwd> -c <commandstring> 
    269   // 
    270   // ./check_nscp -H 192.168.0.167 -p 1234 -s pwd -c 'CheckFileSize&ShowAll&MaxWarn=1024M&MaxCrit=4096M&File:WIN=c:\WINDOWS\*.*' 
    271   // WIN: 1G (2110962363B)|WIN:2110962363:1073741824:4294967296 
    272269  NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 
    273270  std::list<std::string> args = arrayBuffer::arrayBuffer2list(argLen, char_args); 
     
    276273    return NSCAPI::returnCRIT; 
    277274  } 
    278   long long maxWarn = 0; 
    279   long long maxCrit = 0; 
    280   long long minWarn = 0; 
    281   long long minCrit = 0; 
     275  checkHolders::SizeMaxMin<> crit; 
     276  checkHolders::SizeMaxMin<> warn; 
    282277  bool bShowAll = false; 
    283   std::list<std::pair<std::string,std::string> > paths; 
     278  std::list<PathConatiner> paths; 
    284279 
    285280  std::list<std::string>::const_iterator cit; 
     
    288283    std::pair<std::string,std::string> p = strEx::split(arg,"="); 
    289284    if (p.first == "File") { 
    290       paths.push_back(std::pair<std::string,std::string>("",p.second)); 
     285      paths.push_back(PathConatiner(p.second, warn, crit)); 
    291286    } else if (p.first == "MaxWarn") { 
    292       maxWarn = strEx::stoi64_as_BKMG(p.second); 
     287      warn.max.set(p.second); 
    293288    } else if (p.first == "MinWarn") { 
    294       minWarn = strEx::stoi64_as_BKMG(p.second); 
     289      warn.min.set(p.second); 
    295290    } else if (p.first == "MaxCrit") { 
    296       maxCrit = strEx::stoi64_as_BKMG(p.second); 
     291      crit.max.set(p.second); 
    297292    } else if (p.first == "MinCrit") { 
    298       minCrit = strEx::stoi64_as_BKMG(p.second); 
     293      crit.min.set(p.second); 
    299294    } else if (p.first == SHOW_ALL) { 
    300295      bShowAll = true; 
     
    302297      std::pair<std::string,std::string> p2 = strEx::split(p.first,":"); 
    303298      if (p2.first == "File") { 
    304         paths.push_back(std::pair<std::string,std::string>(p2.second,p.second)); 
     299        paths.push_back(PathConatiner(p.second, p2.second, warn, crit)); 
    305300      } else { 
    306301        message = "Unknown command: " + p.first; 
     
    313308  } 
    314309 
    315   std::list<std::pair<std::string,std::string> >::const_iterator pit; 
     310  std::list<PathConatiner>::const_iterator pit; 
    316311  for (pit = paths.begin(); pit != paths.end(); ++pit) { 
     312    PathConatiner path = (*pit); 
    317313    std::string tstr; 
    318314    GetSize sizeFinder; 
    319     std::string sName = (*pit).first; 
    320     if (sName.empty()) 
    321       sName = (*pit).second; 
    322     RecursiveScanDirectory((*pit).second, sizeFinder); 
    323  
    324     if ((maxCrit!=0) && (sizeFinder.getSize() > maxCrit)) { 
    325       tstr = sName + ": " + strEx::itos_as_BKMG(sizeFinder.getSize()); 
    326       returnCode = NSCAPI::returnCRIT; 
    327     } else if (sizeFinder.getSize() < minCrit) { 
    328       tstr = sName + ": " + strEx::itos_as_BKMG(sizeFinder.getSize()); 
     315    std::string sName = path.getName(); 
     316    RecursiveScanDirectory(path.getPath(), sizeFinder); 
     317 
     318    if (path.crit_.max.hasBounds() && path.crit_.max.checkMAX(sizeFinder.getSize())) { 
     319      tstr += path.crit_.max.prettyPrint(sName, sizeFinder.getSize()) + " > critical"; 
    329320      NSCHelper::escalteReturnCodeToCRIT(returnCode); 
    330     } else if ((maxWarn!=0)&&(sizeFinder.getSize() > maxWarn)) { 
    331       tstr = sName +  ": " + strEx::itos_as_BKMG(sizeFinder.getSize()); 
     321    } else if (path.crit_.min.hasBounds() && path.crit_.min.checkMIN(sizeFinder.getSize())) { 
     322      tstr += path.crit_.min.prettyPrint(sName, sizeFinder.getSize()) + " < critical"; 
     323      NSCHelper::escalteReturnCodeToCRIT(returnCode); 
     324    } else if (path.warn_.max.hasBounds() && path.warn_.max.checkMAX(sizeFinder.getSize())) { 
     325      tstr += path.warn_.max.prettyPrint(sName, sizeFinder.getSize()) + " > warning"; 
    332326      NSCHelper::escalteReturnCodeToWARN(returnCode); 
    333     } else if (sizeFinder.getSize() < minWarn) { 
    334       tstr = sName +  ": " + strEx::itos_as_BKMG(sizeFinder.getSize()); 
     327    } else if (path.warn_.min.hasBounds() && path.warn_.min.checkMIN(sizeFinder.getSize())) { 
     328      tstr += path.warn_.min.prettyPrint(sName, sizeFinder.getSize()) + " < warning"; 
    335329      NSCHelper::escalteReturnCodeToWARN(returnCode); 
    336330    } else if (bShowAll) { 
    337331      tstr = sName +  ": " + strEx::itos_as_BKMG(sizeFinder.getSize()); 
    338332    } 
    339     if (!(*pit).first.empty()) 
    340       perf += (*pit).first + "=" + strEx::itos(sizeFinder.getSize()) + ";" + strEx::itos(maxWarn) + ";" + strEx::itos(maxCrit) + " "; 
     333    perf += checkHolders::SizeMaxMin<>::printPerf(sName, sizeFinder.getSize(), path.warn_, path.crit_); 
    341334    if (!message.empty() && !tstr.empty()) 
    342335      message += ", "; 
    343336    if (!tstr.empty()) 
    344       message += tstr; 
     337      message = tstr; 
    345338  } 
    346339  if (message.empty()) 
     
    351344} 
    352345 
    353  
    354 #define BUFFER_SIZE 1024*64 
    355  
    356346NSCAPI::nagiosReturn CheckDisk::handleCommand(const strEx::blindstr command, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) { 
    357347  if (command == "CheckFileSize") { 
  • trunk/modules/CheckSystem/CheckSystem.cpp

    r7da80b5 re93e741  
    593593    try { 
    594594      PDH::PDHQuery pdh; 
    595       PDHCollectors::StaticPDHCounterListenerInt counter; 
     595      PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> counter; 
    596596      std::string name = (*it).first; 
    597597      if (name.empty()) 
     
    601601      pdh.collect(); 
    602602      if (bNSCLientCompatible) { 
    603 //        std::cout << counter.getValue() << std::endl; 
    604603        msg += strEx::itos(counter.getValue()); 
    605604      } else { 
     
    632631  if (msg.empty()) 
    633632    msg = "OK all counters within bounds."; 
    634   else 
     633  else if (!bNSCLientCompatible) 
    635634    msg = NSCHelper::translateReturn(returnCode) + ": " + msg; 
    636635  return returnCode; 
  • trunk/modules/CheckSystem/PDHCollector.cpp

    r7da80b5 re93e741  
    5050*/ 
    5151DWORD PDHCollector::threadProc(LPVOID lpParameter) { 
     52  hStopEvent_ = CreateEvent(NULL, TRUE, FALSE, NULL); 
     53  if (!hStopEvent_) { 
     54    NSC_LOG_ERROR_STD("Create StopEvent failed: " + strEx::itos(GetLastError())); 
     55    return 0; 
     56  } 
    5257  PDH::PDHQuery pdh; 
    5358  pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_MEM_PAGE_LIMIT, C_SYSTEM_MEM_PAGE_LIMIT_DEFAULT), &memCmtLim); 
     
    6368  } 
    6469 
    65   hStopEvent_ = CreateEvent(NULL, TRUE, FALSE, NULL); 
    66   if (!hStopEvent_) { 
    67     NSC_LOG_ERROR_STD("Create StopEvent failed: " + strEx::itos(GetLastError())); 
    68     return 0; 
    69   } 
    7070 
    7171  do { 
  • trunk/modules/CheckSystem/PDHCollector.h

    r7da80b5 re93e741  
    3030  int checkIntervall_; 
    3131 
    32   PDHCollectors::StaticPDHCounterListenerInt memCmtLim; 
    33   PDHCollectors::StaticPDHCounterListenerInt memCmt; 
    34   PDHCollectors::StaticPDHCounterListenerInt upTime; 
    35   PDHCollectors::RoundINTPDHBufferListener cpu; 
     32  PDHCollectors::StaticPDHCounterListener<__int64, PDH_FMT_LARGE> memCmtLim; 
     33  PDHCollectors::StaticPDHCounterListener<__int64, PDH_FMT_LARGE> memCmt; 
     34  PDHCollectors::StaticPDHCounterListener<__int64, PDH_FMT_LARGE> upTime; 
     35  PDHCollectors::RoundINTPDHBufferListener<__int64, PDH_FMT_LARGE> cpu; 
    3636 
    3737public: 
  • trunk/modules/NSClientListener/NSClientListener.cpp

    r7da80b5 re93e741  
    180180    case REQ_SERVICESTATE:  // Some check_nt commands return the return code (coded as a string) 
    181181    case REQ_PROCSTATE: 
    182       return NSCHelper::translateReturn(ret) + "&" + message; 
     182      return strEx::itos(NSCHelper::nagios2int(ret)) + "& " + message; 
    183183 
    184184    default:        // "New" check_nscp also returns performance data 
Note: See TracChangeset for help on using the changeset viewer.