Changeset 99bb030 in nscp
- Timestamp:
- 03/20/06 16:50:33 (7 years ago)
- Children:
- 8b89aba
- Parents:
- c3579b8
- Location:
- trunk
- Files:
-
- 22 edited
-
NSC.dist (modified) (2 diffs)
-
NSClient++.cpp (modified) (6 diffs)
-
NSClient++.vcproj (modified) (4 diffs)
-
changelog (modified) (1 diff)
-
include/SSLSocket.cpp (modified) (2 diffs)
-
include/SSLSocket.h (modified) (1 diff)
-
include/Settings.h (modified) (6 diffs)
-
include/Socket.h (modified) (7 diffs)
-
include/config.h (modified) (5 diffs)
-
include/strEx.h (modified) (1 diff)
-
modules/CheckDisk/CheckDisk.cpp (modified) (10 diffs)
-
modules/CheckDisk/CheckDisk.h (modified) (1 diff)
-
modules/CheckEventLog/CheckEventLog.cpp (modified) (1 diff)
-
modules/CheckEventLog/CheckEventLog.h (modified) (1 diff)
-
modules/CheckSystem/CheckSystem.cpp (modified) (3 diffs)
-
modules/CheckSystem/CheckSystem.def (modified) (1 diff)
-
modules/CheckSystem/CheckSystem.h (modified) (4 diffs)
-
modules/CheckSystem/CheckSystem.vcproj (modified) (1 diff)
-
modules/CheckWMI/CheckWMI.cpp (modified) (1 diff)
-
modules/NRPEListener/NRPEListener.cpp (modified) (2 diffs)
-
modules/NSClientListener/NSClientListener.cpp (modified) (2 diffs)
-
modules/SysTray/SysTray.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/NSC.dist
r9bc31a8 r99bb030 51 51 52 52 [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 ; 53 58 ;# NSCLIENT PORT NUMBER 54 59 ; This is the port the NSClientListener.dll will listen to. 55 60 ;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= 56 66 57 67 … … 87 97 ; This option controls if SSL should be used on the socket. 88 98 ;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 89 110 90 111 [NRPE Handlers] -
trunk/NSClient++.cpp
r9bc31a8 r99bb030 20 20 #include <Socket.h> 21 21 #include <b64/b64.h> 22 #include <PDHCounter.h>23 #include <PDHCollectors.h>24 22 25 23 … … 89 87 g_bConsoleLog = true; 90 88 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 }169 89 } else if ( _stricmp( "test", argv[1]+1 ) == 0 ) { 170 90 #ifdef _DEBUG … … 176 96 */ 177 97 #endif 178 179 98 g_bConsoleLog = true; 180 99 mainClient.InitiateService(); … … 469 388 470 389 bool NSClientT::logDebug() { 471 if (g_bConsoleLog)472 return true;473 390 typedef enum status {unknown, debug, nodebug }; 474 391 static status d = unknown; … … 491 408 */ 492 409 void 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())) { 496 411 return; 497 412 } 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) { 507 428 case NSCAPI::critical: 508 429 k ="c"; … … 520 441 k ="d"; 521 442 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 } 535 454 } 536 455 } -
trunk/NSClient++.vcproj
r237da21 r99bb030 112 112 <Tool 113 113 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" 115 115 OutputFile=".\Debug/NSClient++.exe" 116 116 LinkIncremental="1" … … 178 178 echo Removing old archive 179 179 cmd /c "del $(InputDir)\Dist\$(InputName).zip" 180 echo Copying documenation181 mkdir $(TargetDir)\docs182 xcopy /s /e /c /q /y $(InputDir)\docs $(TargetDir)\docs183 180 echo Making archive 184 181 7z.exe a -r -tzip -bd $(InputDir)\Dist\$(InputName).zip $(InputDir)\Dist\* … … 187 184 <Tool 188 185 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" 190 187 OutputFile=".\Dist/NSClient++.exe" 191 188 LinkIncremental="1" … … 336 333 </File> 337 334 <File 338 RelativePath=".\ Settings.h">335 RelativePath=".\include\Settings.h"> 339 336 </File> 340 337 <File -
trunk/changelog
rc3579b8 r99bb030 1 1 TODO: 2 2 * Process times and similar ? 3 * Add bind_to_address in the socket4 3 * Fix configuration GUI (low priority) 5 * Fix installer ( low priority)4 * Fix installer (after configuration UI) 6 5 * Service check to use Auto (filter by started setting etc.) 7 6 * Add module for relaying events 8 * Check multitasking problems on the sockets.9 7 * Add filtering to WMI module 10 8 * 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 11 2006-03-02 MickeM 12 * Fixed bug in INI-file reader (memory leak) 13 14 2006-03-01 MickeM 15 * Fixed bug in CheckFile (now dates work correctly) 16 17 2006-02-26 MickeM 18 + Added syntax option to CheckFile (%filename%, %creation%, %access%, %write%, %size%). 19 20 2006-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 34 2006-02-2? MickeM 15 35 + Added new Interface for Modules (NSCommandLineExec that allows modules to execute things give from command line. 16 36 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 118 118 } 119 119 120 void simpleSSL::Listener::StartListener( int port) {120 void simpleSSL::Listener::StartListener(std::string host, int port, unsigned int listenQue) { 121 121 // @todo init SSL 122 122 … … 141 141 simpleSSL::Crypto::setLockingCallback(locking_function); 142 142 } 143 144 tBase::StartListener(port); 143 tBase::StartListener(host, port, listenQue); 145 144 } 146 145 void simpleSSL::Listener::StopListener() { -
trunk/include/SSLSocket.h
rf22f5a9 r99bb030 285 285 context = c; 286 286 } 287 virtual void StartListener( int port);287 virtual void StartListener(std::string host, int port, unsigned int listenQue); 288 288 virtual void StopListener(); 289 289 }; -
trunk/include/Settings.h
r9bc31a8 r99bb030 5 5 #include <map> 6 6 #include <windows.h> 7 #include <INISettings.h> 7 8 #define BUFF_LEN 4096 8 9 class Section {10 };11 9 12 10 class SettingsT 13 11 { 14 12 private: 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; 16 20 typedef std::map<std::string,saveKeyList> saveSectionList; 17 std::string file_;18 21 saveSectionList data_; 19 22 bool bHasInternalData; 23 INISettings iniManager; 20 24 public: 21 25 typedef std::list<std::string> sectionList; … … 33 37 */ 34 38 void setFile(std::string file) { 35 file_ = file;39 iniManager.setFile(file); 36 40 } 37 41 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 } 50 52 } 51 53 } 52 delete [] buffer; 54 } 55 56 sectionList getSections(unsigned int bufferLength = BUFF_LEN) { 57 sectionList ret; 58 ret = iniManager.getSections(); 53 59 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); 55 62 } 56 63 } … … 65 72 * @return A list with all keys from the section 66 73 */ 67 sectionList getSection(std::string section ) {74 sectionList getSection(std::string section, unsigned int bufferLength = BUFF_LEN) { 68 75 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); 82 77 if (bHasInternalData) { 83 78 saveSectionList::const_iterator it = data_.find(section); … … 105 100 saveKeyList::const_iterator kit = it->second.find(key); 106 101 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"; 108 106 } 109 107 } 110 108 } 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); 115 110 return ret; 116 111 } … … 118 113 void setString(std::string section, std::string key, std::string value) { 119 114 bHasInternalData = true; 120 (data_[section])[key] = value; 115 (data_[section])[key].sVal = value; 116 (data_[section])[key].type = valueStruct::sType; 121 117 } 122 118 … … 129 125 */ 130 126 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; 132 133 } 133 134 }; -
trunk/include/Socket.h
r9bc31a8 r99bb030 101 101 this->ioctlsocket(FIONBIO, &NoBlock); 102 102 } 103 static unsigned long inet_addr(std::string addr) { 104 return ::inet_addr(addr.c_str()); 105 } 103 106 static std::string getHostByName(std::string ip) { 104 107 hostent* remoteHost; … … 128 131 throw SocketException("bind failed: ", ::WSAGetLastError()); 129 132 } 130 virtual void listen(int backlog = 0) {133 virtual void listen(int backlog = SOMAXCONN) { 131 134 assert(socket_); 132 135 if (::listen(socket_, backlog) == SOCKET_ERROR) … … 215 218 typedef Thread<ListenerThread> listenThreadManager; 216 219 217 u_short port_; 220 u_short bindPort_; 221 u_long bindAddres_; 222 unsigned int listenQue_; 218 223 listenThreadManager threadManager_; 219 224 socketResponses responderList_; … … 230 235 ListenerThread() : hStopEvent_(NULL) {} 231 236 DWORD threadProc(LPVOID lpParameter); 237 bool hasThread() const { 238 return hStopEvent_ != NULL; 239 } 232 240 void exitThread(void) { 233 241 assert(hStopEvent_ != NULL); … … 240 248 241 249 public: 242 Listener() : pHandler_(NULL) {};250 Listener() : pHandler_(NULL), bindPort_(0), bindAddres_(INADDR_ANY), listenQue_(0) {}; 243 251 virtual ~Listener() { 244 252 if (responderList_.size() > 0) { … … 265 273 } 266 274 }; 267 275 /* 268 276 virtual void StartListener(int port) { 269 port_ = port;277 bindPort_ = port; 270 278 threadManager_.createThread(this); 271 279 } 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 } 272 303 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 } 276 314 tBase::close(); 277 315 } … … 385 423 try { 386 424 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_)); 388 426 core->bind(); 389 core->listen(10); 427 if (core->listenQue_ != 0) 428 core->listen(core->listenQue_); 429 else 430 core->listen(); 390 431 core->setNonBlock(); 391 432 while (!(WaitForSingleObject(hStopEvent_, 100) == WAIT_OBJECT_0)) { -
trunk/include/config.h
r9bc31a8 r99bb030 5 5 6 6 // Version 7 #define SZVERSION "0.2.5 f 2006-02-14"7 #define SZVERSION "0.2.5h 2006-03-01" 8 8 9 9 // internal name of the service … … 24 24 #define NASTY_METACHARS "|`&><'\"\\[]{}" /* This may need to be modified for windows directory seperator */ 25 25 26 #define DATE_FORMAT "%#c" 27 26 28 27 29 // Default Argument string (for consistency) … … 37 39 #define NSCLIENT_SETTINGS_VERSION "version" 38 40 #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 39 45 40 46 // NRPE Settings headlines … … 45 51 #define NRPE_SETTINGS_PORT "port" 46 52 #define NRPE_SETTINGS_PORT_DEFAULT 5666 53 #define NRPE_SETTINGS_BINDADDR "bind_to_address" 54 #define NRPE_SETTINGS_BINDADDR_DEFAULT "" 47 55 #define NRPE_SETTINGS_ALLOW_ARGUMENTS "allow_arguments" 48 56 #define NRPE_SETTINGS_ALLOW_ARGUMENTS_DEFAULT 0 … … 51 59 #define NRPE_SETTINGS_USE_SSL "use_ssl" 52 60 #define NRPE_SETTINGS_USE_SSL_DEFAULT 1 61 #define NRPE_SETTINGS_LISTENQUE "socket_back_log" 62 #define NRPE_SETTINGS_LISTENQUE_DEFAULT 0 53 63 54 64 // Check System Settings -
trunk/include/strEx.h
rc3579b8 r99bb030 27 27 buf[l] = 0; 28 28 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); 29 37 } 30 38 -
trunk/modules/CheckDisk/CheckDisk.cpp
r9bc31a8 r99bb030 243 243 244 244 struct 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) { 247 247 ullSize = ((info.nFileSizeHigh * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)info.nFileSizeLow); 248 248 ullCreationTime = ((info.ftCreationTime.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)info.ftCreationTime.dwLowDateTime); … … 258 258 std::string filename; 259 259 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 260 269 }; 261 270 … … 265 274 filters::filter_all_times fileAccessed; 266 275 filters::filter_all_times fileWritten; 276 static const __int64 MSECS_TO_100NS = 10000; 267 277 268 278 inline bool hasFilter() { … … 273 283 if ((fileSize.hasFilter())&&(fileSize.matchFilter(value.ullSize))) 274 284 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))) 280 290 return true; 281 291 return false; … … 317 327 bool bError; 318 328 std::string message; 329 std::string syntax; 319 330 unsigned long long now; 320 331 unsigned int hit_count; … … 353 364 } 354 365 if ((bFilterIn&&bMatch)||(!bFilterIn&&!bMatch)) { 355 strEx::append_list(message, info. filename);366 strEx::append_list(message, info.render(syntax)); 356 367 hit_count++; 357 368 } … … 411 422 unsigned int truncate = 0; 412 423 CheckFileConatiner query; 424 std::string syntax = "%filename%"; 413 425 414 426 try { … … 416 428 MAP_OPTIONS_NUMERIC_ALL(query, "") 417 429 MAP_OPTIONS_STR2INT("truncate", truncate) 430 MAP_OPTIONS_STR("syntax", syntax) 418 431 MAP_OPTIONS_PUSH("path", paths) 419 432 MAP_OPTIONS_PUSH("file", paths) … … 436 449 GetSystemTimeAsFileTime(&now); 437 450 finder.now = ((now.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)now.dwLowDateTime); 438 439 451 finder.syntax = syntax; 440 452 for (std::list<std::string>::const_iterator pit = paths.begin(); pit != paths.end(); ++pit) { 441 453 recursive_scan<file_filter_function>((*pit), finder); … … 448 460 message = message.substr(0, truncate-4) + "..."; 449 461 if (message.empty()) 450 message = "CheckFile isok";462 message = "CheckFile ok"; 451 463 return returnCode; 452 464 } -
trunk/modules/CheckDisk/CheckDisk.h
r9bc31a8 r99bb030 16 16 17 17 std::string getModuleName() { 18 return "CheckDisk Various Disk related checks.";18 return "CheckDisk"; 19 19 } 20 20 std::string getModuleDescription() { 21 return "CheckDi ck 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."; 22 22 } 23 23 NSCModuleWrapper::module_version getModuleVersion() { -
trunk/modules/CheckEventLog/CheckEventLog.cpp
rc3579b8 r99bb030 291 291 } else { 292 292 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()) + ")"; 294 295 message += "[" + record.enumStrings() + "]"; 295 296 } -
trunk/modules/CheckEventLog/CheckEventLog.h
rc3579b8 r99bb030 2 2 3 3 #include <strEx.h> 4 #include <config.h> 4 5 #include <checkHelpers.hpp> 5 6 #include <filter_framework.hpp> 6 7 7 8 #define DATE_FORMAT "%#c"9 8 10 9 class CheckEventLog { -
trunk/modules/CheckSystem/CheckSystem.cpp
r9bc31a8 r99bb030 12 12 #include <map> 13 13 14 CheckSystem g NSClientCompat;14 CheckSystem gCheckSystem; 15 15 16 16 /** … … 107 107 return false; 108 108 } 109 /* 110 */ 109 110 int 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 111 192 /** 112 193 * Main command parser and delegator. … … 696 777 return returnCode; 697 778 } 698 NSC_WRAPPERS_MAIN_DEF(g NSClientCompat);779 NSC_WRAPPERS_MAIN_DEF(gCheckSystem); 699 780 NSC_WRAPPERS_IGNORE_MSG_DEF(); 700 NSC_WRAPPERS_HANDLE_CMD_DEF(gNSClientCompat); 701 NSC_WRAPPERS_HANDLE_CONFIGURATION(gNSClientCompat); 781 NSC_WRAPPERS_HANDLE_CMD_DEF(gCheckSystem); 782 NSC_WRAPPERS_HANDLE_CONFIGURATION(gCheckSystem); 783 NSC_WRAPPERS_CLI_DEF(gCheckSystem); 702 784 703 785 -
trunk/modules/CheckSystem/CheckSystem.def
r24f7192 r99bb030 13 13 NSGetConfigurationMeta 14 14 NSGetModuleDescription 15 NSCommandLineExec -
trunk/modules/CheckSystem/CheckSystem.h
r9bc31a8 r99bb030 4 4 5 5 NSC_WRAPPERS_MAIN(); 6 NSC_WRAPPERS_CLI(); 6 7 7 8 class CheckSystem { … … 34 35 */ 35 36 std::string getModuleName() { 36 return " System Checks Module.";37 return "CheckSystem"; 37 38 } 38 39 /** … … 51 52 bool hasMessageHandler(); 52 53 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); 54 55 55 56 NSCAPI::nagiosReturn checkCPU(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf); … … 60 61 NSCAPI::nagiosReturn checkCounter(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf); 61 62 62 63 63 }; -
trunk/modules/CheckSystem/CheckSystem.vcproj
r24f7192 r99bb030 178 178 </File> 179 179 <File 180 RelativePath=".\CheckSystem.def"> 181 </File> 182 <File 180 183 RelativePath="..\..\include\EnumNtSrv.cpp"> 181 184 </File> -
trunk/modules/CheckWMI/CheckWMI.cpp
r117fcf5 r99bb030 77 77 return NSCAPI::returnCRIT; 78 78 } 79 int val = (*vals.begin()).second;80 /* 79 int val = 0; //(*vals.begin()).second; 80 81 81 for (std::map<std::string,int>::const_iterator it = vals.begin(); it != vals.end(); ++it) { 82 82 std::cout << "Values: " << (*it).first << " = " << (*it).second << std::endl; 83 83 } 84 */ 84 85 85 query.setDefault(tmpObject); 86 86 query.runCheck(val, returnCode, message, perf); -
trunk/modules/NRPEListener/NRPEListener.cpp
r24f7192 r99bb030 50 50 allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), ",")); 51 51 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); 52 55 if (bUseSSL_) { 53 56 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); 55 58 } else { 56 59 socket_.setHandler(this); 57 socket_.StartListener( NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_PORT, NRPE_SETTINGS_PORT_DEFAULT));60 socket_.StartListener(host, port, backLog); 58 61 } 59 62 } catch (simpleSocket::SocketException e) { … … 71 74 if (bUseSSL_) { 72 75 socket_ssl_.removeHandler(this); 73 socket_ssl_.StopListener(); 76 if (socket_ssl_.hasListener()) 77 socket_ssl_.StopListener(); 74 78 } else { 75 79 socket_.removeHandler(this); 76 socket_.StopListener(); 80 if (socket_.hasListener()) 81 socket_.StopListener(); 77 82 } 78 83 } catch (simpleSocket::SocketException e) { -
trunk/modules/NSClientListener/NSClientListener.cpp
r9bc31a8 r99bb030 41 41 bool NSClientListener::loadModule() { 42 42 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); 43 46 try { 44 47 socket.setHandler(this); 45 socket.StartListener( NSCModuleHelper::getSettingsInt(NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_PORT, NSCLIENT_SETTINGS_PORT_DEFAULT));48 socket.StartListener(host, port, backLog); 46 49 } catch (simpleSocket::SocketException e) { 47 50 NSC_LOG_ERROR_STD("Exception caught: " + e.getMessage()); … … 53 56 try { 54 57 socket.removeHandler(this); 55 socket.StopListener(); 58 if (socket.hasListener()) 59 socket.StopListener(); 56 60 } catch (simpleSocket::SocketException e) { 57 61 NSC_LOG_ERROR_STD("Exception caught: " + e.getMessage()); -
trunk/modules/SysTray/SysTray.cpp
r9bc31a8 r99bb030 19 19 SysTray::~SysTray() {} 20 20 bool 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) { 23 27 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 28 return true;
Note: See TracChangeset
for help on using the changeset viewer.








