Changeset 5d8e0b5 in nscp for trunk/modules/CheckDisk


Ignore:
Timestamp:
04/19/05 00:50:16 (8 years ago)
Author:
Michael Medin <michael@…>
Children:
ae192e3
Parents:
ce6eabf
Message:

MAJOR CHANGES
2004-04-19 MickeM

+ Added SSL support
+ Added alot of new options
+ Added documentation

  • Renamed and restructured NSCLientCompat to CheckSystem
  • *ALOT* of fixes all over : We are now starting to get to something that is "stable" : This means that soon you might actually be able to use this.
Location:
trunk/modules/CheckDisk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/modules/CheckDisk/CheckDisk.cpp

    rf705d34 r5d8e0b5  
    66#include <strEx.h> 
    77#include <time.h> 
     8#include <utils.h> 
    89 
    910CheckDisk gCheckDisk; 
     
    8283} 
    8384 
    84 NSCAPI::nagiosReturn CheckDisk::CheckFileSize(const unsigned int argLen, char **char_args, std::string &message, std::string &perf) { 
     85NSCAPI::nagiosReturn CheckDisk::CheckDriveSize(const unsigned int argLen, char **char_args, std::string &message, std::string &perf) { 
    8586  // CheckFileSize 
    86   // request: CheckFileSize&<option>&<option>... 
     87  // request: CheckFileSize <option> <option>... 
    8788  // <option>     MaxWarn=<size gmkb> 
    8889  //          MaxCrit=<size gmkb> 
     
    100101  // Examples: 
    101102  // <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 
     202NSCAPI::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\*.* 
    103221  //       CheckFileSize 
    104222  // 
     
    196314  if (command == "CheckFileSize") { 
    197315    return CheckFileSize(argLen, char_args, msg, perf); 
     316  } else if (command == "CheckDriveSize") { 
     317    return CheckDriveSize(argLen, char_args, msg, perf); 
     318 
    198319//  } else if (command == "CheckFileDate") { 
    199320  }  
  • trunk/modules/CheckDisk/CheckDisk.h

    rc515660 r5d8e0b5  
    1818  // Check commands 
    1919  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); 
    2021}; 
  • trunk/modules/CheckDisk/CheckDisk.vcproj

    rebcb766 r5d8e0b5  
    2121        Optimization="0" 
    2222        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" 
    2424        MinimalRebuild="TRUE" 
    2525        BasicRuntimeChecks="3" 
    26         RuntimeLibrary="1" 
     26        RuntimeLibrary="3" 
    2727        UsePrecompiledHeader="3" 
    2828        WarningLevel="3" 
     
    7171        Name="VCCLCompilerTool" 
    7272        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" 
    7575        UsePrecompiledHeader="3" 
    7676        WarningLevel="3" 
     
    112112    </Configuration> 
    113113    <Configuration 
    114       Name="Dynamic Linkage|Win32" 
    115       OutputDirectory="$(ConfigurationName)" 
    116       IntermediateDirectory="$(ConfigurationName)" 
    117       ConfigurationType="2" 
    118       CharacterSet="2"> 
    119       <Tool 
    120         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       <Tool 
    129         Name="VCCustomBuildTool"/> 
    130       <Tool 
    131         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       <Tool 
    142         Name="VCMIDLTool"/> 
    143       <Tool 
    144         Name="VCPostBuildEventTool"/> 
    145       <Tool 
    146         Name="VCPreBuildEventTool"/> 
    147       <Tool 
    148         Name="VCPreLinkEventTool"/> 
    149       <Tool 
    150         Name="VCResourceCompilerTool"/> 
    151       <Tool 
    152         Name="VCWebServiceProxyGeneratorTool"/> 
    153       <Tool 
    154         Name="VCXMLDataGeneratorTool"/> 
    155       <Tool 
    156         Name="VCWebDeploymentTool"/> 
    157       <Tool 
    158         Name="VCManagedWrapperGeneratorTool"/> 
    159       <Tool 
    160         Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 
    161     </Configuration> 
    162     <Configuration 
    163       Name="Debug Dynamic Linkage|Win32" 
    164       OutputDirectory="$(ConfigurationName)" 
    165       IntermediateDirectory="$(ConfigurationName)" 
    166       ConfigurationType="2" 
    167       CharacterSet="2"> 
    168       <Tool 
    169         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       <Tool 
    181         Name="VCCustomBuildTool"/> 
    182       <Tool 
    183         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       <Tool 
    193         Name="VCMIDLTool"/> 
    194       <Tool 
    195         Name="VCPostBuildEventTool"/> 
    196       <Tool 
    197         Name="VCPreBuildEventTool"/> 
    198       <Tool 
    199         Name="VCPreLinkEventTool"/> 
    200       <Tool 
    201         Name="VCResourceCompilerTool"/> 
    202       <Tool 
    203         Name="VCWebServiceProxyGeneratorTool"/> 
    204       <Tool 
    205         Name="VCXMLDataGeneratorTool"/> 
    206       <Tool 
    207         Name="VCWebDeploymentTool"/> 
    208       <Tool 
    209         Name="VCManagedWrapperGeneratorTool"/> 
    210       <Tool 
    211         Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 
    212     </Configuration> 
    213     <Configuration 
    214114      Name="Distribution|Win32" 
    215115      OutputDirectory="$(ConfigurationName)" 
     
    292192        </FileConfiguration> 
    293193        <FileConfiguration 
    294           Name="Dynamic Linkage|Win32"> 
     194          Name="Distribution|Win32"> 
    295195          <Tool 
    296196            Name="VCCLCompilerTool" 
    297197            UsePrecompiledHeader="1"/> 
    298198        </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"/> 
    304213        </FileConfiguration> 
    305214        <FileConfiguration 
     
    307216          <Tool 
    308217            Name="VCCLCompilerTool" 
    309             UsePrecompiledHeader="1"/> 
     218            UsePrecompiledHeader="0"/> 
    310219        </FileConfiguration> 
    311220      </File> 
     
    323232      <File 
    324233        RelativePath=".\stdafx.h"> 
     234      </File> 
     235      <File 
     236        RelativePath="..\..\include\utils.h"> 
    325237      </File> 
    326238    </Filter> 
Note: See TracChangeset for help on using the changeset viewer.