- Timestamp:
- 05/29/05 20:58:08 (8 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- e26cfe0
- Parents:
- 1d9338a
- Location:
- modules
- Files:
-
- 5 edited
-
CheckDisk/CheckDisk.cpp (modified) (14 diffs)
-
CheckSystem/CheckSystem.cpp (modified) (3 diffs)
-
CheckSystem/PDHCollector.cpp (modified) (2 diffs)
-
CheckSystem/PDHCollector.h (modified) (1 diff)
-
NSClientListener/NSClientListener.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
modules/CheckDisk/CheckDisk.cpp
r1d9338a r6654022 83 83 } 84 84 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 85 struct 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 }; 93 93 94 94 NSCAPI::nagiosReturn CheckDisk::CheckDriveSize(const unsigned int argLen, char **char_args, std::string &message, std::string &perf) { … … 111 111 bool bFilterFixed = false; 112 112 bool bFilterCDROM = false; 113 std::list< std::string> drives;113 std::list<DriveConatiner> drives; 114 114 115 115 std::list<std::string>::const_iterator cit; … … 118 118 std::pair<std::string,std::string> p = strEx::split(arg,"="); 119 119 if (p.first == "Drive") { 120 drives.push_back( p.second);120 drives.push_back(DriveConatiner(p.second, warn, crit)); 121 121 } else if (p.first == "MaxWarn") { 122 122 warn.max.set(p.second); … … 145 145 bCheckAll = true; 146 146 } else { 147 drives.push_back( p.first);147 drives.push_back(DriveConatiner(p.first, warn, crit)); 148 148 } 149 149 } … … 158 158 UINT drvType = GetDriveType(drv.c_str()); 159 159 if ((!bFilter)&&(drvType == DRIVE_FIXED)) { 160 drives.push_back( drv);160 drives.push_back(DriveConatiner(drv, warn, crit)); 161 161 } else if ((bFilter)&&(bFilterFixed)&&(drvType==DRIVE_FIXED)) { 162 drives.push_back( drv);162 drives.push_back(DriveConatiner(drv, warn, crit)); 163 163 } else if ((bFilter)&&(bFilterCDROM)&&(drvType==DRIVE_CDROM)) { 164 drives.push_back( drv);164 drives.push_back(DriveConatiner(drv, warn, crit)); 165 165 } else if ((bFilter)&&(bFilterRemote)&&(drvType==DRIVE_REMOTE)) { 166 drives.push_back( drv);166 drives.push_back(DriveConatiner(drv, warn, crit)); 167 167 } else if ((bFilter)&&(bFilterRemovable)&&(drvType==DRIVE_REMOVABLE)) { 168 drives.push_back( drv);168 drives.push_back(DriveConatiner(drv, warn, crit)); 169 169 } 170 170 } … … 174 174 } 175 175 176 for (std::list< std::string>::iterator it = drives.begin();it!=drives.end();it++) {177 std::stringdrive = (*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()); 181 181 182 182 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) + ")"; 184 184 return NSCAPI::returnUNKNOWN; 185 185 } 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) + ")"; 187 187 return NSCAPI::returnUNKNOWN; 188 188 } 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) + ")"; 190 190 return NSCAPI::returnUNKNOWN; 191 191 } 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) + ")"; 193 193 return NSCAPI::returnUNKNOWN; 194 194 } 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) + ")"; 196 196 return NSCAPI::returnUNKNOWN; 197 197 } … … 200 200 ULARGE_INTEGER totalNumberOfBytes; 201 201 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_; 204 204 return NSCAPI::returnUNKNOWN; 205 205 } … … 216 216 checkHolders::drive_size usedSpace = totalNumberOfBytes.QuadPart-totalNumberOfFreeBytes.QuadPart; 217 217 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"; 220 220 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"; 223 223 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"; 226 226 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"; 229 229 NSCHelper::escalteReturnCodeToWARN(returnCode); 230 230 } 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_); 234 234 if (!message.empty() && !tStr.empty()) 235 235 message += ", "; … … 245 245 } 246 246 247 struct 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 247 268 NSCAPI::nagiosReturn CheckDisk::CheckFileSize(const unsigned int argLen, char **char_args, std::string &message, std::string &perf) { 248 // CheckFileSize249 // request: CheckFileSize <option> <option>...250 // <option> MaxWarn=<size gmkb>251 // MaxCrit=<size gmkb>252 // MinWarn=<size gmkb>253 // MinCrit=<size gmkb>254 // ShowAll255 // File=<path>256 // File:<shortname>=<path>257 //258 // Return: <return state>&<return string>...259 // <return state> 0 - No errors260 // 1 - Unknown261 // 2 - Errors262 // <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 // CheckFileSize267 //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:4294967296272 269 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 273 270 std::list<std::string> args = arrayBuffer::arrayBuffer2list(argLen, char_args); … … 276 273 return NSCAPI::returnCRIT; 277 274 } 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; 282 277 bool bShowAll = false; 283 std::list< std::pair<std::string,std::string>> paths;278 std::list<PathConatiner> paths; 284 279 285 280 std::list<std::string>::const_iterator cit; … … 288 283 std::pair<std::string,std::string> p = strEx::split(arg,"="); 289 284 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)); 291 286 } else if (p.first == "MaxWarn") { 292 maxWarn = strEx::stoi64_as_BKMG(p.second);287 warn.max.set(p.second); 293 288 } else if (p.first == "MinWarn") { 294 minWarn = strEx::stoi64_as_BKMG(p.second);289 warn.min.set(p.second); 295 290 } else if (p.first == "MaxCrit") { 296 maxCrit = strEx::stoi64_as_BKMG(p.second);291 crit.max.set(p.second); 297 292 } else if (p.first == "MinCrit") { 298 minCrit = strEx::stoi64_as_BKMG(p.second);293 crit.min.set(p.second); 299 294 } else if (p.first == SHOW_ALL) { 300 295 bShowAll = true; … … 302 297 std::pair<std::string,std::string> p2 = strEx::split(p.first,":"); 303 298 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)); 305 300 } else { 306 301 message = "Unknown command: " + p.first; … … 313 308 } 314 309 315 std::list< std::pair<std::string,std::string>>::const_iterator pit;310 std::list<PathConatiner>::const_iterator pit; 316 311 for (pit = paths.begin(); pit != paths.end(); ++pit) { 312 PathConatiner path = (*pit); 317 313 std::string tstr; 318 314 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"; 329 320 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"; 332 326 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"; 335 329 NSCHelper::escalteReturnCodeToWARN(returnCode); 336 330 } else if (bShowAll) { 337 331 tstr = sName + ": " + strEx::itos_as_BKMG(sizeFinder.getSize()); 338 332 } 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_); 341 334 if (!message.empty() && !tstr.empty()) 342 335 message += ", "; 343 336 if (!tstr.empty()) 344 message += tstr;337 message = tstr; 345 338 } 346 339 if (message.empty()) … … 351 344 } 352 345 353 354 #define BUFFER_SIZE 1024*64355 356 346 NSCAPI::nagiosReturn CheckDisk::handleCommand(const strEx::blindstr command, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) { 357 347 if (command == "CheckFileSize") { -
modules/CheckSystem/CheckSystem.cpp
r1d9338a r6654022 593 593 try { 594 594 PDH::PDHQuery pdh; 595 PDHCollectors::StaticPDHCounterListener Intcounter;595 PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> counter; 596 596 std::string name = (*it).first; 597 597 if (name.empty()) … … 601 601 pdh.collect(); 602 602 if (bNSCLientCompatible) { 603 // std::cout << counter.getValue() << std::endl;604 603 msg += strEx::itos(counter.getValue()); 605 604 } else { … … 632 631 if (msg.empty()) 633 632 msg = "OK all counters within bounds."; 634 else 633 else if (!bNSCLientCompatible) 635 634 msg = NSCHelper::translateReturn(returnCode) + ": " + msg; 636 635 return returnCode; -
modules/CheckSystem/PDHCollector.cpp
r1d9338a r6654022 50 50 */ 51 51 DWORD 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 } 52 57 PDH::PDHQuery pdh; 53 58 pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_MEM_PAGE_LIMIT, C_SYSTEM_MEM_PAGE_LIMIT_DEFAULT), &memCmtLim); … … 63 68 } 64 69 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 }70 70 71 71 do { -
modules/CheckSystem/PDHCollector.h
r1d9338a r6654022 30 30 int checkIntervall_; 31 31 32 PDHCollectors::StaticPDHCounterListener IntmemCmtLim;33 PDHCollectors::StaticPDHCounterListener IntmemCmt;34 PDHCollectors::StaticPDHCounterListener IntupTime;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; 36 36 37 37 public: -
modules/NSClientListener/NSClientListener.cpp
r1d9338a r6654022 180 180 case REQ_SERVICESTATE: // Some check_nt commands return the return code (coded as a string) 181 181 case REQ_PROCSTATE: 182 return NSCHelper::translateReturn(ret) + "&" + message;182 return strEx::itos(NSCHelper::nagios2int(ret)) + "& " + message; 183 183 184 184 default: // "New" check_nscp also returns performance data
Note: See TracChangeset
for help on using the changeset viewer.








