Changeset 6654022 in nscp for modules


Ignore:
Timestamp:
05/29/05 20:58:08 (8 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
e26cfe0
Parents:
1d9338a
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:
modules
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • modules/CheckDisk/CheckDisk.cpp

    r1d9338a r6654022  
    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") { 
  • modules/CheckSystem/CheckSystem.cpp

    r1d9338a r6654022  
    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; 
  • modules/CheckSystem/PDHCollector.cpp

    r1d9338a r6654022  
    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 { 
  • modules/CheckSystem/PDHCollector.h

    r1d9338a r6654022  
    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: 
  • modules/NSClientListener/NSClientListener.cpp

    r1d9338a r6654022  
    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.