Changeset 76aafc4 in nscp
- Timestamp:
- 10/26/06 07:03:39 (7 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- 7aef770
- Parents:
- 70f2d7b
- Files:
-
- 19 edited
-
NSC.dist (modified) (2 diffs)
-
NSClient++.cpp (modified) (2 diffs)
-
NSClient++.h (modified) (1 diff)
-
NSClient++.sln (modified) (2 diffs)
-
changelog (modified) (1 diff)
-
include/INISettings.h (modified) (4 diffs)
-
include/NSCAPI.h (modified) (2 diffs)
-
include/NSCHelper.cpp (modified) (4 diffs)
-
include/NSCHelper.h (modified) (2 diffs)
-
include/PDHCounter.h (modified) (2 diffs)
-
include/REGSettings.h (modified) (8 diffs)
-
include/Settings.h (modified) (3 diffs)
-
include/Socket.h (modified) (2 diffs)
-
include/TSettings.h (modified) (1 diff)
-
include/config.h (modified) (2 diffs)
-
modules/CheckSystem/CheckSystem.cpp (modified) (1 diff)
-
modules/CheckSystem/PDHCollector.cpp (modified) (2 diffs)
-
modules/NRPEListener/NRPEListener.cpp (modified) (2 diffs)
-
modules/NSClientListener/NSClientListener.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
NSC.dist
raabbd97 r76aafc4 19 19 ; CheckWMI IS AN EXTREM EARLY IDEA SO DONT USE FOR PRODUCTION ENVIROMNEMTS! 20 20 ;CheckWMI.dll 21 ; 22 ; RemoteConfiguration IS AN EXTREM EARLY IDEA SO DONT USE FOR PRODUCTION ENVIROMNEMTS! 23 ;RemoteConfiguration.dll 21 24 22 25 [Settings] … … 37 40 ; 38 41 ;# USE THIS FILE 39 ; Use the INI file as opposed to the registry if this is 0 the registry will be used instead. 42 ; Use the INI file as opposed to the registry if this is 0 and the use_reg in the registry is set to 1 43 ; the registry will be used instead. 40 44 use_file=1 41 45 -
NSClient++.cpp
r70f2d7b r76aafc4 608 608 return NSCAPI::isSuccess; 609 609 } 610 611 NSCAPI::errorReturn NSAPISetSettingsString(const char* section, const char* key, const char* value) { 612 Settings::getInstance()->setString(section, key, value); 613 return NSCAPI::isSuccess; 614 } 615 NSCAPI::errorReturn NSAPISetSettingsInt(const char* section, const char* key, int value) { 616 Settings::getInstance()->setInt(section, key, value); 617 return NSCAPI::isSuccess; 618 } 619 NSCAPI::errorReturn NSAPIWriteSettings(int type) { 620 try { 621 if (type == NSCAPI::settings_registry) 622 Settings::getInstance()->write(REGSettings::getType()); 623 else if (type == NSCAPI::settings_inifile) 624 Settings::getInstance()->write(INISettings::getType()); 625 else 626 Settings::getInstance()->write(); 627 } catch (SettingsException e) { 628 LOG_ERROR_STD(e.getMessage()); 629 return NSCAPI::hasFailed; 630 } 631 return NSCAPI::isSuccess; 632 } 633 NSCAPI::errorReturn NSAPIReadSettings(int type) { 634 try { 635 if (type == NSCAPI::settings_registry) 636 Settings::getInstance()->read(REGSettings::getType()); 637 else if (type == NSCAPI::settings_inifile) 638 Settings::getInstance()->read(INISettings::getType()); 639 else 640 Settings::getInstance()->read(); 641 } catch (SettingsException e) { 642 LOG_ERROR_STD(e.getMessage()); 643 return NSCAPI::hasFailed; 644 } 645 return NSCAPI::isSuccess; 646 } 647 NSCAPI::errorReturn NSAPIRehash(int flag) { 648 return NSCAPI::critical; 649 } 650 610 651 611 652 LPVOID NSAPILoader(char*buffer) { … … 634 675 if (stricmp(buffer, "NSAPIDecrypt") == 0) 635 676 return &NSAPIDecrypt; 677 if (stricmp(buffer, "NSAPISetSettingsString") == 0) 678 return &NSAPISetSettingsString; 679 if (stricmp(buffer, "NSAPISetSettingsInt") == 0) 680 return &NSAPISetSettingsInt; 681 if (stricmp(buffer, "NSAPIWriteSettings") == 0) 682 return &NSAPIWriteSettings; 683 if (stricmp(buffer, "NSAPIReadSettings") == 0) 684 return &NSAPIReadSettings; 685 if (stricmp(buffer, "NSAPIRehash") == 0) 686 return &NSAPIRehash; 636 687 return NULL; 637 688 } -
NSClient++.h
r70f2d7b r76aafc4 104 104 NSCAPI::errorReturn NSAPIEncrypt(unsigned int algorithm, const char* inBuffer, unsigned int inBufLen, char* outBuf, unsigned int *outBufLen); 105 105 NSCAPI::errorReturn NSAPIDecrypt(unsigned int algorithm, const char* inBuffer, unsigned int inBufLen, char* outBuf, unsigned int *outBufLen); 106 NSCAPI::errorReturn NSAPISetSettingsString(const char* section, const char* key, const char* value); 107 NSCAPI::errorReturn NSAPISetSettingsInt(const char* section, const char* key, int value); 108 NSCAPI::errorReturn NSAPIWriteSettings(int type); 109 NSCAPI::errorReturn NSAPIReadSettings(int type); 110 NSCAPI::errorReturn NSAPIRehash(int flag); 111 106 112 ////////////////////////////////////////////////////////////////////////// 107 113 // Log macros to simplify logging -
NSClient++.sln
r70f2d7b r76aafc4 47 47 EndProject 48 48 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CheckWMI", "modules\CheckWMI\CheckWMI.vcproj", "{E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}" 49 ProjectSection(ProjectDependencies) = postProject 50 EndProjectSection 51 EndProject 52 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RemoteConfiguration", "modules\RemoteConfiguration\RemoteConfiguration.vcproj", "{E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}" 49 53 ProjectSection(ProjectDependencies) = postProject 50 54 EndProjectSection … … 117 121 {BD93F0C3-E342-4D68-9717-FCAC2E7189AA}.Debug.Build.0 = Debug|Win32 118 122 {BD93F0C3-E342-4D68-9717-FCAC2E7189AA}.Distribution.ActiveCfg = Debug|Win32 119 {BD93F0C3-E342-4D68-9717-FCAC2E7189AA}.Distribution.Build.0 = Debug|Win32120 123 {BD93F0C3-E342-4D68-9717-FCAC2E7189AA}.Release.ActiveCfg = Release|Win32 124 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug.ActiveCfg = Debug|Win32 125 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug.Build.0 = Debug|Win32 126 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Distribution.ActiveCfg = Distribution|Win32 127 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Distribution.Build.0 = Distribution|Win32 128 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Release.ActiveCfg = Release|Win32 129 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Release.Build.0 = Release|Win32 121 130 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug.ActiveCfg = Debug|Win32 122 131 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug.Build.0 = Debug|Win32 -
changelog
rf42280d r76aafc4 8 8 * Fix WMI module 9 9 * Fix PDH problems 10 * Add API for rehashing the daemon (or implement it the API is there but does nothing) 11 * Add option to recheck DNS in real time 12 13 2006-10-05 MickeM 14 * Yayyy!!! (first fix in a looong while :) 15 * Fixed a W2k3 "bug" (actually just an incorrect error) but the: 16 "e .\PDHCollector.cpp(130) Failed to query performance counters..." is no more... 17 + Added option to NRPE/NSClient section to not-cache host names (for dyndns etc.) 18 NOTICE this is "not safe" really in so far as someone might hi-jack your DNS and quickly gain 19 access to your nagios box (probably only a theoretical problem but hey! :) 20 NOTICE this is "slow" since all hosts in the list are "looked up" each time you get a NRPE/NSClient 21 request it will be "slow" but I think it is not that much of a problem really. 22 NOTICE I dont have the posibility to test this so feel free to report if it works and if it doesn't. 23 Set cache_allowed_hosts=0 to disable host cache 24 25 2006-04-04 MickeM 26 * Fixed a few more bugs to the INI/REG readers 27 28 2006-04-02 MickeM 29 * Could all magicians stop trying to kill me? 30 *Please* i don't like to die! 31 32 2006-03-31 MickeM 33 * Damn necromancers! stop 0wning my ass all the time! 34 35 2006-03-29 MickeM 36 + Added API for saving/reading settings 37 38 2006-03-28 MickeM 39 + Added REG/INI parsers 40 * *NOTICE* You need to add an option (use_file=1) to your nsc.ini file or new builds wont work. 41 42 2006-03-25 MickeM 43 * Oblivion f*cking roxx! 10 44 11 45 2006-03-02 MickeM -
include/INISettings.h
r70f2d7b r76aafc4 7 7 #include <TSettings.h> 8 8 #include <config.h> 9 #include <iostream> 9 10 10 11 #define BUFF_LEN 4096 … … 27 28 std::string getActiveType() { 28 29 return "INI-file"; 30 } 31 int getActiveTypeID() { 32 return INISettings::getType(); 33 } 34 static int getType() { 35 return 1; 29 36 } 30 37 … … 70 77 if (buffer[i] == '\0') { 71 78 std::string s = &buffer[last]; 72 ret.push_back(s); 79 std::size_t p = s.find('='); 80 if (p == std::string::npos) 81 ret.push_back(s); 82 else 83 ret.push_back(s.substr(0,p)); 73 84 last = i+1; 74 85 } … … 93 104 94 105 void setString(std::string section, std::string key, std::string value) { 106 // if (value.size() > 0) 107 WritePrivateProfileString(section.c_str(), key.c_str(), NULL, file_.c_str()); 95 108 WritePrivateProfileString(section.c_str(), key.c_str(), value.c_str(), file_.c_str()); 109 // else 110 // WritePrivateProfileString(section.c_str(), key.c_str(), NULL, file_.c_str()); 96 111 } 97 112 -
include/NSCAPI.h
r75d5e70 r76aafc4 33 33 const int hasFailed = 0; 34 34 const int isInvalidBufferLen = -2; 35 36 35 37 typedef int nagiosReturn; 36 38 typedef int boolReturn; … … 39 41 40 42 const int xor = 1; 43 44 // Settings types 45 const int settings_default = 0; 46 const int settings_registry = 1; 47 const int settings_inifile = 2; 41 48 42 49 // Various message Types -
include/NSCHelper.cpp
r6817602 r76aafc4 110 110 lpNSAPIEncrypt fNSAPIEncrypt = NULL; 111 111 lpNSAPIDecrypt fNSAPIDecrypt = NULL; 112 lpNSAPISetSettingsString fNSAPISetSettingsString = NULL; 113 lpNSAPISetSettingsInt fNSAPISetSettingsInt = NULL; 114 lpNSAPIWriteSettings fNSAPIWriteSettings = NULL; 115 lpNSAPIReadSettings fNSAPIReadSettings = NULL; 116 lpNSAPIRehash fNSAPIRehash = NULL; 117 112 118 } 113 119 … … 374 380 } 375 381 376 377 378 379 382 std::string NSCModuleHelper::Encrypt(std::string str, unsigned int algorithm) { 380 383 if (!fNSAPIEncrypt) … … 408 411 } 409 412 return ""; 413 } 414 NSCAPI::errorReturn NSCModuleHelper::SetSettingsString(std::string section, std::string key, std::string value) { 415 if (!fNSAPISetSettingsString) 416 throw NSCMHExcpetion("NSCore has not been initiated..."); 417 return fNSAPISetSettingsString(section.c_str(), key.c_str(), value.c_str()); 418 } 419 NSCAPI::errorReturn NSCModuleHelper::SetSettingsInt(std::string section, std::string key, int value) { 420 if (!fNSAPISetSettingsInt) 421 throw NSCMHExcpetion("NSCore has not been initiated..."); 422 return fNSAPISetSettingsInt(section.c_str(), key.c_str(), value); 423 } 424 NSCAPI::errorReturn NSCModuleHelper::WriteSettings(int type) { 425 if (!fNSAPIWriteSettings) 426 throw NSCMHExcpetion("NSCore has not been initiated..."); 427 return fNSAPIWriteSettings(type); 428 } 429 NSCAPI::errorReturn NSCModuleHelper::ReadSettings(int type) { 430 if (!fNSAPIReadSettings) 431 throw NSCMHExcpetion("NSCore has not been initiated..."); 432 return fNSAPIReadSettings(type); 433 } 434 NSCAPI::errorReturn NSCModuleHelper::Rehash(int flag) { 435 if (!fNSAPIRehash) 436 throw NSCMHExcpetion("NSCore has not been initiated..."); 437 return fNSAPIRehash(flag); 410 438 } 411 439 … … 481 509 NSCModuleHelper::fNSAPIDecrypt = (NSCModuleHelper::lpNSAPIDecrypt)f("NSAPIDecrypt"); 482 510 NSCModuleHelper::fNSAPIEncrypt = (NSCModuleHelper::lpNSAPIEncrypt)f("NSAPIEncrypt"); 511 NSCModuleHelper::fNSAPISetSettingsString = (NSCModuleHelper::lpNSAPISetSettingsString)f("NSAPISetSettingsString"); 512 NSCModuleHelper::fNSAPISetSettingsInt = (NSCModuleHelper::lpNSAPISetSettingsInt)f("NSAPISetSettingsInt"); 513 NSCModuleHelper::fNSAPIWriteSettings = (NSCModuleHelper::lpNSAPIWriteSettings)f("NSAPIWriteSettings"); 514 NSCModuleHelper::fNSAPIReadSettings = (NSCModuleHelper::lpNSAPIReadSettings)f("NSAPIReadSettings"); 515 NSCModuleHelper::fNSAPIRehash = (NSCModuleHelper::lpNSAPIRehash)f("NSAPIRehash"); 483 516 return NSCAPI::isSuccess; 484 517 } -
include/NSCHelper.h
r6817602 r76aafc4 87 87 typedef NSCAPI::errorReturn (*lpNSAPIEncrypt)(unsigned int, const char*, unsigned int, char*, unsigned int *); 88 88 typedef NSCAPI::errorReturn (*lpNSAPIDecrypt)(unsigned int, const char*, unsigned int, char*, unsigned int *); 89 typedef NSCAPI::errorReturn (*lpNSAPISetSettingsString)(const char*, const char*, const char*); 90 typedef NSCAPI::errorReturn (*lpNSAPISetSettingsInt)(const char*, const char*, int); 91 typedef NSCAPI::errorReturn (*lpNSAPIWriteSettings)(int); 92 typedef NSCAPI::errorReturn (*lpNSAPIReadSettings)(int); 93 typedef NSCAPI::errorReturn (*lpNSAPIRehash)(int); 89 94 90 95 // Helper functions for calling into the core … … 105 110 std::string Encrypt(std::string str, unsigned int algorithm = NSCAPI::xor); 106 111 std::string Decrypt(std::string str, unsigned int algorithm = NSCAPI::xor); 112 NSCAPI::errorReturn SetSettingsString(std::string section, std::string key, std::string value); 113 NSCAPI::errorReturn SetSettingsInt(std::string section, std::string key, int value); 114 NSCAPI::errorReturn WriteSettings(int type); 115 NSCAPI::errorReturn ReadSettings(int type); 116 NSCAPI::errorReturn Rehash(int flag); 107 117 }; 108 118 -
include/PDHCounter.h
r6817602 r76aafc4 82 82 dwQueryUserData = info->dwQueryUserData; 83 83 szFullPath = info->szFullPath; 84 if (info->szMachineName) 85 szMachineName = info->szMachineName; 86 if (info->szObjectName) 87 szObjectName = info->szObjectName; 88 if (info->szInstanceName) 89 szInstanceName = info->szInstanceName; 90 if (info->szParentInstance) 91 szParentInstance = info->szParentInstance; 92 dwInstanceIndex = info->dwInstanceIndex; 93 if (info->szCounterName) 94 szCounterName = info->szCounterName; 84 95 if (explainText) { 85 if (info->szMachineName) 86 szMachineName = info->szMachineName; 87 if (info->szObjectName) 88 szObjectName = info->szObjectName; 89 if (info->szInstanceName) 90 szInstanceName = info->szInstanceName; 91 if (info->szParentInstance) 92 szParentInstance = info->szParentInstance; 93 dwInstanceIndex = info->dwInstanceIndex; 94 if (info->szCounterName) 95 szCounterName = info->szCounterName; 96 if (info->szExplainText) 97 szExplainText = info->szExplainText; 96 98 } 97 99 } … … 119 121 } 120 122 121 PDHCounterInfo getCounterInfo( ) {123 PDHCounterInfo getCounterInfo(BOOL bExplainText = FALSE) { 122 124 assert(hCounter_ != NULL); 123 125 PDH_STATUS status; 124 126 BYTE *lpBuffer = new BYTE[1025]; 125 127 DWORD bufSize = 1024; 126 if ((status = PdhGetCounterInfo(hCounter_, TRUE, &bufSize, (PDH_COUNTER_INFO*)lpBuffer)) != ERROR_SUCCESS) {128 if ((status = PdhGetCounterInfo(hCounter_, bExplainText, &bufSize, (PDH_COUNTER_INFO*)lpBuffer)) != ERROR_SUCCESS) { 127 129 throw PDHException(name_, "getCounterInfo failed (no query)", status); 128 130 } -
include/REGSettings.h
r70f2d7b r76aafc4 20 20 21 21 static bool hasSettings() { 22 return getInt_(NS_HKEY_ROOT, NS_REG_ROOT , "use_reg", 0) == 1;22 return getInt_(NS_HKEY_ROOT, NS_REG_ROOT "\\" MAIN_SECTION_TITLE, MAIN_USEREG, 0) == 1; 23 23 } 24 24 … … 51 51 52 52 void setString(std::string section, std::string key, std::string value) { 53 setString_(NS_HKEY_ROOT, std::string((std::string)NS_REG_ROOT + "\\" + section).c_str(), key.c_str(), value.c_str()); 53 54 } 54 55 … … 64 65 } 65 66 void setInt(std::string section, std::string key, int value) { 66 } 67 67 setInt_(NS_HKEY_ROOT, std::string((std::string)NS_REG_ROOT + "\\" + section).c_str(), key.c_str(), value); 68 } 69 70 static bool setString_(HKEY hKey, LPCTSTR lpszPath, LPCTSTR lpszKey, LPCTSTR value) { 71 HKEY hTemp; 72 if (RegCreateKeyEx(hKey, lpszPath, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hTemp, NULL) != ERROR_SUCCESS) { 73 return false; 74 } 75 DWORD cbData = static_cast<DWORD>(strlen(value)); 76 BYTE *bData = new BYTE[cbData+1]; 77 strncpy(reinterpret_cast<char*>(bData), value, cbData); 78 BOOL bRet = RegSetValueEx(hTemp, lpszKey, NULL, REG_SZ, bData, cbData); 79 RegCloseKey(hTemp); 80 delete [] bData; 81 return (bRet == ERROR_SUCCESS); 82 } 83 84 int getActiveTypeID() { 85 return REGSettings::getType(); 86 } 87 static int getType() { 88 return 2; 89 } 90 91 static bool setInt_(HKEY hKey, LPCTSTR lpszPath, LPCTSTR lpszKey, DWORD value) { 92 HKEY hTemp; 93 if (RegCreateKeyEx(hKey, lpszPath, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hTemp, NULL) != ERROR_SUCCESS) { 94 return false; 95 } 96 BOOL bRet = RegSetValueEx(hTemp, lpszKey, NULL, REG_DWORD, reinterpret_cast<const BYTE*>(&value), sizeof(DWORD)); 97 RegCloseKey(hTemp); 98 return (bRet == ERROR_SUCCESS); 99 } 68 100 69 101 static std::string getString_(HKEY hKey, LPCTSTR lpszPath, LPCTSTR lpszKey, std::string def) { … … 74 106 } 75 107 DWORD type; 76 DWORD cbData = 1024; 108 const DWORD data_length = 2048; 109 DWORD cbData = data_length; 77 110 BYTE *bData = new BYTE[cbData]; 78 BOOL bRet = RegQueryValueEx(hTemp, lpszKey, NULL, &type, bData, &cbData); 79 if (type != REG_SZ) { 80 bRet = false; 81 } 82 RegCloseKey(hTemp); 83 if (bRet) { 84 ret = (LPCTSTR)bData; 85 } 111 LONG lRet = RegQueryValueEx(hTemp, lpszKey, NULL, &type, bData, &cbData); 112 if (lRet == ERROR_SUCCESS) { 113 if (type == REG_SZ) { 114 if (cbData < data_length-1) { 115 bData[cbData] = 0; 116 ret = reinterpret_cast<LPCTSTR>(bData); 117 } else { 118 std::cout << "getString_::Buffersize to small: " << lpszPath << "." << lpszKey << ": " << type << std::endl; 119 } 120 } else if (type == REG_DWORD) { 121 DWORD dw = *(reinterpret_cast<DWORD*>(bData)); 122 ret = strEx::itos(dw); 123 } else { 124 std::cout << "getString_::Unsupported type: " << lpszPath << "." << lpszKey << ": " << type << std::endl; 125 } 126 } else { 127 std::cout << "getString_::Error: " << lpszPath << "." << lpszKey << ": " << lRet << std::endl; 128 } 129 RegCloseKey(hTemp); 86 130 delete [] bData; 87 131 return ret; … … 95 139 } 96 140 DWORD type; 97 DWORD cbData = 1024;98 BYTE *bData = new BYTE[ sizeof(DWORD)];141 DWORD cbData = sizeof(DWORD); 142 BYTE *bData = new BYTE[cbData+1]; 99 143 bRet = RegQueryValueEx(hTemp, lpszKey, NULL, &type, bData, &cbData); 100 144 if (type != REG_DWORD) { … … 103 147 RegCloseKey(hTemp); 104 148 if (bRet == ERROR_SUCCESS) { 105 ret = (DWORD)*bData;149 ret = static_cast<DWORD>(*bData); 106 150 } 107 151 delete [] bData; … … 115 159 return ret; 116 160 } 117 DWORD cValues=0;118 DWORD cMaxValLen;161 DWORD cValues=0; 162 DWORD cMaxValLen=0; 119 163 // Get the class name and the value count. 120 164 bRet = RegQueryInfoKey(hTemp,NULL,NULL,NULL,NULL,NULL,NULL,&cValues,&cMaxValLen,NULL,NULL,NULL); 165 cMaxValLen++; 121 166 if ((bRet == ERROR_SUCCESS)&&(cValues>0)) { 122 167 TCHAR *lpValueName = new TCHAR[cMaxValLen+1]; 123 168 for (unsigned int i=0; i<cValues; i++) { 124 169 DWORD len = cMaxValLen; 125 bRet = RegEnumValue(h Key, i, lpValueName, &len, NULL, NULL, NULL, NULL);170 bRet = RegEnumValue(hTemp, i, lpValueName, &len, NULL, NULL, NULL, NULL); 126 171 if (bRet == ERROR_SUCCESS) { 127 172 ret.push_back(std::string(lpValueName)); 173 } else { 174 std::cout << "getValues_::Error: " << bRet << ": " << lpszPath << "[" << i << "]" << std::endl; 175 128 176 } 129 177 } … … 143 191 // Get the class name and the value count. 144 192 bRet = RegQueryInfoKey(hTemp,NULL,NULL,NULL,&cSubKeys,&cMaxKeyLen,NULL,NULL,NULL,NULL,NULL,NULL); 193 cMaxKeyLen++; 145 194 if ((bRet == ERROR_SUCCESS)&&(cSubKeys>0)) { 146 195 TCHAR *lpValueName = new TCHAR[cMaxKeyLen+1]; 147 196 for (unsigned int i=0; i<cSubKeys; i++) { 148 197 DWORD len = cMaxKeyLen; 149 bRet = RegEnumKey(h Key, i, lpValueName, len);198 bRet = RegEnumKey(hTemp, i, lpValueName, len); 150 199 if (bRet == ERROR_SUCCESS) { 151 200 ret.push_back(std::string(lpValueName)); 201 } else { 202 std::cout << "getSubKeys_::Error: " << bRet << ": " << lpszPath << "[" << i << "]" << std::endl; 152 203 } 153 204 } -
include/Settings.h
r70f2d7b r76aafc4 32 32 typedef std::map<std::string,saveKeyList> saveSectionList; 33 33 saveSectionList data_; 34 std::string file_; 34 35 bool bHasInternalData; 35 36 TSettings *settingsManager; … … 57 58 */ 58 59 void setFile(std::string file, bool forceini = false) { 60 file_ = file; 59 61 if (forceini) { 60 62 if (settingsManager) … … 78 80 #define UNLIKELY_VALUE_1 -1234 79 81 #define UNLIKELY_VALUE_2 -4321 80 void read() { 81 sectionList sections = getSections(); 82 void read(int type = -1) { 83 bool bNew = false; 84 TSettings *sM = settingsManager; 85 if ((type != -1)&&(type != settingsManager->getActiveTypeID())) { 86 if (type == REGSettings::getType()) { 87 sM = new REGSettings(); 88 bNew = true; 89 } else if (type == INISettings::getType()) { 90 sM = new INISettings(file_); 91 bNew = true; 92 } else { 93 throw SettingsException("Invalid settings subsystem specified"); 94 } 95 } 96 if (sM == NULL) { 97 throw SettingsException("Invalid settings subsystem specified"); 98 } 99 sectionList sections = sM->getSections(); 82 100 for (sectionList::const_iterator it=sections.begin();it!=sections.end();++it) { 83 sectionList section = getSection(*it);101 sectionList section = sM->getSection(*it); 84 102 for (sectionList::const_iterator it2=section.begin();it2!=section.end();++it2) { 85 int i = getInt((*it), (*it2), UNLIKELY_VALUE_1); 103 std::string s = sM->getString((*it), (*it2)); 104 int i = strEx::stoi(s); 105 std::string s2 = strEx::itos(i); 106 std::cout << "importing: " << (*it) << "/" << (*it2) << "=" << s << std::endl; 107 if (s == s2) { 108 setInt((*it), (*it2), i); 109 } else { 110 setString((*it), (*it2), s); 111 } 112 113 /* 114 std::cout << " Key: " << (*it2) << std::endl; 115 int i = sM->getInt((*it), (*it2), UNLIKELY_VALUE_1); 116 std::cout << "Int vaöl: " << i << std::endl; 86 117 if (i == UNLIKELY_VALUE_1) { 87 if (getInt((*it), (*it2), UNLIKELY_VALUE_2)==UNLIKELY_VALUE_2) 88 getString((*it), (*it2)); 89 } 90 } 91 } 92 } 93 void write() { 118 if (sM->getInt((*it), (*it2), UNLIKELY_VALUE_2)==UNLIKELY_VALUE_2) { 119 std::cout << "Writing: " << (*it) << " - " << (*it2) << " - " << sM->getString((*it), (*it2)) << std::endl; 120 setString((*it), (*it2), sM->getString((*it), (*it2))); 121 } else 122 setInt((*it), (*it2), i); 123 } else if (i == 0) { 124 std::string s = sM->getString((*it), (*it2)); 125 std::cout << "Size: " << s.size() << " |" << s << "| " << std::endl; 126 if (s.size() == 0) 127 setString((*it), (*it2), s); 128 else 129 setInt((*it), (*it2), i); 130 } else 131 setInt((*it), (*it2), i); 132 */ 133 } 134 } 135 if (bNew) { 136 delete sM; 137 } 138 } 139 void write(int type = -1) { 140 bool bNew = false; 141 TSettings *sM = settingsManager; 142 if ((type != -1)&&(type != settingsManager->getActiveTypeID())) { 143 if (type == REGSettings::getType()) { 144 sM = new REGSettings(); 145 bNew = true; 146 } else if (type == INISettings::getType()) { 147 sM = new INISettings(file_); 148 bNew = true; 149 } else { 150 throw SettingsException("Invalid settings subsystem specified"); 151 } 152 } 153 if (sM == NULL) { 154 throw SettingsException("Invalid settings subsystem specified"); 155 } 94 156 if (bHasInternalData) { 95 157 for (saveSectionList::const_iterator it=data_.begin();it!=data_.end();++it) { 96 158 for (saveKeyList::const_iterator kit = it->second.begin(); kit != it->second.end(); ++kit) { 97 159 if (kit->second.type == valueStruct::sType) 98 setString(it->first, kit->first, kit->second.sVal); 99 else 100 setInt(it->first, kit->first, kit->second.iVal); 101 } 102 } 160 sM->setString(it->first, kit->first, kit->second.sVal); 161 else 162 sM->setInt(it->first, kit->first, kit->second.iVal); 163 } 164 } 165 } 166 if (bNew) { 167 delete sM; 103 168 } 104 169 } -
include/Socket.h
rf42280d r76aafc4 462 462 private: 463 463 host_list allowedHosts_; 464 public: 465 void setAllowedHosts(host_list allowedHosts) { 464 bool cachedAddresses_; 465 public: 466 allowedHosts() : cachedAddresses_(true) {} 467 void setAllowedHosts(host_list allowedHosts, bool cachedAddresses) { 468 cachedAddresses_ = cachedAddresses; 466 469 if ((!allowedHosts.empty()) && (allowedHosts.front() == "") ) 467 470 allowedHosts.pop_front(); 468 471 allowedHosts_ = allowedHosts; 469 for (host_list::iterator it = allowedHosts_.begin();it!=allowedHosts_.end();++it) { 470 if (((*it).length() > 0) && (std::isalpha((*it)[0]))) { 471 std::string s = (*it); 472 try { 473 *it = simpleSocket::Socket::getHostByName(s); 474 } catch (simpleSocket::SocketException e) { 475 e; 472 if (cachedAddresses_) { 473 for (host_list::iterator it = allowedHosts_.begin();it!=allowedHosts_.end();++it) { 474 if (((*it).length() > 0) && (std::isalpha((*it)[0]))) { 475 std::string s = (*it); 476 try { 477 *it = simpleSocket::Socket::getHostByName(s); 478 } catch (simpleSocket::SocketException e) { 479 e; 480 } 476 481 } 477 482 } … … 482 487 return true; 483 488 host_list::const_iterator cit; 489 if (!cachedAddresses_) { 490 for (host_list::iterator it = allowedHosts_.begin();it!=allowedHosts_.end();++it) { 491 if (((*it).length() > 0) && (std::isalpha((*it)[0]))) { 492 std::string s = (*it); 493 try { 494 *it = simpleSocket::Socket::getHostByName(s); 495 } catch (simpleSocket::SocketException e) { 496 e; 497 } 498 } 499 } 500 } 484 501 for (cit = allowedHosts_.begin();cit!=allowedHosts_.end();++cit) { 485 502 if ( (*cit) == s) -
include/TSettings.h
r70f2d7b r76aafc4 23 23 virtual int getInt(std::string section, std::string key, int defaultValue = 0) = 0; 24 24 virtual void setInt(std::string section, std::string key, int value) = 0; 25 virtual int getActiveTypeID() = 0; 25 26 }; -
include/config.h
r70f2d7b r76aafc4 96 96 #define MAIN_SECTION_TITLE "Settings" 97 97 #define MAIN_USEFILE "use_file" 98 #define MAIN_USEREG "use_reg" 98 99 #define MAIN_USEFILE_DEFAULT 0 99 100 #define MAIN_MASTERKEY "master_key" … … 105 106 #define MAIN_ALLOWED_HOSTS "allowed_hosts" 106 107 #define MAIN_ALLOWED_HOSTS_DEFAULT "127.0.0.1" 108 #define MAIN_ALLOWED_HOSTS_CACHE "cache_allowed_hosts" 109 #define MAIN_ALLOWED_HOSTS_CACHE_DEFAULT 1 107 110 108 111 -
modules/CheckSystem/CheckSystem.cpp
rf42280d r76aafc4 117 117 std::string counter = "\\" + (*it).name + "(" + (*it2).name + ")\\" + (*it3).name; 118 118 std::cout << "testing: " << counter << ": "; 119 std::list<std::string> errors; 120 std::list<std::string> status; 119 121 std::string error; 122 bool bStatus = true; 120 123 if (PDH::Enumerations::validate(counter, error)) { 121 st d::cout << " found ";124 status.push_back("open"); 122 125 } else { 123 std::cout << " *NOT* found (" << error << ") " << std::endl;124 b reak;126 errors.push_back("NOT found: " + error); 127 bStatus = false; 125 128 } 126 bool bOpend = false;127 try {129 if (bStatus) { 130 PDH::PDHCounter *pCounter = NULL; 128 131 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; 132 try { 133 PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> cDouble; 134 pCounter = pdh.addCounter(counter, &cDouble); 135 pdh.open(); 136 137 if (pCounter != NULL) { 138 try { 139 PDH::PDHCounterInfo info = pCounter->getCounterInfo(); 140 errors.push_back("CounterName: " + info.szCounterName); 141 errors.push_back("ExplainText: " + info.szExplainText); 142 errors.push_back("FullPath: " + info.szFullPath); 143 errors.push_back("InstanceName: " + info.szInstanceName); 144 errors.push_back("MachineName: " + info.szMachineName); 145 errors.push_back("ObjectName: " + info.szObjectName); 146 errors.push_back("ParentInstance: " + info.szParentInstance); 147 errors.push_back("Type: " + strEx::itos(info.dwType)); 148 errors.push_back("Scale: " + strEx::itos(info.lScale)); 149 errors.push_back("Default Scale: " + strEx::itos(info.lDefaultScale)); 150 errors.push_back("Status: " + strEx::itos(info.CStatus)); 151 status.push_back("described"); 152 } catch (const PDH::PDHException e) { 153 errors.push_back("Describe failed: " + e.getError()); 154 bStatus = false; 155 } 156 } 157 158 pdh.gatherData(); 159 pdh.close(); 160 status.push_back("queried"); 161 } catch (const PDH::PDHException e) { 162 errors.push_back("Query failed: " + e.getError()); 163 bStatus = false; 164 try { 165 pdh.gatherData(); 166 pdh.close(); 167 bStatus = true; 168 } catch (const PDH::PDHException e) { 169 errors.push_back("Query failed (again!): " + e.getError()); 170 } 171 } 172 138 173 } 139 std::cout << " open "; 140 std::cout << std::endl; 174 if (!bStatus) { 175 std::list<std::string>::const_iterator cit = status.begin(); 176 for (;cit != status.end(); ++cit) { 177 std::cout << *cit << ", "; 178 } 179 std::cout << std::endl; 180 std::cout << " | Log" << std::endl; 181 std::cout << "--+------ -- -" << std::endl; 182 cit = errors.begin(); 183 for (;cit != errors.end(); ++cit) { 184 std::cout << " | " << *cit << std::endl; 185 } 186 } else { 187 std::list<std::string>::const_iterator cit = status.begin(); 188 for (;cit != status.end(); ++cit) { 189 std::cout << *cit << ", ";; 190 } 191 std::cout << std::endl; 192 } 141 193 } 142 194 } -
modules/CheckSystem/PDHCollector.cpp
raabbd97 r76aafc4 120 120 121 121 DWORD waitStatus = 0; 122 bool first = true; 122 123 do { 123 124 MutexLock mutex(mutexHandler); … … 128 129 pdh.gatherData(); 129 130 } catch (const PDH::PDHException &e) { 130 NSC_LOG_ERROR_STD("Failed to query performance counters: " + e.getError()); 131 if (first) { // If this is the first run an error will be thrown since the data is not yet avalible 132 // This is "ok" but perhaps another solution would be better, but this works :) 133 first = false; 134 } else { 135 NSC_LOG_ERROR_STD("Failed to query performance counters: " + e.getError()); 136 } 131 137 } 132 138 } -
modules/NRPEListener/NRPEListener.cpp
rf42280d r76aafc4 28 28 return ret; 29 29 } 30 bool getCacheAllowedHosts() { 31 int val = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, MAIN_ALLOWED_HOSTS_CACHE, -1); 32 if (val == -1) 33 val = NSCModuleHelper::getSettingsInt(MAIN_SECTION_TITLE, MAIN_ALLOWED_HOSTS_CACHE, MAIN_ALLOWED_HOSTS_CACHE_DEFAULT); 34 return val==1?true:false; 35 } 30 36 31 37 bool NRPEListener::loadModule() { … … 33 39 timeout = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_TIMEOUT ,NRPE_SETTINGS_TIMEOUT_DEFAULT); 34 40 std::list<std::string> commands = NSCModuleHelper::getSettingsSection(NRPE_HANDLER_SECTION_TITLE); 35 std::list<std::string>::iterator it; 36 for (it = commands.begin(); it != commands.end(); it++) { 37 strEx::token t = strEx::getToken(*it, '='); 38 if (t.first.substr(0,7) == "command") { 39 strEx::token t2 = strEx::getToken(t.first, '['); 40 t2 = strEx::getToken(t2.second, ']'); 41 t.first = t2.first; 42 } 43 if (t.first.empty() || t.second.empty()) { 41 std::list<std::string>::const_iterator it; 42 for (it = commands.begin(); it != commands.end(); ++it) { 43 std::string command_name; 44 if (((*it).length() > 7)&&((*it).substr(0,7) == "command")) { 45 strEx::token t = strEx::getToken((*it), '['); 46 t = strEx::getToken(t.second, ']'); 47 command_name = t.first; 48 } else { 49 command_name = (*it); 50 } 51 std::string s = NSCModuleHelper::getSettingsString(NRPE_HANDLER_SECTION_TITLE, (*it), ""); 52 if (command_name.empty() || s.empty()) { 44 53 NSC_LOG_ERROR_STD("Invalid command definition: " + (*it)); 45 54 } else { 46 addCommand( t.first.c_str(), t.second);47 } 48 } 49 50 allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), ",") );55 addCommand(command_name.c_str(), s); 56 } 57 } 58 59 allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), ","), getCacheAllowedHosts()); 51 60 try { 52 61 unsigned short port = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_PORT, NRPE_SETTINGS_PORT_DEFAULT); -
modules/NSClientListener/NSClientListener.cpp
raabbd97 r76aafc4 38 38 return ret; 39 39 } 40 bool getCacheAllowedHosts() { 41 int val = NSCModuleHelper::getSettingsInt(NSCLIENT_SECTION_TITLE, MAIN_ALLOWED_HOSTS_CACHE, -1); 42 if (val == -1) 43 val = NSCModuleHelper::getSettingsInt(MAIN_SECTION_TITLE, MAIN_ALLOWED_HOSTS_CACHE, MAIN_ALLOWED_HOSTS_CACHE_DEFAULT); 44 return val==1?true:false; 45 } 40 46 41 47 bool NSClientListener::loadModule() { 42 allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), ",") );48 allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), ","), getCacheAllowedHosts()); 43 49 unsigned short port = NSCModuleHelper::getSettingsInt(NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_PORT, NSCLIENT_SETTINGS_PORT_DEFAULT); 44 50 std::string host = NSCModuleHelper::getSettingsString(NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_BINDADDR, NSCLIENT_SETTINGS_BINDADDR_DEFAULT);
Note: See TracChangeset
for help on using the changeset viewer.








