Changeset 394f7a1 in nscp
- Timestamp:
- 02/18/08 23:21:23 (5 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- 95e4ace
- Parents:
- c1fe385
- Files:
-
- 6 added
- 2 deleted
- 26 edited
-
AutoBuild.h (modified) (1 diff)
-
NSC.dist (modified) (3 diffs)
-
NSClient++-2005.sln (modified) (2 diffs)
-
NSClient++.cpp (modified) (4 diffs)
-
NSClient++.h (modified) (1 diff)
-
changelog (modified) (1 diff)
-
include/Mutex.h (modified) (1 diff)
-
include/PDHCollectors.h (modified) (13 diffs)
-
include/SSLSocket.cpp (modified) (2 diffs)
-
include/SSLSocket.h (modified) (3 diffs)
-
include/Socket.cpp (modified) (2 diffs)
-
include/Socket.h (modified) (6 diffs)
-
include/config.h (modified) (1 diff)
-
include/strEx.h (modified) (1 diff)
-
modules/CheckExternalScripts/CheckExternalScripts.cpp (modified) (3 diffs)
-
modules/CheckExternalScripts/CheckExternalScripts.h (modified) (3 diffs)
-
modules/CheckSystem/CheckSystem.cpp (modified) (2 diffs)
-
modules/CheckSystem/PDHCollector.cpp (modified) (8 diffs)
-
modules/CheckSystem/PDHCollector.h (modified) (2 diffs)
-
modules/NRPEClient/NRPEClient-2005.vcproj (added)
-
modules/NRPEClient/NRPEClient.cpp (added)
-
modules/NRPEClient/NRPEClient.def (added)
-
modules/NRPEClient/NRPEClient.h (added)
-
modules/NRPEClient/stdafx.cpp (added)
-
modules/NRPEClient/stdafx.h (added)
-
modules/NRPEListener/NRPEListener-2005.vcproj (modified) (2 diffs)
-
modules/NRPEListener/NRPEListener.cpp (modified) (8 diffs)
-
modules/NRPEListener/NRPEListener.h (modified) (2 diffs)
-
modules/NRPEListener/NRPEPacket.cpp (deleted)
-
modules/NRPEListener/NRPEPacket.h (deleted)
-
modules/NSCAAgent/NSCAAgent.cpp (modified) (3 diffs)
-
modules/NSCAAgent/NSCAAgent.h (modified) (1 diff)
-
modules/NSCAAgent/NSCAThread.cpp (modified) (3 diffs)
-
modules/NSCAAgent/nsca_enrypt.hpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
AutoBuild.h
r7a156f4 r394f7a1 3 3 // change the FALSE to TRUE for autoincrement of build number 4 4 #define INCREMENT_VERSION TRUE 5 #define FILEVER 0,3,0,5 46 #define PRODUCTVER 0,3,0,5 47 #define STRFILEVER _T("0.3.0.5 4")8 #define STRPRODUCTVER _T("0.3.0.5 4")9 #define STRPRODUCTDATE _T("2008-02-1 2")5 #define FILEVER 0,3,0,58 6 #define PRODUCTVER 0,3,0,58 7 #define STRFILEVER _T("0.3.0.58") 8 #define STRPRODUCTVER _T("0.3.0.58") 9 #define STRPRODUCTDATE _T("2008-02-14") 10 10 #endif // AUTOBUILD_H -
NSC.dist
rc1fe385 r394f7a1 83 83 ;socket_timeout=30 84 84 85 [NRPE] 86 ;# NRPE PORT NUMBER 87 ; This is the port the NRPEListener.dll will listen to. 88 ;port=5666 89 ; 90 ;# COMMAND TIMEOUT 91 ; This specifies the maximum number of seconds that the NRPE daemon will allow plug-ins to finish executing before killing them off. 92 ;command_timeout=60 93 ; 94 ;# COMMAND ARGUMENT PROCESSING 95 ; This option determines whether or not the NRPE daemon will allow clients to specify arguments to commands that are executed. 96 ;allow_arguments=0 97 ; 98 ;# COMMAND ALLOW NASTY META CHARS 99 ; This option determines whether or not the NRPE daemon will allow clients to specify nasty (as in |`&><'"\[]{}) characters in arguments. 100 ;allow_nasty_meta_chars=0 101 ; 102 ;# USE SSL SOCKET 103 ; This option controls if SSL should be used on the socket. 104 ;use_ssl=1 105 ; 106 ;# BIND TO ADDRESS 107 ; Allows you to bind server to a specific local address. This has to be a dotted ip adress not a hostname. 108 ; Leaving this blank will bind to all avalible IP adresses. 109 ; bind_to_address= 110 ; 111 ;# ALLOWED HOST ADDRESSES 112 ; This is a comma-delimited list of IP address of hosts that are allowed to talk to NRPE deamon. 113 ; If you leave this blank the global version will be used instead. 114 ;allowed_hosts= 115 ; 116 ;# SCRIPT DIRECTORY 117 ; All files in this directory will become check commands. 118 ; *WARNING* This is undoubtedly dangerous so use with care! 119 ;script_dir=scripts\ 120 ; 121 ;# SOCKET TIMEOUT 122 ; Timeout when reading packets on incoming sockets. If the data has not arrived withint this time we will bail out. 123 ;socket_timeout=30 85 124 86 125 [Check System] … … 136 175 137 176 138 [NRPE] 139 ;# NRPE PORT NUMBER 140 ; This is the port the NRPEListener.dll will listen to. 141 ;port=5666 142 ; 143 ;# COMMAND TIMEOUT 144 ; This specifies the maximum number of seconds that the NRPE daemon will allow plug-ins to finish executing before killing them off. 145 ;command_timeout=60 146 ; 147 ;# COMMAND ARGUMENT PROCESSING 148 ; This option determines whether or not the NRPE daemon will allow clients to specify arguments to commands that are executed. 149 ;allow_arguments=0 150 ; 151 ;# COMMAND ALLOW NASTY META CHARS 152 ; This option determines whether or not the NRPE daemon will allow clients to specify nasty (as in |`&><'"\[]{}) characters in arguments. 153 ;allow_nasty_meta_chars=0 154 ; 155 ;# USE SSL SOCKET 156 ; This option controls if SSL should be used on the socket. 157 ;use_ssl=1 177 178 179 ; [includes] 180 ;# The order when used is "reversed" thus the last included file will be "first" 181 ;# Included files can include other files (be carefull only do basic recursive checking) 182 ; 183 ; myotherfile.ini 184 ; real.ini 185 186 187 [NSCA Agent] 188 ;# CHECK INTERVALL (in seconds) 189 ; How often we should run the checks and submit the results. 190 ;interval=5 191 ; 192 ;# ENCRYPTION METHOD 193 ; This option determines the method by which the send_nsca client will encrypt the packets it sends 194 ; to the nsca daemon. The encryption method you choose will be a balance between security and 195 ; performance, as strong encryption methods consume more processor resources. 196 ; You should evaluate your security needs when choosing an encryption method. 197 ; 198 ; Note: The encryption method you specify here must match the decryption method the nsca daemon uses 199 ; (as specified in the nsca.cfg file)!! 200 ; Values: 201 ; 0 = None (Do NOT use this option) 202 ; 1 = Simple XOR (No security, just obfuscation, but very fast) 203 ; 2 = DES 204 ; 3 = 3DES (Triple DES) 205 ; 4 = CAST-128 206 ; 6 = xTEA 207 ; 8 = BLOWFISH 208 ; 9 = TWOFISH 209 ; 11 = RC2 210 ; 14 = RIJNDAEL-128 (AES) 211 ; 20 = SERPENT 212 ;encryption_method=14 213 ; 214 ;# ENCRYPTION PASSWORD 215 ; This is the password/passphrase that should be used to encrypt the sent packets. 216 ;password= 158 217 ; 159 218 ;# BIND TO ADDRESS 160 219 ; Allows you to bind server to a specific local address. This has to be a dotted ip adress not a hostname. 161 ; Leaving this blank will bind to all avalible IP adresses. 162 ; bind_to_address= 163 ; 164 ;# ALLOWED HOST ADDRESSES 165 ; This is a comma-delimited list of IP address of hosts that are allowed to talk to NRPE deamon. 166 ; If you leave this blank the global version will be used instead. 167 ;allowed_hosts= 168 ; 169 ;# SCRIPT DIRECTORY 170 ; All files in this directory will become check commands. 171 ; *WARNING* This is undoubtedly dangerous so use with care! 172 ;script_dir=scripts\ 173 ; 174 ;# SOCKET TIMEOUT 175 ; Timeout when reading packets on incoming sockets. If the data has not arrived withint this time we will bail out. 176 ;socket_timeout=30 177 178 220 ; Leaving this blank will bind to "one" local interface. 221 ; -- not supported as of now -- 222 ;bind_to_address= 223 ; 224 ;# LOCAL HOST NAME 225 ; The name of this host (if empty "computername" will be used. 226 ;hostname= 227 ; 228 ;# NAGIOS SERVER ADDRESS 229 ; The address to the nagios server to submit results to. 230 ;nsca_host=192.168.0.1 231 ; 232 ;# NAGIOS SERVER PORT 233 ; The port to the nagios server to submit results to. 234 ;nsca_port=5667 235 ; 236 237 ;# CHECK COMMAND LIST 238 ; The checks to run everytime we submit results back to nagios 239 ; Any command(alias/key) starting with a host_ is sent as HOST_COMMAND others are sent as SERVICE_COMMANDS 240 ; where the alias/key is used as service name. 241 ; 242 [NSCA Commands] 243 ;my_cpu_check=checkCPU warn=80 crit=90 time=20m time=10s time=4 244 ;my_mem_check=checkMem MaxWarn=80% MaxCrit=90% ShowAll type=page 245 ;my_svc_check=checkServiceState CheckAll exclude=wampmysqld exclude=MpfService 246 ;host_check=check_ok 179 247 180 248 [NRPE Handlers] … … 206 274 ;check_nok=scripts\xlong.bat 207 275 ;check_vbs=cscript.exe //T:30 //NoLogo scripts\check_vb.vbs 208 209 210 ; [includes]211 ;# The order when used is "reversed" thus the last included file will be "first"212 ;# Included files can include other files (be carefull only do basic recursive checking)213 ;214 ; myotherfile.ini215 ; real.ini216 217 218 [NSCA Agent]219 ;# CHECK INTERVALL (in seconds)220 ; How often we should run the checks and submit the results.221 ;interval=5222 ;223 ;# ENCRYPTION METHOD224 ; This option determines the method by which the send_nsca client will encrypt the packets it sends225 ; to the nsca daemon. The encryption method you choose will be a balance between security and226 ; performance, as strong encryption methods consume more processor resources.227 ; You should evaluate your security needs when choosing an encryption method.228 ;229 ; Note: The encryption method you specify here must match the decryption method the nsca daemon uses230 ; (as specified in the nsca.cfg file)!!231 ; Values:232 ; 0 = None (Do NOT use this option)233 ; 1 = Simple XOR (No security, just obfuscation, but very fast)234 ; 2 = DES235 ; 3 = 3DES (Triple DES)236 ; 4 = CAST-128237 ; 6 = xTEA238 ; 8 = BLOWFISH239 ; 9 = TWOFISH240 ; 11 = RC2241 ; 14 = RIJNDAEL-128 (AES)242 ; 20 = SERPENT243 ;encryption_method=14244 ;245 ;# ENCRYPTION PASSWORD246 ; This is the password/passphrase that should be used to encrypt the sent packets.247 ;password=248 ;249 ;# BIND TO ADDRESS250 ; Allows you to bind server to a specific local address. This has to be a dotted ip adress not a hostname.251 ; Leaving this blank will bind to "one" local interface.252 ; -- not supported as of now --253 ;bind_to_address=254 ;255 ;# LOCAL HOST NAME256 ; The name of this host (if empty "computername" will be used.257 ;hostname=258 ;259 ;# NAGIOS SERVER ADDRESS260 ; The address to the nagios server to submit results to.261 ;nsca_host=192.168.0.1262 ;263 ;# NAGIOS SERVER PORT264 ; The port to the nagios server to submit results to.265 ;nsca_port=5667266 ;267 268 ;# CHECK COMMAND LIST269 ; The checks to run everytime we submit results back to nagios270 ; Any command(alias/key) starting with a host_ is sent as HOST_COMMAND others are sent as SERVICE_COMMANDS271 ; where the alias/key is used as service name.272 ;273 [NSCA Commands]274 ;my_cpu_check=checkCPU warn=80 crit=90 time=20m time=10s time=4275 ;my_mem_check=checkMem MaxWarn=80% MaxCrit=90% ShowAll type=page276 ;my_svc_check=checkServiceState CheckAll exclude=wampmysqld exclude=MpfService277 ;host_check=check_ok -
NSClient++-2005.sln
rce57b1b r394f7a1 52 52 EndProject 53 53 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Crypt++", "..\Crypt++\Crypt++.vcproj", "{630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}" 54 EndProject 55 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NRPEClient", "modules\NRPEClient\NRPEClient-2005.vcproj", "{4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}" 54 56 EndProject 55 57 Global … … 720 722 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Release|Win32.Build.0 = Release|Win32 721 723 {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A}.Release|x64.ActiveCfg = Release|Win32 724 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug|Any CPU.ActiveCfg = Debug|x64 725 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug|Itanium.ActiveCfg = Debug|x64 726 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug|Mixed Platforms.ActiveCfg = Debug|x64 727 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug|Mixed Platforms.Build.0 = Debug|x64 728 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug|Win32.ActiveCfg = Debug|Win32 729 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug|Win32.Build.0 = Debug|Win32 730 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug|x64.ActiveCfg = Debug|x64 731 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug|x64.Build.0 = Debug|x64 732 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug-MemCheck|Any CPU.ActiveCfg = Debug-MemCheck|x64 733 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug-MemCheck|Itanium.ActiveCfg = Debug-MemCheck|x64 734 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug-MemCheck|Mixed Platforms.ActiveCfg = Debug-MemCheck|x64 735 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug-MemCheck|Mixed Platforms.Build.0 = Debug-MemCheck|x64 736 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug-MemCheck|Win32.ActiveCfg = Debug-MemCheck|Win32 737 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug-MemCheck|Win32.Build.0 = Debug-MemCheck|Win32 738 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug-MemCheck|x64.ActiveCfg = Debug-MemCheck|x64 739 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug-MemCheck|x64.Build.0 = Debug-MemCheck|x64 740 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Distribution|Any CPU.ActiveCfg = Distribution|x64 741 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Distribution|Itanium.ActiveCfg = Distribution|x64 742 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Distribution|Mixed Platforms.ActiveCfg = Distribution|x64 743 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Distribution|Mixed Platforms.Build.0 = Distribution|x64 744 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Distribution|Win32.ActiveCfg = Distribution|Win32 745 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Distribution|Win32.Build.0 = Distribution|Win32 746 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Distribution|x64.ActiveCfg = Distribution|x64 747 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Distribution|x64.Build.0 = Distribution|x64 748 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Nightly|Any CPU.ActiveCfg = Nightly|x64 749 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Nightly|Itanium.ActiveCfg = Nightly|x64 750 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Nightly|Mixed Platforms.ActiveCfg = Nightly|x64 751 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Nightly|Mixed Platforms.Build.0 = Nightly|x64 752 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Nightly|Win32.ActiveCfg = Nightly|Win32 753 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Nightly|Win32.Build.0 = Nightly|Win32 754 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Nightly|x64.ActiveCfg = Nightly|x64 755 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Nightly|x64.Build.0 = Nightly|x64 756 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Release|Any CPU.ActiveCfg = Release|x64 757 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Release|Itanium.ActiveCfg = Release|x64 758 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Release|Mixed Platforms.ActiveCfg = Release|x64 759 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Release|Mixed Platforms.Build.0 = Release|x64 760 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Release|Win32.ActiveCfg = Release|Win32 761 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Release|Win32.Build.0 = Release|Win32 762 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Release|x64.ActiveCfg = Release|x64 763 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Release|x64.Build.0 = Release|x64 722 764 EndGlobalSection 723 765 GlobalSection(SolutionProperties) = preSolution -
NSClient++.cpp
r7a156f4 r394f7a1 40 40 int wmain(int argc, TCHAR* argv[], TCHAR* envp[]) 41 41 { 42 srand( (unsigned)time( NULL ) ); 42 43 int nRetCode = 0; 43 44 if ( (argc > 1) && ((*argv[1] == '-') || (*argv[1] == '/')) ) { … … 133 134 std::wstring s = _T(""); 134 135 std::wstring buff = _T(""); 135 std::wcin >> s; 136 while (s != _T("exit")) { 137 if (std::cin.peek() < 15) { 136 while (true) { 137 std::wcin >> s; 138 if (s == _T("exit")) { 139 std::wcout << _T("Exiting...") << std::endl; 140 break; 141 } else if (s == _T("off") && buff == _T("debug ")) { 142 std::wcout << _T("Setting debug log off...") << std::endl; 143 mainClient.enableDebug(false); 144 } else if (s == _T("on") && buff == _T("debug ")) { 145 std::wcout << _T("Setting debug log on...") << std::endl; 146 mainClient.enableDebug(true); 147 } else if (std::cin.peek() < 15) { 138 148 buff += s; 139 149 strEx::token t = strEx::getToken(buff, ' '); … … 148 158 buff += s + _T(" "); 149 159 } 150 std::wcin >> s;151 160 } 152 161 mainClient.TerminateService(); … … 533 542 534 543 bool NSClientT::logDebug() { 535 typedef enum status {unknown, debug, nodebug }; 536 static status d = unknown; 537 if (d == unknown) { 544 if (debug_ == log_unknown) { 538 545 try { 539 546 if (Settings::getInstance()->getInt(_T("log"), _T("debug"), 0) == 1) 540 d =debug;547 debug_ = log_debug; 541 548 else 542 d =nodebug;549 debug_ = log_nodebug; 543 550 } catch (SettingsException e) { 544 d =debug;545 } 546 } 547 return (d ==debug);551 debug_ = log_debug; 552 } 553 } 554 return (debug_ == log_debug); 548 555 } 549 556 -
NSClient++.h
r7a156f4 r394f7a1 70 70 MutexRW m_mutexRWcmdDescriptions; 71 71 cmdMap cmdDescriptions_; 72 bool debug_; 72 typedef enum log_status {log_unknown, log_debug, log_nodebug }; 73 log_status debug_; 73 74 74 75 public: 75 76 // c-tor, d-tor 76 NSClientT(void) : debug_( false) {}77 NSClientT(void) : debug_(log_unknown) {} 77 78 virtual ~NSClientT(void) {} 78 79 void enableDebug(bool debug = true) { 79 debug_ = debug; 80 if (debug) 81 debug_ = log_debug; 82 else 83 debug_ = log_nodebug; 80 84 } 81 85 -
changelog
rc1fe385 r394f7a1 5 5 * Add module for relaying events 6 6 * Add API for rehashing the daemon (or implement it the API is there but does nothing) 7 8 2008-02-18 MickeM 9 + Added propper output handling to process subsystem (now you can execute programs tat return "much" data. 10 + Added select support for SSL_write (now you can send "any amount of data" to the (SSL) socket. 11 Since check_nrpe doesn't do this it wont work in that end, but still... 12 13 2008-02-16 MickeM 14 + Refactored ExternalCommand handling so NRPE and new module does the same thing. 7 15 8 16 2008-02-14 MickeM -
include/Mutex.h
r1a35b3f r394f7a1 174 174 } 175 175 }; 176 177 class ManualMutexLock { 178 private: 179 bool bHasMutex; // Status: true if we have a mutex lock 180 HANDLE hMutex_; // Handle to the mutex object. 181 DWORD dwWaitResult; // Result from the mutex operations 182 public: 183 /** 184 * Default c-tor. 185 * Waits for the mutex object. 186 * @param hMutex The mutex to use 187 * @timeout The timeout before abandoning wait 188 */ 189 ManualMutexLock(HANDLE hMutex) : bHasMutex(false), hMutex_(hMutex) {} 190 191 /** 192 * Waits for the mutex object. 193 * @timeout The timeout before abandoning wait 194 */ 195 void lock(DWORD timeout = 5000L) { 196 if (hMutex_ == NULL) { 197 std::wcout << _T("Error in mutex lock: ") << std::endl; 198 bHasMutex = false; 199 return; 200 } 201 dwWaitResult = WaitForSingleObject(hMutex_, timeout); 202 switch (dwWaitResult) { 203 // The thread got mutex ownership. 204 case WAIT_OBJECT_0: 205 bHasMutex = true; 206 break; 207 case WAIT_TIMEOUT: 208 bHasMutex = false; 209 break; 210 case WAIT_ABANDONED: 211 bHasMutex = false; 212 break; 213 } 214 } 215 /** 216 * An attempt to simplify the has mutex thingy (don't know if it works, haven't tried it since I wrote this class a few years ago :) 217 * @return true if we have a mutex lock. 218 */ 219 operator bool () const { 220 return bHasMutex; 221 } 222 /** 223 * Check if we actually got the mutex (might have timed out) 224 * @return 225 */ 226 bool hasMutex() const { 227 return bHasMutex; 228 } 229 /** 230 * Default d-tor. 231 * Release the mutex 232 */ 233 virtual ~ManualMutexLock() { 234 if (bHasMutex) 235 ReleaseMutex(hMutex_); 236 bHasMutex = false; 237 } 238 /** 239 * Release the mutex 240 */ 241 void release() { 242 if (bHasMutex) 243 ReleaseMutex(hMutex_); 244 bHasMutex = false; 245 } 246 /** 247 * Get the result of the wait operation. 248 * @return Result of the wait operation 249 */ 250 DWORD getWaitResult() const { 251 return dwWaitResult; 252 } 253 }; -
include/PDHCollectors.h
rdc65e35 r394f7a1 22 22 23 23 #include <PDHCounter.h> 24 24 #include <Mutex.h> 25 25 namespace PDHCollectors { 26 26 const int format_large = 0x00000400; … … 28 28 const int format_double = 0x00000200; 29 29 30 template <class TType = __int64, int TCollectionFormat = format_large> 30 class PDHException { 31 std::wstring error_; 32 public: 33 PDHException(std::wstring error) : error_(error) {} 34 std::wstring getError() const { return error_; } 35 36 }; 37 class TPDHCounterMutex { 38 public: 39 virtual void lock() = 0; 40 virtual bool hasLock(bool silent = true) = 0; 41 virtual void release() = 0; 42 }; 43 44 class PDHCounterNoMutex : public TPDHCounterMutex { 45 public: 46 void lock() {} 47 bool hasLock(bool silent = true) { 48 return true; 49 } 50 void release() {} 51 }; 52 class PDHCounterNormalMutex : public TPDHCounterMutex { 53 MutexHandler mutex_; 54 ManualMutexLock lock_; 55 public: 56 PDHCounterNormalMutex() : lock_(mutex_) {} 57 void lock() { 58 lock_.lock(); 59 } 60 bool hasLock(bool silent = true) { 61 if (!silent && !lock_.hasMutex()) { 62 std::wcout << _T("We never got the mutex... sorry...") << std::endl; 63 } 64 return lock_.hasMutex(); 65 } 66 void release() { 67 lock_.release(); 68 } 69 }; 70 class PDHCounterMutexHandler { 71 private: 72 TPDHCounterMutex *mutex_; // Handle to the mutex object. 73 public: 74 /** 75 * Default c-tor. 76 * Waits for the mutex object. 77 * @param mutex The mutex to use 78 * @timeout The timeout before abandoning wait 79 */ 80 PDHCounterMutexHandler(TPDHCounterMutex *mutex) : mutex_(mutex) { 81 if (mutex == NULL) { 82 std::wcout << _T("Error in mutex lock: ") << std::endl; 83 mutex = NULL; 84 return; 85 } 86 mutex->lock(); 87 } 88 /** 89 * An attempt to simplify the has mutex thingy (don't know if it works, haven't tried it since I wrote this class a few years ago :) 90 * @return true if we have a mutex lock. 91 */ 92 operator bool () const { 93 return mutex_!=NULL&&mutex_->hasLock(); 94 } 95 /** 96 * Check if we actually got the mutex (might have timed out) 97 * @return 98 */ 99 bool hasLock(bool silent = true) const { 100 return mutex_!=NULL&&mutex_->hasLock(silent); 101 } 102 /** 103 * Default d-tor. 104 * Release the mutex 105 */ 106 virtual ~PDHCounterMutexHandler() { 107 mutex_->release(); 108 } 109 }; 110 111 template <class TType, int TCollectionFormat, class TMutextHandler = PDHCounterNoMutex> 31 112 class StaticPDHCounterListener {}; 32 113 33 template <class TType >34 class StaticPDHCounterListener<TType, format_double > : public PDH::PDHCounterListener {114 template <class TType, class TMutextHandler> 115 class StaticPDHCounterListener<TType, format_double, TMutextHandler> : public PDH::PDHCounterListener { 35 116 TType value_; 117 TMutextHandler mutex_; 36 118 public: 37 119 StaticPDHCounterListener() : value_(0) {} 38 120 virtual void collect(const PDH::PDHCounter &counter) { 121 PDHCounterMutexHandler mutex(&mutex_); 122 if (!mutex.hasLock()) 123 return; 39 124 value_ = counter.getDoubleValue(); 40 125 } 41 126 void attach(const PDH::PDHCounter &counter){} 42 127 void detach(const PDH::PDHCounter &counter){} 43 TType getValue() const { 128 TType getValue() { 129 PDHCounterMutexHandler mutex(&mutex_); 130 if (!mutex.hasLock()) 131 return -1; 44 132 return value_; 45 133 } … … 49 137 }; 50 138 51 template <class TType >52 class StaticPDHCounterListener<TType, format_long > : public PDH::PDHCounterListener {139 template <class TType, class TMutextHandler> 140 class StaticPDHCounterListener<TType, format_long, TMutextHandler> : public PDH::PDHCounterListener { 53 141 TType value_; 142 TMutextHandler mutex_; 54 143 public: 55 144 StaticPDHCounterListener() : value_(0) {} 56 145 virtual void collect(const PDH::PDHCounter &counter) { 146 PDHCounterMutexHandler mutex(&mutex_); 147 if (!mutex.hasLock()) 148 return; 57 149 value_ = counter.getIntValue(); 58 150 } 59 151 void attach(const PDH::PDHCounter &counter){} 60 152 void detach(const PDH::PDHCounter &counter){} 61 TType getValue() const { 153 TType getValue() { 154 PDHCounterMutexHandler mutex(&mutex_); 155 if (!mutex.hasLock()) 156 return -1; 62 157 return value_; 63 158 } … … 67 162 }; 68 163 69 template <class TType> 70 class StaticPDHCounterListener<TType, format_large> : public PDH::PDHCounterListener { 164 template <class TType, class TMutextHandler> 165 class StaticPDHCounterListener<TType, format_large, TMutextHandler> : public PDH::PDHCounterListener { 166 TMutextHandler mutex_; 71 167 TType value_; 72 168 public: 73 169 StaticPDHCounterListener() : value_(0) {} 74 170 virtual void collect(const PDH::PDHCounter &counter) { 171 PDHCounterMutexHandler mutex(&mutex_); 172 if (!mutex.hasLock()) 173 return; 75 174 value_ = counter.getInt64Value(); 76 175 } 77 176 void attach(const PDH::PDHCounter &counter){} 78 177 void detach(const PDH::PDHCounter &counter){} 79 TType getValue() const { 178 TType getValue() { 179 PDHCounterMutexHandler mutex(&mutex_); 180 if (!mutex.hasLock()) 181 return -1; 80 182 return value_; 81 183 } … … 86 188 87 189 88 template <class TType = __int64>190 template <class TType, class TMutextHandler> 89 191 class RoundINTPDHBufferListenerImpl : public PDH::PDHCounterListener { 192 TMutextHandler mutex_; 90 193 unsigned int length; 91 194 TType *buffer; … … 94 197 RoundINTPDHBufferListenerImpl() : buffer(NULL), length(0), current(0) {} 95 198 RoundINTPDHBufferListenerImpl(int length_) : length(length_), current(0) { 199 PDHCounterMutexHandler mutex(mutex_); 200 if (!mutex.hasLock()) 201 return; 96 202 buffer = new int[length]; 97 203 for (unsigned int i=0; i<length;i++) … … 99 205 } 100 206 virtual ~RoundINTPDHBufferListenerImpl() { 207 PDHCounterMutexHandler mutex(&mutex_); 208 if (!mutex.hasLock()) 209 return; 101 210 delete [] buffer; 102 211 } … … 110 219 */ 111 220 void resize(int newLength) { 221 PDHCounterMutexHandler mutex(&mutex_); 222 if (!mutex.hasLock()) 223 return; 112 224 delete [] buffer; 113 225 … … 126 238 void detach(const PDH::PDHCounter &counter){} 127 239 void pushValue(TType value) { 240 PDHCounterMutexHandler mutex(&mutex_); 241 if (!mutex.hasLock()) 242 return; 128 243 if (buffer == NULL) 129 244 return; … … 134 249 current = 0; 135 250 } 136 double getAvrage(unsigned int backItems) const { 251 double getAvrage(unsigned int backItems) { 252 PDHCounterMutexHandler mutex(&mutex_); 253 if (!mutex.hasLock(true)) 254 throw PDHException(_T("Failed to get mutex :(")); 137 255 if ((backItems == 0) || (backItems >= length)) 138 256 return -1; … … 157 275 158 276 159 template <class TType = __int64, DWORD TCollectionFormat = format_large>160 class RoundINTPDHBufferListener : public RoundINTPDHBufferListenerImpl<TType > {161 }; 162 163 template <class TType >164 class RoundINTPDHBufferListener<TType, format_double > : public RoundINTPDHBufferListenerImpl<TType> {277 template <class TType, DWORD TCollectionFormat, class TMutextHandler = PDHCounterNoMutex> 278 class RoundINTPDHBufferListener : public RoundINTPDHBufferListenerImpl<TType, TMutextHandler> { 279 }; 280 281 template <class TType, class TMutextHandler> 282 class RoundINTPDHBufferListener<TType, format_double, TMutextHandler> : public RoundINTPDHBufferListenerImpl<TType, TMutextHandler> { 165 283 public: 166 284 RoundINTPDHBufferListener() {} … … 175 293 }; 176 294 177 template <class TType >178 class RoundINTPDHBufferListener<TType, format_long > : public RoundINTPDHBufferListenerImpl<TType> {295 template <class TType, class TMutextHandler> 296 class RoundINTPDHBufferListener<TType, format_long, TMutextHandler> : public RoundINTPDHBufferListenerImpl<TType, TMutextHandler> { 179 297 public: 180 298 RoundINTPDHBufferListener() {} … … 189 307 }; 190 308 191 template <class TType >192 class RoundINTPDHBufferListener<TType, format_large > : public RoundINTPDHBufferListenerImpl<TType> {309 template <class TType, class TMutextHandler> 310 class RoundINTPDHBufferListener<TType, format_large, TMutextHandler> : public RoundINTPDHBufferListenerImpl<TType, TMutextHandler> { 193 311 public: 194 312 RoundINTPDHBufferListener() {} -
include/SSLSocket.cpp
r47b843a r394f7a1 68 68 69 69 70 bool simpleSSL::sSSL::readAll(simpleSocket:: Socket *report_to, simpleSocket::DataBuffer &buffer, unsigned int tmpBufferLength /* = 1024*/, int maxLength /*= -1*/) {70 bool simpleSSL::sSSL::readAll(simpleSocket::DataBuffer &buffer, unsigned int tmpBufferLength /* = 1024*/, int maxLength /*= -1*/) { 71 71 char *tmpBuffer = new char[tmpBufferLength+1]; 72 72 if (!ssl_) … … 81 81 if ((rc == SSL_ERROR_WANT_READ) || (rc == SSL_ERROR_WANT_WRITE)) 82 82 return true; 83 report_to->printError(_T(__FILE__), __LINE__, _T("Could not read from socket: ") + strEx::itos(rc));84 83 throw simpleSocket::SocketException(_T("Could not read from socket: ") + strEx::itos(rc)); 85 84 } 86 85 return n>0; 87 86 } 88 void simpleSSL::sSSL::send(const char * buf, unsigned int len) { 87 88 bool simpleSSL::sSSL::sendAll(const char * buffer, unsigned int len) { 89 89 if (!ssl_) 90 90 create(); 91 int rc = SSL_write(ssl_, buf, len); 92 if (rc <= 0) 93 throw SSLException(_T("Socket write failed: "), rc, getError(rc)); 91 int n = SSL_write(ssl_, buffer, len); 92 if (n <= 0) { 93 int rc = getError(n); 94 if ((rc == SSL_ERROR_WANT_READ) || (rc == SSL_ERROR_WANT_WRITE)) 95 return true; 96 throw simpleSocket::SocketException(_T("Could not write to socket: ") + strEx::itos(rc)); 97 } 98 return false; 94 99 } 95 100 -
include/SSLSocket.h
r47b843a r394f7a1 230 230 context_ = context; 231 231 } 232 bool readAll (simpleSocket::Socket *report_to, simpleSocket::DataBuffer &buffer, unsigned int tmpBufferLength = 1024, int maxLength = -1); 232 bool readAll (simpleSocket::DataBuffer &buffer, unsigned int tmpBufferLength = 1024, int maxLength = -1); 233 bool sendAll(const char * buffer, unsigned int len); 233 234 void send(const char * buf, unsigned int len); 234 235 }; … … 262 263 virtual bool readAll (simpleSocket::DataBuffer &buffer, unsigned int tmpBufferLength = 1024, int maxLength = -1) { 263 264 try { 264 return ssl.readAll(this, buffer, tmpBufferLength, maxLength); 265 } catch (simpleSSL::SSLException e) { 266 throw simpleSocket::SocketException(e.getMessage()); 267 } 268 } 265 return ssl.readAll(buffer, tmpBufferLength, maxLength); 266 } catch (simpleSSL::SSLException e) { 267 throw simpleSocket::SocketException(e.getMessage()); 268 } catch (...) { 269 throw simpleSocket::SocketException(_T("Unhandeled socket exception")); 270 } 271 } 272 virtual bool sendAll(const char * buffer, unsigned int len) { 273 try { 274 return ssl.sendAll(buffer, len); 275 } catch (simpleSSL::SSLException e) { 276 throw simpleSocket::SocketException(e.getMessage()); 277 } catch (...) { 278 throw simpleSocket::SocketException(_T("Unhandeled socket exception")); 279 } 280 } 281 /* 282 269 283 virtual int send(const char * buf, unsigned int len, int flags = 0) { 270 284 try { … … 275 289 return 0; 276 290 } 291 */ 277 292 virtual void close() { 278 293 ssl.shutdown(); -
include/Socket.cpp
r035c51f r394f7a1 50 50 break; 51 51 n=recv(socket_,tmpBuffer,tmpBufferLength,0); 52 std::wcout << _T("read (2): ") << n << std::endl;53 52 } else { 54 53 // Buffer not full, we got it "all" … … 68 67 } 69 68 69 bool simpleSocket::Socket::sendAll(const char * buffer, unsigned int len) { 70 int n = send(buffer, len, 0); 71 if (n == SOCKET_ERROR) { 72 int ret = ::WSAGetLastError(); 73 if (ret == WSAEWOULDBLOCK) 74 return false; 75 throw SocketException(_T("recv returned SOCKET_ERROR: "), ret); 76 } 77 return false; 78 } 70 79 71 80 /** -
include/Socket.h
rce57b1b r394f7a1 143 143 buffer_[length_] = 0; 144 144 } 145 std::wstring toString() { 146 std::wstringstream ss; 147 for (unsigned int i =0;i<length_;i++) { 148 if (i%64==0) { 149 ss << std::endl; 150 } 151 if (buffer_[i] < 30 || buffer_[i] > 'z') 152 ss << _T(" "); 153 else 154 ss << buffer_[i]; 155 } 156 return ss.str(); 145 std::string toString() { 146 return strEx::format_buffer(buffer_, length_); 157 147 } 158 148 }; … … 163 153 sockaddr_in from_; 164 154 sockaddr_in to_; 155 fd_set read_, write_, excp_; 165 156 166 157 public: 167 158 Socket() : socket_(NULL) { 159 FD_ZERO(&read_); 160 FD_ZERO(&write_); 161 FD_ZERO(&excp_); 168 162 } 169 163 Socket(SOCKET socket) : socket_(socket) { 164 FD_ZERO(&read_); 165 FD_ZERO(&write_); 166 FD_ZERO(&excp_); 170 167 } 171 168 Socket(int type, int protocol) : socket_(NULL) { 172 169 socket_ = ::socket(AF_INET, type, protocol); 170 FD_ZERO(&read_); 171 FD_ZERO(&write_); 172 FD_ZERO(&excp_); 173 173 } 174 174 Socket(bool create) : socket_(NULL) { 175 175 if (create) 176 176 socket_ = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 177 FD_ZERO(&read_); 178 FD_ZERO(&write_); 179 FD_ZERO(&excp_); 177 180 } 178 181 … … 181 184 from_ = other.from_; 182 185 other.socket_ = NULL; 186 read_ = other.read_; 187 write_ = other.write_; 188 excp_ = other.excp_; 183 189 } 184 190 virtual ~Socket() { … … 217 223 virtual void setNonBlock() { 218 224 unsigned long NoBlock = 1; 225 FD_SET(socket_, &read_); 226 FD_SET(socket_, &write_); 227 FD_SET(socket_, &excp_); 219 228 this->ioctlsocket(FIONBIO, &NoBlock); 220 229 } 230 virtual bool canRead(long timeout = -1) { 231 timeval timeout_; 232 timeout_.tv_sec = timeout; 233 FD_SET(socket_, &read_); 234 FD_SET(socket_, &write_); 235 FD_SET(socket_, &excp_); 236 if (timeout == -1) 237 ::select(NULL, &read_, &write_, &excp_, NULL); 238 else 239 ::select(NULL, &read_, &write_, &excp_, &timeout_); 240 if (FD_ISSET(socket_, &read_)) 241 return true; 242 return false; 243 } 244 virtual bool canWrite(long timeout = -1) { 245 timeval timeout_; 246 timeout_.tv_sec = timeout; 247 FD_SET(socket_, &read_); 248 FD_SET(socket_, &write_); 249 FD_SET(socket_, &excp_); 250 if (timeout == -1) 251 ::select(NULL, &read_, &write_, &excp_, NULL); 252 else 253 ::select(NULL, &read_, &write_, &excp_, &timeout_); 254 return FD_ISSET(socket_, &write_); 255 } 256 221 257 static unsigned long inet_addr(std::wstring addr) { 222 258 return ::inet_addr(strEx::wstring_to_string(addr).c_str()); … … 268 304 } 269 305 virtual bool readAll(DataBuffer &buffer, unsigned int tmpBufferLength = 1024, int maxLength = -1); 306 virtual bool sendAll(const char * buffer, unsigned int len); 307 308 int inline sendAll(DataBuffer &buffer) { 309 return sendAll(buffer.getBuffer(), buffer.getLength()); 310 } 311 312 virtual int send(const char * buf, unsigned int len, int flags = 0) { 313 assert(socket_); 314 return ::send(socket_, buf, len, flags); 315 } 316 int inline send(DataBuffer &buffer, int flags = 0) { 317 return send(buffer.getBuffer(), buffer.getLength(), flags); 318 } 270 319 271 320 virtual void socket(int af, int type, int protocol ) { … … 300 349 from_.sin_addr.s_addr=addr; 301 350 from_.sin_port=port; 302 }303 virtual int send(const char * buf, unsigned int len, int flags = 0) {304 assert(socket_);305 return ::send(socket_, buf, len, flags);306 }307 int inline send(DataBuffer &buffer, int flags = 0) {308 return send(buffer.getBuffer(), buffer.getLength(), flags);309 351 } 310 352 virtual void ioctlsocket(long cmd, u_long *argp) { -
include/config.h
r65ec1fa r394f7a1 163 163 #define NSCA_PASSWORD _T("password") 164 164 #define NSCA_PASSWORD_DEFAULT _T("") 165 #define NSCA_DEBUG_THREADS _T("debug_threads") 166 #define NSCA_DEBUG_THREADS_DEFAULT 1 165 167 166 168 #define C_SYSTEM_SVC_ALL_0 _T("check_all_services[SERVICE_BOOT_START]") -
include/strEx.h
rde8ef76 r394f7a1 89 89 } 90 90 91 inline std::wstring format_buffer(const wchar_t* buf, unsigned int len) { 92 std::wstringstream ss; 93 std::wstring chars; 94 for (unsigned int i=0;i<len;i++) { 95 ss << std::hex << buf[i]; 96 ss << _T(", "); 97 if (buf[i] >= ' ' && buf[i] <= 'z') 98 chars += buf[i]; 99 else 100 chars += '?'; 101 if (i%32==0) { 102 ss << chars; 103 ss << _T("\n"); 104 chars = _T(""); 105 } 106 } 107 return ss.str(); 108 } 109 inline std::string format_buffer(const char* buf, unsigned int len) { 110 std::stringstream ss; 111 std::string chars; 112 for (unsigned int i=0;i<len;i++) { 113 if (i%32==0) { 114 if (i > 0) { 115 ss << chars; 116 ss << "\n"; 117 } 118 chars = ""; 119 ss << std::hex << std::setw(8) << std::setfill('0') << i; 120 ss << ": "; 121 } 122 ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(static_cast<unsigned char>(buf[i])); 123 ss << ", "; 124 if (buf[i] < 30 || buf[i] == 127) 125 chars += '?'; 126 else 127 chars += buf[i]; 128 } 129 return ss.str(); 130 } 131 91 132 inline std::wstring format_date(time_t time, std::wstring format = _T("%Y-%m-%d %H:%M:%S")) { 92 133 TCHAR buf[51]; -
modules/CheckExternalScripts/CheckExternalScripts.cpp
rce57b1b r394f7a1 91 91 addAllScriptsFrom(scriptDirectory_); 92 92 } 93 root_ = NSCModuleHelper::getBasePath(); 93 94 return true; 94 95 } … … 136 137 return NSCModuleHelper::InjectSplitAndCommand(cd.command, cd.arguments, ' ', message, perf, true); 137 138 } else { 138 return executeNRPECommand(cd.command + _T(" ") + args, message, perf); 139 int result = process::executeProcess(root_, cd.command + _T(" ") + args, message, perf, timeout); 140 if (!NSCHelper::isNagiosReturnCode(result)) { 141 NSC_LOG_ERROR_STD(_T("The command (") + cd.command + _T(") returned an invalid return code: ") + strEx::itos(result)); 142 return NSCAPI::returnUNKNOWN; 143 } 144 return NSCHelper::int2nagios(result); 139 145 /* 140 146 } else if (cd.type == script_dir) { … … 149 155 150 156 } 151 #define MAX_INPUT_BUFFER 1024152 153 int CheckExternalScripts::executeNRPECommand(std::wstring command, std::wstring &msg, std::wstring &perf)154 {155 NSCAPI::nagiosReturn result;156 PROCESS_INFORMATION pi;157 STARTUPINFO si;158 HANDLE hChildOutR, hChildOutW, hChildInR, hChildInW;159 SECURITY_ATTRIBUTES sec;160 DWORD dwstate, dwexitcode;161 int retval;162 163 164 // Set up members of SECURITY_ATTRIBUTES structure.165 166 sec.nLength = sizeof(SECURITY_ATTRIBUTES);167 sec.bInheritHandle = TRUE;168 sec.lpSecurityDescriptor = NULL;169 170 // CreateProcess doesn't work with a const command171 TCHAR *cmd = new TCHAR[command.length()+1];172 if (cmd == NULL) {173 NSC_LOG_ERROR(_T("Failed to allocate memory for command buffer (") + command + _T(")."));174 return NSCAPI::returnUNKNOWN;175 }176 wcsncpy_s(cmd, command.length()+1, command.c_str(), command.length());177 cmd[command.length()] = 0;178 std::wstring root = NSCModuleHelper::getBasePath();179 180 // Create Pipes181 if (!CreatePipe(&hChildInR, &hChildInW, &sec, 0)) {182 NSC_LOG_ERROR(_T("Failed to create pipe for (") + command + _T(") return code: ") + error::lookup::last_error());183 return NSCAPI::returnUNKNOWN;184 }185 if (!CreatePipe(&hChildOutR, &hChildOutW, &sec, 0)) {186 NSC_LOG_ERROR(_T("Failed to create pipe for (") + command + _T(") return code: ") + error::lookup::last_error());187 return NSCAPI::returnUNKNOWN;188 }189 190 // Set up members of STARTUPINFO structure.191 192 ZeroMemory(&si, sizeof(STARTUPINFO));193 si.cb = sizeof(STARTUPINFO);194 si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;195 si.hStdInput = hChildInR;196 si.hStdOutput = hChildOutW;197 si.hStdError = hChildOutW;198 si.wShowWindow = SW_HIDE;199 200 // Create the child process.201 BOOL processOK = CreateProcess(NULL, cmd, // command line202 NULL, // process security attributes203 NULL, // primary thread security attributes204 TRUE, // handles are inherited205 0, // creation flags206 NULL, // use parent's environment207 root.c_str(), // use parent's current directory208 &si, // STARTUPINFO pointer209 &pi); // receives PROCESS_INFORMATION210 delete [] cmd;211 212 if (processOK) {213 dwstate = WaitForSingleObject(pi.hProcess, 1000*timeout);214 CloseHandle(hChildInR);215 CloseHandle(hChildInW);216 CloseHandle(hChildOutW);217 218 if (dwstate == WAIT_TIMEOUT) {219 TerminateProcess(pi.hProcess, 5);220 msg = _T("The check (") + command + _T(") didn't respond within the timeout period (") + strEx::itos(timeout) + _T("s)!");221 result = NSCAPI::returnUNKNOWN;222 } else {223 DWORD dwread;224 //TCHAR *buf = new TCHAR[MAX_INPUT_BUFFER+1];225 char *buf = new char[MAX_INPUT_BUFFER+1];226 //retval = ReadFile(hChildOutR, buf, MAX_INPUT_BUFFER*sizeof(WCHAR), &dwread, NULL);227 retval = ReadFile(hChildOutR, buf, MAX_INPUT_BUFFER*sizeof(char), &dwread, NULL);228 if (!retval || dwread == 0) {229 msg = _T("No output available from command...");230 } else {231 buf[dwread] = 0;232 msg = strEx::string_to_wstring(buf);233 //msg = buf;234 //strEx::token t = strEx::getToken(msg, '\n');235 strEx::token t = strEx::getToken(msg, '|');236 msg = t.first;237 std::wstring::size_type pos = msg.find_last_not_of(_T("\n\r "));238 if (pos != std::wstring::npos) {239 if (pos == msg.size())240 msg = msg.substr(0,pos);241 else242 msg = msg.substr(0,pos+1);243 }244 //if (msg[msg.size()-1] == '\n')245 perf = t.second;246 }247 delete [] buf;248 if (GetExitCodeProcess(pi.hProcess, &dwexitcode) == 0) {249 NSC_LOG_ERROR(_T("Failed to get commands (") + command + _T(") return code: ") + error::lookup::last_error());250 dwexitcode = NSCAPI::returnUNKNOWN;251 }252 if (!NSCHelper::isNagiosReturnCode(dwexitcode)) {253 NSC_LOG_ERROR(_T("The command (") + command + _T(") returned an invalid return code: ") + strEx::itos(dwexitcode));254 dwexitcode = NSCAPI::returnUNKNOWN;255 }256 result = NSCHelper::int2nagios(dwexitcode);257 }258 CloseHandle(pi.hThread);259 CloseHandle(pi.hProcess);260 CloseHandle(hChildOutR);261 }262 else {263 msg = _T("NSCP failed to create process (") + command + _T("): ") + error::lookup::last_error();264 result = NSCAPI::returnUNKNOWN;265 CloseHandle(hChildInR);266 CloseHandle(hChildInW);267 CloseHandle(hChildOutW);268 CloseHandle(pi.hThread);269 CloseHandle(pi.hProcess);270 CloseHandle(hChildOutR);271 }272 return result;273 }274 157 275 158 -
modules/CheckExternalScripts/CheckExternalScripts.h
rc1d545e r394f7a1 23 23 #include <map> 24 24 #include <error.hpp> 25 #include <execute_process.hpp> 25 26 26 27 class CheckExternalScripts { … … 37 38 unsigned int timeout; 38 39 std::wstring scriptDirectory_; 40 std::wstring root_; 39 41 40 42 public: … … 76 78 77 79 private: 78 int executeNRPECommand(std::wstring command, std::wstring &msg, std::wstring &perf);79 80 void addAllScriptsFrom(std::wstring path); 80 81 void addCommand(strEx::blindstr key, std::wstring cmd = _T(""), std::wstring args = _T("")) { -
modules/CheckSystem/CheckSystem.cpp
rde8ef76 r394f7a1 402 402 int value = pObject->getCPUAvrage(load.data + _T("m")); 403 403 if (value == -1) { 404 msg = _T("ERROR: We don't collect data this far back: ") + load.getAlias();404 msg = _T("ERROR: Could not get data for ") + load.getAlias() + _T(" perhaps we don't collect data this far back?"); 405 405 return NSCAPI::returnUNKNOWN; 406 406 } … … 720 720 } 721 721 } 722 NSC_DEBUG_MSG_STD(_T("Perf data: ") + strEx::itos(bPerfData) + _T(":") + perf);723 722 724 723 if (msg.empty()) -
modules/CheckSystem/PDHCollector.cpp
r7a156f4 r394f7a1 159 159 bool bInit = true; 160 160 161 if (!loadCounter(pdh)) { 162 pdh.removeAllCounters(); 163 NSC_DEBUG_MSG_STD(_T("We aparently failed to load counters trying to use default (English) counters or those configured in nsc.ini")); 164 SetThreadLocale(MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT)); 165 pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_MEM_PAGE_LIMIT, C_SYSTEM_MEM_PAGE_LIMIT_DEFAULT), &memCmtLim); 166 pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_MEM_PAGE, C_SYSTEM_MEM_PAGE_DEFAULT), &memCmt); 167 pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_UPTIME, C_SYSTEM_UPTIME_DEFAULT), &upTime); 168 pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_CPU, C_SYSTEM_MEM_CPU_DEFAULT), &cpu); 169 try { 170 pdh.open(); 171 } catch (const PDH::PDHException &e) { 172 NSC_LOG_ERROR_STD(_T("Failed to open performance counters: ") + e.getError()); 161 { 162 WriteLock lock(&mutex_, true, 5000); 163 if (!lock.IsLocked()) { 164 NSC_LOG_ERROR_STD(_T("Failed to get mutex when trying to start thread... thread will now die...")); 173 165 bInit = false; 166 } else if (!loadCounter(pdh)) { 167 pdh.removeAllCounters(); 168 NSC_DEBUG_MSG_STD(_T("We aparently failed to load counters trying to use default (English) counters or those configured in nsc.ini")); 169 SetThreadLocale(MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT)); 170 pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_MEM_PAGE_LIMIT, C_SYSTEM_MEM_PAGE_LIMIT_DEFAULT), &memCmtLim); 171 pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_MEM_PAGE, C_SYSTEM_MEM_PAGE_DEFAULT), &memCmt); 172 pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_UPTIME, C_SYSTEM_UPTIME_DEFAULT), &upTime); 173 pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_CPU, C_SYSTEM_MEM_CPU_DEFAULT), &cpu); 174 try { 175 pdh.open(); 176 } catch (const PDH::PDHException &e) { 177 NSC_LOG_ERROR_STD(_T("Failed to open performance counters: ") + e.getError()); 178 bInit = false; 179 } 174 180 } 175 181 } … … 181 187 std::list<std::wstring> errors; 182 188 { 183 MutexLock mutex(mutexHandler);184 if (! mutex.hasMutex())189 ReadLock lock(&mutex_, true, 5000); 190 if (!lock.IsLocked()) 185 191 NSC_LOG_ERROR(_T("Failed to get Mutex!")); 186 192 else { … … 210 216 211 217 { 212 MutexLock mutex(mutexHandler);213 if (! mutex.hasMutex()) {218 WriteLock lock(&mutex_, true, 5000); 219 if (!lock.IsLocked()) { 214 220 NSC_LOG_ERROR(_T("Failed to get Mute when closing thread!")); 215 221 } … … 235 241 if (hStopEvent_ == NULL) 236 242 NSC_LOG_ERROR(_T("Stop event is not created!")); 237 else 238 if (!SetEvent(hStopEvent_)) { 243 else if (!SetEvent(hStopEvent_)) { 239 244 NSC_LOG_ERROR_STD(_T("SetStopEvent failed")); 240 }245 } 241 246 } 242 247 /** … … 247 252 int PDHCollector::getCPUAvrage(std::wstring time) { 248 253 unsigned int mseconds = strEx::stoui_as_time(time, checkIntervall_*100); 249 MutexLock mutex(mutexHandler);250 if (! mutex.hasMutex()) {254 ReadLock lock(&mutex_, true, 5000); 255 if (!lock.IsLocked()) { 251 256 NSC_LOG_ERROR(_T("Failed to get Mutex!")); 252 257 return -1; 253 258 } 254 return static_cast<int>(cpu.getAvrage(mseconds / (checkIntervall_*100))); 259 try { 260 return static_cast<int>(cpu.getAvrage(mseconds / (checkIntervall_*100))); 261 } catch (PDHCollectors::PDHException &e) { 262 NSC_LOG_ERROR(_T("Failed to get (sub) Mutex!")); 263 return -1; 264 } 255 265 } 256 266 /** … … 261 271 */ 262 272 long long PDHCollector::getUptime() { 263 MutexLock mutex(mutexHandler);264 if (! mutex.hasMutex()) {273 ReadLock lock(&mutex_, true, 5000); 274 if (!lock.IsLocked()) { 265 275 NSC_LOG_ERROR(_T("Failed to get Mutex!")); 266 276 return -1; … … 273 283 */ 274 284 unsigned long long PDHCollector::getMemCommitLimit() { 275 MutexLock mutex(mutexHandler);276 if (! mutex.hasMutex()) {285 ReadLock lock(&mutex_, true, 5000); 286 if (!lock.IsLocked()) { 277 287 NSC_LOG_ERROR(_T("Failed to get Mutex!")); 278 288 return -1; … … 286 296 */ 287 297 unsigned long long PDHCollector::getMemCommit() { 288 MutexLock mutex(mutexHandler);289 if (! mutex.hasMutex()) {298 ReadLock lock(&mutex_, true, 5000); 299 if (!lock.IsLocked()) { 290 300 NSC_LOG_ERROR(_T("Failed to get Mutex!")); 291 301 return -1; -
modules/CheckSystem/PDHCollector.h
r47b843a r394f7a1 23 23 #include "PDHCollectors.h" 24 24 #include <thread.h> 25 #include <Mutex .h>25 #include <MutexRW.h> 26 26 27 27 /** … … 46 46 class PDHCollector { 47 47 private: 48 MutexHandler mutexHandler; 48 49 MutexRW mutex_; 49 50 HANDLE hStopEvent_; 50 51 int checkIntervall_; 51 52 52 PDHCollectors::StaticPDHCounterListener<unsigned __int64, PDHCollectors::format_large > memCmtLim;53 PDHCollectors::StaticPDHCounterListener<unsigned __int64, PDHCollectors::format_large > memCmt;54 PDHCollectors::StaticPDHCounterListener<__int64, PDHCollectors::format_large > upTime;55 PDHCollectors::RoundINTPDHBufferListener<__int64, PDHCollectors::format_large > cpu;53 PDHCollectors::StaticPDHCounterListener<unsigned __int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> memCmtLim; 54 PDHCollectors::StaticPDHCounterListener<unsigned __int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> memCmt; 55 PDHCollectors::StaticPDHCounterListener<__int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> upTime; 56 PDHCollectors::RoundINTPDHBufferListener<__int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> cpu; 56 57 57 58 public: -
modules/NRPEListener/NRPEListener-2005.vcproj
r3f69109 r394f7a1 1401 1401 </File> 1402 1402 <File 1403 RelativePath=".\NRPEPacket.cpp"1404 >1405 </File>1406 <File1407 1403 RelativePath="..\..\include\NSCHelper.cpp" 1408 1404 > … … 2104 2100 <File 2105 2101 RelativePath=".\NRPEListener.h" 2106 >2107 </File>2108 <File2109 RelativePath=".\NRPEPacket.h"2110 2102 > 2111 2103 </File> -
modules/NRPEListener/NRPEListener.cpp
r7a156f4 r394f7a1 24 24 #include <time.h> 25 25 #include <config.h> 26 #include "NRPEPacket.h"27 26 #include <msvc_wrappers.h> 28 27 … … 128 127 return false; 129 128 } 129 root_ = NSCModuleHelper::getBasePath(); 130 130 131 131 return true; … … 228 228 return NSCModuleHelper::InjectSplitAndCommand(t.first, sTarget, '!', message, perf); 229 229 } else if (cd.type == script) { 230 return executeNRPECommand(args, message, perf); 230 int result = process::executeProcess(root_, args, message, perf, timeout); 231 if (!NSCHelper::isNagiosReturnCode(result)) { 232 NSC_LOG_ERROR_STD(_T("The command (") + command.c_str() + _T(") returned an invalid return code: ") + strEx::itos(result)); 233 return NSCAPI::returnUNKNOWN; 234 } 235 return NSCHelper::int2nagios(result); 231 236 } else if (cd.type == script_dir) { 232 237 std::wstring args = arrayBuffer::arrayBuffer2string(char_args, argLen, _T(" ")); 233 238 std::wstring cmd = scriptDirectory_ + command.c_str() + _T(" ") +args; 234 return executeNRPECommand(cmd, message, perf); 239 int result = process::executeProcess(root_, cmd, message, perf, timeout); 240 if (!NSCHelper::isNagiosReturnCode(result)) { 241 NSC_LOG_ERROR_STD(_T("The command (") + command.c_str() + _T(") returned an invalid return code: ") + strEx::itos(result)); 242 return NSCAPI::returnUNKNOWN; 243 } 244 return NSCHelper::int2nagios(result); 235 245 } else { 236 246 NSC_LOG_ERROR_STD(_T("Unknown script type: ") + command.c_str()); … … 239 249 240 250 } 241 int NRPEListener::executeNRPECommand(std::wstring command, std::wstring &msg, std::wstring &perf) 242 { 243 NSCAPI::nagiosReturn result; 244 PROCESS_INFORMATION pi; 245 STARTUPINFO si; 246 HANDLE hChildOutR, hChildOutW, hChildInR, hChildInW; 247 SECURITY_ATTRIBUTES sec; 248 DWORD dwstate, dwexitcode; 249 int retval; 250 251 252 // Set up members of SECURITY_ATTRIBUTES structure. 253 254 sec.nLength = sizeof(SECURITY_ATTRIBUTES); 255 sec.bInheritHandle = TRUE; 256 sec.lpSecurityDescriptor = NULL; 257 258 // Create Pipes 259 CreatePipe(&hChildInR, &hChildInW, &sec, 0); 260 CreatePipe(&hChildOutR, &hChildOutW, &sec, 0); 261 262 // Set up members of STARTUPINFO structure. 263 264 ZeroMemory(&si, sizeof(STARTUPINFO)); 265 si.cb = sizeof(STARTUPINFO); 266 si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW; 267 si.hStdInput = hChildInR; 268 si.hStdOutput = hChildOutW; 269 si.hStdError = hChildOutW; 270 si.wShowWindow = SW_HIDE; 271 272 273 // CreateProcess doesn't work with a const command 274 TCHAR *cmd = new TCHAR[command.length()+1]; 275 wcsncpy_s(cmd, command.length()+1, command.c_str(), command.length()); 276 cmd[command.length()] = 0; 277 std::wstring root = NSCModuleHelper::getBasePath(); 278 279 // Create the child process. 280 BOOL processOK = CreateProcess(NULL, cmd, // command line 281 NULL, // process security attributes 282 NULL, // primary thread security attributes 283 TRUE, // handles are inherited 284 0, // creation flags 285 NULL, // use parent's environment 286 root.c_str(), // use parent's current directory 287 &si, // STARTUPINFO pointer 288 &pi); // receives PROCESS_INFORMATION 289 delete [] cmd; 290 291 if (processOK) { 292 dwstate = WaitForSingleObject(pi.hProcess, 1000*timeout); 293 CloseHandle(hChildInR); 294 CloseHandle(hChildInW); 295 CloseHandle(hChildOutW); 296 297 if (dwstate == WAIT_TIMEOUT) { 298 TerminateProcess(pi.hProcess, 5); 299 msg = _T("The check (") + command + _T(") didn't respond within the timeout period (") + strEx::itos(timeout) + _T("s)!"); 300 result = NSCAPI::returnUNKNOWN; 301 } else { 302 DWORD dwread; 303 std::string str; 304 #define BUFF_SIZE 4096 305 char *buf = new char[BUFF_SIZE+1]; 306 do { 307 retval = ReadFile(hChildOutR, buf, BUFF_SIZE, &dwread, NULL); 308 if (retval == 0) 309 break; 310 if (dwread > BUFF_SIZE) 311 break; 312 buf[dwread] = 0; 313 str += buf; 314 } while (dwread == BUFF_SIZE); 315 delete [] buf; 316 if (str.empty()) { 317 msg = _T("No output available from command..."); 318 } else { 319 msg = strEx::string_to_wstring(str); 320 strEx::token t = strEx::getToken(msg, '|'); 321 msg = t.first; 322 std::wstring::size_type pos = msg.find_last_not_of(_T("\n\r ")); 323 if (pos != std::wstring::npos) { 324 if (pos == msg.size()) 325 msg = msg.substr(0,pos); 326 else 327 msg = msg.substr(0,pos+1); 328 } 329 perf = t.second; 330 } 331 if (GetExitCodeProcess(pi.hProcess, &dwexitcode) == 0) { 332 NSC_LOG_ERROR(_T("Failed to get commands (") + command + _T(") return code: ") + error::lookup::last_error()); 333 dwexitcode = NSCAPI::returnUNKNOWN; 334 } 335 if (!NSCHelper::isNagiosReturnCode(dwexitcode)) { 336 NSC_LOG_ERROR(_T("The command (") + command + _T(") returned an invalid return code: ") + strEx::itos(dwexitcode)); 337 dwexitcode = NSCAPI::returnUNKNOWN; 338 } 339 result = NSCHelper::int2nagios(dwexitcode); 340 } 341 CloseHandle(pi.hThread); 342 CloseHandle(pi.hProcess); 343 CloseHandle(hChildOutR); 344 } 345 else { 346 msg = _T("NRPE_NT failed to create process (") + command + _T("): ") + error::lookup::last_error(); 347 result = NSCAPI::returnUNKNOWN; 348 CloseHandle(hChildInR); 349 CloseHandle(hChildInW); 350 CloseHandle(hChildOutW); 351 CloseHandle(pi.hThread); 352 CloseHandle(pi.hProcess); 353 CloseHandle(hChildOutR); 354 } 355 return result; 356 } 251 357 252 void NRPEListener::onClose() 358 253 {} … … 400 295 return; 401 296 } 402 client->send(block); 297 int maxWait = socketTimeout_*10; 298 for (i=0;i<maxWait;i++) { 299 bool lastReadHasMore = false; 300 try { 301 if (client->canWrite()) 302 lastReadHasMore = client->sendAll(block); 303 } catch (simpleSocket::SocketException e) { 304 NSC_LOG_MESSAGE(_T("Could not send NRPE packet from socket :") + e.getMessage()); 305 client->close(); 306 return; 307 } 308 if (!lastReadHasMore) { 309 client->close(); 310 return; 311 } 312 Sleep(100); 313 } 314 if (i >= maxWait) { 315 NSC_LOG_ERROR_STD(_T("Timeout reading NRPE-packet (increase socket_timeout)")); 316 client->close(); 317 return; 318 } 403 319 } 404 320 } catch (simpleSocket::SocketException e) { … … 406 322 } catch (NRPEException e) { 407 323 NSC_LOG_ERROR_STD(_T("NRPEException: ") + e.getMessage()); 324 } catch (...) { 325 NSC_LOG_ERROR_STD(_T("Unhandled Exception in NRPE listner...")); 408 326 } 409 327 client->close(); … … 413 331 if (p.getType() != NRPEPacket::queryPacket) { 414 332 NSC_LOG_ERROR(_T("Request is not a query.")); 415 throw NRPEException(_T("Invalid query type "));333 throw NRPEException(_T("Invalid query type: ") + strEx::itos(p.getType())); 416 334 } 417 335 if (p.getVersion() != NRPEPacket::version2) { … … 470 388 ret = NSCAPI::returnUNKNOWN; 471 389 } 472 if (msg.length() > buffer_length_) {390 if (msg.length() >= buffer_length_) { 473 391 NSC_LOG_ERROR(_T("Truncating returndata as it is bigger then NRPE allowes :(")); 474 392 msg = msg.substr(0,buffer_length_-1); -
modules/NRPEListener/NRPEListener.h
r7a156f4 r394f7a1 24 24 #include <SSLSocket.h> 25 25 #include <map> 26 #include "NRPEPacket.h" 26 #include <nrpe/NRPEPacket.hpp> 27 #include <execute_process.hpp> 27 28 28 29 class NRPEListener : public simpleSocket::ListenerHandler { … … 48 49 std::wstring scriptDirectory_; 49 50 unsigned int buffer_length_; 51 std::wstring root_; 50 52 51 53 public: -
modules/NSCAAgent/NSCAAgent.cpp
r5ca3931 r394f7a1 45 45 * @return 46 46 */ 47 NSCAAgent::NSCAAgent() : pdhThread(_T("NSCAThread")){}47 NSCAAgent::NSCAAgent() {} 48 48 /** 49 49 * Default d-tor … … 57 57 */ 58 58 bool NSCAAgent::loadModule() { 59 pdhThread.createThread(); 60 std::list<std::wstring> checks = NSCModuleHelper::getSettingsSection(NSCA_CMD_SECTION_TITLE); 61 int interval = NSCModuleHelper::getSettingsInt(NSCA_AGENT_SECTION_TITLE, NSCA_INTERVAL, NSCA_INTERVAL_DEFAULT); 59 //pdhThread.createThread(); 60 //std::list<std::wstring> checks = NSCModuleHelper::getSettingsSection(NSCA_CMD_SECTION_TITLE); 61 //int interval = NSCModuleHelper::getSettingsInt(NSCA_AGENT_SECTION_TITLE, NSCA_INTERVAL, NSCA_INTERVAL_DEFAULT); 62 int e_threads = NSCModuleHelper::getSettingsInt(NSCA_AGENT_SECTION_TITLE, NSCA_DEBUG_THREADS, NSCA_DEBUG_THREADS_DEFAULT); 63 64 for (int i=1;i<e_threads;i++) { 65 std::wstring id = _T("nsca_t_") + strEx::itos(i); 66 NSCAThreadImpl *thread = new NSCAThreadImpl(id); 67 extra_threads.push_back(thread); 68 } 69 for (std::list<NSCAThreadImpl*>::const_iterator cit=extra_threads.begin();cit != extra_threads.end(); ++cit) { 70 (*cit)->createThread(reinterpret_cast<LPVOID>(rand())); 71 } 62 72 63 73 return true; … … 69 79 */ 70 80 bool NSCAAgent::unloadModule() { 81 /* 71 82 if (!pdhThread.exitThread(20000)) { 72 83 std::wcout << _T("MAJOR ERROR: Could not unload thread...") << std::endl; 73 84 NSC_LOG_ERROR(_T("Could not exit the thread, memory leak and potential corruption may be the result...")); 85 } 86 */ 87 for (std::list<NSCAThreadImpl*>::iterator it=extra_threads.begin();it != extra_threads.end(); ++it) { 88 if (!(*it)->exitThread(20000)) { 89 std::wcout << _T("MAJOR ERROR: Could not unload thread...") << std::endl; 90 NSC_LOG_ERROR(_T("Could not exit the thread, memory leak and potential corruption may be the result...")); 91 } 74 92 } 75 93 return true; -
modules/NSCAAgent/NSCAAgent.h
r5ca3931 r394f7a1 31 31 CheckMemory memoryChecker; 32 32 int processMethod_; 33 NSCAThreadImpl pdhThread; 33 // NSCAThreadImpl pdhThread; 34 std::list<NSCAThreadImpl*> extra_threads; 34 35 35 36 public: -
modules/NSCAAgent/NSCAThread.cpp
rc1fe385 r394f7a1 60 60 NSCAPI::nagiosReturn ret = NSCModuleHelper::InjectCommand(cmd_.c_str(), args_.getLen(), args_.get(), msg, perf); 61 61 result.service = alias_; 62 result.code = conv_code(ret);63 62 if (ret == NSCAPI::returnIgnored) { 64 63 result.result = _T("Command was not found: ") + cmd_; 64 result.code = NSCAPI::returnUNKNOWN; 65 65 } else if (ret == NSCAPI::returnInvalidBufferLen) { 66 66 result.result = _T("Result was to long: ") + cmd_; 67 result.code = NSCAPI::returnUNKNOWN; 67 68 } else { 68 69 result.result = msg + _T("|") + perf; 70 result.code = conv_code(ret); 69 71 if (result.result.length() >= NSCA_MAX_PLUGINOUTPUT_LENGTH) { 70 72 NSC_LOG_ERROR(_T("NSCA return data truncated")); … … 72 74 } 73 75 } 74 NSC_LOG_MESSAGE_STD(_T("Result: ") + result.toString());76 //NSC_DEBUG_MSG_STD(_T("Result: ") + result.toString()); 75 77 return result; 76 78 } … … 107 109 } 108 110 111 srand( reinterpret_cast<int>(lpParameter) ); 112 109 113 DWORD waitStatus = 0; 114 int drift = (checkIntervall_*rand())/RAND_MAX ; 115 NSC_LOG_ERROR_STD(_T("Drifting: ") + strEx::itos(drift)); 116 waitStatus = WaitForSingleObject(hStopEvent_, drift*1000); 117 if (waitStatus != WAIT_TIMEOUT) { 118 NSC_LOG_ERROR_STD(_T("Drift failed... strange...")); 119 } 120 NSC_LOG_ERROR_STD(_T("Done drifting: ") + strEx::itos(drift)); 110 121 int remain = checkIntervall_; 111 122 while (((waitStatus = WaitForSingleObject(hStopEvent_, remain*1000)) == WAIT_TIMEOUT)) { -
modules/NSCAAgent/nsca_enrypt.hpp
rce57b1b r394f7a1 92 92 /* generate an encryption/description key using the password */ 93 93 int keysize=get_keySize(); 94 std::cout << "keysize: " << keysize << std::endl;95 94 96 95 unsigned char *key = new unsigned char[keysize+1];
Note: See TracChangeset
for help on using the changeset viewer.








