Changeset 1d9338a in nscp


Ignore:
Timestamp:
05/23/05 21:24:32 (8 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
6654022
Parents:
af5bc4b
Message:

2005-05-23 MickeM

+ Added obfuscated password support
+ Added some more debug info on commands (returncode, and input args)
+ Added some more comments ot the NSC.ini
+ Added central password "override"
+ Added central "host override"
+ Fixed bug with external commands always getting WARNING state

2005-05-22 MickeM

+ Added debug outout for command
+ Added timestamps for log-to-file (date_mask to configure format)
+ Added support for "no password" with check_nt
+ Added log of bad password on NSClient requests.

  • Some threading issues fixed (I hate threading :)
Files:
3 added
33 edited

Legend:

Unmodified
Added
Removed
  • NSClient++.cpp

    raf5bc4b r1d9338a  
    1919#include <charEx.h> 
    2020#include <Socket.h> 
     21#include <b64/b64.h> 
     22 
    2123 
    2224NSClient mainClient;  // Global core instance. 
     
    5557        return -1; 
    5658      } 
     59    } else if ( _stricmp( "encrypt", argv[1]+1 ) == 0 ) { 
     60      g_bConsoleLog = true; 
     61      std::string password; 
     62      Settings::getInstance()->setFile(mainClient.getBasePath() + "NSC.ini"); 
     63      std::cout << "Enter password to encrypt (has to be a single word): "; 
     64      std::cin >> password; 
     65      std::string xor_pwd = Encrypt(password); 
     66      std::cout << "obfuscated_password=" << xor_pwd << std::endl; 
     67      if (password != Decrypt(xor_pwd))  
     68        std::cout << "ERROR: Password did not match!" << std::endl; 
     69      Settings::destroyInstance(); 
     70      return 0; 
    5771    } else if ( _stricmp( "start", argv[1]+1 ) == 0 ) { 
    5872      g_bConsoleLog = true; 
     
    7084    } else if ( _stricmp( "test", argv[1]+1 ) == 0 ) { 
    7185#ifdef _DEBUG 
     86      /* 
    7287      strEx::run_test_getToken(); 
    7388      strEx::run_test_replace(); 
    7489      charEx::run_test_getToken(); 
    7590      arrayBuffer::run_testArrayBuffer(); 
     91      */ 
    7692#endif 
    7793 
     
    92108      } 
    93109      mainClient.TerminateService(); 
    94       LOG_MESSAGE("DONE!"); 
    95  
    96110      return 0; 
    97111    } else { 
     
    137151  try { 
    138152    mainClient.unloadPlugins(); 
    139     LOG_DEBUG("Plugins unloaded..."); 
    140153  } catch(NSPluginException *e) { 
    141154    std::cout << "Exception raised: " << e->error_ << " in module: " << e->file_ << std::endl;; 
     
    179192    return; 
    180193  } 
    181   /* 
    182   MutexLock lock(pluginMutex); 
    183   if (!lock.hasMutex()) { 
    184     LOG_ERROR("FATAL ERROR: Could not get mutex."); 
    185     return; 
    186   } 
    187   */ 
    188194  std::list<std::string>::const_iterator it; 
    189195  for (it = plugins.begin(); it != plugins.end(); ++it) { 
     
    201207      return; 
    202208    } 
    203     /*  MutexLock lock(pluginMutex,20000); 
    204     if (!lock.hasMutex()) { 
    205     LOG_ERROR("FATAL ERROR: Could not get mutex."); 
    206     return; 
    207     } 
    208     */ 
    209209    commandHandlers_.clear(); 
    210     { 
    211       /*    MutexLock lock(messageMutex,20000); 
    212       if (!lock.hasMutex()) { 
    213       LOG_ERROR("FATAL ERROR: Could not get mutex (we will now crash BTW)."); 
    214       } else { 
    215       messageHandlers_.clear(); 
    216       } 
    217       */ 
    218       messageHandlers_.clear(); 
    219     } 
     210    messageHandlers_.clear(); 
    220211  } 
    221212  { 
     
    231222    } 
    232223  } 
    233  
    234224  { 
    235225    WriteLock writeLock(&m_mutexRW, true, 10000); 
     
    259249 */ 
    260250void NSClientT::addPlugin(plugin_type plugin) { 
    261   { 
    262     ReadLock readLock(&m_mutexRW, true, 5000); 
    263     if (!readLock.IsLocked()) { 
    264       LOG_ERROR("FATAL ERROR: Could not get read-mutex."); 
    265       return; 
    266     } 
    267     plugin->load(); 
    268   } 
    269   /* 
    270   MutexLock lock(pluginMutex); 
    271   if (!lock.hasMutex()) { 
    272     LOG_ERROR("FATAL ERROR: Could not get mutex."); 
    273     return; 
    274   } 
    275   */ 
    276  
     251  plugin->load(); 
    277252  { 
    278253    WriteLock writeLock(&m_mutexRW, true, 10000); 
     
    298273  NSCAPI::nagiosReturn ret = injectRAW(command.c_str(), aLen, aBuf, mBuf, 1023, pBuf, 1023); 
    299274  arrayBuffer::destroyArrayBuffer(aBuf, aLen); 
    300   if ( (ret == NSCAPI::returnInvalidBufferLen) || (ret == NSCAPI::returnIgnored) ) 
     275  if ( (ret == NSCAPI::returnInvalidBufferLen) || (ret == NSCAPI::returnIgnored) ) { 
     276    delete [] mBuf; 
     277    delete [] pBuf; 
    301278    return ret; 
     279  } 
    302280  msg = mBuf; 
    303281  perf = pBuf; 
     
    320298 */ 
    321299NSCAPI::nagiosReturn NSClientT::injectRAW(const char* command, const unsigned int argLen, char **argument, char *returnMessageBuffer, unsigned int returnMessageBufferLen, char *returnPerfBuffer, unsigned int returnPerfBufferLen) { 
     300  if (logDebug()) { 
     301    LOG_DEBUG_STD("Injecting: " + (std::string) command + ": " + arrayBuffer::arrayBuffer2string(argument, argLen, ", ")); 
     302  } 
    322303  ReadLock readLock(&m_mutexRW, true, 5000); 
    323304  if (!readLock.IsLocked()) { 
     
    325306    return NSCAPI::returnUNKNOWN; 
    326307  } 
    327 /*  MutexLock lock(pluginMutex); 
    328   if (!lock.hasMutex()) { 
    329     LOG_ERROR_STD("Failed to get mutex (" + strEx::itos(lock.getWaitResult()) + "), command ignored..."); 
    330     return NSCAPI::returnUNKNOWN; 
    331   } 
    332 */ 
    333308  for (pluginList::size_type i = 0; i < commandHandlers_.size(); i++) { 
    334309    try { 
     
    344319        case NSCAPI::returnCRIT: 
    345320        case NSCAPI::returnUNKNOWN: 
    346 //          LOG_DEBUG_STD("Injected Result: " +(std::string) returnMessageBuffer); 
    347 //          LOG_DEBUG_STD("Injected Performance Result: " +(std::string) returnPerfBuffer); 
     321          LOG_DEBUG_STD("Injected Result: " + NSCHelper::translateReturn(c) + "  --  " + (std::string)(returnMessageBuffer)); 
     322          LOG_DEBUG_STD("Injected Performance Result: " +(std::string) returnPerfBuffer); 
    348323          return c; 
    349324        default: 
     
    359334  return NSCAPI::returnIgnored; 
    360335} 
     336 
     337bool NSClientT::logDebug() { 
     338  if (g_bConsoleLog) 
     339    return true; 
     340  typedef enum status {unknown, debug, nodebug }; 
     341  static status d = unknown; 
     342  if (d == unknown) { 
     343    if (Settings::getInstance()->getInt("log", "debug", 0) == 1) 
     344      d = debug; 
     345    else 
     346      d = nodebug; 
     347  } 
     348  return (d == debug); 
     349} 
     350 
    361351/** 
    362352 * Report a message to all logging enabled modules. 
     
    379369    return; 
    380370  } 
    381   /* 
    382   MutexLock lock(messageMutex); 
    383   if (!lock.hasMutex()) { 
    384     std::cout << "Message was lost as the core was locked..." << std::endl; 
    385     std::cout << message << std::endl; 
    386     return; 
    387   } 
    388   */ 
    389371  if (g_bConsoleLog) { 
    390372    std::string k = "?"; 
     
    408390    std::cout << k << " " << file << "(" << line << ") " << message << std::endl; 
    409391  } 
    410   if (msgType == NSCAPI::debug) { 
    411     typedef enum status {unknown, debug, nodebug }; 
    412     static status d = unknown; 
    413     if (d == unknown) { 
    414       if (Settings::getInstance()->getInt("log", "debug", 0) == 1) 
    415         d = debug; 
    416       else 
    417         d = nodebug; 
    418     } 
    419     if (d == nodebug) 
    420       return; 
     392  if ((msgType == NSCAPI::debug)&&(!logDebug())) { 
     393    return; 
    421394  } 
    422395  for (pluginList::size_type i = 0; i< messageHandlers_.size(); i++) { 
     
    480453} 
    481454 
     455NSCAPI::boolReturn NSAPICheckLogMessages(int messageType) { 
     456  if (mainClient.logDebug()) 
     457    return NSCAPI::istrue; 
     458  return NSCAPI::isfalse; 
     459} 
     460 
     461std::string Encrypt(std::string str, unsigned int algorithm) { 
     462  unsigned int len = 0; 
     463  NSAPIEncrypt(algorithm, str.c_str(), str.size(), NULL, &len); 
     464  len+=2; 
     465  char *buf = new char[len+1]; 
     466  NSCAPI::errorReturn ret = NSAPIEncrypt(algorithm, str.c_str(), str.size(), buf, &len); 
     467  if (ret == NSCAPI::isSuccess) { 
     468    std::string ret = buf; 
     469    delete [] buf; 
     470    return ret; 
     471  } 
     472  return ""; 
     473} 
     474std::string Decrypt(std::string str, unsigned int algorithm) { 
     475  unsigned int len = 0; 
     476  NSAPIDecrypt(algorithm, str.c_str(), str.size(), NULL, &len); 
     477  len+=2; 
     478  char *buf = new char[len+1]; 
     479  NSCAPI::errorReturn ret = NSAPIDecrypt(algorithm, str.c_str(), str.size(), buf, &len); 
     480  if (ret == NSCAPI::isSuccess) { 
     481    std::string ret = buf; 
     482    delete [] buf; 
     483    return ret; 
     484  } 
     485  return ""; 
     486} 
     487 
     488NSCAPI::errorReturn NSAPIEncrypt(unsigned int algorithm, const char* inBuffer, unsigned int inBufLen, char* outBuf, unsigned int *outBufLen) { 
     489  if (algorithm != NSCAPI::xor) { 
     490    LOG_ERROR("Unknown algortihm requested."); 
     491    return NSCAPI::hasFailed; 
     492  } 
     493  std::string s = inBuffer; 
     494  std::string key = Settings::getInstance()->getString(MAIN_SECTION_TITLE, MAIN_MASTERKEY, MAIN_MASTERKEY_DEFAULT); 
     495  char *c = new char[inBufLen+1]; 
     496  strncpy(c, inBuffer, inBufLen); 
     497  for (int i=0,j=0;i<inBufLen;i++,j++) { 
     498    if (j > key.size()) 
     499      j = 0; 
     500    c[i] ^= key[j]; 
     501  } 
     502  unsigned int len = b64::b64_encode(reinterpret_cast<void*>(c), inBufLen, outBuf, *outBufLen); 
     503  delete [] c; 
     504  if (outBuf) { 
     505    if ((len == 0)||(len >= *outBufLen)) { 
     506      LOG_ERROR("Invalid out buffer length."); 
     507      return NSCAPI::isInvalidBufferLen; 
     508    } 
     509    outBuf[len] = 0; 
     510    *outBufLen = len; 
     511  } else { 
     512    *outBufLen = len; 
     513  } 
     514  return NSCAPI::isSuccess; 
     515} 
     516 
     517NSCAPI::errorReturn NSAPIDecrypt(unsigned int algorithm, const char* inBuffer, unsigned int inBufLen, char* outBuf, unsigned int *outBufLen) { 
     518  if (algorithm != NSCAPI::xor) { 
     519    LOG_ERROR("Unknown algortihm requested."); 
     520    return NSCAPI::hasFailed; 
     521  } 
     522  unsigned int len =  b64::b64_decode(inBuffer, inBufLen, reinterpret_cast<void*>(outBuf), *outBufLen); 
     523  if (outBuf) { 
     524    if ((len == 0)||(len >= *outBufLen)) { 
     525      LOG_ERROR("Invalid out buffer length."); 
     526      return NSCAPI::isInvalidBufferLen; 
     527    } 
     528    std::string key = Settings::getInstance()->getString(MAIN_SECTION_TITLE, MAIN_MASTERKEY, MAIN_MASTERKEY_DEFAULT); 
     529    for (int i=0,j=0;i<len;i++,j++) { 
     530      if (j > key.size()) 
     531        j = 0; 
     532      outBuf[i] ^= key[j]; 
     533    } 
     534    outBuf[len] = 0; 
     535    *outBufLen = len; 
     536  } else { 
     537    *outBufLen = len; 
     538  } 
     539  return NSCAPI::isSuccess; 
     540} 
    482541 
    483542LPVOID NSAPILoader(char*buffer) { 
     
    500559  if (stricmp(buffer, "NSAPIGetBasePath") == 0) 
    501560    return &NSAPIGetBasePath; 
     561  if (stricmp(buffer, "NSAPICheckLogMessages") == 0) 
     562    return &NSAPICheckLogMessages; 
     563  if (stricmp(buffer, "NSAPIEncrypt") == 0) 
     564    return &NSAPIEncrypt; 
     565  if (stricmp(buffer, "NSAPIDecrypt") == 0) 
     566    return &NSAPIDecrypt; 
    502567  return NULL; 
    503568} 
  • NSClient++.h

    raf5bc4b r1d9338a  
    4444  std::string basePath; 
    4545  MutexHandler internalVariables; 
    46 //  MutexHandler pluginMutex; 
    4746  MutexHandler messageMutex; 
    4847  MutexRW  m_mutexRW; 
     
    7271  void unloadPlugins(void); 
    7372 
     73  bool logDebug(); 
     74 
    7475private: 
    7576  void addPlugin(plugin_type plugin); 
     
    7879 
    7980typedef NTService<NSClientT> NSClient; 
     81 
     82 
     83std::string Encrypt(std::string str, unsigned int algorithm = NSCAPI::xor); 
     84std::string Decrypt(std::string str, unsigned int algorithm = NSCAPI::xor); 
    8085 
    8186////////////////////////////////////////////////////////////////////////// 
     
    95100NSCAPI::nagiosReturn NSAPIInject(const char* command, const unsigned int argLen, char **argument, char *returnMessageBuffer, unsigned int returnMessageBufferLen, char *returnPerfBuffer, unsigned int returnPerfBufferLen); 
    96101NSCAPI::errorReturn NSAPIGetSettingsSection(const char*, char***, unsigned int *); 
     102NSCAPI::boolReturn NSAPICheckLogMessages(int messageType); 
     103NSCAPI::errorReturn NSAPIEncrypt(unsigned int algorithm, const char* inBuffer, unsigned int inBufLen, char* outBuf, unsigned int *outBufLen); 
     104NSCAPI::errorReturn NSAPIDecrypt(unsigned int algorithm, const char* inBuffer, unsigned int inBufLen, char* outBuf, unsigned int *outBufLen); 
    97105////////////////////////////////////////////////////////////////////////// 
    98106// Log macros to simplify logging 
  • NSClient++.vcproj

    raf5bc4b r1d9338a  
    174174      <Tool 
    175175        Name="VCCustomBuildTool" 
    176         CommandLine="echo Copying documentation 
    177 cmd /c &quot;copy $(InputDir)\*.html $(InputDir)\Dist\&quot; 
    178 echo Copying dependency DLLs 
    179 cmd /c &quot;copy $(InputDir)\dist_dll\*.dll $(InputDir)\Dist\&quot; 
     176        CommandLine="echo Copying dependency DLLs 
     177cmd /c &quot;xcopy /Q /Y $(InputDir)\dist_dll\*.dll $(InputDir)\Dist\&quot; 
    180178echo Removing old archive 
    181179cmd /c &quot;del $(InputDir)\Dist\$(InputName).zip&quot; 
     180echo Copying documenation 
     181mkdir $(TargetDir)\docs 
     182xcopy /s /e /c /q /y $(InputDir)\docs $(TargetDir)\docs 
    182183echo Making archive 
    1831847z.exe a -r -tzip -bd $(InputDir)\Dist\$(InputName).zip $(InputDir)\Dist\* 
     
    234235      </File> 
    235236      <File 
     237        RelativePath=".\include\b64\b64.c"> 
     238        <FileConfiguration 
     239          Name="Release|Win32"> 
     240          <Tool 
     241            Name="VCCLCompilerTool" 
     242            UsePrecompiledHeader="0"/> 
     243        </FileConfiguration> 
     244        <FileConfiguration 
     245          Name="Debug|Win32"> 
     246          <Tool 
     247            Name="VCCLCompilerTool" 
     248            UsePrecompiledHeader="0"/> 
     249        </FileConfiguration> 
     250        <FileConfiguration 
     251          Name="Distribution|Win32"> 
     252          <Tool 
     253            Name="VCCLCompilerTool" 
     254            UsePrecompiledHeader="0"/> 
     255        </FileConfiguration> 
     256      </File> 
     257      <File 
    236258        RelativePath=".\include\NSCHelper.cpp"> 
    237259      </File> 
    238260      <File 
    239261        RelativePath=".\NSClient++.cpp"> 
    240       </File> 
    241       <File 
    242         RelativePath=".\NSClient++.def"> 
    243262      </File> 
    244263      <File 
     
    362381        </FileConfiguration> 
    363382        <FileConfiguration 
    364           Name="Distribution|Win32"> 
     383          Name="Distribution|Win32" 
     384          ExcludedFromBuild="TRUE"> 
    365385          <Tool 
    366386            Name="VCCustomBuildTool" 
  • changelog

    raf5bc4b r1d9338a  
     12005-05-23 MickeM 
     2 + Added obfuscated password support 
     3 + Added some more debug info on commands (returncode, and input args) 
     4 + Added some more comments  ot the NSC.ini 
     5 + Added central password "override" 
     6 + Added central "host override" 
     7 + Fixed bug with external commands always getting WARNING state 
     8 
     92005-05-22 MickeM 
     10 + Added debug outout for command 
     11 + Added timestamps for log-to-file (date_mask to configure format) 
     12 + Added support for "no password" with check_nt 
     13 + Added log of bad password on NSClient requests. 
     14 * Some threading issues fixed (I hate threading :) 
     15 
     162005-05-19 MickeM 
     17 * Verified NT4 compatibility 
     18 
    1192005-05-18 MickeM 
    220 * Fixed bug in NSC.ini (section title for Check System was wrong) 
    3  + Added multitasking for plugins (now two plugins can handle requests simultaniously) 
    4  * Fixed som minor issues here and there 
     21 + Added multitasking for plug-ins (now two plug-ins can handle requests simultaneously) 
     22 * Fixed some minor issues here and there 
    523 
    6242005-05-15 MickeM 
     
    1331 + Added support for Volumes (CheckDisk) 
    1432 + Added support for checking all drives of a certain kind 
    15  + Added support for altering filter (makes it posible to check removale drives) 
    16  + Created webpage and better documentation 
     33 + Added support for altering filter (makes it possible to check removable drives) 
     34 + Created web page and better documentation 
    1735 
    18362005-04-20 MickeM 
    19  + Added multitasking to socket listsner (it can now handle multiple connections) 
     37 + Added multitasking to socket listener (it can now handle multiple connections) 
    2038 * Fixed bug in NSClientListener now "seqv" in check_nt shouldn't happen. 
    2139 + Added COUNTER support to NSClient and CheckSystem 
     
    23412005-04-19 MickeM 
    2442 + Added SSL support 
    25  + Added alot of new options 
     43 + Added a lot of new options 
    2644 + Added documentation 
    2745 * Renamed and restructured NSCLientCompat to CheckSystem 
  • docs/CheckDisk/index.html

    re655f61 r1d9338a  
    11<html> 
    2  
    32<head> 
    43<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 
    54<title>CheckDisk</title> 
    65<link rel="stylesheet" type="text/css" href="../nscplus.css"> 
     6<base target="_self"> 
    77</head> 
    88 
     
    1212  <h1>CheckDisk.dll</h1> 
    1313  <p>The CheckDisk module has various disk related checks currently focusing on  
    14   size. But hopefully it will be extended with date existance and many other disk  
    15   related checks in the furture. Feel free to request checks that you need.</p> 
     14  size. But hopefully it will be extended with date existence and many other disk  
     15  related checks in the future. Feel free to request checks that you need.</p> 
    1616  <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" id="table4"> 
    1717    <tr> 
     
    9191  </table> 
    9292  <p>The “Size with optional postfix” is a way to simply specify large sizes by  
    93   adding unit postfix. The avalible postfixes are B for Byte, K for KiloByte,  
    94   M for MegaByte and finally G for GigaByte. </p> 
     93  adding unit postfix. The available postfixes are B for Byte, K for Kilobyte,  
     94  M for Megabyte and finally G for Gigabyte. </p> 
    9595  <h3>Examples</h3> 
    9696  <div class="example"> 
    9797    <ul> 
    9898      <li> 
    99       <p>Check the size of the windows directory and make sure it stays  
    100       below 1 gigabyte:</p> 
     99      <p><b>Check the size of the windows directory and make sure it stays below  
     100      1 gigabyte:</b></p> 
    101101      <p><code>CheckFileSize ShowAll MaxWarn=1024M MaxCrit=4096M File:WIN=c:\WINDOWS\*.*</code></p> 
    102102      <p><code>WARNING: WIN: 2G (2325339822B)|WIN=2325339822;1073741824;4294967296</code></p> 
    103       </li> 
    104       <li> 
    105       <p>Check the size of the pagefile.sys and make sure it stays  
    106       above 1 gigabyte:</p> 
     103      <div class="config"> 
     104        <p>define command { </p> 
     105        <p>&nbsp;&nbsp;&nbsp; command_name CheckFileSize </p> 
     106        <p>&nbsp;&nbsp;&nbsp; command_line check_nrpe -H $HOSTADDRESS$ -p  
     107        5666 -c CheckFileSize -a ShowAll MaxWarn=$ARG1$ MaxCrit=$ARG2$  
     108        File:$ARG4$=$ARG5$ </p> 
     109        <p>}</p> 
     110        <p>&nbsp;&nbsp;&nbsp; check_command CheckFileSize!1024M!4096M!WIN!c:\WINDOWS\*.* 
     111        </p> 
     112      </div> 
     113      </li> 
     114      <li> 
     115      <p><b>Check the size of the pagefile.sys and make sure it stays  
     116      above 1 gigabyte:</b></p> 
    107117      <p><code>CheckFileSize ShowAll MinWarn=1G MinCrit=512M File=c:\pagefile.sys</code></p> 
    108118      <p><code>OK: c:\pagefile.sys: 1G (1610612736B)</code></p> 
     119      <div class="config"> 
     120        <p>define command { </p> 
     121        <p>&nbsp;&nbsp;&nbsp; command_name CheckPageFile </p> 
     122        <p>&nbsp;&nbsp;&nbsp; command_line check_nrpe -H $HOSTADDRESS$ -p  
     123        5666 -c CheckFileSize -a ShowAll MinWarn=$ARG1$ MinCrit=$ARG2$  
     124        File:PageFile=c:\pagefile.sys </p> 
     125        <p>}</p> 
     126        <p>&nbsp;&nbsp;&nbsp; check_command CheckPageFile!1G!512M</p> 
     127      </div> 
    109128      </li> 
    110129    </ul> 
     
    161180      <td valign="top">FIXED, CDROM, REMOVABLE</td> 
    162181      <td valign="top">Filter for drive type to prevent checking drives of  
    163       certain kinds (most useful when using CheckAll). The default is  
    164       FIXED</td> 
     182      certain kinds (most useful when using CheckAll). The default is FIXED</td> 
    165183    </tr> 
    166184    <tr> 
     
    171189  </table> 
    172190  <p>The “Size with optional postfix” is a way to simply specify large sizes by  
    173   adding unit postfix. The availible postfixes are B for Byte, K for KiloByte,  
    174   M for MegaByte, G for GigaByte and finally % for percent free space. </p> 
     191  adding unit postfix. The available postfixes are B for Byte, K for Kilobyte,  
     192  M for Megabyte, G for Gigabyte and finally % for percent free space. </p> 
    175193  <h3>Examples</h3> 
    176194  <div class="example"> 
    177195    <ul> 
    178196      <li> 
    179       <p>Check the size of C:\ and make sure it has 50% free space:</p> 
    180       <p><code>CheckDriveSize ShowAll MaxWarn=50% MaxWarn=75% Drive=c:\</code></p> 
     197      <p><b>Check the size of C:\ and make sure it has 50% free space:</b></p> 
     198      <p><code>CheckDriveSize ShowAll MaxWarn=50% MaxCrit=75% Drive=c:\</code></p> 
    181199      <p><code>OK: c:: 63G (68374007808B)|c:=85% 50;75;</code></p> 
    182       </li> 
    183       <li> 
    184       <p>To check the size of mounted volume c:\volumne_test and make sure it has 1M free space</p> 
    185       <p><code>CheckDriveSize ShowAll MaxWarn=1M MaxCrit=2M Drive="c:\\volumne_test\\"</code></p> 
     200      <div class="config"> 
     201        <p>define command { </p> 
     202        <p>&nbsp;&nbsp;&nbsp; command_name CheckDriveSize </p> 
     203        <p>&nbsp;&nbsp;&nbsp; command_line check_nrpe -H $HOSTADDRESS$ -p  
     204        5666 -c CheckDriveSize -a Drive=$ARG1$ ShowAll MaxWarn=$ARG2$  
     205        MaxCrit=$ARG3$ </p> 
     206        <p>}</p> 
     207        <p>&nbsp;&nbsp;&nbsp; check_command CheckDriveSize!C:\!50%!75%</p> 
     208      </div> 
     209      </li> 
     210      <li> 
     211      <p><b>To check the size of mounted volume c:\volumne_test and make sure  
     212      it has 1M free space</b></p> 
     213      <p><code>CheckDriveSize ShowAll MaxWarn=1M MaxCrit=2M Drive=&quot;c:\\volumne_test\\&quot;</code></p> 
    186214      <p><code>CRITICAL: c:\volumne_test\: 3M (4193280B)|c:\volumne_test\=4193280;0;0;</code></p> 
    187       </li> 
    188       <li> 
    189       <p>To check the size of all fixed and network drives and make sure they are at least 50% full</p> 
    190       <p><code>CheckDriveSize -a MinWarn=50% MinCrit=25% CheckAll FilterType=FIXED FilterType=REMOTE</code></p> 
    191       <p><code>WARNING: X:\: 28% < warning|C:\=84% 50%;25%; X:\=28% 50%;25%; Y:\=98% 50%;25%;</code></p> 
     215      <div class="config"> 
     216        <p>&nbsp;&nbsp;&nbsp; check_command CheckDriveSize!<code>c:\volumne_test\</code>!1M!2M</p> 
     217      </div> 
     218      </li> 
     219      <li> 
     220      <p><b>To check the size of all fixed and network drives and make sure they  
     221      are at least 50% full</b></p> 
     222      <p><code>CheckDriveSize -a MinWarn=50% MinCrit=25% CheckAll FilterType=FIXED  
     223      FilterType=REMOTE</code></p> 
     224      <p><code>WARNING: X:\: 28% &lt; warning|C:\=84% 50%;25%; X:\=28% 50%;25%;  
     225      Y:\=98% 50%;25%;</code></p> 
     226      <div class="config"> 
     227        <p>define command { </p> 
     228        <p>&nbsp;&nbsp;&nbsp; command_name CheckAllDrives </p> 
     229        <p>&nbsp;&nbsp;&nbsp; command_line check_nrpe -H $HOSTADDRESS$ -p  
     230        5666 -c CheckDriveSize -a Drive=$ARG1$ CheckAll FilterType=FIXED  
     231      FilterType=REMOTE MinWarn=$ARG1$ MinCrit=$ARG2$ </p> 
     232        <p>}</p> 
     233        <p>&nbsp;&nbsp;&nbsp; check_command CheckAllDrives!25%!50%</p> 
     234      </div> 
    192235      </li> 
    193236    </ul> 
    194237  </div> 
    195238</div> 
     239 
    196240</body> 
    197241 
  • docs/CheckEventLog/index.html

    re655f61 r1d9338a  
    11<html> 
    2  
    32<head> 
    43<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 
     4<meta http-equiv="Content-Language" content="en-us"> 
    55<title>CheckEventLog</title> 
    66<link rel="stylesheet" type="text/css" href="../nscplus.css"> 
     7<base target="_self"> 
    78</head> 
    89 
     
    2829  <p>Yet to be written</p> 
    2930  <p>A quick introduction though:</p> 
    30   <p>First option is the logfile to parse. (Application, System etc)</p> 
     31  <p>First option is the log file to parse. (Application, System etc)</p> 
    3132  <p>Options have the following format.</p> 
    3233  <p>warn.require.eventType=warning</p> 
  • docs/CheckHelpers/index.html

    re655f61 r1d9338a  
    33<head> 
    44<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 
     5<meta http-equiv="Content-Language" content="en-us"> 
    56<title>CheckDisk</title> 
    67<link rel="stylesheet" type="text/css" href="../nscplus.css"> 
     8<base target="_self"> 
    79</head> 
    810 
     
    2022    <tr> 
    2123      <td valign="top">CheckAlwaysOK</td> 
    22       <td valign="top">Alter the retun code of another check to always return  
     24      <td valign="top">Alter the return code of another check to always return  
    2325      OK.</td> 
    2426    </tr> 
    2527    <tr> 
    2628      <td valign="top">CheckAlwaysCRITICAL</td> 
    27       <td valign="top">Alter the retun code of another check to always return  
     29      <td valign="top">Alter the return code of another check to always return  
    2830      CRITICAL.</td> 
    2931    </tr> 
    3032    <tr> 
    3133      <td valign="top">CheckAlwaysWARNING</td> 
    32       <td valign="top">Alter the retun code of another check to always return  
     34      <td valign="top">Alter the return code of another check to always return  
    3335      WARNING.</td> 
    3436    </tr> 
    3537    <tr> 
    3638      <td valign="top">CheckMultiple</td> 
    37       <td valign="top">Runs multiple checks and returns the worsta state.  
    38       Usefull for minimizing network traffic and command defenitions.</td> 
     39      <td valign="top">Runs multiple checks and returns the worst state. Useful  
     40      for minimizing network traffic and command definitions.</td> 
    3941    </tr> 
    4042  </table> 
     
    4244  <p><i>This module has no configuration directives.</i></p> 
    4345  <h2>CheckAlwaysOK</h2> 
    44   <p>Runs another check and aters the return state to always return OK.</p> 
     46  <p>Runs another check and alters the return state to always return OK.</p> 
    4547  <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" id="table5"> 
    4648    <tr> 
     
    7375  </div> 
    7476  <h2>CheckAlwaysCRITICAL</h2> 
    75   <p>Runs another check and ater the return state to always return CRITICAL.</p> 
     77  <p>Runs another check and alters the return state to always return CRITICAL.</p> 
    7678  <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" id="table5"> 
    7779    <tr> 
     
    104106  </div> 
    105107  <h2>CheckAlwaysWARNING</h2> 
    106   <p>Runs another check and ater the return state to always return WARNING.</p> 
     108  <p>Runs another check and alter the return state to always return WARNING.</p> 
    107109  <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" id="table5"> 
    108110    <tr> 
     
    135137  </div> 
    136138  <h2>CheckMultiple</h2> 
    137   <p>Runs multiple checks and returns the worst state. It allows you to check an entire system in one go.</p> 
     139  <p>Runs multiple checks and returns the worst state. It allows you to check  
     140  an entire system in one go.</p> 
    138141  <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" id="table5"> 
    139142    <tr> 
     
    145148      <td valign="top">command</td> 
    146149      <td valign="top">The command to run</td> 
    147       <td valign="top">A command to execute, you can have any number of  
    148       this option.</td> 
     150      <td valign="top">A command to execute, you can have any number of this  
     151      option.</td> 
    149152    </tr> 
    150153  </table> 
     
    153156    <ul> 
    154157      <li> 
    155       <p>Run two checks (CheckDriveSize and ChEckMeM) and return the worst state. Performance data and  
    156       message is collected and concatenated.</p> 
    157       <p><code>CheckMultiple command=CheckDriveSize MaxWarn=1M MaxCrit=2M Drive=c:\\volumne_test\\ command=ChEckMeM MaxWarn=80% MaxCrit=90%</code></p> 
    158       <p><code>CRITICAL: c:\volumne_test\: 3M (4193280B) > critical, OK memory within bounds.|c:\volumne_test\=4193280;1024K (1048576B);2M (2097152B); page=31% 80%;90%;</code></p> 
     158      <p>Run two checks (CheckDriveSize and ChEckMeM) and return the worst  
     159      state. Performance data and message is collected and concatenated.</p> 
     160      <p><code>CheckMultiple command=CheckDriveSize MaxWarn=1M MaxCrit=2M  
     161      Drive=c:\\volumne_test\\ command=ChEckMeM MaxWarn=80% MaxCrit=90%</code></p> 
     162      <p><code>CRITICAL: c:\volumne_test\: 3M (4193280B) &gt; critical, OK memory  
     163      within bounds.|c:\volumne_test\=4193280;1024K (1048576B);2M (2097152B);  
     164      page=31% 80%;90%;</code></p> 
    159165      </li> 
    160166    </ul> 
  • docs/CheckSystem/index.html

    re655f61 r1d9338a  
    33<head> 
    44<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 
     5<meta http-equiv="Content-Language" content="en-us"> 
    56<title>CheckSystem</title> 
    67<link rel="stylesheet" type="text/css" href="../nscplus.css"> 
     
    4243  <p>This module needs configuration as PDH counters are version and language  
    4344  specific. This means that unless you use an English language windows 2000 you  
    44   will most likely have to edit this. There is also some other tweks that can  
     45  will most likely have to edit this. There is also some other tweaks that can  
    4546  be configured such as check resolution and buffer size. For more details on  
    4647  how to configure this refer to the Configuration section.</p> 
     
    158159    <ul> 
    159160      <li> 
    160       <p>Check that the system has been running for atleast a day:</p> 
     161      <p>Check that the system has been running for at least a day:</p> 
    161162      <p><code>checkUpTime warn=1d crit=12h</code></p> 
    162163      <p><code>Client has uptime (19h) &lt; warning (24h)</code></p> 
     
    303304  counters use the program perfmon that is shipped with windows. An important  
    304305  note is that performance counters are language and version specific.</p> 
     306  <p><i><b>This is currently broken and will be fixed in the next version.</b></i></p> 
    305307  <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" id="table16"> 
    306308    <tr> 
     
    346348    <tr> 
    347349      <td valign="top">Counter:&lt;name&gt;</td> 
    348       <td valign="top">Perfomance Counter</td> 
     350      <td valign="top">Performance Counter</td> 
    349351      <td valign="top">Add a named performance counter. The &lt;name&gt; will be  
    350352      used as an alias.</td> 
  • docs/Configuration/index.html

    re655f61 r1d9338a  
    33<head> 
    44<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 
     5<meta http-equiv="Content-Language" content="en-us"> 
    56<title>Configuration</title> 
    67<link rel="stylesheet" type="text/css" href="../nscplus.css"> 
     
    2324  has a lot of examples and comments so make sure you change this before you use  
    2425  NSClient++ as some of the examples might be potential security issues.</p> 
     26  <h2>[Settings]</h2> 
     27  <p>This section has options for how logging is performed. First off notice that  
     28  for logging to make sense you need to enable the “FileLogger.dll” module that  
     29  logs all log data to a text file in the same directory as the NSClient++ binary  
     30  if you don’t enable any logging module nothing will be logged.</p> 
     31  <p>The options you have available here are</p> 
     32  <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" id="table21"> 
     33    <tr> 
     34      <td valign="top">Option</td> 
     35      <td valign="top">Default value</td> 
     36      <td valign="top">Description</td> 
     37    </tr> 
     38    <tr> 
     39      <td valign="top">obfuscated_password</td> 
     40      <td valign="top">...</td> 
     41      <td valign="top">An obfuscated version of password. For more details  
     42      refer to the password option below.</td> 
     43    </tr> 
     44    <tr> 
     45      <td valign="top">password</td> 
     46      <td valign="top">...</td> 
     47      <td valign="top">The password used by various (presently only  
     48      NSClient) daemons. If no password is set everyone will be able to  
     49      use this service remotely.</td> 
     50    </tr> 
     51    <tr> 
     52      <td valign="top">allowed_hosts</td> 
     53      <td valign="top">127.0.0.1</td> 
     54      <td valign="top">A list (comma separated) with hosts that are  
     55      allowed to connect and query data. If this is empty all hosts will  
     56      be allowed to query data.</td> 
     57    </tr> 
     58  </table> 
    2559  <h2>[Log]</h2> 
    2660  <p>This section has options for how logging is performed. First off notice that  
     
    4781      this is relative to the NSClient++ binary.</td> 
    4882    </tr> 
     83    <tr> 
     84      <td valign="top">date_mask</td> 
     85      <td valign="top">%Y-%m-%d %H:%M:%S</td> 
     86      <td valign="top">The date format used when logging to a file</td> 
     87    </tr> 
    4988  </table> 
    5089  <h2>[Systray]</h2> 
     
    79118    </tr> 
    80119    <tr> 
     120      <td valign="top">obfuscated_password</td> 
     121      <td valign="top">&nbsp;</td> 
     122      <td valign="top">An obfuscated version of password. For more details  
     123      refer to the password option below. </td> 
     124    </tr> 
     125    <tr> 
    81126      <td valign="top">password</td> 
    82127      <td valign="top">&nbsp;</td> 
    83128      <td valign="top">The password that incoming client needs to authorize  
    84       themselves by.</td> 
     129      themselves by. This option will replace the one found under Settings  
     130      for NSClient. If this is blank the option found under Settings will  
     131      be used. If both are blank everyone will be granted access.</td> 
    85132    </tr> 
    86133    <tr> 
     
    88135      <td valign="top">&nbsp;</td> 
    89136      <td valign="top">A list (coma separated) with hosts that are allowed  
    90       to poll information from NSClient++</td> 
    91     </tr> 
    92     <tr> 
    93       <td valign="top">use_ssl</td> 
    94       <td valign="top">0</td> 
    95       <td valign="top">Boolean value to toggle SSL encryption. This is not  
    96       yet supported in any client I know of but as the underlying structure  
    97       (NRPE) supports it I thought Id might add it if someone wants to update  
    98       check_nt to support SSL.<b>Not implemented in this version</b></td> 
    99     </tr> 
    100   </table> 
     137      to poll information from NSClient++. This will replace the one found  
     138      under Setting for NSClient if present. If not present the same  
     139      option found under Settings will be used. If both are blank all  
     140      hosts will be allowed to access the system</td> 
     141    </tr> 
     142    </table> 
    101143  <h2>[NRPE]</h2> 
    102144  <p>This is configuration for the NRPE module that controls how the NRPE listener  
     
    117159      <td valign="top">&nbsp;</td> 
    118160      <td valign="top">A list (coma separated) with hosts that are allowed  
    119       to poll information from NSClient++</td> 
     161      to poll information from NRPE. This will replace the one found under  
     162      Setting for NRPE if present. If not present the same option found  
     163      under Settings will be used. If both are blank all hosts will be  
     164      allowed to access the system</td> 
    120165    </tr> 
    121166    <tr> 
     
    129174      <td valign="top">60</td> 
    130175      <td valign="top">The maximum time in seconds that a command can execute.  
    131       (if more then this execution will be aborted).<b>NOTICE</b> this only  
     176      (if more then this execution will be aborted).<b> NOTICE</b> this only  
    132177      affects external commands not internal ones.</td> 
    133178    </tr> 
     
    156201  The latter is the preferred way as it is shorter.</p> 
    157202  <h2>[Check System]</h2> 
    158   <p>Here you can set various options to configure the Syetem Check module.</p> 
     203  <p>Here you can set various options to configure the System Check module.</p> 
    159204  <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" id="table20"> 
    160205    <tr> 
     
    179224    <tr> 
    180225      <td valign="top">CounterPageLimit</td> 
    181       <td valign="top">\\\\.\\Memory\\Commit Limit</td> 
     226      <td valign="top">\Memory\Commit Limit</td> 
    182227      <td valign="top">Counter to use to check upper memory limit.</td> 
    183228    </tr> 
    184229    <tr> 
    185230      <td valign="top">CounterPage</td> 
    186       <td valign="top">\\\\.\\Memory\\Committed Bytes</td> 
     231      <td valign="top">\Memory\Committed Bytes</td> 
    187232      <td valign="top">Counter to use to check current memory usage.</td> 
    188233    </tr> 
    189234    <tr> 
    190235      <td valign="top">CounterUptime</td> 
    191       <td valign="top">\\\\.\\System\\System Up Time</td> 
     236      <td valign="top">\System\System Up Time</td> 
    192237      <td valign="top">Counter to use to check the uptime of the system.</td> 
    193238    </tr> 
    194239    <tr> 
    195240      <td valign="top">CounterCPU</td> 
    196       <td valign="top">\\\\.\\Processor(_total)\\% Processor Time</td> 
    197       <td valign="top">Counter to use for CPU load.</td> 
     241      <td valign="top">\Processor(_total)\% Processor Time</td> 
     242      <td valign="top">Counter to use for CPU load. For NT4 this has to be  
     243      altered to &quot;\System\% Total Processor Time&quot; as PDH definitions have changed.</td> 
    198244    </tr> 
    199245  </table> 
  • docs/FileLogger/index.html

    re655f61 r1d9338a  
    33<head> 
    44<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 
     5<meta http-equiv="Content-Language" content="en-us"> 
    56<title>FileLogger</title> 
    67<link rel="stylesheet" type="text/css" href="../nscplus.css"> 
  • docs/NRPEListener/index.html

    r1e62ed5 r1d9338a  
    33<head> 
    44<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 
     5<meta http-equiv="Content-Language" content="en-us"> 
    56<title>NRPEListener</title> 
    67<link rel="stylesheet" type="text/css" href="../nscplus.css"> 
  • docs/SysTray/index.html

    raf5bc4b r1d9338a  
    33<head> 
    44<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 
     5<meta http-equiv="Content-Language" content="en-us"> 
    56<title>SysTray</title> 
    67<link rel="stylesheet" type="text/css" href="../nscplus.css"> 
  • docs/index.html

    r1e62ed5 r1d9338a  
    99  <frameset cols="212,*"> 
    1010    <frame name="contents" target="main" src="menu.html" scrolling="no" noresize> 
    11     <frame name="main" src="welcome.html" scrolling="auto"> 
     11    <frame name="main" src="welcome.html" scrolling="auto" target="_self"> 
    1212  </frameset> 
    1313  <noframes> 
  • docs/nscplus.css

    r1e62ed5 r1d9338a  
    111111  padding: 5px; 
    112112} 
     113 
     114.config { 
     115  padding: 0px 0px 0px 20px; 
     116  border: none; 
     117  background: lightgrey; 
     118  font-style: italic; 
     119  clear: both; 
     120} 
     121 
     122 
     123 
     124 
  • docs/welcome.html

    r1e62ed5 r1d9338a  
    11<html> 
    2  
    32<head> 
    43<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 
    54<title>About NSClient++</title> 
    65<link rel="stylesheet" type="text/css" href="nscplus.css"> 
     6<base target="_self"> 
    77</head> 
    88 
     
    2323plug-in is of course the most powerful way but requires knowledge of C++ or other  
    2424language which can produce DLLs and interface with regular C programs.</p> 
     25<p>As for checking with NSClient++ I would recommend 
     26<a href="http://sourceforge.net/project/showfiles.php?group_id=26589&package_id=40241"> 
     27NRPE</a> as it is a lot more flexible then check_nt. But NSClient has full  
     28support for check_nt and if there is an interest I could probably add support  
     29for check_nt from nc_net.</p> 
    2530<h1>News</h1> 
    2631<table id="table17"   border="0" cellspacing="0" cellpadding="0" class="MsoNormalTable" > 
    2732  <tr> 
    28     <td>2005-05-14</td> 
     33    <td valign="top">2005-05-23</td> 
     34    <td>New version available.<p>Has many new features and some enhancements  
     35    as well as NT4 Compatibility (verified this time).</p> 
     36    <p>Added:</p> 
     37    <ul> 
     38      <li>Multitasking support for requests.</li> 
     39      <li>NRPE support for checkCounter</li> 
     40      <li>CheckHelpers module to alter the result of various check and  
     41      similar things </li> 
     42      <li>Support for Volumes (CheckDisk)</li> 
     43      <li>Support for checking all drives</li> 
     44      <li>Support for altering filter (makes it possible to check  
     45      removable/network drives)</li> 
     46      <li>Webpage and better documentation</li> 
     47      <li>Obfuscated password support (try NSClient++ /encrypt)</li> 
     48      <li>Central host/password options in INI file (look for [Settings])</li> 
     49    </ul> 
     50    <p>Enhances/Fixes:</p> 
     51    <ul> 
     52      <li>Some threading issues fixed</li> 
     53      <li>Verified NT4 compatibility</li> 
     54      <li>Fixed bug in NSC.ini (section title for Check System was wrong)</li> 
     55      <li>Fixed some minor issues here and there</li> 
     56      <li>Make check commands ignore case</li> 
     57      <li>Better debugging log (timestamps, better info, etc)</li> 
     58      <li>Support for password-less NSClient</li> 
     59    </ul> 
     60    </td> 
     61  </tr> 
     62  <tr> 
     63    <td valign="top">2005-05-14</td> 
    2964    <td>New webpage is created and semi updated.</td> 
    3065  </tr> 
     
    3368<p>NSClient can be found at its source forge page 
    3469<a href="http://nscplus.sf.net" target="_top">http://nscplus.sf.net</a></p> 
    35 <p>Latest version is <a href="http://prdownloads.sourceforge.net/nscplus/NSClient++-0.1.0-a2.zip?download">NSClient++ 0.1.0 Alpha 2.zip</a> </p> 
     70<p>Latest version is <a href="http://prdownloads.sourceforge.net/nscplus/NSClient++-0.2.0.zip?download">NSClient++ 0.2.0.zip</a></p> 
    3671<h1>Modules</h1> 
    3772<p>NSClient++ comes with a few modules out of the box that does various checks.  
     
    104139  <tr> 
    105140    <td width="221" colspan="2"><b><a href="CheckHelpers/index.html">CheckHelpers</a></b></td> 
    106     <td>Various helper function, doesn't check anything it it self but can  
     141    <td>Various helper function, doesn't check anything in it self but can  
    107142    help make things simpler.</td> 
    108143  </tr> 
  • include/Mutex.h

    r1e62ed5 r1d9338a  
    101101   */ 
    102102  MutexLock(HANDLE hMutex, DWORD timeout = 5000L) : bHasMutex(false), hMutex_(hMutex) { 
     103    if (hMutex_ == NULL) 
     104      std::cout << "Whops..." << std::endl; 
    103105    assert(hMutex_ != NULL); 
    104106    dwWaitResult = WaitForSingleObject(hMutex_, timeout); 
  • include/NSCAPI.h

    r81e29d8 r1d9338a  
    2222  } errorReturn; 
    2323#else 
    24   const int returnCRIT = 2; 
    2524  const int returnOK = 0; 
    2625  const int returnWARN = 1; 
     26  const int returnCRIT = 2; 
    2727  const int returnUNKNOWN = 4; 
    2828  const int returnInvalidBufferLen = -2; 
     
    3838#endif 
    3939 
     40  const int xor = 1; 
    4041 
    4142  // Various message Types 
  • include/NSCHelper.cpp

    r1e62ed5 r1d9338a  
    107107  lpNSAPIStopServer fNSAPIStopServer = NULL; 
    108108  lpNSAPIInject fNSAPIInject = NULL; 
     109  lpNSAPICheckLogMessages fNSAPICheckLogMessages = NULL; 
     110  lpNSAPIEncrypt fNSAPIEncrypt = NULL; 
     111  lpNSAPIDecrypt fNSAPIDecrypt = NULL; 
    109112} 
    110113 
     
    123126 */ 
    124127void NSCModuleHelper::Message(int msgType, std::string file, int line, std::string message) { 
    125   if (fNSAPIMessage)  
     128  if (fNSAPIMessage) { 
     129    if ((msgType == NSCAPI::debug) && (!logDebug())) 
     130      return; 
    126131    return fNSAPIMessage(msgType, file.c_str(), line, message.c_str()); 
     132  } 
    127133  else 
    128134    std::cout << "NSCore not loaded..." << std::endl << message << std::endl; 
     
    354360  return ret; 
    355361} 
     362 
     363 
     364bool NSCModuleHelper::logDebug() { 
     365  typedef enum status {unknown, debug, nodebug }; 
     366  static status d = unknown; 
     367  if (d == unknown) { 
     368    if (checkLogMessages(debug)== NSCAPI::istrue) 
     369      d = debug; 
     370    else 
     371      d = nodebug; 
     372  } 
     373  return (d == debug); 
     374} 
     375 
     376 
     377 
     378 
     379std::string NSCModuleHelper::Encrypt(std::string str, unsigned int algorithm) { 
     380  if (!fNSAPIEncrypt) 
     381    throw NSCMHExcpetion("NSCore has not been initiated..."); 
     382  unsigned int len = 0; 
     383  fNSAPIEncrypt(algorithm, str.c_str(), str.size(), NULL, &len); 
     384  len+=2; 
     385  char *buf = new char[len+1]; 
     386  NSCAPI::errorReturn ret = fNSAPIEncrypt(algorithm, str.c_str(), str.size(), buf, &len); 
     387  if (ret == NSCAPI::isSuccess) { 
     388    std::string ret = buf; 
     389    delete [] buf; 
     390    return ret; 
     391  } 
     392  return ""; 
     393} 
     394std::string NSCModuleHelper::Decrypt(std::string str, unsigned int algorithm) { 
     395  if (!fNSAPIDecrypt) 
     396    throw NSCMHExcpetion("NSCore has not been initiated..."); 
     397  unsigned int len = 0; 
     398  fNSAPIDecrypt(algorithm, str.c_str(), str.size(), NULL, &len); 
     399  len+=2; 
     400  char *buf = new char[len+1]; 
     401  NSCAPI::errorReturn ret = fNSAPIDecrypt(algorithm, str.c_str(), str.size(), buf, &len); 
     402  if (ret == NSCAPI::isSuccess) { 
     403    std::string ret = buf; 
     404    delete [] buf; 
     405    return ret; 
     406  } 
     407  return ""; 
     408} 
     409 
     410 
     411bool NSCModuleHelper::checkLogMessages(int type) { 
     412  if (!fNSAPICheckLogMessages) 
     413    throw NSCMHExcpetion("NSCore has not been initiated..."); 
     414  return fNSAPICheckLogMessages(type) == NSCAPI::istrue; 
     415} 
    356416/** 
    357417 * Retrieve the application version as a string (in human readable format) from the core. 
     
    416476  NSCModuleHelper::fNSAPIInject = (NSCModuleHelper::lpNSAPIInject)f("NSAPIInject"); 
    417477  NSCModuleHelper::fNSAPIGetBasePath = (NSCModuleHelper::lpNSAPIGetBasePath)f("NSAPIGetBasePath"); 
     478  NSCModuleHelper::fNSAPICheckLogMessages = (NSCModuleHelper::lpNSAPICheckLogMessages)f("NSAPICheckLogMessages"); 
     479  NSCModuleHelper::fNSAPIDecrypt = (NSCModuleHelper::lpNSAPIDecrypt)f("NSAPIDecrypt"); 
     480  NSCModuleHelper::fNSAPIEncrypt = (NSCModuleHelper::lpNSAPIEncrypt)f("NSAPIEncrypt"); 
    418481  return NSCAPI::isSuccess; 
    419482} 
  • include/NSCHelper.h

    r1e62ed5 r1d9338a  
    8484  typedef NSCAPI::nagiosReturn (*lpNSAPIInject)(const char*, const unsigned int, char **, char *, unsigned int, char *, unsigned int); 
    8585  typedef LPVOID (*lpNSAPILoader)(char*); 
     86  typedef NSCAPI::boolReturn (*lpNSAPICheckLogMessages)(int); 
     87  typedef NSCAPI::errorReturn (*lpNSAPIEncrypt)(unsigned int, const char*, unsigned int, char*, unsigned int *); 
     88  typedef NSCAPI::errorReturn (*lpNSAPIDecrypt)(unsigned int, const char*, unsigned int, char*, unsigned int *); 
    8689 
    8790  // Helper functions for calling into the core 
     
    98101  void StopService(void); 
    99102  std::string getBasePath(); 
     103  bool logDebug(); 
     104  bool checkLogMessages(int type); 
     105  std::string Encrypt(std::string str, unsigned int algorithm = NSCAPI::xor); 
     106  std::string Decrypt(std::string str, unsigned int algorithm = NSCAPI::xor); 
    100107}; 
    101108 
  • include/PDHCollectors.h

    rcea178b r1d9338a  
    44 
    55namespace PDHCollectors { 
    6   class StaticPDHCounterListener : public PDH::PDHCounterListener { 
     6  class StaticPDHCounterListenerInt : public PDH::PDHCounterListener { 
    77    __int64 value_; 
    88  public: 
     
    1616    } 
    1717    __int64 getValue() const { 
     18      return value_; 
     19    } 
     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 { 
    1833      return value_; 
    1934    } 
  • include/PDHCounter.h

    raf5bc4b r1d9338a  
    7777        listener_->collect(*this); 
    7878    } 
     79    double getDoubleValue() const { 
     80      return data_.doubleValue; 
     81    } 
    7982    __int64 getInt64Value() const { 
    8083      return data_.largeValue; 
     
    128131        throw PDHException("PdhCloseQuery failed", status); 
    129132      hQuery_ = NULL; 
     133      for (CounterList::iterator it = counters_.begin(); it != counters_.end(); it++) { 
     134        delete (*it); 
     135      } 
     136      counters_.clear(); 
    130137    } 
    131138 
  • include/Socket.cpp

    r1e62ed5 r1d9338a  
    77 * @param error  
    88 */ 
    9 void simpleSocket::Socket::printError(std::string error) { 
    10   NSC_LOG_ERROR_STD(error); 
     9void simpleSocket::Socket::printError(std::string FILE, int LINE, std::string error) { 
     10  NSCModuleHelper::Message(NSCAPI::error, FILE, LINE, error); 
    1111} 
    1212 
  • include/Socket.h

    r1e62ed5 r1d9338a  
    1818      return error_; 
    1919    } 
    20      
     20 
    2121  }; 
    2222  class DataBuffer { 
     
    150150      return inet_ntoa(from_.sin_addr); 
    151151    } 
    152     virtual void printError(std::string error); 
     152    virtual void printError(std::string file, int line, std::string error); 
    153153  }; 
    154154 
     
    161161 
    162162  /** 
    163    * @ingroup NSClient++ 
    164    * Socket responder class. 
    165    * This is a background thread that listens to the socket and executes incoming commands. 
    166    * 
    167    * @version 1.0 
    168    * first version 
    169    * 
    170    * @date 02-12-2005 
    171    * 
    172    * @author mickem 
    173    * 
    174    * @par license 
    175    * This code is absolutely free to use and modify. The code is provided "as is" with 
    176    * no expressed or implied warranty. The author accepts no liability if it causes 
    177    * any damage to your computer, causes your pet to fall ill, increases baldness 
    178    * or makes your car start emitting strange noises when you start it up. 
    179    * This code has no bugs, just undocumented features! 
    180    *  
    181    * @todo This is not very well written and should probably be reworked. 
    182    * 
    183    * @bug  
    184    * 
    185    */ 
     163  * @ingroup NSClient++ 
     164  * Socket responder class. 
     165  * This is a background thread that listens to the socket and executes incoming commands. 
     166  * 
     167  * @version 1.0 
     168  * first version 
     169  * 
     170  * @date 02-12-2005 
     171  * 
     172  * @author mickem 
     173  * 
     174  * @par license 
     175  * This code is absolutely free to use and modify. The code is provided "as is" with 
     176  * no expressed or implied warranty. The author accepts no liability if it causes 
     177  * any damage to your computer, causes your pet to fall ill, increases baldness 
     178  * or makes your car start emitting strange noises when you start it up. 
     179  * This code has no bugs, just undocumented features! 
     180  *  
     181  * @todo This is not very well written and should probably be reworked. 
     182  * 
     183  * @bug  
     184  * 
     185  */ 
    186186  template <class TListenerType = simpleSocket::Socket, class TSocketType = TListenerType> 
    187187  class Listener : public TListenerType { 
     
    191191  private: 
    192192    struct simpleResponderBundle { 
     193      bool terminated; 
    193194      HANDLE hThread; 
    194195      unsigned dwThreadID; 
     
    226227    Listener() : pHandler_(NULL) {}; 
    227228    virtual ~Listener() { 
    228       if (responderList_.size() > 0) 
    229         std::cout << "We had stale processes running then the socket closed." << std::endl; 
    230       // @todo check if we have stale processes here (if so log an error) 
     229      if (responderList_.size() > 0) { 
     230        MutexLock lock(responderMutex_); 
     231        if (!lock.hasMutex()) { 
     232          printError(__FILE__, __LINE__, "Failed to get responder mutex (cannot terminate socket threads)."); 
     233        } else { 
     234          for (socketResponses::iterator it = responderList_.begin(); it != responderList_.end(); ++it) { 
     235            if (WaitForSingleObject( (*it).hThread, 1000) == WAIT_OBJECT_0) { 
     236            } else { 
     237              if (!TerminateThread((*it).hThread, -1)) { 
     238                printError(__FILE__, __LINE__, "We failed to terminate check thread."); 
     239              } else { 
     240                if (WaitForSingleObject( (*it).hThread, 5000) == WAIT_OBJECT_0) { 
     241                  CloseHandle((*it).hThread); 
     242                } else { 
     243                  printError(__FILE__, __LINE__, "We failed to terminate check thread (wait timed out)."); 
     244                } 
     245              } 
     246            } 
     247          } 
     248          responderList_.clear(); 
     249        } 
     250      } 
    231251    }; 
    232252 
     
    255275    }; 
    256276    void addResponder(tSocket *client) { 
     277      MutexLock lock(responderMutex_); 
     278      if (!lock.hasMutex()) { 
     279        printError(__FILE__, __LINE__, "Failed to get responder mutex."); 
     280        return; 
     281      } 
     282      for (socketResponses::iterator it = responderList_.begin(); it != responderList_.end();) { 
     283        if ( (*it).terminated) { 
     284          if (WaitForSingleObject( (*it).hThread, 500) == WAIT_OBJECT_0) { 
     285            CloseHandle((*it).hThread); 
     286            responderList_.erase(it++); 
     287          } 
     288        } else 
     289          ++it; 
     290      } 
    257291      simpleResponderBundle data; 
    258       // @todo protect 
    259292      srp_data *lpData = new srp_data; 
    260293      lpData->pCore = this; 
    261294      lpData->client = client; 
    262295 
    263       MutexLock lock(responderMutex_); 
    264       if (!lock.hasMutex()) { 
    265         printError("Failed to get responder mutex."); 
    266         return; 
    267       } 
    268296      data.hThread = reinterpret_cast<HANDLE>(::_beginthreadex( NULL, 0, &socketResponceProc, lpData, 0, &data.dwThreadID)); 
     297      data.terminated = false; 
    269298      responderList_.push_back(data); 
    270299    } 
     
    272301      MutexLock lock(responderMutex_); 
    273302      if (!lock.hasMutex()) { 
    274         printError("Failed to get responder mutex when trying to free thread."); 
     303        printError(__FILE__, __LINE__, "Failed to get responder mutex when trying to free thread."); 
    275304        return false; 
    276305      } 
    277306      for (socketResponses::iterator it = responderList_.begin(); it != responderList_.end(); ++it) { 
    278307        if ( (*it).dwThreadID == dwThreadID) { 
    279           responderList_.erase(it); 
     308          (*it).terminated = true; 
    280309          return true; 
    281310        } 
     
    316345    pCore->onAccept(client); 
    317346  } catch (SocketException e) { 
    318     pCore->printError(e.getMessage() + " killing socket..."); 
     347    pCore->printError(__FILE__, __LINE__, e.getMessage() + " killing socket..."); 
    319348  } 
    320349  client->close(); 
    321350  delete client; 
    322351  if (!pCore->removeResponder(GetCurrentThreadId())) { 
    323     pCore->printError("Could not remove thread: " + strEx::itos(GetCurrentThreadId())); 
     352    pCore->printError(__FILE__, __LINE__, "Could not remove thread: " + strEx::itos(GetCurrentThreadId())); 
    324353  } 
    325354  _endthreadex(0); 
     
    335364  hStopEvent_ = CreateEvent(NULL, TRUE, FALSE, NULL); 
    336365  if (!hStopEvent_) { 
    337     core->printError("Create StopEvent failed: " + strEx::itos(GetLastError())); 
     366    core->printError(__FILE__, __LINE__, "Create StopEvent failed: " + strEx::itos(GetLastError())); 
    338367    return 0; 
    339368  } 
     
    352381        } 
    353382      } catch (SocketException e) { 
    354         core->printError(e.getMessage() + ", attempting to resume..."); 
     383        core->printError(__FILE__, __LINE__, e.getMessage() + ", attempting to resume..."); 
    355384      } 
    356385    } 
    357386  } catch (SocketException e) { 
    358     core->printError(e.getMessage()); 
     387    core->printError(__FILE__, __LINE__, e.getMessage()); 
    359388  } 
    360389  core->shutdown(SD_BOTH); 
     
    364393  hStopEvent_ = NULL; 
    365394  if (!CloseHandle(hTmp)) { 
    366     core->printError("CloseHandle StopEvent failed: " + strEx::itos(GetLastError())); 
     395    core->printError(__FILE__, __LINE__, "CloseHandle StopEvent failed: " + strEx::itos(GetLastError())); 
    367396  } 
    368397  return 0; 
  • include/config.h

    r1e62ed5 r1d9338a  
    55 
    66// Version 
    7 #define SZVERSION "0.3.0 a1 2005-05-16" 
     7#define SZVERSION "0.2.0 2005-05-21" 
    88 
    99// internal name of the service 
     
    3131#define NSCLIENT_SETTINGS_PORT "port" 
    3232#define NSCLIENT_SETTINGS_PORT_DEFAULT 12489 
    33 #define NSCLIENT_SETTINGS_ALLOWED "allowed_hosts" 
    34 #define NSCLIENT_SETTINGS_ALLOWED_DEFAULT "" 
    35 #define NSCLIENT_SETTINGS_PWD "password" 
    36 #define NSCLIENT_SETTINGS_PWD_DEFAULT "" 
     33#define NSCLIENT_SETTINGS_VERSION "version" 
     34#define NSCLIENT_SETTINGS_VERSION_DEFAULT "auto" 
    3735 
    3836// NRPE Settings headlines 
     
    4139#define NRPE_SETTINGS_TIMEOUT "command_timeout" 
    4240#define NRPE_SETTINGS_TIMEOUT_DEFAULT 60 
    43 #define NRPE_SETTINGS_ALLOWED "allowed_hosts" 
    44 #define NRPE_SETTINGS_ALLOWED_DEFAULT "" 
    4541#define NRPE_SETTINGS_PORT "port" 
    4642#define NRPE_SETTINGS_PORT_DEFAULT 5666 
     
    7470#define LOG_SECTION_TITLE "log" 
    7571#define LOG_FILENAME "file"  
    76 #define LOG_FILENAME_DEFAULT "nsclient.log"  
     72#define LOG_FILENAME_DEFAULT "nsclient.log" 
     73#define LOG_DATEMASK "date_mask" 
     74#define LOG_DATEMASK_DEFAULT "%Y-%m-%d %H:%M:%S" 
    7775 
     76// Main Settings 
     77#define MAIN_SECTION_TITLE "Settings" 
     78#define MAIN_MASTERKEY "master_key"  
     79#define MAIN_MASTERKEY_DEFAULT "This is a secret key thet you should change" 
     80#define MAIN_OBFUSCATED_PASWD "obfuscated_password" 
     81#define MAIN_OBFUSCATED_PASWD_DEFAULT "" 
     82#define MAIN_SETTINGS_PWD "password" 
     83#define MAIN_SETTINGS_PWD_DEFAULT "" 
     84#define MAIN_ALLOWED_HOSTS "allowed_hosts" 
     85#define MAIN_ALLOWED_HOSTS_DEFAULT "127.0.0.1" 
  • include/thread.h

    rcea178b r1d9338a  
    77public: 
    88  std::string e_; 
    9   ThreadException(std::string e) : e_(e) {} 
     9  ThreadException(std::string e) : e_(e) { 
     10    std::cout << e << std::endl; 
     11  } 
    1012}; 
    1113 
     
    6971        throw ThreadException("Could not retrieve mutex when killing thread, we are fucked..."); 
    7072      } 
    71       if (hThread_) 
    72         CloseHandle(hThread_); 
    7373      hThread_ = NULL; 
    7474      if (hStopEvent_) 
     
    9999    delete param; 
    100100 
    101     if (hStopEvent != NULL) { 
    102       instance->threadProc(lpParam); 
    103       SetEvent(hStopEvent); 
    104     } 
     101    instance->threadProc(lpParam); 
    105102    pCore->terminate(); 
     103    SetEvent(hStopEvent); 
    106104    _endthread(); 
    107105  } 
     
    135133    } 
    136134    hThread_ = reinterpret_cast<HANDLE>(::_beginthread(threadProc, 0, reinterpret_cast<VOID*>(param))); 
    137     assert(hThread_ != NULL); 
    138135  } 
    139136  /** 
     
    153150      assert(hStopEvent_ != NULL); 
    154151      pObject_->exitThread(); 
    155       dwWaitResult = WaitForSingleObject(hStopEvent_, delay); 
    156152    } 
     153    dwWaitResult = WaitForSingleObject(hStopEvent_, delay); 
    157154    switch (dwWaitResult) { 
    158155      // The thread got mutex ownership. 
     
    182179    return pObject_; 
    183180  } 
    184   T* getThread() const { 
     181  T* getThread() { 
    185182    MutexLock mutex(hMutex_, 5000L); 
    186183    if (!mutex.hasMutex()) { 
     
    197194    delete pObject_; 
    198195    pObject_ = NULL; 
    199     CloseHandle(hStopEvent_); 
    200     hStopEvent_ = NULL; 
    201196    hThread_ = NULL; 
    202197  } 
  • modules/CheckDisk/CheckDisk.cpp

    r1e62ed5 r1d9338a  
    204204      return NSCAPI::returnUNKNOWN; 
    205205    } 
     206    //10597515264&80015491072 
    206207 
    207208    if (bNSClient) { 
    208       message += strEx::itos(totalNumberOfFreeBytes.QuadPart) + "&"; 
    209       message += strEx::itos(totalNumberOfBytes.QuadPart) + "&"; 
     209      if (!message.empty()) 
     210        message += "&"; 
     211      message += strEx::itos(totalNumberOfFreeBytes.QuadPart); 
     212      message += "&"; 
     213      message += strEx::itos(totalNumberOfBytes.QuadPart); 
    210214    } else { 
    211215      std::string tStr; 
     
    236240  if (message.empty()) 
    237241    message = "All drive sizes are within bounds."; 
    238   else 
     242  else if (!bNSClient) 
    239243    message = NSCHelper::translateReturn(returnCode) + ": " + message; 
    240244  return returnCode; 
  • modules/CheckSystem/CheckSystem.cpp

    raf5bc4b r1d9338a  
    297297  NSCAPI::nagiosReturn ret = NSCAPI::returnOK; 
    298298  bool bShowAll = false; 
     299  bool bNSClient = false; 
    299300 
    300301  for (arrayBuffer::arrayList::const_iterator it = stl_args.begin(); it != stl_args.end(); ++it) { 
     
    302303    if (t.first == SHOW_ALL) 
    303304      bShowAll = true; 
     305    else if (t.first == NSCLIENT) 
     306      bNSClient = true; 
    304307    else if (t.first == SHOW_FAIL)  { 
    305308      bShowAll = false; 
     
    339342  } 
    340343  if (msg.empty()) 
    341     msg ="All services ok."; 
     344    msg ="All services are running."; 
     345  else if (!bNSClient) 
     346    msg = NSCHelper::translateReturn(ret) + ": " + msg; 
    342347  return ret; 
    343348} 
     
    345350 
    346351/** 
    347  * Check availible memory and return various check results 
     352 * Check available memory and return various check results 
    348353 * Example: checkMem showAll maxWarn=50 maxCrit=75 
    349354 * 
     
    468473  NSCAPI::nagiosReturn ret = NSCAPI::returnOK; 
    469474  bool bShowAll = false; 
     475  bool bNSClient = false; 
    470476 
    471477  for (arrayBuffer::arrayList::const_iterator it = stl_args.begin(); it != stl_args.end(); ++it) { 
     
    473479    if (t.first == SHOW_ALL) 
    474480      bShowAll = true; 
     481    else if (t.first == NSCLIENT) 
     482      bNSClient = true; 
    475483    else if (t.first == SHOW_FAIL)  { 
    476484      bShowAll = false; 
     
    518526  if (msg.empty()) 
    519527    msg ="All processes ok."; 
     528  else if (!bNSClient) 
     529    msg = NSCHelper::translateReturn(ret) + ": " + msg; 
    520530  return ret; 
    521531} 
     
    583593    try { 
    584594      PDH::PDHQuery pdh; 
    585       PDHCollectors::StaticPDHCounterListener counter; 
     595      PDHCollectors::StaticPDHCounterListenerInt counter; 
    586596      std::string name = (*it).first; 
    587597      if (name.empty()) 
     
    591601      pdh.collect(); 
    592602      if (bNSCLientCompatible) { 
     603//        std::cout << counter.getValue() << std::endl; 
    593604        msg += strEx::itos(counter.getValue()); 
    594605      } else { 
  • modules/CheckSystem/PDHCollector.cpp

    raf5bc4b r1d9338a  
    3636 
    3737/** 
    38  * Thread that collects the data every "CHECK_INTERVAL" seconds. 
    39  * 
    40  * @param lpParameter Not used 
    41  * @return thread exit status 
    42  * 
    43  * @author mickem 
    44  * 
    45  * @date 03-13-2004 
    46  * 
    47  * @bug If we have "custom named" counters ? 
    48  * @bug This whole concept needs work I think. 
    49  * 
    50  */ 
     38* Thread that collects the data every "CHECK_INTERVAL" seconds. 
     39* 
     40* @param lpParameter Not used 
     41* @return thread exit status 
     42* 
     43* @author mickem 
     44* 
     45* @date 03-13-2004 
     46* 
     47* @bug If we have "custom named" counters ? 
     48* @bug This whole concept needs work I think. 
     49* 
     50*/ 
    5151DWORD PDHCollector::threadProc(LPVOID lpParameter) { 
    5252  PDH::PDHQuery pdh; 
     
    103103 
    104104/** 
    105  * Request termination of the thread (waiting for thread termination is not handled) 
    106  */ 
     105* Request termination of the thread (waiting for thread termination is not handled) 
     106*/ 
    107107void PDHCollector::exitThread(void) { 
    108108  MutexLock mutex(mutexHandler); 
     
    116116    if (!SetEvent(hStopEvent_)) { 
    117117      NSC_LOG_ERROR_STD("SetStopEvent failed"); 
    118   } 
     118    } 
    119119} 
    120120/** 
    121  * Get the average CPU usage for "time" 
    122  * @param time Time to check  
    123  * @return average CPU usage 
    124  */ 
     121* Get the average CPU usage for "time" 
     122* @param time Time to check  
     123* @return average CPU usage 
     124*/ 
    125125int PDHCollector::getCPUAvrage(std::string time) { 
    126126  unsigned int mseconds = strEx::stoui_as_time(time, checkIntervall_*100); 
     
    133133} 
    134134/** 
    135  * Get uptime from counter 
    136  * @bug Do we need to collect this all the time ? (perhaps we can collect this in real time ?) 
    137  * @return uptime for the system 
    138  * @bug Are we overflow protected here ? (seem to recall some issues with overflow before ?) 
    139  */ 
     135* Get uptime from counter 
     136* @bug Do we need to collect this all the time ? (perhaps we can collect this in real time ?) 
     137* @return uptime for the system 
     138* @bug Are we overflow protected here ? (seem to recall some issues with overflow before ?) 
     139*/ 
    140140long long PDHCollector::getUptime() { 
    141141  MutexLock mutex(mutexHandler); 
     
    147147} 
    148148/** 
    149  * Memory commit limit (your guess is as good as mine to what this is :) 
    150  * @return Some form of memory check 
    151  */ 
     149* Memory commit limit (your guess is as good as mine to what this is :) 
     150* @return Some form of memory check 
     151*/ 
    152152long long PDHCollector::getMemCommitLimit() { 
    153153  MutexLock mutex(mutexHandler); 
     
    159159} 
    160160/** 
    161  * 
    162  * Memory committed bytes (your guess is as good as mine to what this is :) 
    163  * @return Some form of memory check 
    164  */ 
     161* 
     162* Memory committed bytes (your guess is as good as mine to what this is :) 
     163* @return Some form of memory check 
     164*/ 
    165165long long PDHCollector::getMemCommit() { 
    166166  MutexLock mutex(mutexHandler); 
  • modules/CheckSystem/PDHCollector.h

    raf5bc4b r1d9338a  
    3030  int checkIntervall_; 
    3131 
    32   PDHCollectors::StaticPDHCounterListener memCmtLim; 
    33   PDHCollectors::StaticPDHCounterListener memCmt; 
    34   PDHCollectors::StaticPDHCounterListener upTime; 
     32  PDHCollectors::StaticPDHCounterListenerInt memCmtLim; 
     33  PDHCollectors::StaticPDHCounterListenerInt memCmt; 
     34  PDHCollectors::StaticPDHCounterListenerInt upTime; 
    3535  PDHCollectors::RoundINTPDHBufferListener cpu; 
    3636 
  • modules/FileLogger/FileLogger.cpp

    rcea178b r1d9338a  
    44#include "stdafx.h" 
    55#include "FileLogger.h" 
     6 
     7#include <sys/timeb.h> 
     8#include <time.h> 
    69 
    710FileLogger gFileLogger; 
     
    1821} 
    1922 
     23std::string FileLogger::getFileName() 
     24{ 
     25  if (file_.empty()) { 
     26    file_ = NSCModuleHelper::getSettingsString(LOG_SECTION_TITLE, LOG_FILENAME, LOG_FILENAME_DEFAULT); 
     27    if (file_.find("\\") == std::string::npos) 
     28      file_ = NSCModuleHelper::getBasePath() + "\\" + file_; 
     29  } 
     30  return file_; 
     31} 
     32 
    2033bool FileLogger::loadModule() { 
    21   file_ = NSCModuleHelper::getSettingsString(LOG_SECTION_TITLE, LOG_FILENAME, LOG_FILENAME_DEFAULT); 
     34  _tzset(); 
     35  getFileName(); 
     36  format_ = NSCModuleHelper::getSettingsString(LOG_SECTION_TITLE, LOG_DATEMASK, LOG_DATEMASK_DEFAULT); 
    2237  return true; 
    2338} 
     
    2641} 
    2742std::string FileLogger::getModuleName() { 
    28   return "File logger: " + NSCModuleHelper::getSettingsString(LOG_SECTION_TITLE, LOG_FILENAME, LOG_FILENAME_DEFAULT); 
     43  return "File logger: " + getFileName(); 
    2944} 
    3045NSCModuleWrapper::module_version FileLogger::getModuleVersion() { 
     
    3954} 
    4055void FileLogger::handleMessage(int msgType, char* file, int line, char* message) { 
     56  char buffer[64]; 
    4157  std::ofstream stream(file_.c_str(), std::ios::app); 
    42   stream << NSCHelper::translateMessageType(msgType) << ":" << file << ":" << line << ": " << message << std::endl; 
     58  __time64_t ltime; 
     59  _time64( &ltime ); 
     60  struct tm *today = _localtime64( &ltime ); 
     61  if (today) { 
     62    int len = strftime(buffer, 63, format_.c_str(), today); 
     63    if ((len < 1)||(len > 64)) 
     64      strncpy(buffer, "???", 63); 
     65    else 
     66      buffer[len] = 0; 
     67  } else { 
     68    strncpy(buffer, "???", 63); 
     69  } 
     70  stream << buffer << ": " << NSCHelper::translateMessageType(msgType) << ":" << file << ":" << line << ": " << message << std::endl; 
    4371} 
    4472 
  • modules/FileLogger/FileLogger.h

    ra0528c4 r1d9338a  
    66private: 
    77  std::string file_; 
     8  std::string format_; 
    89 
    910public: 
     
    1920  void handleMessage(int msgType, char* file, int line, char* message); 
    2021  int handleCommand(char* command, char **argument, char *returnBuffer, int returnBufferLen); 
     22 
     23 
     24  std::string getFileName(); 
    2125}; 
  • modules/NRPEListener/NRPEListener.cpp

    r1e62ed5 r1d9338a  
    2222} 
    2323 
    24  
     24std::string getAllowedHosts() { 
     25  std::string ret = NSCModuleHelper::getSettingsString(NRPE_SECTION_TITLE, MAIN_ALLOWED_HOSTS, ""); 
     26  if (ret.empty()) 
     27    ret = NSCModuleHelper::getSettingsString(MAIN_SECTION_TITLE, MAIN_ALLOWED_HOSTS, MAIN_ALLOWED_HOSTS_DEFAULT); 
     28  return ret; 
     29} 
    2530 
    2631bool NRPEListener::loadModule() { 
     
    4348  } 
    4449 
    45   allowedHosts.setAllowedHosts(strEx::splitEx(NSCModuleHelper::getSettingsString(NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOWED, NRPE_SETTINGS_ALLOWED_DEFAULT), ",")); 
     50  allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), ",")); 
    4651  try { 
    4752    if (bUseSSL_) { 
     
    201206      } 
    202207      delete [] buf; 
    203       result = NSCHelper::int2nagios(GetExitCodeProcess(pi.hProcess, &dwexitcode)); 
     208      GetExitCodeProcess(pi.hProcess, &dwexitcode); 
     209      result = NSCHelper::int2nagios(dwexitcode); 
    204210    } 
    205211    CloseHandle(pi.hThread); 
  • modules/NSClientListener/NSClientListener.cpp

    r1e62ed5 r1d9338a  
    3232NSClientListener::~NSClientListener() { 
    3333} 
     34std::string getAllowedHosts() { 
     35  std::string ret = NSCModuleHelper::getSettingsString(NRPE_SECTION_TITLE, MAIN_ALLOWED_HOSTS, ""); 
     36  if (ret.empty()) 
     37    ret = NSCModuleHelper::getSettingsString(MAIN_SECTION_TITLE, MAIN_ALLOWED_HOSTS, MAIN_ALLOWED_HOSTS_DEFAULT); 
     38  return ret; 
     39} 
    3440 
    3541bool NSClientListener::loadModule() { 
    36   allowedHosts.setAllowedHosts(strEx::splitEx(NSCModuleHelper::getSettingsString(NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_ALLOWED, NSCLIENT_SETTINGS_ALLOWED_DEFAULT), ",")); 
     42  allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), ",")); 
    3743  try { 
    3844    socket.setHandler(this); 
     
    8591*/ 
    8692 
     93 
     94std::string getPassword() { 
     95  static std::string password = ""; 
     96  if (password.empty()) { 
     97    password = NSCModuleHelper::getSettingsString(NSCLIENT_SECTION_TITLE, MAIN_OBFUSCATED_PASWD, MAIN_OBFUSCATED_PASWD_DEFAULT); 
     98    if (password.empty()) 
     99      password= NSCModuleHelper::getSettingsString(MAIN_SECTION_TITLE, MAIN_OBFUSCATED_PASWD, MAIN_OBFUSCATED_PASWD_DEFAULT); 
     100    if (!password.empty()) { 
     101      password = NSCModuleHelper::Decrypt(password); 
     102    } else { 
     103      password = NSCModuleHelper::getSettingsString(NSCLIENT_SECTION_TITLE, MAIN_SETTINGS_PWD, MAIN_SETTINGS_PWD_DEFAULT); 
     104      if (password.empty()) 
     105        password = NSCModuleHelper::getSettingsString(MAIN_SECTION_TITLE, MAIN_SETTINGS_PWD, MAIN_SETTINGS_PWD_DEFAULT); 
     106    } 
     107  } 
     108  return password; 
     109} 
     110 
    87111std::string NSClientListener::parseRequest(std::string buffer)  { 
    88112  strEx::token pwd = strEx::getToken(buffer, '&'); 
    89   if ( (pwd.first.empty()) || (pwd.first != NSCModuleHelper::getSettingsString(NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_PWD, NSCLIENT_SETTINGS_PWD_DEFAULT)) ) 
    90     return "ERROR: Invalid password."; 
    91   if (pwd.second.empty()) 
     113  std::string rPwd = getPassword(); 
     114  if ((pwd.first != rPwd) && ((pwd.first == "None") && (!rPwd.empty())) ) { 
     115    NSC_LOG_ERROR_STD("Invalid password (" + pwd.first + ")."); 
     116    return "ERROR: Invalid password.";  
     117  } if (pwd.second.empty()) 
    92118    return "ERRRO: No command specified."; 
    93119  strEx::token cmd = strEx::getToken(pwd.second, '&'); 
     
    113139    case REQ_CLIENTVERSION: 
    114140      { 
    115         std::string v = NSCModuleHelper::getSettingsString("nsclient compat", "version", "modern"); 
    116         if (v == "modern") 
     141        std::string v = NSCModuleHelper::getSettingsString(NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_VERSION, NSCLIENT_SETTINGS_VERSION_DEFAULT); 
     142        if (v == "auto") 
    117143          return NSCModuleHelper::getApplicationName() + " " + NSCModuleHelper::getApplicationVersionString(); 
    118         return NSCModuleHelper::getSettingsString("nsclient compat", "version", "modern"); 
     144        return v; 
    119145      } 
    120146    case REQ_SERVICESTATE: 
    121147      cmd.first = "checkServiceState"; 
     148      cmd.second += "&nsclient"; 
    122149      break; 
    123150    case REQ_PROCSTATE: 
    124151      cmd.first = "checkProcState"; 
     152      cmd.second += "&nsclient"; 
    125153      break; 
    126154    case REQ_MEMUSE: 
Note: See TracChangeset for help on using the changeset viewer.