Changeset 452fd41 in nscp
- Timestamp:
- 03/28/05 12:24:08 (8 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- aaa9a22
- Parents:
- 1a5449e
- Files:
-
- 1 added
- 31 edited
-
NSClient++.cpp (modified) (5 diffs)
-
NSClient++.h (modified) (1 diff)
-
NSClient++.sln (modified) (3 diffs)
-
NSClient++.vcproj (modified) (7 diffs)
-
StdAfx.h (modified) (1 diff)
-
changelog (modified) (1 diff)
-
dist_dll/placeholder.txt (added)
-
include/Socket.cpp (modified) (4 diffs)
-
include/Socket.h (modified) (3 diffs)
-
include/strEx.h (modified) (1 diff)
-
include/thread.h (modified) (8 diffs)
-
modules/CheckDisk/CheckDisk.vcproj (modified) (2 diffs)
-
modules/CheckEventLog/CheckEventLog.vcproj (modified) (3 diffs)
-
modules/FileLogger/FileLogger.cpp (modified) (1 diff)
-
modules/FileLogger/FileLogger.vcproj (modified) (2 diffs)
-
modules/NRPEListener/NRPEListener.cpp (modified) (4 diffs)
-
modules/NRPEListener/NRPEListener.vcproj (modified) (3 diffs)
-
modules/NRPEListener/NRPESocket.cpp (modified) (3 diffs)
-
modules/NRPEListener/NRPESocket.h (modified) (2 diffs)
-
modules/NRPEListener/stdafx.h (modified) (1 diff)
-
modules/NSClientCompat/NSClientCompat.cpp (modified) (6 diffs)
-
modules/NSClientCompat/NSClientCompat.h (modified) (1 diff)
-
modules/NSClientCompat/NSClientCompat.vcproj (modified) (2 diffs)
-
modules/NSClientCompat/PDHCollector.cpp (modified) (4 diffs)
-
modules/NSClientCompat/PDHCollector.h (modified) (1 diff)
-
modules/NSClientListener/NSClientListener.cpp (modified) (2 diffs)
-
modules/NSClientListener/NSClientListener.vcproj (modified) (2 diffs)
-
modules/NSClientListener/NSClientSocket.cpp (modified) (2 diffs)
-
modules/NSClientListener/NSClientSocket.h (modified) (3 diffs)
-
modules/SysTray/SysTray.cpp (modified) (1 diff)
-
modules/SysTray/SysTray.vcproj (modified) (2 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
NSClient++.cpp
r1a5449e r452fd41 18 18 #include "Settings.h" 19 19 #include <charEx.h> 20 #include <Socket.h> 20 21 21 22 NSClient mainClient; // Global core instance. … … 107 108 Settings::getInstance()->setFile(getBasePath() + "NSC.ini"); 108 109 110 try { 111 simpleSocket::Socket::WSAStartup(); 112 } catch (simpleSocket::SocketException e) { 113 LOG_ERROR_STD("Uncaught exception: " + e.getMessage()); 114 } 115 109 116 SettingsT::sectionList list = Settings::getInstance()->getSection("modules"); 110 117 for (SettingsT::sectionList::iterator it = list.begin(); it != list.end(); it++) { … … 123 130 void NSClientT::TerminateService(void) { 124 131 try { 125 LOG_DEBUG("Socket closed, unloading plugins...");126 132 mainClient.unloadPlugins(); 127 133 LOG_DEBUG("Plugins unloaded..."); 128 134 } catch(NSPluginException *e) { 129 135 std::cout << "Exception raised: " << e->error_ << " in module: " << e->file_ << std::endl;; 136 } 137 try { 138 simpleSocket::Socket::WSACleanup(); 139 } catch (simpleSocket::SocketException e) { 140 LOG_ERROR_STD("Uncaught exception: " + e.getMessage()); 130 141 } 131 142 Settings::destroyInstance(); … … 229 240 NSCAPI::nagiosReturn NSClientT::injectRAW(const char* command, const unsigned int argLen, char **argument, char *returnMessageBuffer, unsigned int returnMessageBufferLen, char *returnPerfBuffer, unsigned int returnPerfBufferLen) { 230 241 MutexLock lock(pluginMutex); 231 232 LOG_MESSAGE_STD("Injecting: " + command);233 242 234 243 pluginList::const_iterator plit; … … 263 272 } 264 273 /** 265 * Helper function to return the current password (perhaps this should be static ?)266 *267 * @return The current password268 */269 std::string NSClientT::getPassword() {270 return Settings::getInstance()->getString("generic", "password", "");271 }272 /**273 * Execute a command.274 *275 * @param password The password276 * @param cmd The command277 * @param args Arguments as a list<string>278 * @return The result if any, empty string if no result.279 *280 * @todo Make an int return value to set critical/warning/ok/unknown status.281 * ie. pair<int,string>282 */283 /*284 std::string NSClientT::execute(std::string password, std::string cmd, std::list<std::string> args) {285 MutexLock lock(pluginMutex);286 if (!lock.hasMutex()) {287 LOG_ERROR("FATAL ERROR: Could not execute command with a reasonable timeframe. (could not get mutex so core is most likely locked down).");288 return "ERROR: Core was locked down";289 }290 static unsigned int bufferSize = 0;291 if (bufferSize == 0)292 bufferSize = static_cast<unsigned int>(Settings::getInstance()->getInt("main", "bufferSize", 4096));293 294 if (password != getPassword())295 return "ERROR: Authorization denied.";296 297 std::string ret;298 unsigned int len;299 char **arguments = NSCHelper::list2arrayBuffer(args, len);300 // Allocate return buffer301 char* returnbuffer = new char[bufferSize+1];302 pluginList::const_iterator plit;303 for (plit = commandHandlers_.begin(); plit != commandHandlers_.end(); ++plit) {304 try {305 int c = (*plit)->handleCommand(cmd.c_str(), len, arguments, returnbuffer, bufferSize);306 if (c == NSCAPI::handled) { // module handled the message "we are done..."307 ret = returnbuffer;308 break;309 } else if (c == NSCAPI::isfalse) { // Module ignored the message310 LOG_DEBUG("A module ignored this message");311 } else if (c == NSCAPI::invalidBufferLen) { // Buffer is to small312 LOG_ERROR("Return buffer to small, need to increase it in the ini file.");313 } else { // Something else went wrong...314 LOG_ERROR_STD("Unknown error from handleCommand: " + strEx::itos(c));315 }316 } catch(const NSPluginException& e) {317 LOG_ERROR_STD("Exception raised: " + e.error_ + " in module: " + e.file_);318 }319 }320 // delete buffers321 delete [] returnbuffer;322 NSCHelper::destroyArrayBuffer(arguments, len);323 return ret;324 }325 */326 /**327 274 * Report a message to all logging enabled modules. 328 275 * -
NSClient++.h
r1a5449e r452fd41 57 57 58 58 // Member functions 59 static std::string getPassword(void);60 59 std::string getBasePath(void); 61 60 NSCAPI::nagiosReturn injectRAW(const char* command, const unsigned int argLen, char **argument, char *returnMessageBuffer, unsigned int returnMessageBufferLen, char *returnPerfBuffer, unsigned int returnPerfBufferLen); -
NSClient++.sln
r2a94f3f r452fd41 2 2 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NSClient++", "NSClient++.vcproj", "{2286162D-7571-4735-BAC8-4A8D33A4F42D}" 3 3 ProjectSection(ProjectDependencies) = postProject 4 {BA246C01-063A-4548-8957-32D5CC76171B} = {BA246C01-063A-4548-8957-32D5CC76171B} 5 {BBFF8362-C626-4838-B0A2-F695D638AD24} = {BBFF8362-C626-4838-B0A2-F695D638AD24} 6 {08D6246D-1B4A-47A3-965D-296DCC54A4E8} = {08D6246D-1B4A-47A3-965D-296DCC54A4E8} 7 {79F1F571-78A6-4B20-8BD5-0F65CD60012C} = {79F1F571-78A6-4B20-8BD5-0F65CD60012C} 8 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45} = {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45} 9 {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F} = {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F} 10 {2FF60AF6-09AA-49AB-B414-2E8FD01655C6} = {2FF60AF6-09AA-49AB-B414-2E8FD01655C6} 4 11 EndProjectSection 5 12 EndProject … … 38 45 GlobalSection(SolutionConfiguration) = preSolution 39 46 Debug = Debug 47 Distribution = Distribution 40 48 Release = Release 41 49 EndGlobalSection … … 43 51 {2286162D-7571-4735-BAC8-4A8D33A4F42D}.Debug.ActiveCfg = Debug|Win32 44 52 {2286162D-7571-4735-BAC8-4A8D33A4F42D}.Debug.Build.0 = Debug|Win32 53 {2286162D-7571-4735-BAC8-4A8D33A4F42D}.Distribution.ActiveCfg = Distribution|Win32 54 {2286162D-7571-4735-BAC8-4A8D33A4F42D}.Distribution.Build.0 = Distribution|Win32 45 55 {2286162D-7571-4735-BAC8-4A8D33A4F42D}.Release.ActiveCfg = Release|Win32 46 56 {2286162D-7571-4735-BAC8-4A8D33A4F42D}.Release.Build.0 = Release|Win32 47 57 {BBFF8362-C626-4838-B0A2-F695D638AD24}.Debug.ActiveCfg = Debug|Win32 48 58 {BBFF8362-C626-4838-B0A2-F695D638AD24}.Debug.Build.0 = Debug|Win32 59 {BBFF8362-C626-4838-B0A2-F695D638AD24}.Distribution.ActiveCfg = Distribution|Win32 60 {BBFF8362-C626-4838-B0A2-F695D638AD24}.Distribution.Build.0 = Distribution|Win32 49 61 {BBFF8362-C626-4838-B0A2-F695D638AD24}.Release.ActiveCfg = Release|Win32 50 62 {BBFF8362-C626-4838-B0A2-F695D638AD24}.Release.Build.0 = Release|Win32 51 63 {79F1F571-78A6-4B20-8BD5-0F65CD60012C}.Debug.ActiveCfg = Debug|Win32 52 64 {79F1F571-78A6-4B20-8BD5-0F65CD60012C}.Debug.Build.0 = Debug|Win32 65 {79F1F571-78A6-4B20-8BD5-0F65CD60012C}.Distribution.ActiveCfg = Distribution|Win32 66 {79F1F571-78A6-4B20-8BD5-0F65CD60012C}.Distribution.Build.0 = Distribution|Win32 53 67 {79F1F571-78A6-4B20-8BD5-0F65CD60012C}.Release.ActiveCfg = Release|Win32 54 68 {79F1F571-78A6-4B20-8BD5-0F65CD60012C}.Release.Build.0 = Release|Win32 55 69 {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Debug.ActiveCfg = Debug|Win32 56 70 {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Debug.Build.0 = Debug|Win32 71 {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Distribution.ActiveCfg = Distribution|Win32 72 {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Distribution.Build.0 = Distribution|Win32 57 73 {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Release.ActiveCfg = Release|Win32 58 74 {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Release.Build.0 = Release|Win32 59 75 {BA246C01-063A-4548-8957-32D5CC76171B}.Debug.ActiveCfg = Debug|Win32 60 76 {BA246C01-063A-4548-8957-32D5CC76171B}.Debug.Build.0 = Debug|Win32 77 {BA246C01-063A-4548-8957-32D5CC76171B}.Distribution.ActiveCfg = Distribution|Win32 78 {BA246C01-063A-4548-8957-32D5CC76171B}.Distribution.Build.0 = Distribution|Win32 61 79 {BA246C01-063A-4548-8957-32D5CC76171B}.Release.ActiveCfg = Release|Win32 62 80 {BA246C01-063A-4548-8957-32D5CC76171B}.Release.Build.0 = Release|Win32 63 81 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug.ActiveCfg = Debug Dynamic Linkage|Win32 64 82 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug.Build.0 = Debug Dynamic Linkage|Win32 83 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Distribution.ActiveCfg = Distribution|Win32 84 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Distribution.Build.0 = Distribution|Win32 65 85 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Release.ActiveCfg = Dynamic Linkage|Win32 66 86 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Release.Build.0 = Dynamic Linkage|Win32 67 87 {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Debug.ActiveCfg = Debug|Win32 68 88 {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Debug.Build.0 = Debug|Win32 89 {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Distribution.ActiveCfg = Distribution|Win32 90 {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Distribution.Build.0 = Distribution|Win32 69 91 {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Release.ActiveCfg = Release|Win32 70 92 {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Release.Build.0 = Release|Win32 71 93 {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Debug.ActiveCfg = Debug|Win32 72 94 {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Debug.Build.0 = Debug|Win32 95 {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Distribution.ActiveCfg = Distribution|Win32 96 {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Distribution.Build.0 = Distribution|Win32 73 97 {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Release.ActiveCfg = Release|Win32 74 98 {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Release.Build.0 = Release|Win32 -
NSClient++.vcproj
r1a5449e r452fd41 40 40 SuppressStartupBanner="TRUE"/> 41 41 <Tool 42 Name="VCCustomBuildTool"/> 42 Name="VCCustomBuildTool" 43 CommandLine="echo Copying dependency DLLs 44 cmd /c "copy $(InputDir)\dist_dll\*.* $(InputDir)\$(OutDir)\"" 45 Outputs="$(InputDir)\$(OutDir)\msvcp71.dll"/> 43 46 <Tool 44 47 Name="VCLinkerTool" … … 143 146 Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 144 147 </Configuration> 148 <Configuration 149 Name="Distribution|Win32" 150 OutputDirectory="$(ConfigurationName)" 151 IntermediateDirectory="$(ConfigurationName)" 152 ConfigurationType="1" 153 UseOfMFC="0" 154 ATLMinimizesCRunTimeLibraryUsage="FALSE" 155 CharacterSet="2"> 156 <Tool 157 Name="VCCLCompilerTool" 158 Optimization="2" 159 InlineFunctionExpansion="1" 160 AdditionalIncludeDirectories="include" 161 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" 162 StringPooling="TRUE" 163 RuntimeLibrary="2" 164 EnableFunctionLevelLinking="TRUE" 165 UsePrecompiledHeader="3" 166 PrecompiledHeaderThrough="stdafx.h" 167 PrecompiledHeaderFile=".\Release/IconService.pch" 168 AssemblerListingLocation=".\Release/" 169 ObjectFile=".\Release/" 170 ProgramDataBaseFileName=".\Release/" 171 WarningLevel="3" 172 SuppressStartupBanner="TRUE"/> 173 <Tool 174 Name="VCCustomBuildTool" 175 CommandLine="echo Copying dependency DLLs 176 cmd /c "copy $(InputDir)\dist_dll\*.dll $(InputDir)\Dist\" 177 echo Removing old archive 178 cmd /c "del $(InputDir)\Dist\$(InputName).zip" 179 echo Making archive 180 7z.exe a -r -tzip -bd $(InputDir)\Dist\$(InputName).zip $(InputDir)\Dist\*" 181 Outputs="$(InputDir)\Dist\$(ProjectName).zip"/> 182 <Tool 183 Name="VCLinkerTool" 184 AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib" 185 OutputFile=".\Dist/NSClient++.exe" 186 LinkIncremental="1" 187 SuppressStartupBanner="TRUE" 188 IgnoreAllDefaultLibraries="FALSE" 189 IgnoreDefaultLibraryNames="" 190 ModuleDefinitionFile="" 191 ProgramDatabaseFile=".\Release/IconService.pdb" 192 SubSystem="1" 193 OptimizeForWindows98="1" 194 TargetMachine="1"/> 195 <Tool 196 Name="VCMIDLTool" 197 TypeLibraryName=".\Release/IconService.tlb" 198 HeaderFileName=""/> 199 <Tool 200 Name="VCPostBuildEventTool"/> 201 <Tool 202 Name="VCPreBuildEventTool"/> 203 <Tool 204 Name="VCPreLinkEventTool"/> 205 <Tool 206 Name="VCResourceCompilerTool" 207 PreprocessorDefinitions="NDEBUG" 208 Culture="1036" 209 AdditionalIncludeDirectories="./res/"/> 210 <Tool 211 Name="VCWebServiceProxyGeneratorTool"/> 212 <Tool 213 Name="VCXMLDataGeneratorTool"/> 214 <Tool 215 Name="VCWebDeploymentTool"/> 216 <Tool 217 Name="VCManagedWrapperGeneratorTool"/> 218 <Tool 219 Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 220 </Configuration> 145 221 </Configurations> 146 222 <References> … … 187 263 UsePrecompiledHeader="1"/> 188 264 </FileConfiguration> 265 <FileConfiguration 266 Name="Distribution|Win32"> 267 <Tool 268 Name="VCCLCompilerTool" 269 Optimization="2" 270 PreprocessorDefinitions="" 271 UsePrecompiledHeader="1"/> 272 </FileConfiguration> 189 273 </File> 190 274 </Filter> … … 199 283 </File> 200 284 <File 201 RelativePath=".\ config.h">285 RelativePath=".\include\config.h"> 202 286 </File> 203 287 <File … … 238 322 <File 239 323 RelativePath=".\changelog"> 324 <FileConfiguration 325 Name="Distribution|Win32"> 326 <Tool 327 Name="VCCustomBuildTool" 328 CommandLine="echo Copying $(InputFileName)... 329 cmd /c "copy $(InputDir)\$(InputName) $(InputDir)\Dist\"" 330 Outputs="$(InputDir)\Dist\$(InputFileName)"/> 331 </FileConfiguration> 240 332 </File> 241 333 <File 242 334 RelativePath=".\Doxyfile"> 243 335 <FileConfiguration 244 Name="Release|Win32"> 336 Name="Release|Win32" 337 ExcludedFromBuild="TRUE"> 245 338 <Tool 246 339 Name="VCCustomBuildTool" … … 257 350 "/> 258 351 </FileConfiguration> 352 <FileConfiguration 353 Name="Distribution|Win32" 354 ExcludedFromBuild="TRUE"> 355 <Tool 356 Name="VCCustomBuildTool" 357 CommandLine="doxygen.exe $(InputPath) 358 " 359 Outputs=".\Doc"/> 360 </FileConfiguration> 259 361 </File> 260 362 <File … … 264 366 RelativePath=".\NSC.ini"> 265 367 <FileConfiguration 266 Name="Release|Win32" 267 ExcludedFromBuild="TRUE">268 <Tool269 Name="VCCustomBuildTool"270 CommandLine="copy $(InputPath) $(OutDir)\$(InputFileName) 368 Name="Release|Win32"> 369 <Tool 370 Name="VCCustomBuildTool" 371 CommandLine="echo Copying $(InputFileName)... 372 cmd /c "copy $(InputDir)\$(InputFileName) $(InputDir)\$(OutDir)" 271 373 " 272 374 AdditionalDependencies="" 273 Outputs="$( OutDir)\$(InputFileName)"/>274 </FileConfiguration> 275 <FileConfiguration 276 Name="Debug|Win32" 277 ExcludedFromBuild="TRUE">278 <Tool279 Name="VCCustomBuildTool"280 CommandLine="copy $(InputPath) $(OutDir)\$(InputFileName) 375 Outputs="$(InputDir)\$(OutDir)\$(InputFileName)"/> 376 </FileConfiguration> 377 <FileConfiguration 378 Name="Debug|Win32"> 379 <Tool 380 Name="VCCustomBuildTool" 381 CommandLine="echo Copying $(InputFileName)... 382 cmd /c "copy $(InputDir)\$(InputFileName) $(InputDir)\$(OutDir)" 281 383 " 282 Outputs="$(OutDir)\$(InputFileName)"/> 384 Outputs="$(InputDir)\$(OutDir)\$(InputFileName)"/> 385 </FileConfiguration> 386 <FileConfiguration 387 Name="Distribution|Win32"> 388 <Tool 389 Name="VCCustomBuildTool" 390 CommandLine="echo Copying $(InputFileName)... 391 cmd /c "copy $(InputDir)\$(InputFileName) $(InputDir)\Dist\"" 392 AdditionalDependencies="" 393 Outputs="$(InputDir)\Dist\$(InputFileName)"/> 394 </FileConfiguration> 395 </File> 396 <File 397 RelativePath=".\readme.txt"> 398 <FileConfiguration 399 Name="Release|Win32"> 400 <Tool 401 Name="VCCustomBuildTool" 402 CommandLine="" 403 Outputs=""/> 404 </FileConfiguration> 405 <FileConfiguration 406 Name="Debug|Win32"> 407 <Tool 408 Name="VCCustomBuildTool" 409 CommandLine="" 410 Outputs=""/> 411 </FileConfiguration> 412 <FileConfiguration 413 Name="Distribution|Win32"> 414 <Tool 415 Name="VCCustomBuildTool" 416 CommandLine="echo Copying $(InputFileName)... 417 cmd /c "copy $(InputDir)\$(InputFileName) $(InputDir)\Dist\"" 418 Outputs="$(InputDir)\Dist\$(InputFileName)"/> 283 419 </FileConfiguration> 284 420 </File> -
StdAfx.h
r55159fd r452fd41 12 12 13 13 #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers 14 #include < winsock2.h>14 #include <WinSock2.h> 15 15 #include <windows.h> 16 16 -
changelog
r1a5449e r452fd41 1 2005-03-28 MickeM 2 * Changed the Thread class a bit (mutex -> signal, and CreatThread does not return the instance) 3 * Moved settings "keys" fro NRPE to config.h 4 * Changed build options (added Distribution) which builds a zip file under ./dist (requires 7z installed) 5 * Minor tweaks to error/debug logging and small fixes "here and there" 6 1 7 2005-03-26 MickeM 2 8 + NRPE Support (very basic, no encryption, and nothing fancy) -
include/Socket.cpp
r1a5449e r452fd41 31 31 core->listen(10); 32 32 core->ioctlsocket(FIONBIO, &NoBlock); 33 34 NSC_DEBUG_MSG_STD("Currently listeneing to: " + strEx::itos(core->port_));35 36 33 while (!(WaitForSingleObject(hStopEvent, 100) == WAIT_OBJECT_0)) { 37 34 Socket client; … … 42 39 NSC_LOG_ERROR_STD(e.getMessage()); 43 40 } 44 45 CloseHandle(hStopEvent); 46 NSC_DEBUG_MSG("Socket closed!"); 41 HANDLE hTmp = hStopEvent; 42 hStopEvent = NULL; 43 BOOL b = CloseHandle(hTmp); 44 assert(b); 47 45 return 0; 48 46 } … … 54 52 */ 55 53 void simpleSocket::Listener::ListenerThread::exitThread(void) { 56 NSC_DEBUG_MSG("Requesting Socket shutdown!");54 assert(hStopEvent); 57 55 if (!SetEvent(hStopEvent)) { 58 56 NSC_LOG_ERROR_STD("SetStopEvent failed"); … … 85 83 } 86 84 void simpleSocket::Listener::close() { 87 threadManager_.exitThread(); 85 if (threadManager_.hasActiveThread()) 86 if (!threadManager_.exitThread()) 87 throw new SocketException("Could not terminate thread."); 88 88 Socket::close(); 89 89 } -
include/Socket.h
r1a5449e r452fd41 63 63 Socket(Socket &other) { 64 64 socket_ = other.socket_; 65 from_ = other.from_; 65 66 other.socket_ = NULL; 66 67 } … … 74 75 } 75 76 virtual void close() { 76 assert(socket_);77 closesocket(socket_);77 if (socket_) 78 closesocket(socket_); 78 79 socket_ = NULL; 79 80 } … … 115 116 if (::ioctlsocket(socket_, cmd, argp) == SOCKET_ERROR) 116 117 throw SocketException("ioctlsocket failed: ", ::WSAGetLastError()); 118 } 119 std::string getAddrString() { 120 return inet_ntoa(from_.sin_addr); 117 121 } 118 122 -
include/strEx.h
r1a5449e r452fd41 62 62 return itos(i>>24)+"B"; 63 63 } 64 65 typedef std::list<std::string> splitList; 66 inline splitList splitEx(std::string str, std::string key) { 67 splitList ret; 68 std::string::size_type pos = 0, lpos = 0; 69 while ((pos = str.find(key, pos)) != std::string::npos) { 70 ret.push_back(str.substr(lpos, pos-lpos)); 71 lpos = ++pos; 72 } 73 if (lpos < str.size()) 74 ret.push_back(str.substr(lpos)); 75 return ret; 76 } 77 64 78 inline std::pair<std::string,std::string> split(std::string str, std::string key) { 65 79 std::string::size_type pos = str.find(key); -
include/thread.h
r36c340d r452fd41 1 // Thread.h: interface for the Thread class.2 //3 //////////////////////////////////////////////////////////////////////4 5 1 #pragma once 6 7 8 /**9 * @ingroup NSClientCompat10 * Simple unnamed mutex to handle thread exit wait (used by the Thread class below)11 *12 * @version 1.013 * first version14 *15 * @date 02-13-200516 *17 * @author mickem18 *19 * @par license20 * This code is absolutely free to use and modify. The code is provided "as is" with21 * no expressed or implied warranty. The author accepts no liability if it causes22 * any damage to your computer, causes your pet to fall ill, increases baldness23 * or makes your car start emitting strange noises when you start it up.24 * This code has no bugs, just undocumented features!25 *26 */27 class UnnamedMutex {28 private:29 HANDLE hMutex_;30 public:31 /**32 * Default c-tor.33 * Creates an unnamed mutex with a given owner status34 * @param owner true if we want to become owner of the mutex35 */36 UnnamedMutex(bool owner = false) {37 hMutex_ = ::CreateMutex(NULL, owner, NULL);38 }39 /**40 * Default d-tor.41 * Closes the mutex42 */43 virtual ~UnnamedMutex() {44 CloseHandle(hMutex_);45 }46 /**47 * Wait for the mutex or timeout in dwMilliseconds milliseconds.48 * @param dwMilliseconds The timeout value49 * @return status50 */51 DWORD wait(DWORD dwMilliseconds = 0L) {52 return ::WaitForSingleObject(hMutex_, dwMilliseconds);53 }54 /**55 * Release the mutex56 * @return status57 */58 BOOL free() {59 return ::ReleaseMutex(hMutex_);60 }61 };62 2 63 3 /** … … 89 29 HANDLE hThread_; // Thread handle 90 30 DWORD dwThreadID_; // Thread ID 91 UnnamedMutex endMutext; // mutex to wait for end of thread92 31 T* pObject_; // Wrapped object 32 HANDLE hStopEvent_; // Event to signal that the thread has stopped 93 33 94 34 typedef struct thread_param { 95 Thread* core;96 T *instance; 97 LPVOID lpParam; 35 Thread* manager; // The thread manager 36 T *instance; // The thread instance object 37 LPVOID lpParam; // The optional argument to the thread 98 38 } thread_param; 99 39 … … 103 43 * Sets up default values 104 44 */ 105 Thread() : endMutext(false), hThread_(NULL), dwThreadID_(0), pObject_(NULL) {}45 Thread() : hThread_(NULL), dwThreadID_(0), pObject_(NULL), hStopEvent_(NULL) {} 106 46 /** 107 47 * Default d-tor. … … 112 52 if (hThread_) 113 53 CloseHandle(hThread_); 54 if (hStopEvent_) 55 CloseHandle(hStopEvent_); 114 56 } 115 57 … … 125 67 thread_param* param = static_cast<thread_param*>(lpParameter); 126 68 T* instance = param->instance; 127 Thread * core = param->core;69 Thread *manager = param->manager; 128 70 LPVOID lpParam = param->lpParam; 129 71 delete param; 130 core->endMutext.wait(); 72 73 assert(manager->hStopEvent_); 131 74 DWORD ret = instance->threadProc(lpParam); 132 core->endMutext.free(); 133 return 0; 75 BOOL b = SetEvent(manager->hStopEvent_); 76 assert(b); 77 return ret; 134 78 } 135 79 … … 142 86 * @param lpParam An argument to the thread 143 87 * @return An instance of the thread object. 144 * @throws char145 88 * @bug the object return thing is *unsafe* and should be changed (if the thread is terminated that pointer is invalidated without any signal). 146 89 */ 147 T*createThread(LPVOID lpParam = NULL) {148 if (pObject_)149 throw "Could not create thread";90 void createThread(LPVOID lpParam = NULL) { 91 assert(pObject_ == NULL); 92 assert(hStopEvent_ == NULL); 150 93 pObject_ = new T; 151 94 thread_param* param = new thread_param; 152 95 param->instance = pObject_; 153 param-> core= this;96 param->manager = this; 154 97 param->lpParam = lpParam; 98 hStopEvent_ = CreateEvent(NULL, TRUE, FALSE, NULL); 155 99 hThread_ = ::CreateThread(NULL,0,threadProc,reinterpret_cast<VOID*>(param),0,&dwThreadID_); 156 return pObject_;157 100 } 158 101 /** … … 162 105 */ 163 106 bool exitThread(const unsigned int delay = 5000L) { 164 if (!pObject_)165 throw "Could not terminate thread, has not been started yet...";107 assert(pObject_ != NULL); 108 assert(hStopEvent_ != NULL); 166 109 pObject_->exitThread(); 167 DWORD dwWaitResult = endMutext.wait(delay); 110 111 DWORD dwWaitResult = WaitForSingleObject(hStopEvent_, delay); 168 112 switch (dwWaitResult) { 169 113 // The thread got mutex ownership. 170 114 case WAIT_OBJECT_0: 171 // TODO: Potential race condition if multipåle threads try to terminate the thread... 172 delete pObject_; 173 pObject_ = NULL; 174 endMutext.free(); 115 { 116 // @todo pObject should be protected! 117 HANDLE hTmp = hStopEvent_; 118 T* pTmp = pObject_; 119 pObject_ = NULL; 120 delete pTmp; 121 hStopEvent_ = NULL; 122 CloseHandle(hTmp); 123 } 175 124 return true; 176 // Cannot get mutex ownershipdue to time-out.125 // Did not get a signal due to time-out. 177 126 case WAIT_TIMEOUT: 178 127 return false; 179 128 180 // Got ownership of the abandoned mutex object.129 // Never got a signal. 181 130 case WAIT_ABANDONED: 182 131 return false; … … 184 133 return false; 185 134 } 135 bool hasActiveThread() const { 136 // @todo pObject should be protected! 137 return pObject_ != NULL; 138 } 139 const T* getThreadConst() const { 140 // @todo pObject should be protected! 141 return pObject_; 142 } 143 T* getThread() const { 144 // @todo pObject should be protected! 145 return pObject_; 146 } 186 147 }; 187 148 -
modules/CheckDisk/CheckDisk.vcproj
r1a5449e r452fd41 211 211 Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 212 212 </Configuration> 213 <Configuration 214 Name="Distribution|Win32" 215 OutputDirectory="$(ConfigurationName)" 216 IntermediateDirectory="$(ConfigurationName)" 217 ConfigurationType="2" 218 CharacterSet="2"> 219 <Tool 220 Name="VCCLCompilerTool" 221 AdditionalIncludeDirectories="../include;../../include" 222 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" 223 RuntimeLibrary="2" 224 UsePrecompiledHeader="3" 225 WarningLevel="3" 226 Detect64BitPortabilityProblems="TRUE" 227 DebugInformationFormat="3"/> 228 <Tool 229 Name="VCCustomBuildTool"/> 230 <Tool 231 Name="VCLinkerTool" 232 OutputFile="../../Dist/modules/$(ProjectName).dll" 233 LinkIncremental="1" 234 ModuleDefinitionFile="CheckDisk.def" 235 GenerateDebugInformation="TRUE" 236 SubSystem="2" 237 OptimizeReferences="2" 238 EnableCOMDATFolding="2" 239 ImportLibrary="$(OutDir)/CheckDisk.lib" 240 TargetMachine="1"/> 241 <Tool 242 Name="VCMIDLTool"/> 243 <Tool 244 Name="VCPostBuildEventTool"/> 245 <Tool 246 Name="VCPreBuildEventTool"/> 247 <Tool 248 Name="VCPreLinkEventTool"/> 249 <Tool 250 Name="VCResourceCompilerTool"/> 251 <Tool 252 Name="VCWebServiceProxyGeneratorTool"/> 253 <Tool 254 Name="VCXMLDataGeneratorTool"/> 255 <Tool 256 Name="VCWebDeploymentTool"/> 257 <Tool 258 Name="VCManagedWrapperGeneratorTool"/> 259 <Tool 260 Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 261 </Configuration> 213 262 </Configurations> 214 263 <References> … … 250 299 <FileConfiguration 251 300 Name="Debug Dynamic Linkage|Win32"> 301 <Tool 302 Name="VCCLCompilerTool" 303 UsePrecompiledHeader="1"/> 304 </FileConfiguration> 305 <FileConfiguration 306 Name="Distribution|Win32"> 252 307 <Tool 253 308 Name="VCCLCompilerTool" -
modules/CheckEventLog/CheckEventLog.vcproj
r1a5449e r452fd41 71 71 Optimization="0" 72 72 AdditionalIncludeDirectories="../include;../../include" 73 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_STLP_USE_NEWALLOC;_STLP_DEBUG=1 "73 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_STLP_USE_NEWALLOC;_STLP_DEBUG=1;BOOST_REGEX_DYN_LINK" 74 74 MinimalRebuild="TRUE" 75 75 BasicRuntimeChecks="3" … … 89 89 ProgramDatabaseFile="$(OutDir)/CheckEventLog.pdb" 90 90 SubSystem="2" 91 ImportLibrary="$(OutDir)/CheckEventLog.lib" 92 TargetMachine="1"/> 93 <Tool 94 Name="VCMIDLTool"/> 95 <Tool 96 Name="VCPostBuildEventTool"/> 97 <Tool 98 Name="VCPreBuildEventTool" 99 ExcludedFromBuild="TRUE"/> 100 <Tool 101 Name="VCPreLinkEventTool"/> 102 <Tool 103 Name="VCResourceCompilerTool"/> 104 <Tool 105 Name="VCWebServiceProxyGeneratorTool"/> 106 <Tool 107 Name="VCXMLDataGeneratorTool"/> 108 <Tool 109 Name="VCWebDeploymentTool"/> 110 <Tool 111 Name="VCManagedWrapperGeneratorTool"/> 112 <Tool 113 Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 114 </Configuration> 115 <Configuration 116 Name="Distribution|Win32" 117 OutputDirectory="$(ConfigurationName)" 118 IntermediateDirectory="$(ConfigurationName)" 119 ConfigurationType="2" 120 CharacterSet="2"> 121 <Tool 122 Name="VCCLCompilerTool" 123 AdditionalIncludeDirectories="../include;../../include" 124 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;BOOST_REGEX_DYN_LINK" 125 RuntimeLibrary="2" 126 UsePrecompiledHeader="3" 127 WarningLevel="3" 128 Detect64BitPortabilityProblems="TRUE" 129 DebugInformationFormat="3"/> 130 <Tool 131 Name="VCCustomBuildTool"/> 132 <Tool 133 Name="VCLinkerTool" 134 OutputFile="../../Dist/modules/$(ProjectName).dll" 135 LinkIncremental="1" 136 ModuleDefinitionFile="CheckEventLog.def" 137 GenerateDebugInformation="TRUE" 138 SubSystem="2" 139 OptimizeReferences="2" 140 EnableCOMDATFolding="2" 91 141 ImportLibrary="$(OutDir)/CheckEventLog.lib" 92 142 TargetMachine="1"/> … … 144 194 UsePrecompiledHeader="1"/> 145 195 </FileConfiguration> 196 <FileConfiguration 197 Name="Distribution|Win32"> 198 <Tool 199 Name="VCCLCompilerTool" 200 UsePrecompiledHeader="1"/> 201 </FileConfiguration> 146 202 </File> 147 203 </Filter> -
modules/FileLogger/FileLogger.cpp
ra0528c4 r452fd41 26 26 } 27 27 std::string FileLogger::getModuleName() { 28 return " Simple console logger (used for debug purposes).";28 return "File logger: " + NSCModuleHelper::getSettingsString("log", "file", "nsclient.log"); 29 29 } 30 30 NSCModuleWrapper::module_version FileLogger::getModuleVersion() { -
modules/FileLogger/FileLogger.vcproj
r1a5449e r452fd41 111 111 Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 112 112 </Configuration> 113 <Configuration 114 Name="Distribution|Win32" 115 OutputDirectory="$(ConfigurationName)" 116 IntermediateDirectory="$(ConfigurationName)" 117 ConfigurationType="2" 118 CharacterSet="2"> 119 <Tool 120 Name="VCCLCompilerTool" 121 AdditionalIncludeDirectories="../include;../../include" 122 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" 123 RuntimeLibrary="2" 124 UsePrecompiledHeader="3" 125 WarningLevel="3" 126 Detect64BitPortabilityProblems="TRUE" 127 DebugInformationFormat="3"/> 128 <Tool 129 Name="VCCustomBuildTool"/> 130 <Tool 131 Name="VCLinkerTool" 132 OutputFile="../../Dist/modules/$(ProjectName).dll" 133 LinkIncremental="1" 134 ModuleDefinitionFile="FileLogger.def" 135 GenerateDebugInformation="TRUE" 136 SubSystem="2" 137 OptimizeReferences="2" 138 EnableCOMDATFolding="2" 139 ImportLibrary="$(OutDir)/FileLogger.lib" 140 TargetMachine="1"/> 141 <Tool 142 Name="VCMIDLTool"/> 143 <Tool 144 Name="VCPostBuildEventTool"/> 145 <Tool 146 Name="VCPreBuildEventTool"/> 147 <Tool 148 Name="VCPreLinkEventTool"/> 149 <Tool 150 Name="VCResourceCompilerTool"/> 151 <Tool 152 Name="VCWebServiceProxyGeneratorTool"/> 153 <Tool 154 Name="VCXMLDataGeneratorTool"/> 155 <Tool 156 Name="VCWebDeploymentTool"/> 157 <Tool 158 Name="VCManagedWrapperGeneratorTool"/> 159 <Tool 160 Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 161 </Configuration> 113 162 </Configurations> 114 163 <References> … … 142 191 UsePrecompiledHeader="1"/> 143 192 </FileConfiguration> 193 <FileConfiguration 194 Name="Distribution|Win32"> 195 <Tool 196 Name="VCCLCompilerTool" 197 UsePrecompiledHeader="1"/> 198 </FileConfiguration> 144 199 </File> 145 200 </Filter> -
modules/NRPEListener/NRPEListener.cpp
r1a5449e r452fd41 6 6 #include <strEx.h> 7 7 #include <time.h> 8 #include <config.h> 8 9 9 10 NRPEListener gNRPEListener; … … 20 21 } 21 22 22 #define DEFAULT_NRPE_PORT 566623 23 24 24 25 25 bool NRPEListener::loadModule() { 26 timeout = NSCModuleHelper::getSettingsInt( "NRPE", "commandTimeout",60);27 std::list<std::string> commands = NSCModuleHelper::getSettingsSection( "NRPE Handlers");26 timeout = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_TIMEOUT ,60); 27 std::list<std::string> commands = NSCModuleHelper::getSettingsSection(NRPE_HANDLER_SECTION_TITLE); 28 28 std::list<std::string>::iterator it; 29 29 for (it = commands.begin(); it != commands.end(); it++) { … … 40 40 } 41 41 42 simpleSocket::Socket::WSAStartup(); 43 socket.StartListen(NSCModuleHelper::getSettingsInt("NRPE", "port", DEFAULT_NRPE_PORT)); 42 socket.setAllowedHosts(strEx::splitEx(NSCModuleHelper::getSettingsString(NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOWED, ""), ",")); 43 try { 44 socket.StartListen(NSCModuleHelper::getSettingsInt("NSClient", NRPE_SETTINGS_PORT, DEFAULT_NRPE_PORT)); 45 } catch (simpleSocket::SocketException e) { 46 NSC_LOG_ERROR_STD("Exception caught: " + e.getMessage()); 47 return false; 48 } 44 49 return true; 45 50 } 46 51 bool NRPEListener::unloadModule() { 47 socket.close(); 48 simpleSocket::Socket::WSACleanup(); 52 try { 53 socket.close(); 54 } catch (simpleSocket::SocketException e) { 55 NSC_LOG_ERROR_STD("Exception caught: " + e.getMessage()); 56 return false; 57 } 49 58 return true; 50 59 } … … 72 81 73 82 std::string str = (*it).second; 74 if (NSCModuleHelper::getSettingsInt( "NRPE", "AllowArguments", 0) == 0) {83 if (NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_ARGUMENTS, 0) == 1) { 75 84 arrayBuffer::arrayList arr = arrayBuffer::arrayBuffer2list(argLen, char_args); 76 85 arrayBuffer::arrayList::const_iterator cit = arr.begin(); 77 int i=0; 78 79 for (;cit!=arr.end();it++,i++) { 80 strEx::replace(str, "ARG" + strEx::itos(i), (*cit)); 86 int i=1; 87 88 for (;cit!=arr.end();cit++,i++) { 89 if (NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_NASTY_META, 0) == 0) { 90 if ((*cit).find_first_of(NASTY_METACHARS) != std::string::npos) { 91 NSC_LOG_ERROR("Request string contained illegal metachars!"); 92 return NSCAPI::returnIgnored; 93 } 94 } 95 NSC_DEBUG_MSG_STD("Attempting to replace: " + "$ARG" + strEx::itos(i) + "$" + " with " + (*cit)); 96 strEx::replace(str, "$ARG" + strEx::itos(i) + "$", (*cit)); 81 97 } 82 98 } 83 99 84 if (NSCModuleHelper::getSettingsInt("NRPE", "AllowNastyMetaChars", 0) == 0) { 85 if (str.find_first_of(NASTY_METACHARS) != std::string::npos) { 86 NSC_LOG_ERROR("Request command contained illegal metachars!"); 87 return NSCAPI::returnIgnored; 88 } 100 if ((str.substr(0,6) == "inject")&&(str.length() > 7)) { 101 strEx::token t = strEx::getToken(str.substr(7), ' '); 102 NSC_DEBUG_MSG_STD("Injecting: " + t.first + ", " + t.second); 103 return NSCModuleHelper::InjectSplitAndCommand(t.first, t.second, ' ', message, perf); 89 104 } 90 105 -
modules/NRPEListener/NRPEListener.vcproj
r1a5449e r452fd41 113 113 Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 114 114 </Configuration> 115 <Configuration 116 Name="Distribution|Win32" 117 OutputDirectory="$(ConfigurationName)" 118 IntermediateDirectory="$(ConfigurationName)" 119 ConfigurationType="2" 120 CharacterSet="2"> 121 <Tool 122 Name="VCCLCompilerTool" 123 AdditionalIncludeDirectories="../include;../../include" 124 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" 125 RuntimeLibrary="2" 126 UsePrecompiledHeader="3" 127 WarningLevel="3" 128 Detect64BitPortabilityProblems="TRUE" 129 DebugInformationFormat="3"/> 130 <Tool 131 Name="VCCustomBuildTool"/> 132 <Tool 133 Name="VCLinkerTool" 134 AdditionalDependencies="ws2_32.lib" 135 OutputFile="../../Dist/modules/$(ProjectName).dll" 136 LinkIncremental="1" 137 ModuleDefinitionFile="NRPEListener.def" 138 GenerateDebugInformation="TRUE" 139 SubSystem="2" 140 OptimizeReferences="2" 141 EnableCOMDATFolding="2" 142 ImportLibrary="$(OutDir)/NRPEListener.lib" 143 TargetMachine="1"/> 144 <Tool 145 Name="VCMIDLTool"/> 146 <Tool 147 Name="VCPostBuildEventTool"/> 148 <Tool 149 Name="VCPreBuildEventTool"/> 150 <Tool 151 Name="VCPreLinkEventTool"/> 152 <Tool 153 Name="VCResourceCompilerTool"/> 154 <Tool 155 Name="VCWebServiceProxyGeneratorTool"/> 156 <Tool 157 Name="VCXMLDataGeneratorTool"/> 158 <Tool 159 Name="VCWebDeploymentTool"/> 160 <Tool 161 Name="VCManagedWrapperGeneratorTool"/> 162 <Tool 163 Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 164 </Configuration> 115 165 </Configurations> 116 166 <References> … … 153 203 UsePrecompiledHeader="1"/> 154 204 </FileConfiguration> 205 <FileConfiguration 206 Name="Distribution|Win32"> 207 <Tool 208 Name="VCCLCompilerTool" 209 UsePrecompiledHeader="1"/> 210 </FileConfiguration> 155 211 </File> 156 212 </Filter> … … 176 232 <File 177 233 RelativePath=".\stdafx.h"> 234 </File> 235 <File 236 RelativePath="..\..\include\thread.h"> 178 237 </File> 179 238 </Filter> -
modules/NRPEListener/NRPESocket.cpp
r1a5449e r452fd41 130 130 131 131 void NRPESocket::onAccept(simpleSocket::Socket client) { 132 if (!inAllowedHosts(client.getAddrString())) { 133 NSC_LOG_ERROR("Unothorized access from: " + client.getAddrString()); 134 client.close(); 135 return; 136 } 132 137 simpleSocket::DataBuffer block; 133 138 client.readAll(block); … … 153 158 NSC_DEBUG_MSG_STD("Arguments: " + cmd.second); 154 159 155 if (NSCModuleHelper::getSettingsInt( "NRPE", "AllowArguments", 0) == 0) {160 if (NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_ARGUMENTS, 0) == 0) { 156 161 if (!cmd.second.empty()) { 157 162 NSC_LOG_ERROR("Request contained arguments (not currently allowed)."); … … 160 165 } 161 166 } 162 if (NSCModuleHelper::getSettingsInt( "NRPE", "AllowNastyMetaChars", 0) == 0) {167 if (NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_NASTY_META, 0) == 0) { 163 168 if (cmd.first.find_first_of(NASTY_METACHARS) != std::string::npos) { 164 169 NSC_LOG_ERROR("Request command contained illegal metachars!"); -
modules/NRPEListener/NRPESocket.h
r1a5449e r452fd41 1 1 #pragma once 2 2 #include "resource.h" 3 #include <Thread.h>4 #include <Mutex.h>5 #include <WinSock2.h>6 3 #include <Socket.h> 7 #include <string.h>8 4 /** 9 5 * @ingroup NSClient++ … … 36 32 class NRPESocket : public simpleSocket::Listener { 37 33 private: 34 strEx::splitList allowedHosts_; 38 35 39 36 public: 40 37 NRPESocket(); 41 38 virtual ~NRPESocket(); 39 40 void setAllowedHosts(strEx::splitList allowedHosts) { 41 allowedHosts_ = allowedHosts; 42 } 43 bool inAllowedHosts(std::string s) { 44 if (allowedHosts_.empty()) 45 return true; 46 strEx::splitList::const_iterator cit; 47 for (cit = allowedHosts_.begin();cit!=allowedHosts_.end();++cit) { 48 if ( (*cit) == s) 49 return true; 50 } 51 return false; 52 } 42 53 43 54 private: -
modules/NRPEListener/stdafx.h
r2a94f3f r452fd41 14 14 #include <functional> 15 15 16 #include <config.h> 17 16 18 #include <NSCAPI.h> 17 19 #include <NSCHelper.h> -
modules/NSClientCompat/NSClientCompat.cpp
rc4f6204 r452fd41 26 26 * @return 27 27 */ 28 NSClientCompat::NSClientCompat() : pdhCollector(NULL){}28 NSClientCompat::NSClientCompat() {} 29 29 /** 30 30 * Default d-tor … … 38 38 */ 39 39 bool NSClientCompat::loadModule() { 40 pdh Collector = pdhThread.createThread();40 pdhThread.createThread(); 41 41 return true; 42 42 } … … 110 110 std::list<std::string> stl_args; 111 111 NSClientCompat::returnBundle rb; 112 if (command == "checkCPU") { 113 stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); 114 if (stl_args.empty()) { 115 msg = "ERROR: Missing argument exception."; 116 return NSCAPI::returnUNKNOWN; 117 } 118 int warn; 119 int crit; 120 msg = "CPU Load: "; 121 NSCAPI::nagiosReturn ret = NSCAPI::returnOK; 122 for (arrayBuffer::arrayList::const_iterator it = stl_args.begin(); it != stl_args.end(); ++it) { 123 strEx::token t = strEx::getToken((*it), '='); 124 if (t.first == "crit") 125 crit = strEx::stoi(t.second); 126 else if (t.first == "warn") 127 warn = strEx::stoi(t.second); 128 else { 129 PDHCollector *pObject = pdhThread.getThread(); 130 assert(pObject); 131 int v = pObject->getCPUAvrage(strEx::stoi(*it)*(60/CHECK_INTERVAL)); 132 if (v == -1) { 133 msg = "ERROR: We don't collect data that far back."; 134 return NSCAPI::returnCRIT; 135 } else { 136 if (v > warn) 137 NSCHelper::escalteReturnCodeToWARN(ret); 138 if (v > crit) 139 NSCHelper::escalteReturnCodeToCRIT(ret); 140 msg += strEx::itos(v) + "% (" + (*it) + " min average) "; 141 perf += "'" + (*it) + " min average'=" + strEx::itos(v) + "%;" + strEx::itos(warn) + ";" + strEx::itos(crit) + "; "; 142 } 143 } 144 } 145 return ret; 146 } 112 147 113 148 int id = atoi(command.c_str()); 114 if (id == 0) 149 if (id == 0) { 115 150 return NSCAPI::returnIgnored; 151 } 116 152 switch (id) { 117 153 case REQ_CLIENTVERSION: … … 123 159 } 124 160 case REQ_UPTIME: 125 msg= strEx::itos(pdhCollector->getUptime()); 126 return NSCAPI::returnOK; 127 161 { 162 PDHCollector *pObject = pdhThread.getThread(); 163 assert(pObject); 164 msg = strEx::itos(pObject->getUptime()); 165 return NSCAPI::returnOK; 166 } 128 167 case REQ_CPULOAD: 129 168 { … … 135 174 while (!stl_args.empty()) { 136 175 std::string s = stl_args.front(); stl_args.pop_front(); 137 int v = pdhCollector->getCPUAvrage(strEx::stoi(s)*(60/CHECK_INTERVAL)); 176 PDHCollector *pObject = pdhThread.getThread(); 177 assert(pObject); 178 int v = pObject->getCPUAvrage(strEx::stoi(s)*(60/CHECK_INTERVAL)); 138 179 if (v == -1) { 139 180 msg = "ERROR: We don't collect data that far back."; … … 160 201 161 202 case REQ_MEMUSE: 162 msg = strEx::itos(pdhCollector->getMemCommitLimit()) + "&" + 163 strEx::itos(pdhCollector->getMemCommit()); 203 { 204 PDHCollector *pObject = pdhThread.getThread(); 205 assert(pObject); 206 msg = strEx::itos(pObject->getMemCommitLimit()) + "&" + 207 strEx::itos(pObject->getMemCommit()); 208 209 } 164 210 return NSCAPI::returnOK; 165 211 -
modules/NSClientCompat/NSClientCompat.h
rd4f294a r452fd41 7 7 private: 8 8 PDHCollectorThread pdhThread; 9 PDHCollector *pdhCollector;10 9 11 10 public: -
modules/NSClientCompat/NSClientCompat.vcproj
rc4f6204 r452fd41 113 113 Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 114 114 </Configuration> 115 <Configuration 116 Name="Distribution|Win32" 117 OutputDirectory="$(ConfigurationName)" 118 IntermediateDirectory="$(ConfigurationName)" 119 ConfigurationType="2" 120 CharacterSet="2"> 121 <Tool 122 Name="VCCLCompilerTool" 123 AdditionalIncludeDirectories="../include;../../include" 124 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" 125 RuntimeLibrary="2" 126 UsePrecompiledHeader="3" 127 WarningLevel="3" 128 Detect64BitPortabilityProblems="TRUE" 129 DebugInformationFormat="3"/> 130 <Tool 131 Name="VCCustomBuildTool"/> 132 <Tool 133 Name="VCLinkerTool" 134 AdditionalDependencies="Pdh.lib" 135 OutputFile="../../Dist/modules/$(ProjectName).dll" 136 LinkIncremental="1" 137 ModuleDefinitionFile="NSClientCompat.def" 138 GenerateDebugInformation="TRUE" 139 SubSystem="2" 140 OptimizeReferences="2" 141 EnableCOMDATFolding="2" 142 ImportLibrary="$(OutDir)/NSClientCompat.lib" 143 TargetMachine="1"/> 144 <Tool 145 Name="VCMIDLTool"/> 146 <Tool 147 Name="VCPostBuildEventTool"/> 148 <Tool 149 Name="VCPreBuildEventTool"/> 150 <Tool 151 Name="VCPreLinkEventTool"/> 152 <Tool 153 Name="VCResourceCompilerTool"/> 154 <Tool 155 Name="VCWebServiceProxyGeneratorTool"/> 156 <Tool 157 Name="VCXMLDataGeneratorTool"/> 158 <Tool 159 Name="VCWebDeploymentTool"/> 160 <Tool 161 Name="VCManagedWrapperGeneratorTool"/> 162 <Tool 163 Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 164 </Configuration> 115 165 </Configurations> 116 166 <References> … … 156 206 UsePrecompiledHeader="1"/> 157 207 </FileConfiguration> 208 <FileConfiguration 209 Name="Distribution|Win32"> 210 <Tool 211 Name="VCCLCompilerTool" 212 UsePrecompiledHeader="1"/> 213 </FileConfiguration> 158 214 </File> 159 215 </Filter> -
modules/NSClientCompat/PDHCollector.cpp
r36c340d r452fd41 22 22 23 23 24 PDHCollector::PDHCollector() : cpu(BACK_INTERVAL*60/CHECK_INTERVAL), running_(true) {24 PDHCollector::PDHCollector() : cpu(BACK_INTERVAL*60/CHECK_INTERVAL), hStopEvent_(NULL) { 25 25 } 26 26 PDHCollector::~PDHCollector() 27 27 { 28 } 29 30 /** 31 * Check running status (mutex locked) 32 * @return current status of the running flag (or false if we could not get the mutex, though this is most likely a critical state) 33 */ 34 bool PDHCollector::isRunning(void) { 35 MutexLock mutex(mutexHandler); 36 if (!mutex.hasMutex()) { 37 NSC_LOG_ERROR("Failed to get Mutex!"); 38 return false; 39 } 40 return running_; 41 } 42 /** 43 * set running status (to stopped) 44 */ 45 void PDHCollector::stopRunning(void) { 46 MutexLock mutex(mutexHandler); 47 if (!mutex.hasMutex()) { 48 NSC_LOG_ERROR("Failed to get Mutex!"); 49 return; 50 } 51 running_ = false; 52 } 53 /** 54 *set running status (to started) 55 */ 56 void PDHCollector::startRunning(void) { 57 MutexLock mutex(mutexHandler); 58 if (!mutex.hasMutex()) { 59 NSC_LOG_ERROR("Failed to get Mutex!"); 60 return; 61 } 62 running_ = true; 28 if (hStopEvent_) 29 CloseHandle(hStopEvent_); 63 30 } 64 31 … … 92 59 } 93 60 94 startRunning(); 95 while(isRunning()) { 96 { 97 MutexLock mutex(mutexHandler); 98 if (!mutex.hasMutex()) 99 NSC_LOG_ERROR("Failed to get Mutex!"); 100 else { 101 try { 102 pdh.collect(); 103 } catch (const PDH::PDHException &e) { 104 NSC_LOG_ERROR_STD("Failed to query performance counters: " + e.str_); 105 } 106 } 107 } 108 Sleep(CHECK_INTERVAL*1000); 61 hStopEvent_ = CreateEvent(NULL, TRUE, FALSE, NULL); 62 if (!hStopEvent_) { 63 NSC_LOG_ERROR_STD("Create StopEvent failed: " + strEx::itos(GetLastError())); 64 return 0; 109 65 } 110 66 67 do { 68 MutexLock mutex(mutexHandler); 69 if (!mutex.hasMutex()) 70 NSC_LOG_ERROR("Failed to get Mutex!"); 71 else { 72 try { 73 pdh.collect(); 74 } catch (const PDH::PDHException &e) { 75 NSC_LOG_ERROR_STD("Failed to query performance counters: " + e.str_); 76 } 77 } 78 }while (!(WaitForSingleObject(hStopEvent_, CHECK_INTERVAL*1000) == WAIT_OBJECT_0)); 79 80 if (!CloseHandle(hStopEvent_)) 81 NSC_LOG_ERROR_STD("Failed to close stopEvent handle: " + strEx::itos(GetLastError())); 82 else 83 hStopEvent_ = NULL; 111 84 try { 112 85 pdh.close(); … … 114 87 NSC_LOG_ERROR_STD("Failed to close performance counters: " + e.str_); 115 88 } 116 NSC_DEBUG_MSG("PDHCollector - shutdown!");117 89 return 0; 118 90 } … … 123 95 */ 124 96 void PDHCollector::exitThread(void) { 125 NSC_DEBUG_MSG("PDHCollector - Requesting shutdown!"); 126 stopRunning(); 97 if (hStopEvent_ == NULL) 98 NSC_LOG_ERROR("Failed to get Mutex!"); 99 else 100 if (!SetEvent(hStopEvent_)) { 101 NSC_LOG_ERROR_STD("SetStopEvent failed"); 102 } 127 103 } 128 104 /** -
modules/NSClientCompat/PDHCollector.h
ra1e1922 r452fd41 27 27 private: 28 28 MutexHandler mutexHandler; 29 bool running_;29 HANDLE hStopEvent_; 30 30 31 31 PDHCollectors::StaticPDHCounterListener memCmtLim; -
modules/NSClientListener/NSClientListener.cpp
r1a5449e r452fd41 6 6 #include <strEx.h> 7 7 #include <time.h> 8 #include <config.h> 8 9 9 10 NSClientListener gNSClientListener; … … 20 21 } 21 22 22 #define DEFAULT_TCP_PORT 1248923 24 23 bool NSClientListener::loadModule() { 25 socket.StartListen(NSCModuleHelper::getSettingsInt("NSClient", "port", DEFAULT_TCP_PORT)); 24 socket.setAllowedHosts(strEx::splitEx(NSCModuleHelper::getSettingsString("NRPE", "allowed_hosts", ""), ",")); 25 try { 26 socket.StartListen(NSCModuleHelper::getSettingsInt("NSClient", "port", DEFAULT_NSCLIENT_PORT)); 27 } catch (simpleSocket::SocketException e) { 28 NSC_LOG_ERROR_STD("Exception caught: " + e.getMessage()); 29 return false; 30 } 26 31 return true; 27 32 } 28 33 bool NSClientListener::unloadModule() { 29 socket.close(); 34 try { 35 socket.close(); 36 } catch (simpleSocket::SocketException e) { 37 NSC_LOG_ERROR_STD("Exception caught: " + e.getMessage()); 38 return false; 39 } 30 40 return true; 31 41 } -
modules/NSClientListener/NSClientListener.vcproj
rc4f6204 r452fd41 113 113 Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 114 114 </Configuration> 115 <Configuration 116 Name="Distribution|Win32" 117 OutputDirectory="$(ConfigurationName)" 118 IntermediateDirectory="$(ConfigurationName)" 119 ConfigurationType="2" 120 CharacterSet="2"> 121 <Tool 122 Name="VCCLCompilerTool" 123 AdditionalIncludeDirectories="../include;../../include" 124 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;NSCLIENTLISTENER_EXPORTS" 125 RuntimeLibrary="2" 126 UsePrecompiledHeader="3" 127 WarningLevel="3" 128 Detect64BitPortabilityProblems="TRUE" 129 DebugInformationFormat="3"/> 130 <Tool 131 Name="VCCustomBuildTool"/> 132 <Tool 133 Name="VCLinkerTool" 134 AdditionalDependencies="ws2_32.lib" 135 OutputFile="../../Dist/modules/$(ProjectName).dll" 136 LinkIncremental="1" 137 ModuleDefinitionFile="NSClientListener.def" 138 GenerateDebugInformation="TRUE" 139 SubSystem="2" 140 OptimizeReferences="2" 141 EnableCOMDATFolding="2" 142 ImportLibrary="$(OutDir)/NSClientListener.lib" 143 TargetMachine="1"/> 144 <Tool 145 Name="VCMIDLTool"/> 146 <Tool 147 Name="VCPostBuildEventTool"/> 148 <Tool 149 Name="VCPreBuildEventTool"/> 150 <Tool 151 Name="VCPreLinkEventTool"/> 152 <Tool 153 Name="VCResourceCompilerTool"/> 154 <Tool 155 Name="VCWebServiceProxyGeneratorTool"/> 156 <Tool 157 Name="VCXMLDataGeneratorTool"/> 158 <Tool 159 Name="VCWebDeploymentTool"/> 160 <Tool 161 Name="VCManagedWrapperGeneratorTool"/> 162 <Tool 163 Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 164 </Configuration> 115 165 </Configurations> 116 166 <References> … … 150 200 UsePrecompiledHeader="1"/> 151 201 </FileConfiguration> 202 <FileConfiguration 203 Name="Distribution|Win32"> 204 <Tool 205 Name="VCCLCompilerTool" 206 UsePrecompiledHeader="1"/> 207 </FileConfiguration> 152 208 </File> 153 209 </Filter> -
modules/NSClientListener/NSClientSocket.cpp
r1a5449e r452fd41 18 18 strEx::token pwd = strEx::getToken(buffer, '&'); 19 19 NSC_DEBUG_MSG("Password: " + pwd.first); 20 if ( (pwd.first.empty()) || (pwd.first != NSCModuleHelper::getSettingsString(" generic", "password", "")) )20 if ( (pwd.first.empty()) || (pwd.first != NSCModuleHelper::getSettingsString("NSClient", "password", "")) ) 21 21 return "ERROR: Invalid password."; 22 22 if (pwd.second.empty()) … … 49 49 50 50 void NSClientSocket::onAccept(simpleSocket::Socket client) { 51 if (!inAllowedHosts(client.getAddrString())) { 52 NSC_LOG_ERROR("Unothorized access from: " + client.getAddrString()); 53 client.close(); 54 return; 55 } 51 56 simpleSocket::DataBuffer db; 52 57 client.readAll(db); 53 58 if (db.getLength() > 0) { 54 NSC_DEBUG_MSG_STD("Incoming data length: " + strEx::itos(db.getLength()));55 59 std::string incoming(db.getBuffer(), db.getLength()); 56 60 NSC_DEBUG_MSG_STD("Incoming data: " + incoming); -
modules/NSClientListener/NSClientSocket.h
r1a5449e r452fd41 1 1 #pragma once 2 2 #include "resource.h" 3 #include <Thread.h>4 #include <Mutex.h>5 #include <WinSock2.h>6 #include <strEx.h>7 #include <charEx.h>8 3 #include <Socket.h> 9 4 /** … … 33 28 class NSClientSocket : public simpleSocket::Listener { 34 29 private: 30 strEx::splitList allowedHosts_; 35 31 36 32 public: … … 41 37 virtual void onAccept(simpleSocket::Socket client); 42 38 std::string parseRequest(std::string buffer); 39 bool inAllowedHosts(std::string s) { 40 if (allowedHosts_.empty()) 41 return true; 42 strEx::splitList::const_iterator cit; 43 for (cit = allowedHosts_.begin();cit!=allowedHosts_.end();++cit) { 44 if ( (*cit) == s) 45 return true; 46 } 47 return false; 48 } 49 50 public: 51 void setAllowedHosts(strEx::splitList allowedHosts) { 52 allowedHosts_ = allowedHosts; 53 } 54 43 55 }; 44 56 -
modules/SysTray/SysTray.cpp
r402f042 r452fd41 51 51 52 52 std::string SysTray::getModuleName() { 53 return " This is a nice systray module.";53 return "System Tray icon Module."; 54 54 } 55 55 NSCModuleWrapper::module_version SysTray::getModuleVersion() { -
modules/SysTray/SysTray.vcproj
r1a5449e r452fd41 108 108 Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 109 109 </Configuration> 110 <Configuration 111 Name="Distribution|Win32" 112 OutputDirectory="$(ConfigurationName)" 113 IntermediateDirectory="$(ConfigurationName)" 114 ConfigurationType="2" 115 CharacterSet="2"> 116 <Tool 117 Name="VCCLCompilerTool" 118 AdditionalIncludeDirectories="../include;../../include" 119 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" 120 RuntimeLibrary="2" 121 UsePrecompiledHeader="3" 122 WarningLevel="3" 123 Detect64BitPortabilityProblems="TRUE" 124 DebugInformationFormat="3"/> 125 <Tool 126 Name="VCCustomBuildTool"/> 127 <Tool 128 Name="VCLinkerTool" 129 OutputFile="../../Dist/modules/$(ProjectName).dll" 130 LinkIncremental="1" 131 ModuleDefinitionFile="SysTray.def" 132 GenerateDebugInformation="TRUE" 133 SubSystem="2" 134 OptimizeReferences="2" 135 EnableCOMDATFolding="2" 136 ImportLibrary="$(OutDir)/SysTray.lib" 137 TargetMachine="1"/> 138 <Tool 139 Name="VCMIDLTool"/> 140 <Tool 141 Name="VCPostBuildEventTool"/> 142 <Tool 143 Name="VCPreBuildEventTool"/> 144 <Tool 145 Name="VCPreLinkEventTool"/> 146 <Tool 147 Name="VCResourceCompilerTool"/> 148 <Tool 149 Name="VCWebServiceProxyGeneratorTool"/> 150 <Tool 151 Name="VCXMLDataGeneratorTool"/> 152 <Tool 153 Name="VCWebDeploymentTool"/> 154 <Tool 155 Name="VCManagedWrapperGeneratorTool"/> 156 <Tool 157 Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 158 </Configuration> 110 159 </Configurations> 111 160 <References> … … 136 185 UsePrecompiledHeader="1"/> 137 186 </FileConfiguration> 187 <FileConfiguration 188 Name="Distribution|Win32"> 189 <Tool 190 Name="VCCLCompilerTool" 191 UsePrecompiledHeader="1"/> 192 </FileConfiguration> 138 193 </File> 139 194 <File -
readme.txt
r36c340d r452fd41 1 1 NSClient++ is a windows service that allows performance metrics to be gathered by Nagios 2 (and possibly other monitoring tools). It is an attempt to create a NSClient compatible2 (and possibly other monitoring tools). It is an attempt to create a NSClient and NRPE compatible 3 3 but yet extendable performance service for windows. 4 4 5 6 This is an initial NSClient++ test release. 7 8 This version has many of the features from NSClient. 5 NSClient 9 6 The following commands (from check_nt) are supported. 10 7 * CLIENTVERSION … … 16 13 * PROCSTATE 17 14 15 NRPE 16 All scripts "should" work (haven't actually tried myself though). 17 Notice that encryption is still missing. 18 18 19 Installation: 19 20 To install simply copy all files to directory on the server and run 20 the following command: "NSClient++ /install" to un install run:21 the following command: "NSClient++ /install" to un-install run: 21 22 "NSClient++ /uninstall". 22 23 … … 29 30 about - Show some info (version et.al.) 30 31 version - Show some info 31 test - Run interactively (hint: enable ConsoleLogger for 32 this to make sense). Useful for debugging purposes. 32 test - Run interactively. Useful for debugging purposes. 33 33 34 34 The directory structure: 35 35 <install root> 36 36 - NSClient++.exe - The executable (and service) 37 - NSC.ini - The INI file (settings) 37 - NSC.ini - The INI file (settings) 38 - changelog - "Whats new" 39 - *.dll - Various runtime DLLs 40 - readme.txt - This file 38 41 <modules> 39 42 - Various NSClient++ modules available to this instance. 40 43 41 The default modules: 42 CheckEventLog.dll 43 An eventlog checker (has yet to get a Unix client) 44 ConsoleLogger.dll 45 Log messages to console. (Usefull when run with -test) 46 FileLogger.dll 47 Log messages to file (Usefull when run as service) 48 NSClientCompat.dll 49 NSCLient compatibility module. Provides NSClient commands. 50 SysTray.dll 51 Shows a sytray when the service (exe) is started and allows you to 52 view the logfile and inject commands. 44 A quick description of the included modules: 45 * CheckDisk.dll 46 Dick check plug-in (not very complete as of yet). 47 * CheckEventLog.dll 48 A very basic event log checker (HINT feedback wanted :) 49 * FileLogger.dll 50 Log messages to file (Useful when reporting bugs, also please enable debug=1) 51 * NRPEListener.dll 52 NRPE client code. Both listener and executer. 53 Might in the future rename this to NRPE or I will split the module into two. 54 * NSClientCompat.dll 55 NSCLient compatibility module. Provides NSClient commands. 56 This module will be migrated in to various other modules in the "near" future. 57 * NSClientListener.dll 58 The NSClient listener. 59 * SysTray.dll 60 Shows a system tray when the service (exe) is started and allows you to view the log file and inject commands. 53 61 54 62 Settings: 55 The following things can be changed ion the NSC.ini file.63 For details refer to NSC.ini. 56 64 57 [generic] 58 password=secret-password 59 # The password to use. 65 About NSClient++ 66 URL: http://www.sf.net/projects/nscplus 60 67 61 port=1234 62 # The port to bind to 63 64 [main] 65 bufferSize=4096 66 # Maximum buffer size for commands to return 67 68 [log] 69 file=nsclient.log 70 # The file to log to. 71 72 [nsclient compat] 73 version=modern 74 # The version string to return to the client. 75 # Modern returns the nsclient++ version string in a new syntax: 76 # <application> <version> <date> 77 # Notice this is not automated as of yet (as in date/version is not updated). 78 79 [systray] 80 defaultCommand= 81 # The default command to show in the inject command dialog. 82 83 84 Using the API: 85 The following functions are available for a module to "export": (think DLL) 86 87 NSLoadModule 88 - Loading of modules (done when the service starts) 89 NSGetModuleName 90 - Used to get a nice name for the module. 91 NSGetModuleVersion 92 - Not really used but... 93 NSHasCommandHandler 94 - Let the "core" know it can handle commands (from nagios) 95 NSHasMessageHandler 96 - Used to let the "core" know it wants to see all log/debug/error messages that are generated. 97 NSHandleMessage 98 - Used to digest a log/debug/error message. 99 NSHandleCommand 100 - Used to (possibly) digest a command. 101 When a command is "injected" then command is parsed and then sent along to all plugins (which accept commands) in order (they are listed in NSC.ini) and they are allowed to act on the command. If they do act on the command the "injection" is aborted and the resulting "return string" is returned to the "injecter" (normaly check_nt through a TCP stream. The ordering can thus be used to 1, optimize if things are slow (though I fail to see that unless someone makes some pretty f*cked up modules) and priority if one module overlaps the command of another (though then I would recommend someone to change the plugin command strings :) 102 103 NSUnloadModule 104 - Used to unload and terminate "stuff" nicely. (Generally this is when the service terminates) 105 NSModuleHelperInit 106 - Used to send along callbacks to the module (for making calls to the "core". (Ie. To allow the module to inject commands, get versions, names, and settings) 107 108 So the API is quite simple and straight forward (I hope :) 109 110 To make a simple call graph: 111 112 * Service starts: 113 * For each plugin 114 - call NSLoadModule 115 - call NSModuleHelperInit 116 - if NSHasCommandHandler 117 . Send to "command plugin" stack 118 - if NSHasMessageHandler 119 . Send to "message plugin" stack 120 * Wait for socket data 121 - Parse socket data 122 - For each "command plugin" 123 . call NSHandleCommand 124 . if Command handled abort 125 126 <termination signal sent to service> 127 * For each plugin 128 - NSUnloadModule 129 * Terminate service 130 131 <Log/debug/error message generated in a module> 132 * On incoming message: 133 - For each "message plugin" 134 . call NSHandleMessage 135 136 There are a few more things to this but overall I have tried to keep things simple. 137 138 The extensions (to the API) I'm considering as of now (depending on the fallout) is: 139 * "SettingsHandler" to allow registry/INI/* settings modules. As the overhead of reg/ini settings system is quite low, perhaps this is overkill. But I don't know: thinking wildly there might be a reason for someone to want to load settings from a central server or whatever :) 140 141 * "SocketHandlers" though this will not be a specific handler I have considered to refactor out the code and allow the socket handler (that reads the TCP socket and parses the command) to be a plugin when I do SSL as I assume SSL will come with quite a high overhead and thus I might not need it all the time. 142 143 Also as mentioned this might be a good place to do a NRPE socket parser module to allow compatibility with NRPE. But this I assume is a bit in the future as I need to get "NSClient++" before I can get "NRPEClient++"... 144 145 As for PassiveChecks that could be implemented as a plugin today as any plugin can inject commands into the "core". Thus a plugin can be loaded, have a background thread that every X minutes calls "core".injectCommand(); and sends the result over to nagios. (This is how I assume that passive checks work) 146 147 148 149 150 // Michael Medin - michael <at> medin <dot> name - http://www.medin.name 68 Contact the author: 69 Michael Medin 70 EMail: michael <at> medin <dot> name 71 Address: (feel free to send a postcard if you find this useful :) 72 Michael Medin 73 Terapivaegen 6b 3tr 74 SE-141 55 HUDDINGE 75 SWEDEN
Note: See TracChangeset
for help on using the changeset viewer.








