- 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
- Location:
- modules
- Files:
-
- 8 edited
-
CheckDisk/CheckDisk.cpp (modified) (2 diffs)
-
CheckSystem/CheckSystem.cpp (modified) (9 diffs)
-
CheckSystem/PDHCollector.cpp (modified) (6 diffs)
-
CheckSystem/PDHCollector.h (modified) (1 diff)
-
FileLogger/FileLogger.cpp (modified) (4 diffs)
-
FileLogger/FileLogger.h (modified) (2 diffs)
-
NRPEListener/NRPEListener.cpp (modified) (3 diffs)
-
NSClientListener/NSClientListener.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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.








