Changeset 5d8e0b5 in nscp for trunk/modules/CheckDisk
- Timestamp:
- 04/19/05 00:50:16 (8 years ago)
- Children:
- ae192e3
- Parents:
- ce6eabf
- Location:
- trunk/modules/CheckDisk
- Files:
-
- 3 edited
-
CheckDisk.cpp (modified) (4 diffs)
-
CheckDisk.h (modified) (1 diff)
-
CheckDisk.vcproj (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/CheckDisk/CheckDisk.cpp
rf705d34 r5d8e0b5 6 6 #include <strEx.h> 7 7 #include <time.h> 8 #include <utils.h> 8 9 9 10 CheckDisk gCheckDisk; … … 82 83 } 83 84 84 NSCAPI::nagiosReturn CheckDisk::Check FileSize(const unsigned int argLen, char **char_args, std::string &message, std::string &perf) {85 NSCAPI::nagiosReturn CheckDisk::CheckDriveSize(const unsigned int argLen, char **char_args, std::string &message, std::string &perf) { 85 86 // CheckFileSize 86 // request: CheckFileSize &<option>&<option>...87 // request: CheckFileSize <option> <option>... 87 88 // <option> MaxWarn=<size gmkb> 88 89 // MaxCrit=<size gmkb> … … 100 101 // Examples: 101 102 // <return string> <directory> <size gmkb> ... |<shortname>=<size>:<warn>:<crit> 102 // test: CheckFileSize&ShowAll&MaxWarn=1024M&MaxCrit=4096M&File:WIN=c:\WINDOWS\*.* 103 // test: CheckFileSize ShowAll MaxWarn=1024M MaxCrit=4096M File:WIN=c:\WINDOWS\*.* 104 // CheckFileSize 105 // 106 // check_nscp -H <ip> -p <port> -s <passwd> -c <commandstring> 107 // 108 // ./check_nscp -H 192.168.0.167 -p 1234 -s pwd -c 'CheckFileSize&ShowAll&MaxWarn=1024M&MaxCrit=4096M&File:WIN=c:\WINDOWS\*.*' 109 // WIN: 1G (2110962363B)|WIN:2110962363:1073741824:4294967296 110 NSC_DEBUG_MSG("CheckDriveSize"); 111 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 112 std::list<std::string> args = arrayBuffer::arrayBuffer2list(argLen, char_args); 113 if (args.empty()) { 114 message = "Missing argument(s)."; 115 return NSCAPI::returnCRIT; 116 } 117 118 checkHolders::SizeMaxMin warn; 119 checkHolders::SizeMaxMin crit; 120 bool bShowAll = false; 121 bool bNSClient = false; 122 std::list<std::string> drives; 123 124 std::list<std::string>::const_iterator cit; 125 for (cit=args.begin();cit!=args.end();++cit) { 126 std::string arg = *cit; 127 std::pair<std::string,std::string> p = strEx::split(arg,"="); 128 if (p.first == "Drive") { 129 drives.push_back(p.second); 130 } else if (p.first == "MaxWarn") { 131 warn.max.set(p.second); 132 } else if (p.first == "MinWarn") { 133 warn.min.set(p.second); 134 } else if (p.first == "MaxCrit") { 135 crit.max.set(p.second); 136 } else if (p.first == "MinCrit") { 137 crit.min.set(p.second); 138 } else if (p.first == "ShowAll") { 139 bShowAll = true; 140 } else if (p.first == "nsclient") { 141 bNSClient = true; 142 } else { 143 drives.push_back(p.first); 144 } 145 } 146 147 NSC_DEBUG_MSG_STD("Bounds: critical " + crit.min.toString() + " > size > " + crit.max.toString()); 148 NSC_DEBUG_MSG_STD("Bounds: warning " + warn.min.toString() + " > size > " + warn.max.toString()); 149 NSC_DEBUG_MSG_STD("Showall: " + ((bShowAll)?"yeap":"noop")); 150 NSC_DEBUG_MSG_STD("nsclient: " + ((bNSClient)?"yeap":"noop")); 151 152 for (std::list<std::string>::iterator it = drives.begin();it!=drives.end();it++) { 153 std::string drive = (*it); 154 if (drive.length() == 1) 155 drive += ":"; 156 if (GetDriveType(drive.c_str()) != DRIVE_FIXED){ 157 message = "ERROR: Drive is not a fixed drive: " + drive; 158 return NSCAPI::returnUNKNOWN; 159 } 160 ULARGE_INTEGER freeBytesAvailableToCaller; 161 ULARGE_INTEGER totalNumberOfBytes; 162 ULARGE_INTEGER totalNumberOfFreeBytes; 163 if (!GetDiskFreeSpaceEx(drive.c_str(), &freeBytesAvailableToCaller, &totalNumberOfBytes, &totalNumberOfFreeBytes)) { 164 message = "ERROR: Could not get free space for" + drive; 165 return NSCAPI::returnUNKNOWN; 166 } 167 168 if (bNSClient) { 169 message += strEx::itos(totalNumberOfFreeBytes.QuadPart) + "&"; 170 message += strEx::itos(totalNumberOfBytes.QuadPart) + "&"; 171 } else { 172 std::string tStr; 173 long long usedSpace = totalNumberOfBytes.QuadPart-totalNumberOfFreeBytes.QuadPart; 174 long long totalSpace = totalNumberOfBytes.QuadPart; 175 if (crit.max.hasBounds() && crit.max.checkMAX(usedSpace, totalSpace)) { 176 message += crit.max.prettyPrint(drive, usedSpace, totalSpace); 177 NSCHelper::escalteReturnCodeToCRIT(returnCode); 178 } else if (crit.min.hasBounds() && crit.min.checkMIN(usedSpace, totalSpace)) { 179 tStr = crit.min.prettyPrint(drive, usedSpace, totalSpace); 180 NSCHelper::escalteReturnCodeToCRIT(returnCode); 181 } else if (warn.max.hasBounds() && warn.max.checkMAX(usedSpace, totalSpace)) { 182 tStr = warn.max.prettyPrint(drive, usedSpace, totalSpace); 183 NSCHelper::escalteReturnCodeToWARN(returnCode); 184 } else if (warn.min.hasBounds() && warn.min.checkMIN(usedSpace, totalSpace)) { 185 tStr = warn.min.prettyPrint(drive, usedSpace, totalSpace); 186 NSCHelper::escalteReturnCodeToWARN(returnCode); 187 } else if (bShowAll) { 188 tStr = drive + ": " + strEx::itos_as_BKMG(usedSpace); 189 } 190 perf += checkHolders::SizeMaxMin::printPerf(drive, usedSpace, totalSpace, warn, crit); 191 if (!message.empty() && !tStr.empty()) 192 message += ", "; 193 if (!tStr.empty()) 194 message += tStr; 195 } 196 } 197 if (message.empty()) 198 message = "All drive sizes are within bounds."; 199 return returnCode; 200 } 201 202 NSCAPI::nagiosReturn CheckDisk::CheckFileSize(const unsigned int argLen, char **char_args, std::string &message, std::string &perf) { 203 // CheckFileSize 204 // request: CheckFileSize <option> <option>... 205 // <option> MaxWarn=<size gmkb> 206 // MaxCrit=<size gmkb> 207 // MinWarn=<size gmkb> 208 // MinCrit=<size gmkb> 209 // ShowAll 210 // File=<path> 211 // File:<shortname>=<path> 212 // 213 // Return: <return state>&<return string>... 214 // <return state> 0 - No errors 215 // 1 - Unknown 216 // 2 - Errors 217 // <size gmkb> is a size with a possible modifier letter (such as G for gigabyte, M for Megabyte, K for kilobyte etc) 218 // Examples: 219 // <return string> <directory> <size gmkb> ... |<shortname>=<size>:<warn>:<crit> 220 // test: CheckFileSize ShowAll MaxWarn=1024M MaxCrit=4096M File:WIN=c:\WINDOWS\*.* 103 221 // CheckFileSize 104 222 // … … 196 314 if (command == "CheckFileSize") { 197 315 return CheckFileSize(argLen, char_args, msg, perf); 316 } else if (command == "CheckDriveSize") { 317 return CheckDriveSize(argLen, char_args, msg, perf); 318 198 319 // } else if (command == "CheckFileDate") { 199 320 } -
trunk/modules/CheckDisk/CheckDisk.h
rc515660 r5d8e0b5 18 18 // Check commands 19 19 NSCAPI::nagiosReturn CheckFileSize(const unsigned int argLen, char **char_args, std::string &message, std::string &perf); 20 NSCAPI::nagiosReturn CheckDriveSize(const unsigned int argLen, char **char_args, std::string &message, std::string &perf); 20 21 }; -
trunk/modules/CheckDisk/CheckDisk.vcproj
rebcb766 r5d8e0b5 21 21 Optimization="0" 22 22 AdditionalIncludeDirectories="../include;../../include" 23 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_STLP_USE_ STATIC_LIB;_STLP_USE_NEWALLOC"23 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_STLP_USE_NEWALLOC;_STLP_DEBUG=1" 24 24 MinimalRebuild="TRUE" 25 25 BasicRuntimeChecks="3" 26 RuntimeLibrary=" 1"26 RuntimeLibrary="3" 27 27 UsePrecompiledHeader="3" 28 28 WarningLevel="3" … … 71 71 Name="VCCLCompilerTool" 72 72 AdditionalIncludeDirectories="../include;../../include" 73 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS ;_STLP_USE_STATIC_LIB;SYSTRAY_EXPORTS"74 RuntimeLibrary=" 0"73 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" 74 RuntimeLibrary="2" 75 75 UsePrecompiledHeader="3" 76 76 WarningLevel="3" … … 112 112 </Configuration> 113 113 <Configuration 114 Name="Dynamic Linkage|Win32"115 OutputDirectory="$(ConfigurationName)"116 IntermediateDirectory="$(ConfigurationName)"117 ConfigurationType="2"118 CharacterSet="2">119 <Tool120 Name="VCCLCompilerTool"121 AdditionalIncludeDirectories="../include;../../include"122 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"123 RuntimeLibrary="2"124 UsePrecompiledHeader="3"125 WarningLevel="3"126 Detect64BitPortabilityProblems="TRUE"127 DebugInformationFormat="3"/>128 <Tool129 Name="VCCustomBuildTool"/>130 <Tool131 Name="VCLinkerTool"132 OutputFile="../../Release/modules/$(ProjectName).dll"133 LinkIncremental="1"134 ModuleDefinitionFile="CheckDisk.def"135 GenerateDebugInformation="TRUE"136 SubSystem="2"137 OptimizeReferences="2"138 EnableCOMDATFolding="2"139 ImportLibrary="$(OutDir)/CheckDisk.lib"140 TargetMachine="1"/>141 <Tool142 Name="VCMIDLTool"/>143 <Tool144 Name="VCPostBuildEventTool"/>145 <Tool146 Name="VCPreBuildEventTool"/>147 <Tool148 Name="VCPreLinkEventTool"/>149 <Tool150 Name="VCResourceCompilerTool"/>151 <Tool152 Name="VCWebServiceProxyGeneratorTool"/>153 <Tool154 Name="VCXMLDataGeneratorTool"/>155 <Tool156 Name="VCWebDeploymentTool"/>157 <Tool158 Name="VCManagedWrapperGeneratorTool"/>159 <Tool160 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>161 </Configuration>162 <Configuration163 Name="Debug Dynamic Linkage|Win32"164 OutputDirectory="$(ConfigurationName)"165 IntermediateDirectory="$(ConfigurationName)"166 ConfigurationType="2"167 CharacterSet="2">168 <Tool169 Name="VCCLCompilerTool"170 Optimization="0"171 AdditionalIncludeDirectories="../include;../../include"172 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_STLP_USE_NEWALLOC;_STLP_DEBUG=1"173 MinimalRebuild="TRUE"174 BasicRuntimeChecks="3"175 RuntimeLibrary="3"176 UsePrecompiledHeader="3"177 WarningLevel="3"178 Detect64BitPortabilityProblems="TRUE"179 DebugInformationFormat="4"/>180 <Tool181 Name="VCCustomBuildTool"/>182 <Tool183 Name="VCLinkerTool"184 OutputFile="../../Debug/modules/$(ProjectName).dll"185 LinkIncremental="2"186 ModuleDefinitionFile="CheckDisk.def"187 GenerateDebugInformation="TRUE"188 ProgramDatabaseFile="$(OutDir)/CheckDisk.pdb"189 SubSystem="2"190 ImportLibrary="$(OutDir)/CheckDisk.lib"191 TargetMachine="1"/>192 <Tool193 Name="VCMIDLTool"/>194 <Tool195 Name="VCPostBuildEventTool"/>196 <Tool197 Name="VCPreBuildEventTool"/>198 <Tool199 Name="VCPreLinkEventTool"/>200 <Tool201 Name="VCResourceCompilerTool"/>202 <Tool203 Name="VCWebServiceProxyGeneratorTool"/>204 <Tool205 Name="VCXMLDataGeneratorTool"/>206 <Tool207 Name="VCWebDeploymentTool"/>208 <Tool209 Name="VCManagedWrapperGeneratorTool"/>210 <Tool211 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>212 </Configuration>213 <Configuration214 114 Name="Distribution|Win32" 215 115 OutputDirectory="$(ConfigurationName)" … … 292 192 </FileConfiguration> 293 193 <FileConfiguration 294 Name="D ynamic Linkage|Win32">194 Name="Distribution|Win32"> 295 195 <Tool 296 196 Name="VCCLCompilerTool" 297 197 UsePrecompiledHeader="1"/> 298 198 </FileConfiguration> 299 <FileConfiguration 300 Name="Debug Dynamic Linkage|Win32"> 301 <Tool 302 Name="VCCLCompilerTool" 303 UsePrecompiledHeader="1"/> 199 </File> 200 <File 201 RelativePath="..\..\include\utils.cpp"> 202 <FileConfiguration 203 Name="Debug|Win32"> 204 <Tool 205 Name="VCCLCompilerTool" 206 UsePrecompiledHeader="0"/> 207 </FileConfiguration> 208 <FileConfiguration 209 Name="Release|Win32"> 210 <Tool 211 Name="VCCLCompilerTool" 212 UsePrecompiledHeader="0"/> 304 213 </FileConfiguration> 305 214 <FileConfiguration … … 307 216 <Tool 308 217 Name="VCCLCompilerTool" 309 UsePrecompiledHeader=" 1"/>218 UsePrecompiledHeader="0"/> 310 219 </FileConfiguration> 311 220 </File> … … 323 232 <File 324 233 RelativePath=".\stdafx.h"> 234 </File> 235 <File 236 RelativePath="..\..\include\utils.h"> 325 237 </File> 326 238 </Filter>
Note: See TracChangeset
for help on using the changeset viewer.








