Changeset 99bb030 in nscp


Ignore:
Timestamp:
03/20/06 16:50:33 (7 years ago)
Author:
Michael Medin <michael@…>
Children:
8b89aba
Parents:
c3579b8
Message:

* empty log message *

Location:
trunk
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/NSC.dist

    r9bc31a8 r99bb030  
    5151 
    5252[NSClient] 
     53;# ALLOWED HOST ADDRESSES 
     54;  This is a comma-delimited list of IP address of hosts that are allowed to talk to NSClient deamon. 
     55;  If you leave this blank the global version will be used instead. 
     56;allowed_hosts= 
     57; 
    5358;# NSCLIENT PORT NUMBER 
    5459;  This is the port the NSClientListener.dll will listen to. 
    5560;port=12489 
     61; 
     62;# BIND TO ADDRESS 
     63;  Allows you to bind server to a specific local address. This has to be a dotted ip adress not a hostname. 
     64;  Leaving this blank will bind to all avalible IP adresses. 
     65;bind_to_address= 
    5666 
    5767 
     
    8797;  This option controls if SSL should be used on the socket. 
    8898;use_ssl=1 
     99; 
     100;# BIND TO ADDRESS 
     101;  Allows you to bind server to a specific local address. This has to be a dotted ip adress not a hostname. 
     102;  Leaving this blank will bind to all avalible IP adresses. 
     103; bind_to_address= 
     104; 
     105;# ALLOWED HOST ADDRESSES 
     106;  This is a comma-delimited list of IP address of hosts that are allowed to talk to NRPE deamon. 
     107;  If you leave this blank the global version will be used instead. 
     108;allowed_hosts= 
     109 
    89110 
    90111[NRPE Handlers] 
  • trunk/NSClient++.cpp

    r9bc31a8 r99bb030  
    2020#include <Socket.h> 
    2121#include <b64/b64.h> 
    22 #include <PDHCounter.h> 
    23 #include <PDHCollectors.h> 
    2422 
    2523 
     
    8987      g_bConsoleLog = true; 
    9088      LOG_MESSAGE(SZAPPNAME " Version: " SZVERSION); 
    91  
    92  
    93     } else if ( _stricmp( "listpdh", argv[1]+1 ) == 0 ) { 
    94       PDH::Enumerations::Objects lst = PDH::Enumerations::EnumObjects(); 
    95       for (PDH::Enumerations::Objects::iterator it = lst.begin();it!=lst.end();++it) { 
    96         if ((*it).instances.size() > 0) { 
    97           for (PDH::Enumerations::Instances::const_iterator it2 = (*it).instances.begin();it2!=(*it).instances.end();++it2) { 
    98             for (PDH::Enumerations::Counters::const_iterator it3 = (*it).counters.begin();it3!=(*it).counters.end();++it3) { 
    99               std::cout << "\\" << (*it).name << "(" << (*it2).name << ")\\" << (*it3).name << std::endl;; 
    100             } 
    101           } 
    102         } else { 
    103           for (PDH::Enumerations::Counters::const_iterator it2 = (*it).counters.begin();it2!=(*it).counters.end();++it2) { 
    104             std::cout << "\\" << (*it).name << "\\" << (*it2).name << std::endl;; 
    105           } 
    106         } 
    107       } 
    108     } else if ( _stricmp( "debugpdh", argv[1]+1 ) == 0 ) { 
    109       PDH::Enumerations::Objects lst = PDH::Enumerations::EnumObjects(); 
    110       for (PDH::Enumerations::Objects::iterator it = lst.begin();it!=lst.end();++it) { 
    111         if ((*it).instances.size() > 0) { 
    112           for (PDH::Enumerations::Instances::const_iterator it2 = (*it).instances.begin();it2!=(*it).instances.end();++it2) { 
    113             for (PDH::Enumerations::Counters::const_iterator it3 = (*it).counters.begin();it3!=(*it).counters.end();++it3) { 
    114               std::string counter = "\\" + (*it).name + "(" + (*it2).name + ")\\" + (*it3).name; 
    115               std::cout << "testing: " << counter << ": "; 
    116               std::string error; 
    117               if (PDH::Enumerations::validate(counter, error)) { 
    118                 std::cout << " found "; 
    119               } else { 
    120                 std::cout << " *NOT* found (" << error << ") " << std::endl; 
    121                 break; 
    122               } 
    123               bool bOpend = false; 
    124               try { 
    125                 PDH::PDHQuery pdh; 
    126                 PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> cDouble; 
    127                 pdh.addCounter(counter, &cDouble); 
    128                 pdh.open(); 
    129                 pdh.gatherData(); 
    130                 pdh.close(); 
    131                 bOpend = true; 
    132               } catch (const PDH::PDHException e) { 
    133                 std::cout << " could *not* be open (" << e.getError() << ") " << std::endl; 
    134                 break; 
    135               } 
    136               std::cout << " open "; 
    137               std::cout << std::endl; 
    138             } 
    139           } 
    140         } else { 
    141           for (PDH::Enumerations::Counters::const_iterator it2 = (*it).counters.begin();it2!=(*it).counters.end();++it2) { 
    142             std::string counter = "\\" + (*it).name + "\\" + (*it2).name; 
    143             std::cout << "testing: " << counter << ": "; 
    144             std::string error; 
    145             if (PDH::Enumerations::validate(counter, error)) { 
    146               std::cout << " found "; 
    147             } else { 
    148               std::cout << " *NOT* found (" << error << ") " << std::endl; 
    149               break; 
    150             } 
    151             bool bOpend = false; 
    152             try { 
    153               PDH::PDHQuery pdh; 
    154               PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> cDouble; 
    155               pdh.addCounter(counter, &cDouble); 
    156               pdh.open(); 
    157               pdh.gatherData(); 
    158               pdh.close(); 
    159               bOpend = true; 
    160             } catch (const PDH::PDHException e) { 
    161               std::cout << " could *not* be open (" << e.getError() << ") " << std::endl; 
    162               break; 
    163             } 
    164             std::cout << " open "; 
    165             std::cout << std::endl;; 
    166           } 
    167         } 
    168       } 
    16989    } else if ( _stricmp( "test", argv[1]+1 ) == 0 ) { 
    17090#ifdef _DEBUG 
     
    17696      */ 
    17797#endif 
    178  
    17998      g_bConsoleLog = true; 
    18099      mainClient.InitiateService(); 
     
    469388 
    470389bool NSClientT::logDebug() { 
    471   if (g_bConsoleLog) 
    472     return true; 
    473390  typedef enum status {unknown, debug, nodebug }; 
    474391  static status d = unknown; 
     
    491408 */ 
    492409void NSClientT::reportMessage(int msgType, const char* file, const int line, std::string message) { 
    493   ReadLock readLock(&m_mutexRW, true, 5000); 
    494   if (!readLock.IsLocked()) { 
    495     std::cout << "Message was lost as the core was locked..." << std::endl; 
     410  if ((msgType == NSCAPI::debug)&&(!logDebug())) { 
    496411    return; 
    497412  } 
    498   MutexLock lock(messageMutex); 
    499   if (!lock.hasMutex()) { 
    500     std::cout << "Message was lost as the core was locked..." << std::endl; 
    501     std::cout << message << std::endl; 
    502     return; 
    503   } 
    504   if (g_bConsoleLog) { 
    505     std::string k = "?"; 
    506     switch (msgType) { 
     413  { 
     414    ReadLock readLock(&m_mutexRW, true, 5000); 
     415    if (!readLock.IsLocked()) { 
     416      std::cout << "Message was lost as the core was locked..." << std::endl; 
     417      return; 
     418    } 
     419    MutexLock lock(messageMutex); 
     420    if (!lock.hasMutex()) { 
     421      std::cout << "Message was lost as the core was locked..." << std::endl; 
     422      std::cout << message << std::endl; 
     423      return; 
     424    } 
     425    if (g_bConsoleLog) { 
     426      std::string k = "?"; 
     427      switch (msgType) { 
    507428      case NSCAPI::critical: 
    508429        k ="c"; 
     
    520441        k ="d"; 
    521442        break; 
    522     } 
    523     std::cout << k << " " << file << "(" << line << ") " << message << std::endl; 
    524   } 
    525   if ((msgType == NSCAPI::debug)&&(!logDebug())) { 
    526     return; 
    527   } 
    528   for (pluginList::size_type i = 0; i< messageHandlers_.size(); i++) { 
    529     try { 
    530       messageHandlers_[i]->handleMessage(msgType, file, line, message.c_str()); 
    531     } catch(const NSPluginException& e) { 
    532       // Here we are pretty much fucked! (as logging this might cause a loop :) 
    533       std::cout << "Caught: " << e.error_ << " when trying to log a message..." << std::endl; 
    534       std::cout << "This is *really really* bad, now the world is about to end..." << std::endl; 
     443      } 
     444      std::cout << k << " " << file << "(" << line << ") " << message << std::endl; 
     445    } 
     446    for (pluginList::size_type i = 0; i< messageHandlers_.size(); i++) { 
     447      try { 
     448        messageHandlers_[i]->handleMessage(msgType, file, line, message.c_str()); 
     449      } catch(const NSPluginException& e) { 
     450        // Here we are pretty much fucked! (as logging this might cause a loop :) 
     451        std::cout << "Caught: " << e.error_ << " when trying to log a message..." << std::endl; 
     452        std::cout << "This is *really really* bad, now the world is about to end..." << std::endl; 
     453      } 
    535454    } 
    536455  } 
  • trunk/NSClient++.vcproj

    r237da21 r99bb030  
    112112      <Tool 
    113113        Name="VCLinkerTool" 
    114         AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Pdh.lib" 
     114        AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib" 
    115115        OutputFile=".\Debug/NSClient++.exe" 
    116116        LinkIncremental="1" 
     
    178178echo Removing old archive 
    179179cmd /c &quot;del $(InputDir)\Dist\$(InputName).zip&quot; 
    180 echo Copying documenation 
    181 mkdir $(TargetDir)\docs 
    182 xcopy /s /e /c /q /y $(InputDir)\docs $(TargetDir)\docs 
    183180echo Making archive 
    1841817z.exe a -r -tzip -bd $(InputDir)\Dist\$(InputName).zip $(InputDir)\Dist\* 
     
    187184      <Tool 
    188185        Name="VCLinkerTool" 
    189         AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Pdh.lib" 
     186        AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib" 
    190187        OutputFile=".\Dist/NSClient++.exe" 
    191188        LinkIncremental="1" 
     
    336333      </File> 
    337334      <File 
    338         RelativePath=".\Settings.h"> 
     335        RelativePath=".\include\Settings.h"> 
    339336      </File> 
    340337      <File 
  • trunk/changelog

    rc3579b8 r99bb030  
    11TODO:  
    22 * Process times and similar ? 
    3  * Add bind_to_address in the socket 
    43 * Fix configuration GUI (low priority) 
    5  * Fix installer (low priority) 
     4 * Fix installer (after configuration UI) 
    65 * Service check to use Auto (filter by started setting etc.) 
    76 * Add module for relaying events 
    8  * Check multitasking problems on the sockets. 
    97 * Add filtering to WMI module 
    108 * Fix WMI module 
    11  * Check date/time on eventlogs 
    12  * Add support for rendering results (eventlog etc) [In progress] 
    13  
    14 2006-02-12 MickeM 
     9 * Fix PDH problems 
     10 
     112006-03-02 MickeM 
     12 * Fixed bug in INI-file reader (memory leak) 
     13 
     142006-03-01 MickeM 
     15 * Fixed bug in CheckFile (now dates work correctly) 
     16 
     172006-02-26 MickeM 
     18 + Added syntax option to CheckFile (%filename%, %creation%, %access%, %write%, %size%). 
     19 
     202006-02-25 MickeM 
     21 * Fixed Sections problem (now sections can be any size) 
     22 + Added bind_to_address option to both NRPE and NSClient section in the INI file. 
     23   Allows you to bind the listener to a specific IP address (only dotted number not host name). 
     24   This might break things as I had to do some internal rewrite of the Socket classes so be careful :) 
     25 * Disabled default-debug logging (as things are fairly stable, you can still enable it by using debug=1 in the NSC:ini file) 
     26 * "Fixed" socket backlog to use "max responsible value" as opposed to "10" if no value is specified. 
     27 + Added option socket_back_log to both NRPE and NSClient section that allows you to tweak the "back-log" of incoming connections to keep. 
     28   This is an advanced setting and should not be used. If you get "connection refused" when running many client this might be something you want to tweak though. 
     29   And if you then start getting "Socket timeout" you might wanna tweak the timeout value as well because larger value here means it takes "longer" to process a socket. 
     30 - I have looked into the event log problem and dates seem to work here so if anyone still have problems (use the syntax option to debug) let me know. 
     31 * Moved listpdh and debugpdh into the CheckSystem module 
     32 * Removed PDH dependencies from "core exe" means you can run NSClient++ without PDH (though you cant use the CheckSystem module) 
     33  
     342006-02-2? MickeM 
    1535 + Added new Interface for Modules (NSCommandLineExec that allows modules to execute things give from command line. 
    1636   Syntax is NSClient++ <module name> <command> [arguments] and if a module doesn't support this it is simply ignored. 
  • trunk/include/SSLSocket.cpp

    rf22f5a9 r99bb030  
    118118} 
    119119 
    120 void simpleSSL::Listener::StartListener(int port) { 
     120void simpleSSL::Listener::StartListener(std::string host, int port, unsigned int listenQue) { 
    121121  // @todo init SSL 
    122122 
     
    141141    simpleSSL::Crypto::setLockingCallback(locking_function); 
    142142  } 
    143  
    144   tBase::StartListener(port); 
     143  tBase::StartListener(host, port, listenQue); 
    145144} 
    146145void simpleSSL::Listener::StopListener() { 
  • trunk/include/SSLSocket.h

    rf22f5a9 r99bb030  
    285285      context = c; 
    286286    } 
    287     virtual void StartListener(int port); 
     287    virtual void StartListener(std::string host, int port, unsigned int listenQue); 
    288288    virtual void StopListener(); 
    289289  }; 
  • trunk/include/Settings.h

    r9bc31a8 r99bb030  
    55#include <map> 
    66#include <windows.h> 
     7#include <INISettings.h> 
    78#define BUFF_LEN 4096 
    8  
    9 class Section { 
    10 }; 
    119 
    1210class SettingsT 
    1311{ 
    1412private: 
    15   typedef std::map<std::string,std::string> saveKeyList; 
     13  typedef struct { 
     14    typedef enum { sType, iType} typeEnum; 
     15    typeEnum type; 
     16    std::string sVal; 
     17    int iVal; 
     18  } valueStruct; 
     19  typedef std::map<std::string,valueStruct> saveKeyList; 
    1620  typedef std::map<std::string,saveKeyList> saveSectionList; 
    17   std::string file_; 
    1821  saveSectionList data_; 
    1922  bool bHasInternalData; 
     23  INISettings iniManager; 
    2024public: 
    2125  typedef std::list<std::string> sectionList; 
     
    3337   */ 
    3438  void setFile(std::string file) { 
    35     file_ = file; 
     39    iniManager.setFile(file); 
    3640  } 
    3741 
    38   sectionList getSections() { 
    39     sectionList ret; 
    40     char* buffer = new char[BUFF_LEN+1]; 
    41     unsigned int count = ::GetPrivateProfileSectionNames(buffer, BUFF_LEN, file_.c_str()); 
    42     if (count == BUFF_LEN-2) 
    43       throw "Fuck..."; 
    44     unsigned int last = 0; 
    45     for (unsigned int i=0;i<count;i++) { 
    46       if (buffer[i] == '\0') { 
    47         std::string s = &buffer[last]; 
    48         ret.push_back(s); 
    49         last = i+1; 
     42#define UNLIKELY_VALUE -1234 
     43  void read() { 
     44    sectionList sections = getSections(); 
     45    for (sectionList::const_iterator it=sections.begin();it!=sections.end();++it) { 
     46      sectionList section = getSection(*it); 
     47      for (sectionList::const_iterator it2=section.begin();it2!=section.end();++it2) { 
     48        int i = getInt((*it), (*it2), UNLIKELY_VALUE); 
     49        if (i == UNLIKELY_VALUE) { 
     50          getString((*it), (*it2)); 
     51        } 
    5052      } 
    5153    } 
    52     delete [] buffer; 
     54  } 
     55 
     56  sectionList getSections(unsigned int bufferLength = BUFF_LEN) { 
     57    sectionList ret; 
     58    ret = iniManager.getSections(); 
    5359    if (bHasInternalData) { 
    54       for (saveSectionList::const_iterator it = data_.begin(); it != data_.end(); ++it) { 
     60      for (saveSectionList::const_iterator kit = data_.begin(); kit != data_.end(); ++kit) { 
     61        ret.push_back(kit->first); 
    5562      } 
    5663    } 
     
    6572   * @return A list with all keys from the section 
    6673   */ 
    67   sectionList getSection(std::string section) { 
     74  sectionList getSection(std::string section, unsigned int bufferLength = BUFF_LEN) { 
    6875    sectionList ret; 
    69     char* buffer = new char[BUFF_LEN+1]; 
    70     unsigned int count = GetPrivateProfileSection(section.c_str(), buffer, BUFF_LEN, file_.c_str()); 
    71     if (count == BUFF_LEN-2) 
    72       throw "Fuck..."; 
    73     unsigned int last = 0; 
    74     for (unsigned int i=0;i<count;i++) { 
    75       if (buffer[i] == '\0') { 
    76         std::string s = &buffer[last]; 
    77         ret.push_back(s); 
    78         last = i+1; 
    79       } 
    80     } 
    81     delete [] buffer; 
     76    ret = iniManager.getSection(section); 
    8277    if (bHasInternalData) { 
    8378      saveSectionList::const_iterator it = data_.find(section); 
     
    105100        saveKeyList::const_iterator kit = it->second.find(key); 
    106101        if (kit != it->second.end()) { 
    107           return kit->second; 
     102          if (kit->second.type == valueStruct::sType) 
     103            return kit->second.sVal; 
     104          else 
     105            throw "whoops"; 
    108106        } 
    109107      } 
    110108    } 
    111     char* buffer = new char[1024]; 
    112     GetPrivateProfileString(section.c_str(), key.c_str(), defaultValue.c_str(), buffer, 1023, file_.c_str()); 
    113     std::string ret = buffer; 
    114     delete [] buffer; 
     109    std::string ret = iniManager.getString(section, key, defaultValue); 
    115110    return ret; 
    116111  } 
     
    118113  void setString(std::string section, std::string key, std::string value) { 
    119114    bHasInternalData = true; 
    120     (data_[section])[key] = value; 
     115    (data_[section])[key].sVal = value; 
     116    (data_[section])[key].type = valueStruct::sType; 
    121117  } 
    122118 
     
    129125   */ 
    130126  int getInt(std::string section, std::string key, int defaultValue = 0) { 
    131     return GetPrivateProfileInt(section.c_str(), key.c_str(), defaultValue, file_.c_str()); 
     127    return iniManager.getInt(section, key, defaultValue); 
     128  } 
     129  void setInt(std::string section, std::string key, int value) { 
     130    bHasInternalData = true; 
     131    (data_[section])[key].iVal = value; 
     132    (data_[section])[key].type = valueStruct::iType; 
    132133  } 
    133134}; 
  • trunk/include/Socket.h

    r9bc31a8 r99bb030  
    101101      this->ioctlsocket(FIONBIO, &NoBlock); 
    102102    } 
     103    static unsigned long inet_addr(std::string addr) { 
     104      return ::inet_addr(addr.c_str()); 
     105    } 
    103106    static std::string getHostByName(std::string ip) { 
    104107      hostent* remoteHost; 
     
    128131        throw SocketException("bind failed: ", ::WSAGetLastError()); 
    129132    } 
    130     virtual void listen(int backlog = 0) { 
     133    virtual void listen(int backlog = SOMAXCONN) { 
    131134      assert(socket_); 
    132135      if (::listen(socket_, backlog) == SOCKET_ERROR) 
     
    215218    typedef Thread<ListenerThread> listenThreadManager; 
    216219 
    217     u_short port_; 
     220    u_short bindPort_; 
     221    u_long bindAddres_; 
     222    unsigned int listenQue_; 
    218223    listenThreadManager threadManager_; 
    219224    socketResponses responderList_; 
     
    230235      ListenerThread() : hStopEvent_(NULL) {} 
    231236      DWORD threadProc(LPVOID lpParameter); 
     237      bool hasThread() const { 
     238        return hStopEvent_ != NULL; 
     239      } 
    232240      void exitThread(void) { 
    233241        assert(hStopEvent_ != NULL); 
     
    240248 
    241249  public: 
    242     Listener() : pHandler_(NULL) {}; 
     250    Listener() : pHandler_(NULL), bindPort_(0), bindAddres_(INADDR_ANY), listenQue_(0) {}; 
    243251    virtual ~Listener() { 
    244252      if (responderList_.size() > 0) { 
     
    265273      } 
    266274    }; 
    267  
     275/* 
    268276    virtual void StartListener(int port) { 
    269       port_ = port; 
     277      bindPort_ = port; 
    270278      threadManager_.createThread(this); 
    271279    } 
     280    */ 
     281    bool hasListener() { 
     282      try { 
     283        if (threadManager_.hasActiveThread()) { 
     284          const ListenerThread *t = threadManager_.getThreadConst(); 
     285          if (t!=NULL) 
     286            return t->hasThread(); 
     287        } 
     288      } catch (ThreadException e) { 
     289        printError(__FILE__, __LINE__, "Could not access listener thread!"); 
     290        return false; 
     291      } 
     292      return false; 
     293    } 
     294    virtual void StartListener(std::string host, int port, int queLength) { 
     295      bindPort_ = port; 
     296      if (!host.empty()) 
     297        bindAddres_ = TListenerType::inet_addr(host); 
     298      if (bindAddres_ == INADDR_NONE) 
     299        bindAddres_ = INADDR_ANY; 
     300      listenQue_ = queLength; 
     301      threadManager_.createThread(this); 
     302    } 
    272303    virtual void StopListener() { 
    273       if (threadManager_.hasActiveThread()) 
    274         if (!threadManager_.exitThread()) 
    275           throw new SocketException("Could not terminate thread."); 
     304      try { 
     305        if (threadManager_.hasActiveThread()) 
     306          if (!threadManager_.exitThread()) { 
     307            tBase::close(); 
     308            throw new SocketException("Could not terminate thread."); 
     309          } 
     310      } catch (ThreadException e) { 
     311        tBase::close(); 
     312        throw new SocketException("Could not terminate thread (got exception in thread)."); 
     313      } 
    276314      tBase::close(); 
    277315    } 
     
    385423  try { 
    386424    core->socket(AF_INET,SOCK_STREAM,0); 
    387     core->setAddr(AF_INET, INADDR_ANY, htons(core->port_)); 
     425    core->setAddr(AF_INET, core->bindAddres_, htons(core->bindPort_)); 
    388426    core->bind(); 
    389     core->listen(10); 
     427    if (core->listenQue_ != 0) 
     428      core->listen(core->listenQue_); 
     429    else 
     430      core->listen(); 
    390431    core->setNonBlock(); 
    391432    while (!(WaitForSingleObject(hStopEvent_, 100) == WAIT_OBJECT_0)) { 
  • trunk/include/config.h

    r9bc31a8 r99bb030  
    55 
    66// Version 
    7 #define SZVERSION "0.2.5f 2006-02-14" 
     7#define SZVERSION "0.2.5h 2006-03-01" 
    88 
    99// internal name of the service 
     
    2424#define NASTY_METACHARS         "|`&><'\"\\[]{}"        /* This may need to be modified for windows directory seperator */ 
    2525 
     26#define DATE_FORMAT "%#c" 
     27  
    2628 
    2729// Default Argument string (for consistency) 
     
    3739#define NSCLIENT_SETTINGS_VERSION "version" 
    3840#define NSCLIENT_SETTINGS_VERSION_DEFAULT "auto" 
     41#define NSCLIENT_SETTINGS_BINDADDR "bind_to_address" 
     42#define NSCLIENT_SETTINGS_BINDADDR_DEFAULT "" 
     43#define NSCLIENT_SETTINGS_LISTENQUE "socket_back_log" 
     44#define NSCLIENT_SETTINGS_LISTENQUE_DEFAULT 0 
    3945 
    4046// NRPE Settings headlines 
     
    4551#define NRPE_SETTINGS_PORT "port" 
    4652#define NRPE_SETTINGS_PORT_DEFAULT 5666 
     53#define NRPE_SETTINGS_BINDADDR "bind_to_address" 
     54#define NRPE_SETTINGS_BINDADDR_DEFAULT "" 
    4755#define NRPE_SETTINGS_ALLOW_ARGUMENTS "allow_arguments" 
    4856#define NRPE_SETTINGS_ALLOW_ARGUMENTS_DEFAULT 0 
     
    5159#define NRPE_SETTINGS_USE_SSL "use_ssl" 
    5260#define NRPE_SETTINGS_USE_SSL_DEFAULT 1 
     61#define NRPE_SETTINGS_LISTENQUE "socket_back_log" 
     62#define NRPE_SETTINGS_LISTENQUE_DEFAULT 0 
    5363 
    5464// Check System Settings 
  • trunk/include/strEx.h

    rc3579b8 r99bb030  
    2727    buf[l] = 0; 
    2828    return buf; 
     29  } 
     30 
     31  static const __int64 SECS_BETWEEN_EPOCHS = 11644473600; 
     32  static const __int64 SECS_TO_100NS = 10000000; 
     33  inline std::string format_filetime(unsigned long long filetime, std::string format) { 
     34    filetime -= (SECS_BETWEEN_EPOCHS * SECS_TO_100NS); 
     35    filetime /= SECS_TO_100NS; 
     36    return format_date(static_cast<time_t>(filetime), format); 
    2937  } 
    3038 
  • trunk/modules/CheckDisk/CheckDisk.cpp

    r9bc31a8 r99bb030  
    243243 
    244244struct file_info { 
    245   file_info() {} 
    246   file_info(const BY_HANDLE_FILE_INFORMATION info, std::string filename_) : filename(filename_) { 
     245  file_info() : ullCreationTime(0) {} 
     246  file_info(const BY_HANDLE_FILE_INFORMATION info, std::string filename_) : filename(filename_), ullCreationTime(0) { 
    247247    ullSize = ((info.nFileSizeHigh * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)info.nFileSizeLow); 
    248248    ullCreationTime = ((info.ftCreationTime.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)info.ftCreationTime.dwLowDateTime); 
     
    258258  std::string filename; 
    259259 
     260  std::string render(std::string syntax) { 
     261    strEx::replace(syntax, "%filename%", filename); 
     262    strEx::replace(syntax, "%creation%", strEx::format_filetime(ullCreationTime, DATE_FORMAT)); 
     263    strEx::replace(syntax, "%access%", strEx::format_filetime(ullLastAccessTime, DATE_FORMAT)); 
     264    strEx::replace(syntax, "%write%", strEx::format_filetime(ullLastWriteTime, DATE_FORMAT)); 
     265    strEx::replace(syntax, "%size%", strEx::itos_as_BKMG(ullSize)); 
     266    return syntax; 
     267  } 
     268 
    260269}; 
    261270 
     
    265274  filters::filter_all_times fileAccessed; 
    266275  filters::filter_all_times fileWritten; 
     276  static const __int64 MSECS_TO_100NS = 10000; 
    267277 
    268278  inline bool hasFilter() { 
     
    273283    if ((fileSize.hasFilter())&&(fileSize.matchFilter(value.ullSize))) 
    274284      return true; 
    275     else if ((fileCreation.hasFilter())&&(fileCreation.matchFilter(value.ullNow-value.ullCreationTime))) 
    276       return true; 
    277     else if ((fileAccessed.hasFilter())&&(fileAccessed.matchFilter(value.ullNow-value.ullLastAccessTime))) 
    278       return true; 
    279     else if ((fileWritten.hasFilter())&&(fileWritten.matchFilter(value.ullNow-value.ullLastWriteTime))) 
     285    else if ((fileCreation.hasFilter())&&(fileCreation.matchFilter((value.ullNow-value.ullCreationTime)/MSECS_TO_100NS))) 
     286      return true; 
     287    else if ((fileAccessed.hasFilter())&&(fileAccessed.matchFilter((value.ullNow-value.ullLastAccessTime)/MSECS_TO_100NS))) 
     288      return true; 
     289    else if ((fileWritten.hasFilter())&&(fileWritten.matchFilter((value.ullNow-value.ullLastWriteTime)/MSECS_TO_100NS))) 
    280290      return true; 
    281291    return false; 
     
    317327  bool bError; 
    318328  std::string message; 
     329  std::string syntax; 
    319330  unsigned long long now; 
    320331  unsigned int hit_count; 
     
    353364      } 
    354365      if ((bFilterIn&&bMatch)||(!bFilterIn&&!bMatch)) { 
    355         strEx::append_list(message, info.filename); 
     366        strEx::append_list(message, info.render(syntax)); 
    356367        hit_count++; 
    357368      } 
     
    411422  unsigned int truncate = 0; 
    412423  CheckFileConatiner query; 
     424  std::string syntax = "%filename%"; 
    413425 
    414426  try { 
     
    416428      MAP_OPTIONS_NUMERIC_ALL(query, "") 
    417429      MAP_OPTIONS_STR2INT("truncate", truncate) 
     430      MAP_OPTIONS_STR("syntax", syntax) 
    418431      MAP_OPTIONS_PUSH("path", paths) 
    419432      MAP_OPTIONS_PUSH("file", paths) 
     
    436449  GetSystemTimeAsFileTime(&now); 
    437450  finder.now = ((now.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)now.dwLowDateTime); 
    438  
    439  
     451  finder.syntax = syntax; 
    440452  for (std::list<std::string>::const_iterator pit = paths.begin(); pit != paths.end(); ++pit) { 
    441453    recursive_scan<file_filter_function>((*pit), finder); 
     
    448460    message = message.substr(0, truncate-4) + "..."; 
    449461  if (message.empty()) 
    450     message = "CheckFile is ok"; 
     462    message = "CheckFile ok"; 
    451463  return returnCode; 
    452464} 
  • trunk/modules/CheckDisk/CheckDisk.h

    r9bc31a8 r99bb030  
    1616 
    1717  std::string getModuleName() { 
    18     return "CheckDisk Various Disk related checks."; 
     18    return "CheckDisk"; 
    1919  } 
    2020  std::string getModuleDescription() { 
    21     return "CheckDick can check various file and disk related things.\nThe current version has commands to check Size of hard drives and directories."; 
     21    return "CheckDisk can check various file and disk related things.\nThe current version has commands to check Size of hard drives and directories."; 
    2222  } 
    2323  NSCModuleWrapper::module_version getModuleVersion() { 
  • trunk/modules/CheckEventLog/CheckEventLog.cpp

    rc3579b8 r99bb030  
    291291          } else { 
    292292            strEx::append_list(message, record.eventSource()); 
    293             message += "(" + EventLogRecord::translateType(record.eventType()) + ", " + strEx::itos(record.eventID()) + ", " + EventLogRecord::translateSeverity(record.severity()) + ")"; 
     293            message += "(" + EventLogRecord::translateType(record.eventType()) + ", " +  
     294              strEx::itos(record.eventID()) + ", " + EventLogRecord::translateSeverity(record.severity()) + ")"; 
    294295            message += "[" + record.enumStrings() + "]"; 
    295296          } 
  • trunk/modules/CheckEventLog/CheckEventLog.h

    rc3579b8 r99bb030  
    22 
    33#include <strEx.h> 
     4#include <config.h> 
    45#include <checkHelpers.hpp> 
    56#include <filter_framework.hpp> 
    67 
    7  
    8 #define DATE_FORMAT "%#c" 
    98 
    109class CheckEventLog { 
  • trunk/modules/CheckSystem/CheckSystem.cpp

    r9bc31a8 r99bb030  
    1212#include <map> 
    1313 
    14 CheckSystem gNSClientCompat; 
     14CheckSystem gCheckSystem; 
    1515 
    1616/** 
     
    107107  return false; 
    108108} 
    109 /* 
    110 */ 
     109 
     110int CheckSystem::commandLineExec(const char* command,const unsigned int argLen,char** args) { 
     111  if (stricmp(command, "debugpdh") == 0) { 
     112    PDH::Enumerations::Objects lst = PDH::Enumerations::EnumObjects(); 
     113    for (PDH::Enumerations::Objects::iterator it = lst.begin();it!=lst.end();++it) { 
     114      if ((*it).instances.size() > 0) { 
     115        for (PDH::Enumerations::Instances::const_iterator it2 = (*it).instances.begin();it2!=(*it).instances.end();++it2) { 
     116          for (PDH::Enumerations::Counters::const_iterator it3 = (*it).counters.begin();it3!=(*it).counters.end();++it3) { 
     117            std::string counter = "\\" + (*it).name + "(" + (*it2).name + ")\\" + (*it3).name; 
     118            std::cout << "testing: " << counter << ": "; 
     119            std::string error; 
     120            if (PDH::Enumerations::validate(counter, error)) { 
     121              std::cout << " found "; 
     122            } else { 
     123              std::cout << " *NOT* found (" << error << ") " << std::endl; 
     124              break; 
     125            } 
     126            bool bOpend = false; 
     127            try { 
     128              PDH::PDHQuery pdh; 
     129              PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> cDouble; 
     130              pdh.addCounter(counter, &cDouble); 
     131              pdh.open(); 
     132              pdh.gatherData(); 
     133              pdh.close(); 
     134              bOpend = true; 
     135            } catch (const PDH::PDHException e) { 
     136              std::cout << " could *not* be open (" << e.getError() << ") " << std::endl; 
     137              break; 
     138            } 
     139            std::cout << " open "; 
     140            std::cout << std::endl; 
     141          } 
     142        } 
     143      } else { 
     144        for (PDH::Enumerations::Counters::const_iterator it2 = (*it).counters.begin();it2!=(*it).counters.end();++it2) { 
     145          std::string counter = "\\" + (*it).name + "\\" + (*it2).name; 
     146          std::cout << "testing: " << counter << ": "; 
     147          std::string error; 
     148          if (PDH::Enumerations::validate(counter, error)) { 
     149            std::cout << " found "; 
     150          } else { 
     151            std::cout << " *NOT* found (" << error << ") " << std::endl; 
     152            break; 
     153          } 
     154          bool bOpend = false; 
     155          try { 
     156            PDH::PDHQuery pdh; 
     157            PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> cDouble; 
     158            pdh.addCounter(counter, &cDouble); 
     159            pdh.open(); 
     160            pdh.gatherData(); 
     161            pdh.close(); 
     162            bOpend = true; 
     163          } catch (const PDH::PDHException e) { 
     164            std::cout << " could *not* be open (" << e.getError() << ") " << std::endl; 
     165            break; 
     166          } 
     167          std::cout << " open "; 
     168          std::cout << std::endl;; 
     169        } 
     170      } 
     171    } 
     172  } else if (stricmp(command, "listpdh") == 0) { 
     173    PDH::Enumerations::Objects lst = PDH::Enumerations::EnumObjects(); 
     174    for (PDH::Enumerations::Objects::iterator it = lst.begin();it!=lst.end();++it) { 
     175      if ((*it).instances.size() > 0) { 
     176        for (PDH::Enumerations::Instances::const_iterator it2 = (*it).instances.begin();it2!=(*it).instances.end();++it2) { 
     177          for (PDH::Enumerations::Counters::const_iterator it3 = (*it).counters.begin();it3!=(*it).counters.end();++it3) { 
     178            std::cout << "\\" << (*it).name << "(" << (*it2).name << ")\\" << (*it3).name << std::endl;; 
     179          } 
     180        } 
     181      } else { 
     182        for (PDH::Enumerations::Counters::const_iterator it2 = (*it).counters.begin();it2!=(*it).counters.end();++it2) { 
     183          std::cout << "\\" << (*it).name << "\\" << (*it2).name << std::endl;; 
     184        } 
     185      } 
     186    } 
     187  } 
     188  return 0; 
     189} 
     190 
     191 
    111192/** 
    112193 * Main command parser and delegator. 
     
    696777  return returnCode; 
    697778} 
    698 NSC_WRAPPERS_MAIN_DEF(gNSClientCompat); 
     779NSC_WRAPPERS_MAIN_DEF(gCheckSystem); 
    699780NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    700 NSC_WRAPPERS_HANDLE_CMD_DEF(gNSClientCompat); 
    701 NSC_WRAPPERS_HANDLE_CONFIGURATION(gNSClientCompat); 
     781NSC_WRAPPERS_HANDLE_CMD_DEF(gCheckSystem); 
     782NSC_WRAPPERS_HANDLE_CONFIGURATION(gCheckSystem); 
     783NSC_WRAPPERS_CLI_DEF(gCheckSystem); 
    702784 
    703785 
  • trunk/modules/CheckSystem/CheckSystem.def

    r24f7192 r99bb030  
    1313  NSGetConfigurationMeta 
    1414  NSGetModuleDescription 
     15  NSCommandLineExec 
  • trunk/modules/CheckSystem/CheckSystem.h

    r9bc31a8 r99bb030  
    44 
    55NSC_WRAPPERS_MAIN(); 
     6NSC_WRAPPERS_CLI(); 
    67 
    78class CheckSystem { 
     
    3435  */ 
    3536  std::string getModuleName() { 
    36     return "System Checks Module."; 
     37    return "CheckSystem"; 
    3738  } 
    3839  /** 
     
    5152  bool hasMessageHandler(); 
    5253  NSCAPI::nagiosReturn handleCommand(const strEx::blindstr command, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf); 
    53  
     54  int commandLineExec(const char* command,const unsigned int argLen,char** args); 
    5455 
    5556  NSCAPI::nagiosReturn checkCPU(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf); 
     
    6061  NSCAPI::nagiosReturn checkCounter(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf); 
    6162 
    62  
    6363}; 
  • trunk/modules/CheckSystem/CheckSystem.vcproj

    r24f7192 r99bb030  
    178178      </File> 
    179179      <File 
     180        RelativePath=".\CheckSystem.def"> 
     181      </File> 
     182      <File 
    180183        RelativePath="..\..\include\EnumNtSrv.cpp"> 
    181184      </File> 
  • trunk/modules/CheckWMI/CheckWMI.cpp

    r117fcf5 r99bb030  
    7777      return NSCAPI::returnCRIT; 
    7878    } 
    79     int val = (*vals.begin()).second; 
    80 /* 
     79    int val = 0; //(*vals.begin()).second; 
     80 
    8181    for (std::map<std::string,int>::const_iterator it = vals.begin(); it != vals.end(); ++it) { 
    8282      std::cout << "Values: " << (*it).first << " = " << (*it).second << std::endl; 
    8383    } 
    84     */ 
     84 
    8585    query.setDefault(tmpObject); 
    8686    query.runCheck(val, returnCode, message, perf); 
  • trunk/modules/NRPEListener/NRPEListener.cpp

    r24f7192 r99bb030  
    5050  allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), ",")); 
    5151  try { 
     52    unsigned short port = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_PORT, NRPE_SETTINGS_PORT_DEFAULT); 
     53    std::string host = NSCModuleHelper::getSettingsString(NRPE_SECTION_TITLE, NRPE_SETTINGS_BINDADDR, NRPE_SETTINGS_BINDADDR_DEFAULT); 
     54    unsigned int backLog = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_LISTENQUE, NRPE_SETTINGS_LISTENQUE_DEFAULT); 
    5255    if (bUseSSL_) { 
    5356      socket_ssl_.setHandler(this); 
    54       socket_ssl_.StartListener(NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_PORT, NRPE_SETTINGS_PORT_DEFAULT)); 
     57      socket_ssl_.StartListener(host, port, backLog); 
    5558    } else { 
    5659      socket_.setHandler(this); 
    57       socket_.StartListener(NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_PORT, NRPE_SETTINGS_PORT_DEFAULT)); 
     60      socket_.StartListener(host, port, backLog); 
    5861    } 
    5962  } catch (simpleSocket::SocketException e) { 
     
    7174    if (bUseSSL_) { 
    7275      socket_ssl_.removeHandler(this); 
    73       socket_ssl_.StopListener(); 
     76      if (socket_ssl_.hasListener()) 
     77        socket_ssl_.StopListener(); 
    7478    } else { 
    7579      socket_.removeHandler(this); 
    76       socket_.StopListener(); 
     80      if (socket_.hasListener()) 
     81        socket_.StopListener(); 
    7782    } 
    7883  } catch (simpleSocket::SocketException e) { 
  • trunk/modules/NSClientListener/NSClientListener.cpp

    r9bc31a8 r99bb030  
    4141bool NSClientListener::loadModule() { 
    4242  allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), ",")); 
     43  unsigned short port = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NSCLIENT_SETTINGS_PORT, NSCLIENT_SETTINGS_PORT_DEFAULT); 
     44  std::string host = NSCModuleHelper::getSettingsString(NRPE_SECTION_TITLE, NSCLIENT_SETTINGS_BINDADDR, NSCLIENT_SETTINGS_BINDADDR_DEFAULT); 
     45  unsigned int backLog = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_LISTENQUE, NRPE_SETTINGS_LISTENQUE_DEFAULT); 
    4346  try { 
    4447    socket.setHandler(this); 
    45     socket.StartListener(NSCModuleHelper::getSettingsInt(NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_PORT, NSCLIENT_SETTINGS_PORT_DEFAULT)); 
     48    socket.StartListener(host, port, backLog); 
    4649  } catch (simpleSocket::SocketException e) { 
    4750    NSC_LOG_ERROR_STD("Exception caught: " + e.getMessage()); 
     
    5356  try { 
    5457    socket.removeHandler(this); 
    55     socket.StopListener(); 
     58    if (socket.hasListener()) 
     59      socket.StopListener(); 
    5660  } catch (simpleSocket::SocketException e) { 
    5761    NSC_LOG_ERROR_STD("Exception caught: " + e.getMessage()); 
  • trunk/modules/SysTray/SysTray.cpp

    r9bc31a8 r99bb030  
    1919SysTray::~SysTray() {} 
    2020bool SysTray::loadModule() { 
    21   std::cout << "Systray: " << serviceControll::GetServiceType(SZSERVICENAME) << std::endl; 
    22   if ((serviceControll::GetServiceType(SZSERVICENAME)&SERVICE_INTERACTIVE_PROCESS)!=SERVICE_INTERACTIVE_PROCESS) { 
     21  try { 
     22    if ((serviceControll::GetServiceType(SZSERVICENAME)&SERVICE_INTERACTIVE_PROCESS)!=SERVICE_INTERACTIVE_PROCESS) { 
     23      NSC_LOG_ERROR("SysTray is not installed (or it cannot interact with the desktop) SysTray wont be loaded. Run " SZAPPNAME " SysTray install ti change this."); 
     24      return true; 
     25    } 
     26  } catch (serviceControll::SCException e) { 
    2327    NSC_LOG_ERROR("SysTray is not installed (or it cannot interact with the desktop) SysTray wont be loaded. Run " SZAPPNAME " SysTray install ti change this."); 
    2428    return true; 
Note: See TracChangeset for help on using the changeset viewer.