Changeset 1d9338a in nscp
- Timestamp:
- 05/23/05 21:24:32 (8 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- 6654022
- Parents:
- af5bc4b
- Files:
-
- 3 added
- 33 edited
-
NSClient++.cpp (modified) (18 diffs)
-
NSClient++.h (modified) (4 diffs)
-
NSClient++.vcproj (modified) (3 diffs)
-
changelog (modified) (3 diffs)
-
docs/CheckDisk/index.html (modified) (5 diffs)
-
docs/CheckEventLog/index.html (modified) (2 diffs)
-
docs/CheckHelpers/index.html (modified) (8 diffs)
-
docs/CheckSystem/index.html (modified) (5 diffs)
-
docs/Configuration/index.html (modified) (9 diffs)
-
docs/FileLogger/index.html (modified) (1 diff)
-
docs/NRPEListener/index.html (modified) (1 diff)
-
docs/SysTray/index.html (modified) (1 diff)
-
docs/index.html (modified) (1 diff)
-
docs/nscplus.css (modified) (1 diff)
-
docs/welcome.html (modified) (4 diffs)
-
include/Mutex.h (modified) (1 diff)
-
include/NSCAPI.h (modified) (2 diffs)
-
include/NSCHelper.cpp (modified) (4 diffs)
-
include/NSCHelper.h (modified) (2 diffs)
-
include/PDHCollectors.h (modified) (2 diffs)
-
include/PDHCounter.h (modified) (2 diffs)
-
include/Socket.cpp (modified) (1 diff)
-
include/Socket.h (modified) (11 diffs)
-
include/b64/b64.c (added)
-
include/b64/b64.h (added)
-
include/b64/b64.hpp (added)
-
include/config.h (modified) (4 diffs)
-
include/thread.h (modified) (7 diffs)
-
modules/CheckDisk/CheckDisk.cpp (modified) (2 diffs)
-
modules/CheckSystem/CheckSystem.cpp (modified) (9 diffs)
-
modules/CheckSystem/PDHCollector.cpp (modified) (6 diffs)
-
modules/CheckSystem/PDHCollector.h (modified) (1 diff)
-
modules/FileLogger/FileLogger.cpp (modified) (4 diffs)
-
modules/FileLogger/FileLogger.h (modified) (2 diffs)
-
modules/NRPEListener/NRPEListener.cpp (modified) (3 diffs)
-
modules/NSClientListener/NSClientListener.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
NSClient++.cpp
raf5bc4b r1d9338a 19 19 #include <charEx.h> 20 20 #include <Socket.h> 21 #include <b64/b64.h> 22 21 23 22 24 NSClient mainClient; // Global core instance. … … 55 57 return -1; 56 58 } 59 } else if ( _stricmp( "encrypt", argv[1]+1 ) == 0 ) { 60 g_bConsoleLog = true; 61 std::string password; 62 Settings::getInstance()->setFile(mainClient.getBasePath() + "NSC.ini"); 63 std::cout << "Enter password to encrypt (has to be a single word): "; 64 std::cin >> password; 65 std::string xor_pwd = Encrypt(password); 66 std::cout << "obfuscated_password=" << xor_pwd << std::endl; 67 if (password != Decrypt(xor_pwd)) 68 std::cout << "ERROR: Password did not match!" << std::endl; 69 Settings::destroyInstance(); 70 return 0; 57 71 } else if ( _stricmp( "start", argv[1]+1 ) == 0 ) { 58 72 g_bConsoleLog = true; … … 70 84 } else if ( _stricmp( "test", argv[1]+1 ) == 0 ) { 71 85 #ifdef _DEBUG 86 /* 72 87 strEx::run_test_getToken(); 73 88 strEx::run_test_replace(); 74 89 charEx::run_test_getToken(); 75 90 arrayBuffer::run_testArrayBuffer(); 91 */ 76 92 #endif 77 93 … … 92 108 } 93 109 mainClient.TerminateService(); 94 LOG_MESSAGE("DONE!");95 96 110 return 0; 97 111 } else { … … 137 151 try { 138 152 mainClient.unloadPlugins(); 139 LOG_DEBUG("Plugins unloaded...");140 153 } catch(NSPluginException *e) { 141 154 std::cout << "Exception raised: " << e->error_ << " in module: " << e->file_ << std::endl;; … … 179 192 return; 180 193 } 181 /*182 MutexLock lock(pluginMutex);183 if (!lock.hasMutex()) {184 LOG_ERROR("FATAL ERROR: Could not get mutex.");185 return;186 }187 */188 194 std::list<std::string>::const_iterator it; 189 195 for (it = plugins.begin(); it != plugins.end(); ++it) { … … 201 207 return; 202 208 } 203 /* MutexLock lock(pluginMutex,20000);204 if (!lock.hasMutex()) {205 LOG_ERROR("FATAL ERROR: Could not get mutex.");206 return;207 }208 */209 209 commandHandlers_.clear(); 210 { 211 /* MutexLock lock(messageMutex,20000); 212 if (!lock.hasMutex()) { 213 LOG_ERROR("FATAL ERROR: Could not get mutex (we will now crash BTW)."); 214 } else { 215 messageHandlers_.clear(); 216 } 217 */ 218 messageHandlers_.clear(); 219 } 210 messageHandlers_.clear(); 220 211 } 221 212 { … … 231 222 } 232 223 } 233 234 224 { 235 225 WriteLock writeLock(&m_mutexRW, true, 10000); … … 259 249 */ 260 250 void NSClientT::addPlugin(plugin_type plugin) { 261 { 262 ReadLock readLock(&m_mutexRW, true, 5000); 263 if (!readLock.IsLocked()) { 264 LOG_ERROR("FATAL ERROR: Could not get read-mutex."); 265 return; 266 } 267 plugin->load(); 268 } 269 /* 270 MutexLock lock(pluginMutex); 271 if (!lock.hasMutex()) { 272 LOG_ERROR("FATAL ERROR: Could not get mutex."); 273 return; 274 } 275 */ 276 251 plugin->load(); 277 252 { 278 253 WriteLock writeLock(&m_mutexRW, true, 10000); … … 298 273 NSCAPI::nagiosReturn ret = injectRAW(command.c_str(), aLen, aBuf, mBuf, 1023, pBuf, 1023); 299 274 arrayBuffer::destroyArrayBuffer(aBuf, aLen); 300 if ( (ret == NSCAPI::returnInvalidBufferLen) || (ret == NSCAPI::returnIgnored) ) 275 if ( (ret == NSCAPI::returnInvalidBufferLen) || (ret == NSCAPI::returnIgnored) ) { 276 delete [] mBuf; 277 delete [] pBuf; 301 278 return ret; 279 } 302 280 msg = mBuf; 303 281 perf = pBuf; … … 320 298 */ 321 299 NSCAPI::nagiosReturn NSClientT::injectRAW(const char* command, const unsigned int argLen, char **argument, char *returnMessageBuffer, unsigned int returnMessageBufferLen, char *returnPerfBuffer, unsigned int returnPerfBufferLen) { 300 if (logDebug()) { 301 LOG_DEBUG_STD("Injecting: " + (std::string) command + ": " + arrayBuffer::arrayBuffer2string(argument, argLen, ", ")); 302 } 322 303 ReadLock readLock(&m_mutexRW, true, 5000); 323 304 if (!readLock.IsLocked()) { … … 325 306 return NSCAPI::returnUNKNOWN; 326 307 } 327 /* MutexLock lock(pluginMutex);328 if (!lock.hasMutex()) {329 LOG_ERROR_STD("Failed to get mutex (" + strEx::itos(lock.getWaitResult()) + "), command ignored...");330 return NSCAPI::returnUNKNOWN;331 }332 */333 308 for (pluginList::size_type i = 0; i < commandHandlers_.size(); i++) { 334 309 try { … … 344 319 case NSCAPI::returnCRIT: 345 320 case NSCAPI::returnUNKNOWN: 346 // LOG_DEBUG_STD("Injected Result: " +(std::string) returnMessageBuffer);347 //LOG_DEBUG_STD("Injected Performance Result: " +(std::string) returnPerfBuffer);321 LOG_DEBUG_STD("Injected Result: " + NSCHelper::translateReturn(c) + " -- " + (std::string)(returnMessageBuffer)); 322 LOG_DEBUG_STD("Injected Performance Result: " +(std::string) returnPerfBuffer); 348 323 return c; 349 324 default: … … 359 334 return NSCAPI::returnIgnored; 360 335 } 336 337 bool NSClientT::logDebug() { 338 if (g_bConsoleLog) 339 return true; 340 typedef enum status {unknown, debug, nodebug }; 341 static status d = unknown; 342 if (d == unknown) { 343 if (Settings::getInstance()->getInt("log", "debug", 0) == 1) 344 d = debug; 345 else 346 d = nodebug; 347 } 348 return (d == debug); 349 } 350 361 351 /** 362 352 * Report a message to all logging enabled modules. … … 379 369 return; 380 370 } 381 /*382 MutexLock lock(messageMutex);383 if (!lock.hasMutex()) {384 std::cout << "Message was lost as the core was locked..." << std::endl;385 std::cout << message << std::endl;386 return;387 }388 */389 371 if (g_bConsoleLog) { 390 372 std::string k = "?"; … … 408 390 std::cout << k << " " << file << "(" << line << ") " << message << std::endl; 409 391 } 410 if (msgType == NSCAPI::debug) { 411 typedef enum status {unknown, debug, nodebug }; 412 static status d = unknown; 413 if (d == unknown) { 414 if (Settings::getInstance()->getInt("log", "debug", 0) == 1) 415 d = debug; 416 else 417 d = nodebug; 418 } 419 if (d == nodebug) 420 return; 392 if ((msgType == NSCAPI::debug)&&(!logDebug())) { 393 return; 421 394 } 422 395 for (pluginList::size_type i = 0; i< messageHandlers_.size(); i++) { … … 480 453 } 481 454 455 NSCAPI::boolReturn NSAPICheckLogMessages(int messageType) { 456 if (mainClient.logDebug()) 457 return NSCAPI::istrue; 458 return NSCAPI::isfalse; 459 } 460 461 std::string Encrypt(std::string str, unsigned int algorithm) { 462 unsigned int len = 0; 463 NSAPIEncrypt(algorithm, str.c_str(), str.size(), NULL, &len); 464 len+=2; 465 char *buf = new char[len+1]; 466 NSCAPI::errorReturn ret = NSAPIEncrypt(algorithm, str.c_str(), str.size(), buf, &len); 467 if (ret == NSCAPI::isSuccess) { 468 std::string ret = buf; 469 delete [] buf; 470 return ret; 471 } 472 return ""; 473 } 474 std::string Decrypt(std::string str, unsigned int algorithm) { 475 unsigned int len = 0; 476 NSAPIDecrypt(algorithm, str.c_str(), str.size(), NULL, &len); 477 len+=2; 478 char *buf = new char[len+1]; 479 NSCAPI::errorReturn ret = NSAPIDecrypt(algorithm, str.c_str(), str.size(), buf, &len); 480 if (ret == NSCAPI::isSuccess) { 481 std::string ret = buf; 482 delete [] buf; 483 return ret; 484 } 485 return ""; 486 } 487 488 NSCAPI::errorReturn NSAPIEncrypt(unsigned int algorithm, const char* inBuffer, unsigned int inBufLen, char* outBuf, unsigned int *outBufLen) { 489 if (algorithm != NSCAPI::xor) { 490 LOG_ERROR("Unknown algortihm requested."); 491 return NSCAPI::hasFailed; 492 } 493 std::string s = inBuffer; 494 std::string key = Settings::getInstance()->getString(MAIN_SECTION_TITLE, MAIN_MASTERKEY, MAIN_MASTERKEY_DEFAULT); 495 char *c = new char[inBufLen+1]; 496 strncpy(c, inBuffer, inBufLen); 497 for (int i=0,j=0;i<inBufLen;i++,j++) { 498 if (j > key.size()) 499 j = 0; 500 c[i] ^= key[j]; 501 } 502 unsigned int len = b64::b64_encode(reinterpret_cast<void*>(c), inBufLen, outBuf, *outBufLen); 503 delete [] c; 504 if (outBuf) { 505 if ((len == 0)||(len >= *outBufLen)) { 506 LOG_ERROR("Invalid out buffer length."); 507 return NSCAPI::isInvalidBufferLen; 508 } 509 outBuf[len] = 0; 510 *outBufLen = len; 511 } else { 512 *outBufLen = len; 513 } 514 return NSCAPI::isSuccess; 515 } 516 517 NSCAPI::errorReturn NSAPIDecrypt(unsigned int algorithm, const char* inBuffer, unsigned int inBufLen, char* outBuf, unsigned int *outBufLen) { 518 if (algorithm != NSCAPI::xor) { 519 LOG_ERROR("Unknown algortihm requested."); 520 return NSCAPI::hasFailed; 521 } 522 unsigned int len = b64::b64_decode(inBuffer, inBufLen, reinterpret_cast<void*>(outBuf), *outBufLen); 523 if (outBuf) { 524 if ((len == 0)||(len >= *outBufLen)) { 525 LOG_ERROR("Invalid out buffer length."); 526 return NSCAPI::isInvalidBufferLen; 527 } 528 std::string key = Settings::getInstance()->getString(MAIN_SECTION_TITLE, MAIN_MASTERKEY, MAIN_MASTERKEY_DEFAULT); 529 for (int i=0,j=0;i<len;i++,j++) { 530 if (j > key.size()) 531 j = 0; 532 outBuf[i] ^= key[j]; 533 } 534 outBuf[len] = 0; 535 *outBufLen = len; 536 } else { 537 *outBufLen = len; 538 } 539 return NSCAPI::isSuccess; 540 } 482 541 483 542 LPVOID NSAPILoader(char*buffer) { … … 500 559 if (stricmp(buffer, "NSAPIGetBasePath") == 0) 501 560 return &NSAPIGetBasePath; 561 if (stricmp(buffer, "NSAPICheckLogMessages") == 0) 562 return &NSAPICheckLogMessages; 563 if (stricmp(buffer, "NSAPIEncrypt") == 0) 564 return &NSAPIEncrypt; 565 if (stricmp(buffer, "NSAPIDecrypt") == 0) 566 return &NSAPIDecrypt; 502 567 return NULL; 503 568 } -
NSClient++.h
raf5bc4b r1d9338a 44 44 std::string basePath; 45 45 MutexHandler internalVariables; 46 // MutexHandler pluginMutex;47 46 MutexHandler messageMutex; 48 47 MutexRW m_mutexRW; … … 72 71 void unloadPlugins(void); 73 72 73 bool logDebug(); 74 74 75 private: 75 76 void addPlugin(plugin_type plugin); … … 78 79 79 80 typedef NTService<NSClientT> NSClient; 81 82 83 std::string Encrypt(std::string str, unsigned int algorithm = NSCAPI::xor); 84 std::string Decrypt(std::string str, unsigned int algorithm = NSCAPI::xor); 80 85 81 86 ////////////////////////////////////////////////////////////////////////// … … 95 100 NSCAPI::nagiosReturn NSAPIInject(const char* command, const unsigned int argLen, char **argument, char *returnMessageBuffer, unsigned int returnMessageBufferLen, char *returnPerfBuffer, unsigned int returnPerfBufferLen); 96 101 NSCAPI::errorReturn NSAPIGetSettingsSection(const char*, char***, unsigned int *); 102 NSCAPI::boolReturn NSAPICheckLogMessages(int messageType); 103 NSCAPI::errorReturn NSAPIEncrypt(unsigned int algorithm, const char* inBuffer, unsigned int inBufLen, char* outBuf, unsigned int *outBufLen); 104 NSCAPI::errorReturn NSAPIDecrypt(unsigned int algorithm, const char* inBuffer, unsigned int inBufLen, char* outBuf, unsigned int *outBufLen); 97 105 ////////////////////////////////////////////////////////////////////////// 98 106 // Log macros to simplify logging -
NSClient++.vcproj
raf5bc4b r1d9338a 174 174 <Tool 175 175 Name="VCCustomBuildTool" 176 CommandLine="echo Copying documentation 177 cmd /c "copy $(InputDir)\*.html $(InputDir)\Dist\" 178 echo Copying dependency DLLs 179 cmd /c "copy $(InputDir)\dist_dll\*.dll $(InputDir)\Dist\" 176 CommandLine="echo Copying dependency DLLs 177 cmd /c "xcopy /Q /Y $(InputDir)\dist_dll\*.dll $(InputDir)\Dist\" 180 178 echo Removing old archive 181 179 cmd /c "del $(InputDir)\Dist\$(InputName).zip" 180 echo Copying documenation 181 mkdir $(TargetDir)\docs 182 xcopy /s /e /c /q /y $(InputDir)\docs $(TargetDir)\docs 182 183 echo Making archive 183 184 7z.exe a -r -tzip -bd $(InputDir)\Dist\$(InputName).zip $(InputDir)\Dist\* … … 234 235 </File> 235 236 <File 237 RelativePath=".\include\b64\b64.c"> 238 <FileConfiguration 239 Name="Release|Win32"> 240 <Tool 241 Name="VCCLCompilerTool" 242 UsePrecompiledHeader="0"/> 243 </FileConfiguration> 244 <FileConfiguration 245 Name="Debug|Win32"> 246 <Tool 247 Name="VCCLCompilerTool" 248 UsePrecompiledHeader="0"/> 249 </FileConfiguration> 250 <FileConfiguration 251 Name="Distribution|Win32"> 252 <Tool 253 Name="VCCLCompilerTool" 254 UsePrecompiledHeader="0"/> 255 </FileConfiguration> 256 </File> 257 <File 236 258 RelativePath=".\include\NSCHelper.cpp"> 237 259 </File> 238 260 <File 239 261 RelativePath=".\NSClient++.cpp"> 240 </File>241 <File242 RelativePath=".\NSClient++.def">243 262 </File> 244 263 <File … … 362 381 </FileConfiguration> 363 382 <FileConfiguration 364 Name="Distribution|Win32"> 383 Name="Distribution|Win32" 384 ExcludedFromBuild="TRUE"> 365 385 <Tool 366 386 Name="VCCustomBuildTool" -
changelog
raf5bc4b r1d9338a 1 2005-05-23 MickeM 2 + Added obfuscated password support 3 + Added some more debug info on commands (returncode, and input args) 4 + Added some more comments ot the NSC.ini 5 + Added central password "override" 6 + Added central "host override" 7 + Fixed bug with external commands always getting WARNING state 8 9 2005-05-22 MickeM 10 + Added debug outout for command 11 + Added timestamps for log-to-file (date_mask to configure format) 12 + Added support for "no password" with check_nt 13 + Added log of bad password on NSClient requests. 14 * Some threading issues fixed (I hate threading :) 15 16 2005-05-19 MickeM 17 * Verified NT4 compatibility 18 1 19 2005-05-18 MickeM 2 20 * Fixed bug in NSC.ini (section title for Check System was wrong) 3 + Added multitasking for plug ins (now two plugins can handle requests simultaniously)4 * Fixed som minor issues here and there21 + Added multitasking for plug-ins (now two plug-ins can handle requests simultaneously) 22 * Fixed some minor issues here and there 5 23 6 24 2005-05-15 MickeM … … 13 31 + Added support for Volumes (CheckDisk) 14 32 + Added support for checking all drives of a certain kind 15 + Added support for altering filter (makes it pos ible to check removale drives)16 + Created web page and better documentation33 + Added support for altering filter (makes it possible to check removable drives) 34 + Created web page and better documentation 17 35 18 36 2005-04-20 MickeM 19 + Added multitasking to socket list sner (it can now handle multiple connections)37 + Added multitasking to socket listener (it can now handle multiple connections) 20 38 * Fixed bug in NSClientListener now "seqv" in check_nt shouldn't happen. 21 39 + Added COUNTER support to NSClient and CheckSystem … … 23 41 2005-04-19 MickeM 24 42 + Added SSL support 25 + Added a lot of new options43 + Added a lot of new options 26 44 + Added documentation 27 45 * Renamed and restructured NSCLientCompat to CheckSystem -
docs/CheckDisk/index.html
re655f61 r1d9338a 1 1 <html> 2 3 2 <head> 4 3 <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 5 4 <title>CheckDisk</title> 6 5 <link rel="stylesheet" type="text/css" href="../nscplus.css"> 6 <base target="_self"> 7 7 </head> 8 8 … … 12 12 <h1>CheckDisk.dll</h1> 13 13 <p>The CheckDisk module has various disk related checks currently focusing on 14 size. But hopefully it will be extended with date exist ance and many other disk15 related checks in the fu rture. Feel free to request checks that you need.</p>14 size. But hopefully it will be extended with date existence and many other disk 15 related checks in the future. Feel free to request checks that you need.</p> 16 16 <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" id="table4"> 17 17 <tr> … … 91 91 </table> 92 92 <p>The Size with optional postfix is a way to simply specify large sizes by 93 adding unit postfix. The ava lible postfixes are B for Byte, K for KiloByte,94 M for Mega Byte and finally G for GigaByte. </p>93 adding unit postfix. The available postfixes are B for Byte, K for Kilobyte, 94 M for Megabyte and finally G for Gigabyte. </p> 95 95 <h3>Examples</h3> 96 96 <div class="example"> 97 97 <ul> 98 98 <li> 99 <p> Check the size of the windows directory and make sure it stays100 below 1 gigabyte:</p>99 <p><b>Check the size of the windows directory and make sure it stays below 100 1 gigabyte:</b></p> 101 101 <p><code>CheckFileSize ShowAll MaxWarn=1024M MaxCrit=4096M File:WIN=c:\WINDOWS\*.*</code></p> 102 102 <p><code>WARNING: WIN: 2G (2325339822B)|WIN=2325339822;1073741824;4294967296</code></p> 103 </li> 104 <li> 105 <p>Check the size of the pagefile.sys and make sure it stays 106 above 1 gigabyte:</p> 103 <div class="config"> 104 <p>define command { </p> 105 <p> command_name CheckFileSize </p> 106 <p> command_line check_nrpe -H $HOSTADDRESS$ -p 107 5666 -c CheckFileSize -a ShowAll MaxWarn=$ARG1$ MaxCrit=$ARG2$ 108 File:$ARG4$=$ARG5$ </p> 109 <p>}</p> 110 <p> check_command CheckFileSize!1024M!4096M!WIN!c:\WINDOWS\*.* 111 </p> 112 </div> 113 </li> 114 <li> 115 <p><b>Check the size of the pagefile.sys and make sure it stays 116 above 1 gigabyte:</b></p> 107 117 <p><code>CheckFileSize ShowAll MinWarn=1G MinCrit=512M File=c:\pagefile.sys</code></p> 108 118 <p><code>OK: c:\pagefile.sys: 1G (1610612736B)</code></p> 119 <div class="config"> 120 <p>define command { </p> 121 <p> command_name CheckPageFile </p> 122 <p> command_line check_nrpe -H $HOSTADDRESS$ -p 123 5666 -c CheckFileSize -a ShowAll MinWarn=$ARG1$ MinCrit=$ARG2$ 124 File:PageFile=c:\pagefile.sys </p> 125 <p>}</p> 126 <p> check_command CheckPageFile!1G!512M</p> 127 </div> 109 128 </li> 110 129 </ul> … … 161 180 <td valign="top">FIXED, CDROM, REMOVABLE</td> 162 181 <td valign="top">Filter for drive type to prevent checking drives of 163 certain kinds (most useful when using CheckAll). The default is 164 FIXED</td> 182 certain kinds (most useful when using CheckAll). The default is FIXED</td> 165 183 </tr> 166 184 <tr> … … 171 189 </table> 172 190 <p>The Size with optional postfix is a way to simply specify large sizes by 173 adding unit postfix. The avail ible postfixes are B for Byte, K for KiloByte,174 M for Mega Byte, G for GigaByte and finally % for percent free space. </p>191 adding unit postfix. The available postfixes are B for Byte, K for Kilobyte, 192 M for Megabyte, G for Gigabyte and finally % for percent free space. </p> 175 193 <h3>Examples</h3> 176 194 <div class="example"> 177 195 <ul> 178 196 <li> 179 <p> Check the size of C:\ and make sure it has 50% free space:</p>180 <p><code>CheckDriveSize ShowAll MaxWarn=50% Max Warn=75% Drive=c:\</code></p>197 <p><b>Check the size of C:\ and make sure it has 50% free space:</b></p> 198 <p><code>CheckDriveSize ShowAll MaxWarn=50% MaxCrit=75% Drive=c:\</code></p> 181 199 <p><code>OK: c:: 63G (68374007808B)|c:=85% 50;75;</code></p> 182 </li> 183 <li> 184 <p>To check the size of mounted volume c:\volumne_test and make sure it has 1M free space</p> 185 <p><code>CheckDriveSize ShowAll MaxWarn=1M MaxCrit=2M Drive="c:\\volumne_test\\"</code></p> 200 <div class="config"> 201 <p>define command { </p> 202 <p> command_name CheckDriveSize </p> 203 <p> command_line check_nrpe -H $HOSTADDRESS$ -p 204 5666 -c CheckDriveSize -a Drive=$ARG1$ ShowAll MaxWarn=$ARG2$ 205 MaxCrit=$ARG3$ </p> 206 <p>}</p> 207 <p> check_command CheckDriveSize!C:\!50%!75%</p> 208 </div> 209 </li> 210 <li> 211 <p><b>To check the size of mounted volume c:\volumne_test and make sure 212 it has 1M free space</b></p> 213 <p><code>CheckDriveSize ShowAll MaxWarn=1M MaxCrit=2M Drive="c:\\volumne_test\\"</code></p> 186 214 <p><code>CRITICAL: c:\volumne_test\: 3M (4193280B)|c:\volumne_test\=4193280;0;0;</code></p> 187 </li> 188 <li> 189 <p>To check the size of all fixed and network drives and make sure they are at least 50% full</p> 190 <p><code>CheckDriveSize -a MinWarn=50% MinCrit=25% CheckAll FilterType=FIXED FilterType=REMOTE</code></p> 191 <p><code>WARNING: X:\: 28% < warning|C:\=84% 50%;25%; X:\=28% 50%;25%; Y:\=98% 50%;25%;</code></p> 215 <div class="config"> 216 <p> check_command CheckDriveSize!<code>c:\volumne_test\</code>!1M!2M</p> 217 </div> 218 </li> 219 <li> 220 <p><b>To check the size of all fixed and network drives and make sure they 221 are at least 50% full</b></p> 222 <p><code>CheckDriveSize -a MinWarn=50% MinCrit=25% CheckAll FilterType=FIXED 223 FilterType=REMOTE</code></p> 224 <p><code>WARNING: X:\: 28% < warning|C:\=84% 50%;25%; X:\=28% 50%;25%; 225 Y:\=98% 50%;25%;</code></p> 226 <div class="config"> 227 <p>define command { </p> 228 <p> command_name CheckAllDrives </p> 229 <p> command_line check_nrpe -H $HOSTADDRESS$ -p 230 5666 -c CheckDriveSize -a Drive=$ARG1$ CheckAll FilterType=FIXED 231 FilterType=REMOTE MinWarn=$ARG1$ MinCrit=$ARG2$ </p> 232 <p>}</p> 233 <p> check_command CheckAllDrives!25%!50%</p> 234 </div> 192 235 </li> 193 236 </ul> 194 237 </div> 195 238 </div> 239 196 240 </body> 197 241 -
docs/CheckEventLog/index.html
re655f61 r1d9338a 1 1 <html> 2 3 2 <head> 4 3 <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 4 <meta http-equiv="Content-Language" content="en-us"> 5 5 <title>CheckEventLog</title> 6 6 <link rel="stylesheet" type="text/css" href="../nscplus.css"> 7 <base target="_self"> 7 8 </head> 8 9 … … 28 29 <p>Yet to be written</p> 29 30 <p>A quick introduction though:</p> 30 <p>First option is the log file to parse. (Application, System etc)</p>31 <p>First option is the log file to parse. (Application, System etc)</p> 31 32 <p>Options have the following format.</p> 32 33 <p>warn.require.eventType=warning</p> -
docs/CheckHelpers/index.html
re655f61 r1d9338a 3 3 <head> 4 4 <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 5 <meta http-equiv="Content-Language" content="en-us"> 5 6 <title>CheckDisk</title> 6 7 <link rel="stylesheet" type="text/css" href="../nscplus.css"> 8 <base target="_self"> 7 9 </head> 8 10 … … 20 22 <tr> 21 23 <td valign="top">CheckAlwaysOK</td> 22 <td valign="top">Alter the retu n code of another check to always return24 <td valign="top">Alter the return code of another check to always return 23 25 OK.</td> 24 26 </tr> 25 27 <tr> 26 28 <td valign="top">CheckAlwaysCRITICAL</td> 27 <td valign="top">Alter the retu n code of another check to always return29 <td valign="top">Alter the return code of another check to always return 28 30 CRITICAL.</td> 29 31 </tr> 30 32 <tr> 31 33 <td valign="top">CheckAlwaysWARNING</td> 32 <td valign="top">Alter the retu n code of another check to always return34 <td valign="top">Alter the return code of another check to always return 33 35 WARNING.</td> 34 36 </tr> 35 37 <tr> 36 38 <td valign="top">CheckMultiple</td> 37 <td valign="top">Runs multiple checks and returns the worst a state.38 Usefull for minimizing network traffic and command defenitions.</td>39 <td valign="top">Runs multiple checks and returns the worst state. Useful 40 for minimizing network traffic and command definitions.</td> 39 41 </tr> 40 42 </table> … … 42 44 <p><i>This module has no configuration directives.</i></p> 43 45 <h2>CheckAlwaysOK</h2> 44 <p>Runs another check and a ters the return state to always return OK.</p>46 <p>Runs another check and alters the return state to always return OK.</p> 45 47 <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" id="table5"> 46 48 <tr> … … 73 75 </div> 74 76 <h2>CheckAlwaysCRITICAL</h2> 75 <p>Runs another check and a terthe return state to always return CRITICAL.</p>77 <p>Runs another check and alters the return state to always return CRITICAL.</p> 76 78 <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" id="table5"> 77 79 <tr> … … 104 106 </div> 105 107 <h2>CheckAlwaysWARNING</h2> 106 <p>Runs another check and a ter the return state to always return WARNING.</p>108 <p>Runs another check and alter the return state to always return WARNING.</p> 107 109 <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" id="table5"> 108 110 <tr> … … 135 137 </div> 136 138 <h2>CheckMultiple</h2> 137 <p>Runs multiple checks and returns the worst state. It allows you to check an entire system in one go.</p> 139 <p>Runs multiple checks and returns the worst state. It allows you to check 140 an entire system in one go.</p> 138 141 <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" id="table5"> 139 142 <tr> … … 145 148 <td valign="top">command</td> 146 149 <td valign="top">The command to run</td> 147 <td valign="top">A command to execute, you can have any number of 148 thisoption.</td>150 <td valign="top">A command to execute, you can have any number of this 151 option.</td> 149 152 </tr> 150 153 </table> … … 153 156 <ul> 154 157 <li> 155 <p>Run two checks (CheckDriveSize and ChEckMeM) and return the worst state. Performance data and 156 message is collected and concatenated.</p> 157 <p><code>CheckMultiple command=CheckDriveSize MaxWarn=1M MaxCrit=2M Drive=c:\\volumne_test\\ command=ChEckMeM MaxWarn=80% MaxCrit=90%</code></p> 158 <p><code>CRITICAL: c:\volumne_test\: 3M (4193280B) > critical, OK memory within bounds.|c:\volumne_test\=4193280;1024K (1048576B);2M (2097152B); page=31% 80%;90%;</code></p> 158 <p>Run two checks (CheckDriveSize and ChEckMeM) and return the worst 159 state. Performance data and message is collected and concatenated.</p> 160 <p><code>CheckMultiple command=CheckDriveSize MaxWarn=1M MaxCrit=2M 161 Drive=c:\\volumne_test\\ command=ChEckMeM MaxWarn=80% MaxCrit=90%</code></p> 162 <p><code>CRITICAL: c:\volumne_test\: 3M (4193280B) > critical, OK memory 163 within bounds.|c:\volumne_test\=4193280;1024K (1048576B);2M (2097152B); 164 page=31% 80%;90%;</code></p> 159 165 </li> 160 166 </ul> -
docs/CheckSystem/index.html
re655f61 r1d9338a 3 3 <head> 4 4 <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 5 <meta http-equiv="Content-Language" content="en-us"> 5 6 <title>CheckSystem</title> 6 7 <link rel="stylesheet" type="text/css" href="../nscplus.css"> … … 42 43 <p>This module needs configuration as PDH counters are version and language 43 44 specific. This means that unless you use an English language windows 2000 you 44 will most likely have to edit this. There is also some other twe ks that can45 will most likely have to edit this. There is also some other tweaks that can 45 46 be configured such as check resolution and buffer size. For more details on 46 47 how to configure this refer to the Configuration section.</p> … … 158 159 <ul> 159 160 <li> 160 <p>Check that the system has been running for at least a day:</p>161 <p>Check that the system has been running for at least a day:</p> 161 162 <p><code>checkUpTime warn=1d crit=12h</code></p> 162 163 <p><code>Client has uptime (19h) < warning (24h)</code></p> … … 303 304 counters use the program perfmon that is shipped with windows. An important 304 305 note is that performance counters are language and version specific.</p> 306 <p><i><b>This is currently broken and will be fixed in the next version.</b></i></p> 305 307 <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" id="table16"> 306 308 <tr> … … 346 348 <tr> 347 349 <td valign="top">Counter:<name></td> 348 <td valign="top">Perfo mance Counter</td>350 <td valign="top">Performance Counter</td> 349 351 <td valign="top">Add a named performance counter. The <name> will be 350 352 used as an alias.</td> -
docs/Configuration/index.html
re655f61 r1d9338a 3 3 <head> 4 4 <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 5 <meta http-equiv="Content-Language" content="en-us"> 5 6 <title>Configuration</title> 6 7 <link rel="stylesheet" type="text/css" href="../nscplus.css"> … … 23 24 has a lot of examples and comments so make sure you change this before you use 24 25 NSClient++ as some of the examples might be potential security issues.</p> 26 <h2>[Settings]</h2> 27 <p>This section has options for how logging is performed. First off notice that 28 for logging to make sense you need to enable the FileLogger.dll module that 29 logs all log data to a text file in the same directory as the NSClient++ binary 30 if you dont enable any logging module nothing will be logged.</p> 31 <p>The options you have available here are</p> 32 <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" id="table21"> 33 <tr> 34 <td valign="top">Option</td> 35 <td valign="top">Default value</td> 36 <td valign="top">Description</td> 37 </tr> 38 <tr> 39 <td valign="top">obfuscated_password</td> 40 <td valign="top">...</td> 41 <td valign="top">An obfuscated version of password. For more details 42 refer to the password option below.</td> 43 </tr> 44 <tr> 45 <td valign="top">password</td> 46 <td valign="top">...</td> 47 <td valign="top">The password used by various (presently only 48 NSClient) daemons. If no password is set everyone will be able to 49 use this service remotely.</td> 50 </tr> 51 <tr> 52 <td valign="top">allowed_hosts</td> 53 <td valign="top">127.0.0.1</td> 54 <td valign="top">A list (comma separated) with hosts that are 55 allowed to connect and query data. If this is empty all hosts will 56 be allowed to query data.</td> 57 </tr> 58 </table> 25 59 <h2>[Log]</h2> 26 60 <p>This section has options for how logging is performed. First off notice that … … 47 81 this is relative to the NSClient++ binary.</td> 48 82 </tr> 83 <tr> 84 <td valign="top">date_mask</td> 85 <td valign="top">%Y-%m-%d %H:%M:%S</td> 86 <td valign="top">The date format used when logging to a file</td> 87 </tr> 49 88 </table> 50 89 <h2>[Systray]</h2> … … 79 118 </tr> 80 119 <tr> 120 <td valign="top">obfuscated_password</td> 121 <td valign="top"> </td> 122 <td valign="top">An obfuscated version of password. For more details 123 refer to the password option below. </td> 124 </tr> 125 <tr> 81 126 <td valign="top">password</td> 82 127 <td valign="top"> </td> 83 128 <td valign="top">The password that incoming client needs to authorize 84 themselves by.</td> 129 themselves by. This option will replace the one found under Settings 130 for NSClient. If this is blank the option found under Settings will 131 be used. If both are blank everyone will be granted access.</td> 85 132 </tr> 86 133 <tr> … … 88 135 <td valign="top"> </td> 89 136 <td valign="top">A list (coma separated) with hosts that are allowed 90 to poll information from NSClient++</td> 91 </tr> 92 <tr> 93 <td valign="top">use_ssl</td> 94 <td valign="top">0</td> 95 <td valign="top">Boolean value to toggle SSL encryption. This is not 96 yet supported in any client I know of but as the underlying structure 97 (NRPE) supports it I thought Id might add it if someone wants to update 98 check_nt to support SSL.<b>Not implemented in this version</b></td> 99 </tr> 100 </table> 137 to poll information from NSClient++. This will replace the one found 138 under Setting for NSClient if present. If not present the same 139 option found under Settings will be used. If both are blank all 140 hosts will be allowed to access the system</td> 141 </tr> 142 </table> 101 143 <h2>[NRPE]</h2> 102 144 <p>This is configuration for the NRPE module that controls how the NRPE listener … … 117 159 <td valign="top"> </td> 118 160 <td valign="top">A list (coma separated) with hosts that are allowed 119 to poll information from NSClient++</td> 161 to poll information from NRPE. This will replace the one found under 162 Setting for NRPE if present. If not present the same option found 163 under Settings will be used. If both are blank all hosts will be 164 allowed to access the system</td> 120 165 </tr> 121 166 <tr> … … 129 174 <td valign="top">60</td> 130 175 <td valign="top">The maximum time in seconds that a command can execute. 131 (if more then this execution will be aborted).<b> NOTICE</b> this only176 (if more then this execution will be aborted).<b> NOTICE</b> this only 132 177 affects external commands not internal ones.</td> 133 178 </tr> … … 156 201 The latter is the preferred way as it is shorter.</p> 157 202 <h2>[Check System]</h2> 158 <p>Here you can set various options to configure the Sy etem Check module.</p>203 <p>Here you can set various options to configure the System Check module.</p> 159 204 <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" id="table20"> 160 205 <tr> … … 179 224 <tr> 180 225 <td valign="top">CounterPageLimit</td> 181 <td valign="top">\ \\\.\\Memory\\Commit Limit</td>226 <td valign="top">\Memory\Commit Limit</td> 182 227 <td valign="top">Counter to use to check upper memory limit.</td> 183 228 </tr> 184 229 <tr> 185 230 <td valign="top">CounterPage</td> 186 <td valign="top">\ \\\.\\Memory\\Committed Bytes</td>231 <td valign="top">\Memory\Committed Bytes</td> 187 232 <td valign="top">Counter to use to check current memory usage.</td> 188 233 </tr> 189 234 <tr> 190 235 <td valign="top">CounterUptime</td> 191 <td valign="top">\ \\\.\\System\\System Up Time</td>236 <td valign="top">\System\System Up Time</td> 192 237 <td valign="top">Counter to use to check the uptime of the system.</td> 193 238 </tr> 194 239 <tr> 195 240 <td valign="top">CounterCPU</td> 196 <td valign="top">\\\\.\\Processor(_total)\\% Processor Time</td> 197 <td valign="top">Counter to use for CPU load.</td> 241 <td valign="top">\Processor(_total)\% Processor Time</td> 242 <td valign="top">Counter to use for CPU load. For NT4 this has to be 243 altered to "\System\% Total Processor Time" as PDH definitions have changed.</td> 198 244 </tr> 199 245 </table> -
docs/FileLogger/index.html
re655f61 r1d9338a 3 3 <head> 4 4 <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 5 <meta http-equiv="Content-Language" content="en-us"> 5 6 <title>FileLogger</title> 6 7 <link rel="stylesheet" type="text/css" href="../nscplus.css"> -
docs/NRPEListener/index.html
r1e62ed5 r1d9338a 3 3 <head> 4 4 <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 5 <meta http-equiv="Content-Language" content="en-us"> 5 6 <title>NRPEListener</title> 6 7 <link rel="stylesheet" type="text/css" href="../nscplus.css"> -
docs/SysTray/index.html
raf5bc4b r1d9338a 3 3 <head> 4 4 <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 5 <meta http-equiv="Content-Language" content="en-us"> 5 6 <title>SysTray</title> 6 7 <link rel="stylesheet" type="text/css" href="../nscplus.css"> -
docs/index.html
r1e62ed5 r1d9338a 9 9 <frameset cols="212,*"> 10 10 <frame name="contents" target="main" src="menu.html" scrolling="no" noresize> 11 <frame name="main" src="welcome.html" scrolling="auto" >11 <frame name="main" src="welcome.html" scrolling="auto" target="_self"> 12 12 </frameset> 13 13 <noframes> -
docs/nscplus.css
r1e62ed5 r1d9338a 111 111 padding: 5px; 112 112 } 113 114 .config { 115 padding: 0px 0px 0px 20px; 116 border: none; 117 background: lightgrey; 118 font-style: italic; 119 clear: both; 120 } 121 122 123 124 -
docs/welcome.html
r1e62ed5 r1d9338a 1 1 <html> 2 3 2 <head> 4 3 <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 5 4 <title>About NSClient++</title> 6 5 <link rel="stylesheet" type="text/css" href="nscplus.css"> 6 <base target="_self"> 7 7 </head> 8 8 … … 23 23 plug-in is of course the most powerful way but requires knowledge of C++ or other 24 24 language which can produce DLLs and interface with regular C programs.</p> 25 <p>As for checking with NSClient++ I would recommend 26 <a href="http://sourceforge.net/project/showfiles.php?group_id=26589&package_id=40241"> 27 NRPE</a> as it is a lot more flexible then check_nt. But NSClient has full 28 support for check_nt and if there is an interest I could probably add support 29 for check_nt from nc_net.</p> 25 30 <h1>News</h1> 26 31 <table id="table17" border="0" cellspacing="0" cellpadding="0" class="MsoNormalTable" > 27 32 <tr> 28 <td>2005-05-14</td> 33 <td valign="top">2005-05-23</td> 34 <td>New version available.<p>Has many new features and some enhancements 35 as well as NT4 Compatibility (verified this time).</p> 36 <p>Added:</p> 37 <ul> 38 <li>Multitasking support for requests.</li> 39 <li>NRPE support for checkCounter</li> 40 <li>CheckHelpers module to alter the result of various check and 41 similar things </li> 42 <li>Support for Volumes (CheckDisk)</li> 43 <li>Support for checking all drives</li> 44 <li>Support for altering filter (makes it possible to check 45 removable/network drives)</li> 46 <li>Webpage and better documentation</li> 47 <li>Obfuscated password support (try NSClient++ /encrypt)</li> 48 <li>Central host/password options in INI file (look for [Settings])</li> 49 </ul> 50 <p>Enhances/Fixes:</p> 51 <ul> 52 <li>Some threading issues fixed</li> 53 <li>Verified NT4 compatibility</li> 54 <li>Fixed bug in NSC.ini (section title for Check System was wrong)</li> 55 <li>Fixed some minor issues here and there</li> 56 <li>Make check commands ignore case</li> 57 <li>Better debugging log (timestamps, better info, etc)</li> 58 <li>Support for password-less NSClient</li> 59 </ul> 60 </td> 61 </tr> 62 <tr> 63 <td valign="top">2005-05-14</td> 29 64 <td>New webpage is created and semi updated.</td> 30 65 </tr> … … 33 68 <p>NSClient can be found at its source forge page 34 69 <a href="http://nscplus.sf.net" target="_top">http://nscplus.sf.net</a></p> 35 <p>Latest version is <a href="http://prdownloads.sourceforge.net/nscplus/NSClient++-0. 1.0-a2.zip?download">NSClient++ 0.1.0 Alpha 2.zip</a></p>70 <p>Latest version is <a href="http://prdownloads.sourceforge.net/nscplus/NSClient++-0.2.0.zip?download">NSClient++ 0.2.0.zip</a></p> 36 71 <h1>Modules</h1> 37 72 <p>NSClient++ comes with a few modules out of the box that does various checks. … … 104 139 <tr> 105 140 <td width="221" colspan="2"><b><a href="CheckHelpers/index.html">CheckHelpers</a></b></td> 106 <td>Various helper function, doesn't check anything i tit self but can141 <td>Various helper function, doesn't check anything in it self but can 107 142 help make things simpler.</td> 108 143 </tr> -
include/Mutex.h
r1e62ed5 r1d9338a 101 101 */ 102 102 MutexLock(HANDLE hMutex, DWORD timeout = 5000L) : bHasMutex(false), hMutex_(hMutex) { 103 if (hMutex_ == NULL) 104 std::cout << "Whops..." << std::endl; 103 105 assert(hMutex_ != NULL); 104 106 dwWaitResult = WaitForSingleObject(hMutex_, timeout); -
include/NSCAPI.h
r81e29d8 r1d9338a 22 22 } errorReturn; 23 23 #else 24 const int returnCRIT = 2;25 24 const int returnOK = 0; 26 25 const int returnWARN = 1; 26 const int returnCRIT = 2; 27 27 const int returnUNKNOWN = 4; 28 28 const int returnInvalidBufferLen = -2; … … 38 38 #endif 39 39 40 const int xor = 1; 40 41 41 42 // Various message Types -
include/NSCHelper.cpp
r1e62ed5 r1d9338a 107 107 lpNSAPIStopServer fNSAPIStopServer = NULL; 108 108 lpNSAPIInject fNSAPIInject = NULL; 109 lpNSAPICheckLogMessages fNSAPICheckLogMessages = NULL; 110 lpNSAPIEncrypt fNSAPIEncrypt = NULL; 111 lpNSAPIDecrypt fNSAPIDecrypt = NULL; 109 112 } 110 113 … … 123 126 */ 124 127 void NSCModuleHelper::Message(int msgType, std::string file, int line, std::string message) { 125 if (fNSAPIMessage) 128 if (fNSAPIMessage) { 129 if ((msgType == NSCAPI::debug) && (!logDebug())) 130 return; 126 131 return fNSAPIMessage(msgType, file.c_str(), line, message.c_str()); 132 } 127 133 else 128 134 std::cout << "NSCore not loaded..." << std::endl << message << std::endl; … … 354 360 return ret; 355 361 } 362 363 364 bool NSCModuleHelper::logDebug() { 365 typedef enum status {unknown, debug, nodebug }; 366 static status d = unknown; 367 if (d == unknown) { 368 if (checkLogMessages(debug)== NSCAPI::istrue) 369 d = debug; 370 else 371 d = nodebug; 372 } 373 return (d == debug); 374 } 375 376 377 378 379 std::string NSCModuleHelper::Encrypt(std::string str, unsigned int algorithm) { 380 if (!fNSAPIEncrypt) 381 throw NSCMHExcpetion("NSCore has not been initiated..."); 382 unsigned int len = 0; 383 fNSAPIEncrypt(algorithm, str.c_str(), str.size(), NULL, &len); 384 len+=2; 385 char *buf = new char[len+1]; 386 NSCAPI::errorReturn ret = fNSAPIEncrypt(algorithm, str.c_str(), str.size(), buf, &len); 387 if (ret == NSCAPI::isSuccess) { 388 std::string ret = buf; 389 delete [] buf; 390 return ret; 391 } 392 return ""; 393 } 394 std::string NSCModuleHelper::Decrypt(std::string str, unsigned int algorithm) { 395 if (!fNSAPIDecrypt) 396 throw NSCMHExcpetion("NSCore has not been initiated..."); 397 unsigned int len = 0; 398 fNSAPIDecrypt(algorithm, str.c_str(), str.size(), NULL, &len); 399 len+=2; 400 char *buf = new char[len+1]; 401 NSCAPI::errorReturn ret = fNSAPIDecrypt(algorithm, str.c_str(), str.size(), buf, &len); 402 if (ret == NSCAPI::isSuccess) { 403 std::string ret = buf; 404 delete [] buf; 405 return ret; 406 } 407 return ""; 408 } 409 410 411 bool NSCModuleHelper::checkLogMessages(int type) { 412 if (!fNSAPICheckLogMessages) 413 throw NSCMHExcpetion("NSCore has not been initiated..."); 414 return fNSAPICheckLogMessages(type) == NSCAPI::istrue; 415 } 356 416 /** 357 417 * Retrieve the application version as a string (in human readable format) from the core. … … 416 476 NSCModuleHelper::fNSAPIInject = (NSCModuleHelper::lpNSAPIInject)f("NSAPIInject"); 417 477 NSCModuleHelper::fNSAPIGetBasePath = (NSCModuleHelper::lpNSAPIGetBasePath)f("NSAPIGetBasePath"); 478 NSCModuleHelper::fNSAPICheckLogMessages = (NSCModuleHelper::lpNSAPICheckLogMessages)f("NSAPICheckLogMessages"); 479 NSCModuleHelper::fNSAPIDecrypt = (NSCModuleHelper::lpNSAPIDecrypt)f("NSAPIDecrypt"); 480 NSCModuleHelper::fNSAPIEncrypt = (NSCModuleHelper::lpNSAPIEncrypt)f("NSAPIEncrypt"); 418 481 return NSCAPI::isSuccess; 419 482 } -
include/NSCHelper.h
r1e62ed5 r1d9338a 84 84 typedef NSCAPI::nagiosReturn (*lpNSAPIInject)(const char*, const unsigned int, char **, char *, unsigned int, char *, unsigned int); 85 85 typedef LPVOID (*lpNSAPILoader)(char*); 86 typedef NSCAPI::boolReturn (*lpNSAPICheckLogMessages)(int); 87 typedef NSCAPI::errorReturn (*lpNSAPIEncrypt)(unsigned int, const char*, unsigned int, char*, unsigned int *); 88 typedef NSCAPI::errorReturn (*lpNSAPIDecrypt)(unsigned int, const char*, unsigned int, char*, unsigned int *); 86 89 87 90 // Helper functions for calling into the core … … 98 101 void StopService(void); 99 102 std::string getBasePath(); 103 bool logDebug(); 104 bool checkLogMessages(int type); 105 std::string Encrypt(std::string str, unsigned int algorithm = NSCAPI::xor); 106 std::string Decrypt(std::string str, unsigned int algorithm = NSCAPI::xor); 100 107 }; 101 108 -
include/PDHCollectors.h
rcea178b r1d9338a 4 4 5 5 namespace PDHCollectors { 6 class StaticPDHCounterListener : public PDH::PDHCounterListener {6 class StaticPDHCounterListenerInt : public PDH::PDHCounterListener { 7 7 __int64 value_; 8 8 public: … … 16 16 } 17 17 __int64 getValue() const { 18 return value_; 19 } 20 }; 21 class StaticPDHCounterListenerDouble : public PDH::PDHCounterListener { 22 double value_; 23 public: 24 virtual void collect(const PDH::PDHCounter &counter) { 25 setValue(counter.getDoubleValue()); 26 } 27 void attach(const PDH::PDHCounter &counter){} 28 void detach(const PDH::PDHCounter &counter){} 29 void setValue(double value) { 30 value_ = value; 31 } 32 double getValue() const { 18 33 return value_; 19 34 } -
include/PDHCounter.h
raf5bc4b r1d9338a 77 77 listener_->collect(*this); 78 78 } 79 double getDoubleValue() const { 80 return data_.doubleValue; 81 } 79 82 __int64 getInt64Value() const { 80 83 return data_.largeValue; … … 128 131 throw PDHException("PdhCloseQuery failed", status); 129 132 hQuery_ = NULL; 133 for (CounterList::iterator it = counters_.begin(); it != counters_.end(); it++) { 134 delete (*it); 135 } 136 counters_.clear(); 130 137 } 131 138 -
include/Socket.cpp
r1e62ed5 r1d9338a 7 7 * @param error 8 8 */ 9 void simpleSocket::Socket::printError(std::string error) {10 NSC _LOG_ERROR_STD(error);9 void simpleSocket::Socket::printError(std::string FILE, int LINE, std::string error) { 10 NSCModuleHelper::Message(NSCAPI::error, FILE, LINE, error); 11 11 } 12 12 -
include/Socket.h
r1e62ed5 r1d9338a 18 18 return error_; 19 19 } 20 20 21 21 }; 22 22 class DataBuffer { … … 150 150 return inet_ntoa(from_.sin_addr); 151 151 } 152 virtual void printError(std::string error);152 virtual void printError(std::string file, int line, std::string error); 153 153 }; 154 154 … … 161 161 162 162 /** 163 * @ingroup NSClient++164 * Socket responder class.165 * This is a background thread that listens to the socket and executes incoming commands.166 *167 * @version 1.0168 * first version169 *170 * @date 02-12-2005171 *172 * @author mickem173 *174 * @par license175 * This code is absolutely free to use and modify. The code is provided "as is" with176 * no expressed or implied warranty. The author accepts no liability if it causes177 * any damage to your computer, causes your pet to fall ill, increases baldness178 * or makes your car start emitting strange noises when you start it up.179 * This code has no bugs, just undocumented features!180 *181 * @todo This is not very well written and should probably be reworked.182 *183 * @bug184 *185 */163 * @ingroup NSClient++ 164 * Socket responder class. 165 * This is a background thread that listens to the socket and executes incoming commands. 166 * 167 * @version 1.0 168 * first version 169 * 170 * @date 02-12-2005 171 * 172 * @author mickem 173 * 174 * @par license 175 * This code is absolutely free to use and modify. The code is provided "as is" with 176 * no expressed or implied warranty. The author accepts no liability if it causes 177 * any damage to your computer, causes your pet to fall ill, increases baldness 178 * or makes your car start emitting strange noises when you start it up. 179 * This code has no bugs, just undocumented features! 180 * 181 * @todo This is not very well written and should probably be reworked. 182 * 183 * @bug 184 * 185 */ 186 186 template <class TListenerType = simpleSocket::Socket, class TSocketType = TListenerType> 187 187 class Listener : public TListenerType { … … 191 191 private: 192 192 struct simpleResponderBundle { 193 bool terminated; 193 194 HANDLE hThread; 194 195 unsigned dwThreadID; … … 226 227 Listener() : pHandler_(NULL) {}; 227 228 virtual ~Listener() { 228 if (responderList_.size() > 0) 229 std::cout << "We had stale processes running then the socket closed." << std::endl; 230 // @todo check if we have stale processes here (if so log an error) 229 if (responderList_.size() > 0) { 230 MutexLock lock(responderMutex_); 231 if (!lock.hasMutex()) { 232 printError(__FILE__, __LINE__, "Failed to get responder mutex (cannot terminate socket threads)."); 233 } else { 234 for (socketResponses::iterator it = responderList_.begin(); it != responderList_.end(); ++it) { 235 if (WaitForSingleObject( (*it).hThread, 1000) == WAIT_OBJECT_0) { 236 } else { 237 if (!TerminateThread((*it).hThread, -1)) { 238 printError(__FILE__, __LINE__, "We failed to terminate check thread."); 239 } else { 240 if (WaitForSingleObject( (*it).hThread, 5000) == WAIT_OBJECT_0) { 241 CloseHandle((*it).hThread); 242 } else { 243 printError(__FILE__, __LINE__, "We failed to terminate check thread (wait timed out)."); 244 } 245 } 246 } 247 } 248 responderList_.clear(); 249 } 250 } 231 251 }; 232 252 … … 255 275 }; 256 276 void addResponder(tSocket *client) { 277 MutexLock lock(responderMutex_); 278 if (!lock.hasMutex()) { 279 printError(__FILE__, __LINE__, "Failed to get responder mutex."); 280 return; 281 } 282 for (socketResponses::iterator it = responderList_.begin(); it != responderList_.end();) { 283 if ( (*it).terminated) { 284 if (WaitForSingleObject( (*it).hThread, 500) == WAIT_OBJECT_0) { 285 CloseHandle((*it).hThread); 286 responderList_.erase(it++); 287 } 288 } else 289 ++it; 290 } 257 291 simpleResponderBundle data; 258 // @todo protect259 292 srp_data *lpData = new srp_data; 260 293 lpData->pCore = this; 261 294 lpData->client = client; 262 295 263 MutexLock lock(responderMutex_);264 if (!lock.hasMutex()) {265 printError("Failed to get responder mutex.");266 return;267 }268 296 data.hThread = reinterpret_cast<HANDLE>(::_beginthreadex( NULL, 0, &socketResponceProc, lpData, 0, &data.dwThreadID)); 297 data.terminated = false; 269 298 responderList_.push_back(data); 270 299 } … … 272 301 MutexLock lock(responderMutex_); 273 302 if (!lock.hasMutex()) { 274 printError( "Failed to get responder mutex when trying to free thread.");303 printError(__FILE__, __LINE__, "Failed to get responder mutex when trying to free thread."); 275 304 return false; 276 305 } 277 306 for (socketResponses::iterator it = responderList_.begin(); it != responderList_.end(); ++it) { 278 307 if ( (*it).dwThreadID == dwThreadID) { 279 responderList_.erase(it);308 (*it).terminated = true; 280 309 return true; 281 310 } … … 316 345 pCore->onAccept(client); 317 346 } catch (SocketException e) { 318 pCore->printError( e.getMessage() + " killing socket...");347 pCore->printError(__FILE__, __LINE__, e.getMessage() + " killing socket..."); 319 348 } 320 349 client->close(); 321 350 delete client; 322 351 if (!pCore->removeResponder(GetCurrentThreadId())) { 323 pCore->printError( "Could not remove thread: " + strEx::itos(GetCurrentThreadId()));352 pCore->printError(__FILE__, __LINE__, "Could not remove thread: " + strEx::itos(GetCurrentThreadId())); 324 353 } 325 354 _endthreadex(0); … … 335 364 hStopEvent_ = CreateEvent(NULL, TRUE, FALSE, NULL); 336 365 if (!hStopEvent_) { 337 core->printError( "Create StopEvent failed: " + strEx::itos(GetLastError()));366 core->printError(__FILE__, __LINE__, "Create StopEvent failed: " + strEx::itos(GetLastError())); 338 367 return 0; 339 368 } … … 352 381 } 353 382 } catch (SocketException e) { 354 core->printError( e.getMessage() + ", attempting to resume...");383 core->printError(__FILE__, __LINE__, e.getMessage() + ", attempting to resume..."); 355 384 } 356 385 } 357 386 } catch (SocketException e) { 358 core->printError( e.getMessage());387 core->printError(__FILE__, __LINE__, e.getMessage()); 359 388 } 360 389 core->shutdown(SD_BOTH); … … 364 393 hStopEvent_ = NULL; 365 394 if (!CloseHandle(hTmp)) { 366 core->printError( "CloseHandle StopEvent failed: " + strEx::itos(GetLastError()));395 core->printError(__FILE__, __LINE__, "CloseHandle StopEvent failed: " + strEx::itos(GetLastError())); 367 396 } 368 397 return 0; -
include/config.h
r1e62ed5 r1d9338a 5 5 6 6 // Version 7 #define SZVERSION "0. 3.0 a1 2005-05-16"7 #define SZVERSION "0.2.0 2005-05-21" 8 8 9 9 // internal name of the service … … 31 31 #define NSCLIENT_SETTINGS_PORT "port" 32 32 #define NSCLIENT_SETTINGS_PORT_DEFAULT 12489 33 #define NSCLIENT_SETTINGS_ALLOWED "allowed_hosts" 34 #define NSCLIENT_SETTINGS_ALLOWED_DEFAULT "" 35 #define NSCLIENT_SETTINGS_PWD "password" 36 #define NSCLIENT_SETTINGS_PWD_DEFAULT "" 33 #define NSCLIENT_SETTINGS_VERSION "version" 34 #define NSCLIENT_SETTINGS_VERSION_DEFAULT "auto" 37 35 38 36 // NRPE Settings headlines … … 41 39 #define NRPE_SETTINGS_TIMEOUT "command_timeout" 42 40 #define NRPE_SETTINGS_TIMEOUT_DEFAULT 60 43 #define NRPE_SETTINGS_ALLOWED "allowed_hosts"44 #define NRPE_SETTINGS_ALLOWED_DEFAULT ""45 41 #define NRPE_SETTINGS_PORT "port" 46 42 #define NRPE_SETTINGS_PORT_DEFAULT 5666 … … 74 70 #define LOG_SECTION_TITLE "log" 75 71 #define LOG_FILENAME "file" 76 #define LOG_FILENAME_DEFAULT "nsclient.log" 72 #define LOG_FILENAME_DEFAULT "nsclient.log" 73 #define LOG_DATEMASK "date_mask" 74 #define LOG_DATEMASK_DEFAULT "%Y-%m-%d %H:%M:%S" 77 75 76 // Main Settings 77 #define MAIN_SECTION_TITLE "Settings" 78 #define MAIN_MASTERKEY "master_key" 79 #define MAIN_MASTERKEY_DEFAULT "This is a secret key thet you should change" 80 #define MAIN_OBFUSCATED_PASWD "obfuscated_password" 81 #define MAIN_OBFUSCATED_PASWD_DEFAULT "" 82 #define MAIN_SETTINGS_PWD "password" 83 #define MAIN_SETTINGS_PWD_DEFAULT "" 84 #define MAIN_ALLOWED_HOSTS "allowed_hosts" 85 #define MAIN_ALLOWED_HOSTS_DEFAULT "127.0.0.1" -
include/thread.h
rcea178b r1d9338a 7 7 public: 8 8 std::string e_; 9 ThreadException(std::string e) : e_(e) {} 9 ThreadException(std::string e) : e_(e) { 10 std::cout << e << std::endl; 11 } 10 12 }; 11 13 … … 69 71 throw ThreadException("Could not retrieve mutex when killing thread, we are fucked..."); 70 72 } 71 if (hThread_)72 CloseHandle(hThread_);73 73 hThread_ = NULL; 74 74 if (hStopEvent_) … … 99 99 delete param; 100 100 101 if (hStopEvent != NULL) { 102 instance->threadProc(lpParam); 103 SetEvent(hStopEvent); 104 } 101 instance->threadProc(lpParam); 105 102 pCore->terminate(); 103 SetEvent(hStopEvent); 106 104 _endthread(); 107 105 } … … 135 133 } 136 134 hThread_ = reinterpret_cast<HANDLE>(::_beginthread(threadProc, 0, reinterpret_cast<VOID*>(param))); 137 assert(hThread_ != NULL);138 135 } 139 136 /** … … 153 150 assert(hStopEvent_ != NULL); 154 151 pObject_->exitThread(); 155 dwWaitResult = WaitForSingleObject(hStopEvent_, delay);156 152 } 153 dwWaitResult = WaitForSingleObject(hStopEvent_, delay); 157 154 switch (dwWaitResult) { 158 155 // The thread got mutex ownership. … … 182 179 return pObject_; 183 180 } 184 T* getThread() const{181 T* getThread() { 185 182 MutexLock mutex(hMutex_, 5000L); 186 183 if (!mutex.hasMutex()) { … … 197 194 delete pObject_; 198 195 pObject_ = NULL; 199 CloseHandle(hStopEvent_);200 hStopEvent_ = NULL;201 196 hThread_ = NULL; 202 197 } -
modules/CheckDisk/CheckDisk.cpp
r1e62ed5 r1d9338a 204 204 return NSCAPI::returnUNKNOWN; 205 205 } 206 //10597515264&80015491072 206 207 207 208 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); 210 214 } else { 211 215 std::string tStr; … … 236 240 if (message.empty()) 237 241 message = "All drive sizes are within bounds."; 238 else 242 else if (!bNSClient) 239 243 message = NSCHelper::translateReturn(returnCode) + ": " + message; 240 244 return returnCode; -
modules/CheckSystem/CheckSystem.cpp
raf5bc4b r1d9338a 297 297 NSCAPI::nagiosReturn ret = NSCAPI::returnOK; 298 298 bool bShowAll = false; 299 bool bNSClient = false; 299 300 300 301 for (arrayBuffer::arrayList::const_iterator it = stl_args.begin(); it != stl_args.end(); ++it) { … … 302 303 if (t.first == SHOW_ALL) 303 304 bShowAll = true; 305 else if (t.first == NSCLIENT) 306 bNSClient = true; 304 307 else if (t.first == SHOW_FAIL) { 305 308 bShowAll = false; … … 339 342 } 340 343 if (msg.empty()) 341 msg ="All services ok."; 344 msg ="All services are running."; 345 else if (!bNSClient) 346 msg = NSCHelper::translateReturn(ret) + ": " + msg; 342 347 return ret; 343 348 } … … 345 350 346 351 /** 347 * Check avail ible memory and return various check results352 * Check available memory and return various check results 348 353 * Example: checkMem showAll maxWarn=50 maxCrit=75 349 354 * … … 468 473 NSCAPI::nagiosReturn ret = NSCAPI::returnOK; 469 474 bool bShowAll = false; 475 bool bNSClient = false; 470 476 471 477 for (arrayBuffer::arrayList::const_iterator it = stl_args.begin(); it != stl_args.end(); ++it) { … … 473 479 if (t.first == SHOW_ALL) 474 480 bShowAll = true; 481 else if (t.first == NSCLIENT) 482 bNSClient = true; 475 483 else if (t.first == SHOW_FAIL) { 476 484 bShowAll = false; … … 518 526 if (msg.empty()) 519 527 msg ="All processes ok."; 528 else if (!bNSClient) 529 msg = NSCHelper::translateReturn(ret) + ": " + msg; 520 530 return ret; 521 531 } … … 583 593 try { 584 594 PDH::PDHQuery pdh; 585 PDHCollectors::StaticPDHCounterListener counter;595 PDHCollectors::StaticPDHCounterListenerInt counter; 586 596 std::string name = (*it).first; 587 597 if (name.empty()) … … 591 601 pdh.collect(); 592 602 if (bNSCLientCompatible) { 603 // std::cout << counter.getValue() << std::endl; 593 604 msg += strEx::itos(counter.getValue()); 594 605 } else { -
modules/CheckSystem/PDHCollector.cpp
raf5bc4b r1d9338a 36 36 37 37 /** 38 * Thread that collects the data every "CHECK_INTERVAL" seconds.39 *40 * @param lpParameter Not used41 * @return thread exit status42 *43 * @author mickem44 *45 * @date 03-13-200446 *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 */ 51 51 DWORD PDHCollector::threadProc(LPVOID lpParameter) { 52 52 PDH::PDHQuery pdh; … … 103 103 104 104 /** 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 */ 107 107 void PDHCollector::exitThread(void) { 108 108 MutexLock mutex(mutexHandler); … … 116 116 if (!SetEvent(hStopEvent_)) { 117 117 NSC_LOG_ERROR_STD("SetStopEvent failed"); 118 }118 } 119 119 } 120 120 /** 121 * Get the average CPU usage for "time"122 * @param time Time to check123 * @return average CPU usage124 */121 * Get the average CPU usage for "time" 122 * @param time Time to check 123 * @return average CPU usage 124 */ 125 125 int PDHCollector::getCPUAvrage(std::string time) { 126 126 unsigned int mseconds = strEx::stoui_as_time(time, checkIntervall_*100); … … 133 133 } 134 134 /** 135 * Get uptime from counter136 * @bug Do we need to collect this all the time ? (perhaps we can collect this in real time ?)137 * @return uptime for the system138 * @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 */ 140 140 long long PDHCollector::getUptime() { 141 141 MutexLock mutex(mutexHandler); … … 147 147 } 148 148 /** 149 * Memory commit limit (your guess is as good as mine to what this is :)150 * @return Some form of memory check151 */149 * Memory commit limit (your guess is as good as mine to what this is :) 150 * @return Some form of memory check 151 */ 152 152 long long PDHCollector::getMemCommitLimit() { 153 153 MutexLock mutex(mutexHandler); … … 159 159 } 160 160 /** 161 *162 * Memory committed bytes (your guess is as good as mine to what this is :)163 * @return Some form of memory check164 */161 * 162 * Memory committed bytes (your guess is as good as mine to what this is :) 163 * @return Some form of memory check 164 */ 165 165 long long PDHCollector::getMemCommit() { 166 166 MutexLock mutex(mutexHandler); -
modules/CheckSystem/PDHCollector.h
raf5bc4b r1d9338a 30 30 int checkIntervall_; 31 31 32 PDHCollectors::StaticPDHCounterListener memCmtLim;33 PDHCollectors::StaticPDHCounterListener memCmt;34 PDHCollectors::StaticPDHCounterListener upTime;32 PDHCollectors::StaticPDHCounterListenerInt memCmtLim; 33 PDHCollectors::StaticPDHCounterListenerInt memCmt; 34 PDHCollectors::StaticPDHCounterListenerInt upTime; 35 35 PDHCollectors::RoundINTPDHBufferListener cpu; 36 36 -
modules/FileLogger/FileLogger.cpp
rcea178b r1d9338a 4 4 #include "stdafx.h" 5 5 #include "FileLogger.h" 6 7 #include <sys/timeb.h> 8 #include <time.h> 6 9 7 10 FileLogger gFileLogger; … … 18 21 } 19 22 23 std::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 20 33 bool 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); 22 37 return true; 23 38 } … … 26 41 } 27 42 std::string FileLogger::getModuleName() { 28 return "File logger: " + NSCModuleHelper::getSettingsString(LOG_SECTION_TITLE, LOG_FILENAME, LOG_FILENAME_DEFAULT);43 return "File logger: " + getFileName(); 29 44 } 30 45 NSCModuleWrapper::module_version FileLogger::getModuleVersion() { … … 39 54 } 40 55 void FileLogger::handleMessage(int msgType, char* file, int line, char* message) { 56 char buffer[64]; 41 57 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( <ime ); 60 struct tm *today = _localtime64( <ime ); 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; 43 71 } 44 72 -
modules/FileLogger/FileLogger.h
ra0528c4 r1d9338a 6 6 private: 7 7 std::string file_; 8 std::string format_; 8 9 9 10 public: … … 19 20 void handleMessage(int msgType, char* file, int line, char* message); 20 21 int handleCommand(char* command, char **argument, char *returnBuffer, int returnBufferLen); 22 23 24 std::string getFileName(); 21 25 }; -
modules/NRPEListener/NRPEListener.cpp
r1e62ed5 r1d9338a 22 22 } 23 23 24 24 std::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 } 25 30 26 31 bool NRPEListener::loadModule() { … … 43 48 } 44 49 45 allowedHosts.setAllowedHosts(strEx::splitEx( NSCModuleHelper::getSettingsString(NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOWED, NRPE_SETTINGS_ALLOWED_DEFAULT), ","));50 allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), ",")); 46 51 try { 47 52 if (bUseSSL_) { … … 201 206 } 202 207 delete [] buf; 203 result = NSCHelper::int2nagios(GetExitCodeProcess(pi.hProcess, &dwexitcode)); 208 GetExitCodeProcess(pi.hProcess, &dwexitcode); 209 result = NSCHelper::int2nagios(dwexitcode); 204 210 } 205 211 CloseHandle(pi.hThread); -
modules/NSClientListener/NSClientListener.cpp
r1e62ed5 r1d9338a 32 32 NSClientListener::~NSClientListener() { 33 33 } 34 std::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 } 34 40 35 41 bool 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(), ",")); 37 43 try { 38 44 socket.setHandler(this); … … 85 91 */ 86 92 93 94 std::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 87 111 std::string NSClientListener::parseRequest(std::string buffer) { 88 112 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()) 92 118 return "ERRRO: No command specified."; 93 119 strEx::token cmd = strEx::getToken(pwd.second, '&'); … … 113 139 case REQ_CLIENTVERSION: 114 140 { 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") 117 143 return NSCModuleHelper::getApplicationName() + " " + NSCModuleHelper::getApplicationVersionString(); 118 return NSCModuleHelper::getSettingsString("nsclient compat", "version", "modern");144 return v; 119 145 } 120 146 case REQ_SERVICESTATE: 121 147 cmd.first = "checkServiceState"; 148 cmd.second += "&nsclient"; 122 149 break; 123 150 case REQ_PROCSTATE: 124 151 cmd.first = "checkProcState"; 152 cmd.second += "&nsclient"; 125 153 break; 126 154 case REQ_MEMUSE:
Note: See TracChangeset
for help on using the changeset viewer.








