Ignore:
Timestamp:
02/25/05 21:47:45 (8 years ago)
Author:
Michael Medin <michael@…>
Children:
cab471b
Parents:
107bd0f
Message:

Multiple fixes in various places.

  • Added threadding blocks "core"
  • Added new Module (CheckDisk)
  • Added new option [log] / debug=1 to enable debug logs.
  • Added more error messages
  • other minor tweaks and fixes
File:
1 edited

Legend:

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

    r107bd0f rf7f536b  
    5050    if (!(wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)) { 
    5151      size += (wfd.nFileSizeHigh * ((long long)MAXDWORD+1)) + (long long)wfd.nFileSizeLow; 
    52       NSC_LOG_ERROR_STD(wfd.cFileName + ": " + strEx::itos((wfd.nFileSizeHigh * ((long long)MAXDWORD+1)) + (long long)wfd.nFileSizeLow) + " --- " + strEx::itos(size)); 
    5352    } 
    5453    return true; 
     
    8382} 
    8483 
    85  
    86 // CheckDirectorySize&<Directory>&<Directory>... 
    87 // request: CheckDirectorySize&<warning>&<max>&<Directory>&<Directory>... 
    88 // Return: <return state>&<return string>... 
    89 // <return state> 0 - No errors 
    90 //          1 - Unknown 
    91 //          2 - Errors 
    92 // <return string>  <directory> <size mb> ... 
    93 // test: CheckDirectorySize&1024M&4096M&c:\WINDOWS\*.* 
    94 //       CheckDirectorySize 
     84std::string CheckDisk::CheckFileSize(const unsigned int argLen, char **char_args) { 
     85  // CheckFileSize 
     86  // request: CheckFileSize&<option>&<option>... 
     87  // <option>     MaxWarn=<size gmkb> 
     88  //          MaxCrit=<size gmkb> 
     89  //          MinWarn=<size gmkb> 
     90  //          MinCrit=<size gmkb> 
     91  //          ShowAll 
     92  //          File=<path> 
     93  //          File:<shortname>=<path> 
     94  // 
     95  // Return: <return state>&<return string>... 
     96  // <return state> 0 - No errors 
     97  //          1 - Unknown 
     98  //          2 - Errors 
     99  // <size gmkb> is a size with a possible modifier letter (such as G for gigabyte, M for Megabyte, K for kilobyte etc) 
     100  // Examples: 
     101  // <return string>  <directory> <size gmkb> ... |<shortname>=<size>:<warn>:<crit> 
     102  // test: CheckFileSize&ShowAll&MaxWarn=1024M&MaxCrit=4096M&File:WIN=c:\WINDOWS\*.* 
     103  //       CheckFileSize 
     104  // 
     105  // check_nscp -H <ip> -p <port> -s <passwd> -c <commandstring> 
     106  // 
     107  // ./check_nscp -H 192.168.0.167 -p 1234 -s pwd -c 'CheckFileSize&ShowAll&MaxWarn=1024M&MaxCrit=4096M&File:WIN=c:\WINDOWS\*.*' 
     108  // WIN: 1G (2110962363B)|WIN:2110962363:1073741824:4294967296 
     109  NSC_DEBUG_MSG("CheckFileSize"); 
     110  std::string perfData; 
     111  std::string ret; 
     112  NSCAPI::returnCodes returnCode = NSCAPI::returnOK; 
     113  std::list<std::string> args = NSCHelper::makelist(argLen, char_args); 
     114  if (args.empty()) 
     115    return "Missing argument(s)."; 
     116  long long maxWarn = 0; 
     117  long long maxCrit = 0; 
     118  long long minWarn = 0; 
     119  long long minCrit = 0; 
     120  bool bShowAll = false; 
     121  std::list<std::pair<std::string,std::string> > paths; 
     122 
     123  std::list<std::string>::const_iterator cit; 
     124  for (cit=args.begin();cit!=args.end();++cit) { 
     125    std::string arg = *cit; 
     126    std::pair<std::string,std::string> p = strEx::split(arg,"="); 
     127    if (p.first == "File") { 
     128      paths.push_back(std::pair<std::string,std::string>("",p.second)); 
     129    } else if (p.first == "MaxWarn") { 
     130      maxWarn = strEx::stoi64_as_BKMG(p.second); 
     131    } else if (p.first == "MinWarn") { 
     132      minWarn = strEx::stoi64_as_BKMG(p.second); 
     133    } else if (p.first == "MaxCrit") { 
     134      maxCrit = strEx::stoi64_as_BKMG(p.second); 
     135    } else if (p.first == "MinCrit") { 
     136      minCrit = strEx::stoi64_as_BKMG(p.second); 
     137    } else if (p.first == "ShowAll") { 
     138      bShowAll = true; 
     139    } else if (p.first.find(":") != std::string::npos) { 
     140      std::pair<std::string,std::string> p2 = strEx::split(p.first,":"); 
     141      if (p2.first == "File") { 
     142        paths.push_back(std::pair<std::string,std::string>(p2.second,p.second)); 
     143      } else { 
     144        return "Unknown command: " + p.first; 
     145      } 
     146    } else { 
     147      return "Unknown command: " + p.first; 
     148    } 
     149  } 
     150  NSC_DEBUG_MSG_STD("Bounds: critical " + strEx::itos(minCrit) + " > siez > " + strEx::itos(maxCrit)); 
     151  NSC_DEBUG_MSG_STD("Bounds: warning " + strEx::itos(minWarn) + " > size > " + strEx::itos(maxWarn)); 
     152  NSC_DEBUG_MSG_STD("Showall: " + ((bShowAll)?"yeap":"noop")); 
     153 
     154  std::list<std::pair<std::string,std::string> >::const_iterator pit; 
     155  for (pit = paths.begin(); pit != paths.end(); ++pit) { 
     156    std::string tstr; 
     157    GetSize sizeFinder; 
     158    std::string sName = (*pit).first; 
     159    if (sName.empty()) 
     160      sName = (*pit).second; 
     161    RecursiveScanDirectory((*pit).second, sizeFinder); 
     162 
     163    if ((maxCrit!=0) && (sizeFinder.getSize() > maxCrit)) { 
     164      tstr = sName + ": " + strEx::itos_as_BKMG(sizeFinder.getSize()); 
     165      returnCode = NSCAPI::returnCRIT; 
     166    } else if (sizeFinder.getSize() < minCrit) { 
     167      tstr = sName + ": " + strEx::itos_as_BKMG(sizeFinder.getSize()); 
     168      NSCHelper::escalteReturnCodeToCRIT(returnCode); 
     169    } else if ((maxWarn!=0)&&(sizeFinder.getSize() > maxWarn)) { 
     170      tstr = sName +  ": " + strEx::itos_as_BKMG(sizeFinder.getSize()); 
     171      NSCHelper::escalteReturnCodeToWARN(returnCode); 
     172    } else if (sizeFinder.getSize() < minWarn) { 
     173      tstr = sName +  ": " + strEx::itos_as_BKMG(sizeFinder.getSize()); 
     174      NSCHelper::escalteReturnCodeToWARN(returnCode); 
     175    } else if (bShowAll) { 
     176      tstr = sName +  ": " + strEx::itos_as_BKMG(sizeFinder.getSize()); 
     177    } 
     178    if (!(*pit).first.empty()) 
     179      perfData += (*pit).first + "=" + strEx::itos(sizeFinder.getSize()) + ";" + strEx::itos(maxWarn) + ";" + strEx::itos(maxCrit) + " "; 
     180    if (!ret.empty() && !tstr.empty()) 
     181      ret += ", "; 
     182    if (!tstr.empty()) 
     183      ret += tstr; 
     184  } 
     185  if (ret.empty()) 
     186    ret = "OK all file sizes are within bounds."; 
     187  if (!perfData.empty()) 
     188    ret += "|" + perfData; 
     189  return NSCHelper::returnNSCP(returnCode, ret); 
     190} 
     191 
     192 
    95193#define BUFFER_SIZE 1024*64 
    96194 
    97195std::string CheckDisk::handleCommand(const std::string command, const unsigned int argLen, char **char_args) { 
    98   std::string ret; 
    99   if (command == "CheckDirectorySize") { 
    100     std::list<std::string> args = NSCHelper::makelist(argLen, char_args); 
    101     if (args.size() < 3) 
    102       return "Missing argument(s)." + strEx::itos((int)args.size()); 
    103     int iWarn = strEx::stoi64_as_BKMG(args.front()); args.pop_front(); 
    104     int iMax = strEx::stoi64_as_BKMG(args.front()); args.pop_front(); 
    105  
    106     std::list<std::string>::const_iterator cit; 
    107     for (cit=args.begin();cit!=args.end();++cit) { 
    108       GetSize size; 
    109       RecursiveScanDirectory(*cit, size); 
    110       if (!ret.empty()) 
    111         ret += ", "; 
    112       ret += (*cit) + ": " + strEx::itos_as_BKMG(size.getSize()); 
    113     } 
    114   } 
    115   return ret; 
     196  if (command == "CheckFileSize") { 
     197    return CheckFileSize(argLen, char_args); 
     198//  } else if (command == "CheckFileDate") { 
     199  }  
     200  return ""; 
    116201} 
    117202 
Note: See TracChangeset for help on using the changeset viewer.