Changeset e93e741 in nscp
- Timestamp:
- 05/29/05 20:58:08 (8 years ago)
- Children:
- 24f7192
- Parents:
- 7da80b5
- Location:
- trunk
- Files:
-
- 11 edited
-
changelog (modified) (1 diff)
-
docs/CheckDisk/index.html (modified) (2 diffs)
-
include/PDHCollectors.h (modified) (5 diffs)
-
include/PDHCounter.h (modified) (2 diffs)
-
include/strEx.h (modified) (1 diff)
-
include/utils.h (modified) (8 diffs)
-
modules/CheckDisk/CheckDisk.cpp (modified) (14 diffs)
-
modules/CheckSystem/CheckSystem.cpp (modified) (3 diffs)
-
modules/CheckSystem/PDHCollector.cpp (modified) (2 diffs)
-
modules/CheckSystem/PDHCollector.h (modified) (1 diff)
-
modules/NSClientListener/NSClientListener.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/changelog
r7da80b5 re93e741 1 2005-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 1 6 2005-05-23 MickeM 2 7 + Added obfuscated password support -
trunk/docs/CheckDisk/index.html
r7da80b5 re93e741 33 33 <h2>CheckFileSize</h2> 34 34 <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> 36 39 <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" id="table5"> 37 40 <tr> … … 127 130 </div> 128 131 </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> command_name CheckMyFiles </p> 139 <p> 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> check_command CheckMyFiles</p> 143 </div> 144 </li> 129 145 </ul> 130 146 </div> 131 147 <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> 132 154 <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" id="table6"> 133 155 <tr> -
trunk/include/PDHCollectors.h
r7da80b5 re93e741 4 4 5 5 namespace 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_; 8 9 public: 9 10 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 } 11 21 } 12 22 void attach(const PDH::PDHCounter &counter){} 13 23 void detach(const PDH::PDHCounter &counter){} 14 void setValue( __int64value) {24 void setValue(TType value) { 15 25 value_ = value; 16 26 } 17 __int64getValue() const {27 TType getValue() const { 18 28 return value_; 19 29 } 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; 34 32 } 35 33 }; 36 34 37 35 template <class TType = __int64, DWORD TCollectionFormat = PDH_FMT_LARGE> 38 36 class RoundINTPDHBufferListener : public PDH::PDHCounterListener { 39 37 unsigned int length; 40 int*buffer;38 TType *buffer; 41 39 unsigned int current; 42 40 public: … … 64 62 length = newLength; 65 63 66 buffer = new int[length];64 buffer = new TType[length]; 67 65 for (unsigned int i=0; i<length;i++) 68 66 buffer[i] = 0; … … 70 68 } 71 69 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 } 73 80 } 74 81 void attach(const PDH::PDHCounter &counter){} 75 82 void detach(const PDH::PDHCounter &counter){} 76 void pushValue( intvalue) {83 void pushValue(TType value) { 77 84 if (buffer == NULL) 78 85 return; … … 83 90 current = 0; 84 91 } 85 intgetAvrage(unsigned int backItems) const {92 TType getAvrage(unsigned int backItems) const { 86 93 if ((backItems == 0) || (backItems >= length)) 87 94 return -1; … … 98 105 ret += buffer[i]; 99 106 } 100 return static_cast<int>(ret/backItems);107 return (ret/backItems); 101 108 } 102 109 inline unsigned int getLength() const { 103 110 return length; 104 111 } 112 DWORD getFormat() const { 113 return TCollectionFormat; 114 } 105 115 }; 106 116 -
trunk/include/PDHCounter.h
r7da80b5 re93e741 23 23 virtual void attach(const PDHCounter &counter) = 0; 24 24 virtual void detach(const PDHCounter &counter) = 0; 25 virtual DWORD getFormat() const = 0; 25 26 }; 26 27 … … 72 73 return; 73 74 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) 75 78 throw PDHException("PdhGetFormattedCounterValue failed", status); 76 if (listener_) 77 listener_->collect(*this); 79 listener_->collect(*this); 78 80 } 79 81 double getDoubleValue() const { -
trunk/include/strEx.h
rf896cfb re93e741 40 40 } 41 41 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) { 42 47 std::stringstream ss; 43 48 ss << i; -
trunk/include/utils.h
rf896cfb re93e741 22 22 return strEx::itos(value) + "%"; 23 23 } 24 static std::string print_unformated(TType value) { 25 return strEx::itos(value); 26 } 24 27 }; 25 28 … … 34 37 } 35 38 static std::string print(TType value) { 39 return strEx::itos(value); 40 } 41 static std::string print_unformated(TType value) { 36 42 return strEx::itos(value); 37 43 } … … 54 60 55 61 Size() : bHasBounds_(false), value_(0) {}; 62 63 Size(const Size & other) { 64 bHasBounds_ = other.bHasBounds_; 65 value_ = other.value_; 66 } 67 56 68 void set(std::string s) { 57 69 value_ = THandler::parse(s); … … 101 113 102 114 SizePercentage() : type_(none), value_(0) {}; 115 116 SizePercentage(const SizePercentage &other) { 117 type_ = other.type_; 118 value_ = other.value_; 119 }; 103 120 void set(std::string s) { 104 121 std::string::size_type p = s.find_first_of('%'); … … 159 176 typedef SizeMaxMin<TType, THandler, THolder> TMyType; 160 177 178 SizeMaxMin() {} 179 SizeMaxMin(const SizeMaxMin &other) { 180 max = other.max; 181 min = other.min; 182 } 183 161 184 std::string printPerfData() 162 185 { 163 186 if (max.hasBounds()) { 164 return THandler::print (max.value_) + ";";187 return THandler::print_unformated(max.value_) + ";"; 165 188 } else if (min.hasBounds()) { 166 return THandler::print (min.value_) + ";";189 return THandler::print_unformated(min.value_) + ";"; 167 190 } 168 191 return "0;"; … … 180 203 THolder min; 181 204 typedef SizeMaxMinPercentage<TType, THandler, THolder> TMyType; 205 206 SizeMaxMinPercentage() {} 207 SizeMaxMinPercentage(const SizeMaxMinPercentage &other) { 208 max = other.max; 209 min = other.min; 210 } 182 211 183 212 bool isPercentage() { … … 207 236 if (max.hasBounds()) { 208 237 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_) + ";"; 212 241 } 213 242 } else if (min.hasBounds()) { 214 243 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_) + ";"; 218 247 } 219 248 } … … 236 265 237 266 }; 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 else249 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 */265 267 } 266 268 void generate_crc32_table(void); -
trunk/modules/CheckDisk/CheckDisk.cpp
r7da80b5 re93e741 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") { -
trunk/modules/CheckSystem/CheckSystem.cpp
r7da80b5 re93e741 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; -
trunk/modules/CheckSystem/PDHCollector.cpp
r7da80b5 re93e741 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 { -
trunk/modules/CheckSystem/PDHCollector.h
r7da80b5 re93e741 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: -
trunk/modules/NSClientListener/NSClientListener.cpp
r7da80b5 re93e741 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.








