Changeset 1d9338a in nscp for modules


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 :)
Location:
modules
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • 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.