Changeset 452fd41 in nscp


Ignore:
Timestamp:
03/28/05 12:24:08 (8 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
aaa9a22
Parents:
1a5449e
Message:
  • Changed the Thread class a bit (mutex -> signal, and CreatThread? does not return the instance)
  • Moved settings "keys" fro NRPE to config.h
  • Changed build options (added Distribution) which builds a zip file under ./dist (requires 7z installed)
  • Minor tweaks to error/debug logging and small fixes "here and there"
Files:
1 added
31 edited

Legend:

Unmodified
Added
Removed
  • NSClient++.cpp

    r1a5449e r452fd41  
    1818#include "Settings.h" 
    1919#include <charEx.h> 
     20#include <Socket.h> 
    2021 
    2122NSClient mainClient;  // Global core instance. 
     
    107108  Settings::getInstance()->setFile(getBasePath() + "NSC.ini"); 
    108109 
     110  try { 
     111    simpleSocket::Socket::WSAStartup(); 
     112  } catch (simpleSocket::SocketException e) { 
     113    LOG_ERROR_STD("Uncaught exception: " + e.getMessage()); 
     114  } 
     115 
    109116  SettingsT::sectionList list = Settings::getInstance()->getSection("modules"); 
    110117  for (SettingsT::sectionList::iterator it = list.begin(); it != list.end(); it++) { 
     
    123130void NSClientT::TerminateService(void) { 
    124131  try { 
    125     LOG_DEBUG("Socket closed, unloading plugins..."); 
    126132    mainClient.unloadPlugins(); 
    127133    LOG_DEBUG("Plugins unloaded..."); 
    128134  } catch(NSPluginException *e) { 
    129135    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()); 
    130141  } 
    131142  Settings::destroyInstance(); 
     
    229240NSCAPI::nagiosReturn NSClientT::injectRAW(const char* command, const unsigned int argLen, char **argument, char *returnMessageBuffer, unsigned int returnMessageBufferLen, char *returnPerfBuffer, unsigned int returnPerfBufferLen) { 
    230241  MutexLock lock(pluginMutex); 
    231  
    232   LOG_MESSAGE_STD("Injecting: " + command); 
    233242 
    234243  pluginList::const_iterator plit; 
     
    263272} 
    264273/** 
    265  * Helper function to return the current password (perhaps this should be static ?) 
    266  * 
    267  * @return The current password 
    268  */ 
    269 std::string NSClientT::getPassword() { 
    270   return Settings::getInstance()->getString("generic", "password", ""); 
    271 } 
    272 /** 
    273  * Execute a command. 
    274  * 
    275  * @param password The password 
    276  * @param cmd The command 
    277  * @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 buffer 
    301   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 message 
    310         LOG_DEBUG("A module ignored this message"); 
    311       } else if (c == NSCAPI::invalidBufferLen) { // Buffer is to small 
    312         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 buffers 
    321   delete [] returnbuffer; 
    322   NSCHelper::destroyArrayBuffer(arguments, len); 
    323   return ret; 
    324 } 
    325 */ 
    326 /** 
    327274 * Report a message to all logging enabled modules. 
    328275 * 
  • NSClient++.h

    r1a5449e r452fd41  
    5757 
    5858  // Member functions 
    59   static std::string getPassword(void); 
    6059  std::string getBasePath(void); 
    6160  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  
    22Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NSClient++", "NSClient++.vcproj", "{2286162D-7571-4735-BAC8-4A8D33A4F42D}" 
    33  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} 
    411  EndProjectSection 
    512EndProject 
     
    3845  GlobalSection(SolutionConfiguration) = preSolution 
    3946    Debug = Debug 
     47    Distribution = Distribution 
    4048    Release = Release 
    4149  EndGlobalSection 
     
    4351    {2286162D-7571-4735-BAC8-4A8D33A4F42D}.Debug.ActiveCfg = Debug|Win32 
    4452    {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 
    4555    {2286162D-7571-4735-BAC8-4A8D33A4F42D}.Release.ActiveCfg = Release|Win32 
    4656    {2286162D-7571-4735-BAC8-4A8D33A4F42D}.Release.Build.0 = Release|Win32 
    4757    {BBFF8362-C626-4838-B0A2-F695D638AD24}.Debug.ActiveCfg = Debug|Win32 
    4858    {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 
    4961    {BBFF8362-C626-4838-B0A2-F695D638AD24}.Release.ActiveCfg = Release|Win32 
    5062    {BBFF8362-C626-4838-B0A2-F695D638AD24}.Release.Build.0 = Release|Win32 
    5163    {79F1F571-78A6-4B20-8BD5-0F65CD60012C}.Debug.ActiveCfg = Debug|Win32 
    5264    {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 
    5367    {79F1F571-78A6-4B20-8BD5-0F65CD60012C}.Release.ActiveCfg = Release|Win32 
    5468    {79F1F571-78A6-4B20-8BD5-0F65CD60012C}.Release.Build.0 = Release|Win32 
    5569    {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Debug.ActiveCfg = Debug|Win32 
    5670    {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 
    5773    {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Release.ActiveCfg = Release|Win32 
    5874    {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Release.Build.0 = Release|Win32 
    5975    {BA246C01-063A-4548-8957-32D5CC76171B}.Debug.ActiveCfg = Debug|Win32 
    6076    {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 
    6179    {BA246C01-063A-4548-8957-32D5CC76171B}.Release.ActiveCfg = Release|Win32 
    6280    {BA246C01-063A-4548-8957-32D5CC76171B}.Release.Build.0 = Release|Win32 
    6381    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug.ActiveCfg = Debug Dynamic Linkage|Win32 
    6482    {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 
    6585    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Release.ActiveCfg = Dynamic Linkage|Win32 
    6686    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Release.Build.0 = Dynamic Linkage|Win32 
    6787    {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Debug.ActiveCfg = Debug|Win32 
    6888    {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 
    6991    {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Release.ActiveCfg = Release|Win32 
    7092    {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Release.Build.0 = Release|Win32 
    7193    {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Debug.ActiveCfg = Debug|Win32 
    7294    {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 
    7397    {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Release.ActiveCfg = Release|Win32 
    7498    {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Release.Build.0 = Release|Win32 
  • NSClient++.vcproj

    r1a5449e r452fd41  
    4040        SuppressStartupBanner="TRUE"/> 
    4141      <Tool 
    42         Name="VCCustomBuildTool"/> 
     42        Name="VCCustomBuildTool" 
     43        CommandLine="echo Copying dependency DLLs 
     44cmd /c &quot;copy $(InputDir)\dist_dll\*.* $(InputDir)\$(OutDir)\&quot;" 
     45        Outputs="$(InputDir)\$(OutDir)\msvcp71.dll"/> 
    4346      <Tool 
    4447        Name="VCLinkerTool" 
     
    143146        Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 
    144147    </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 
     176cmd /c &quot;copy $(InputDir)\dist_dll\*.dll $(InputDir)\Dist\&quot; 
     177echo Removing old archive 
     178cmd /c &quot;del $(InputDir)\Dist\$(InputName).zip&quot; 
     179echo Making archive 
     1807z.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> 
    145221  </Configurations> 
    146222  <References> 
     
    187263            UsePrecompiledHeader="1"/> 
    188264        </FileConfiguration> 
     265        <FileConfiguration 
     266          Name="Distribution|Win32"> 
     267          <Tool 
     268            Name="VCCLCompilerTool" 
     269            Optimization="2" 
     270            PreprocessorDefinitions="" 
     271            UsePrecompiledHeader="1"/> 
     272        </FileConfiguration> 
    189273      </File> 
    190274    </Filter> 
     
    199283      </File> 
    200284      <File 
    201         RelativePath=".\config.h"> 
     285        RelativePath=".\include\config.h"> 
    202286      </File> 
    203287      <File 
     
    238322      <File 
    239323        RelativePath=".\changelog"> 
     324        <FileConfiguration 
     325          Name="Distribution|Win32"> 
     326          <Tool 
     327            Name="VCCustomBuildTool" 
     328            CommandLine="echo Copying $(InputFileName)... 
     329cmd /c &quot;copy $(InputDir)\$(InputName) $(InputDir)\Dist\&quot;" 
     330            Outputs="$(InputDir)\Dist\$(InputFileName)"/> 
     331        </FileConfiguration> 
    240332      </File> 
    241333      <File 
    242334        RelativePath=".\Doxyfile"> 
    243335        <FileConfiguration 
    244           Name="Release|Win32"> 
     336          Name="Release|Win32" 
     337          ExcludedFromBuild="TRUE"> 
    245338          <Tool 
    246339            Name="VCCustomBuildTool" 
     
    257350"/> 
    258351        </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> 
    259361      </File> 
    260362      <File 
     
    264366        RelativePath=".\NSC.ini"> 
    265367        <FileConfiguration 
    266           Name="Release|Win32" 
    267           ExcludedFromBuild="TRUE"> 
    268           <Tool 
    269             Name="VCCustomBuildTool" 
    270             CommandLine="copy $(InputPath) $(OutDir)\$(InputFileName) 
     368          Name="Release|Win32"> 
     369          <Tool 
     370            Name="VCCustomBuildTool" 
     371            CommandLine="echo Copying $(InputFileName)... 
     372cmd /c &quot;copy $(InputDir)\$(InputFileName) $(InputDir)\$(OutDir)&quot; 
    271373" 
    272374            AdditionalDependencies="" 
    273             Outputs="$(OutDir)\$(InputFileName)"/> 
    274         </FileConfiguration> 
    275         <FileConfiguration 
    276           Name="Debug|Win32" 
    277           ExcludedFromBuild="TRUE"> 
    278           <Tool 
    279             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)... 
     382cmd /c &quot;copy $(InputDir)\$(InputFileName) $(InputDir)\$(OutDir)&quot; 
    281383" 
    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)... 
     391cmd /c &quot;copy $(InputDir)\$(InputFileName) $(InputDir)\Dist\&quot;" 
     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)... 
     417cmd /c &quot;copy $(InputDir)\$(InputFileName) $(InputDir)\Dist\&quot;" 
     418            Outputs="$(InputDir)\Dist\$(InputFileName)"/> 
    283419        </FileConfiguration> 
    284420      </File> 
  • StdAfx.h

    r55159fd r452fd41  
    1212 
    1313#define VC_EXTRALEAN    // Exclude rarely-used stuff from Windows headers 
    14 #include <winsock2.h> 
     14#include <WinSock2.h> 
    1515#include <windows.h> 
    1616 
  • changelog

    r1a5449e r452fd41  
     12005-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 
    172005-03-26 MickeM 
    28 + NRPE Support (very basic, no encryption, and nothing fancy) 
  • include/Socket.cpp

    r1a5449e r452fd41  
    3131    core->listen(10); 
    3232    core->ioctlsocket(FIONBIO, &NoBlock); 
    33  
    34     NSC_DEBUG_MSG_STD("Currently listeneing to: " + strEx::itos(core->port_)); 
    35  
    3633    while (!(WaitForSingleObject(hStopEvent, 100) == WAIT_OBJECT_0)) { 
    3734      Socket client; 
     
    4239    NSC_LOG_ERROR_STD(e.getMessage()); 
    4340  } 
    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); 
    4745  return 0; 
    4846} 
     
    5452*/ 
    5553void simpleSocket::Listener::ListenerThread::exitThread(void) { 
    56   NSC_DEBUG_MSG("Requesting Socket shutdown!"); 
     54  assert(hStopEvent); 
    5755  if (!SetEvent(hStopEvent)) { 
    5856    NSC_LOG_ERROR_STD("SetStopEvent failed"); 
     
    8583} 
    8684void simpleSocket::Listener::close() { 
    87   threadManager_.exitThread(); 
     85  if (threadManager_.hasActiveThread()) 
     86    if (!threadManager_.exitThread()) 
     87      throw new SocketException("Could not terminate thread."); 
    8888  Socket::close(); 
    8989} 
  • include/Socket.h

    r1a5449e r452fd41  
    6363    Socket(Socket &other) { 
    6464      socket_ = other.socket_; 
     65      from_ = other.from_; 
    6566      other.socket_ = NULL; 
    6667    } 
     
    7475    } 
    7576    virtual void close() { 
    76       assert(socket_); 
    77       closesocket(socket_); 
     77      if (socket_) 
     78        closesocket(socket_); 
    7879      socket_ = NULL; 
    7980    } 
     
    115116      if (::ioctlsocket(socket_, cmd, argp) == SOCKET_ERROR) 
    116117        throw SocketException("ioctlsocket failed: ", ::WSAGetLastError()); 
     118    } 
     119    std::string getAddrString() { 
     120      return inet_ntoa(from_.sin_addr); 
    117121    } 
    118122 
  • include/strEx.h

    r1a5449e r452fd41  
    6262    return itos(i>>24)+"B"; 
    6363  } 
     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 
    6478  inline std::pair<std::string,std::string> split(std::string str, std::string key) { 
    6579    std::string::size_type pos = str.find(key); 
  • include/thread.h

    r36c340d r452fd41  
    1 // Thread.h: interface for the Thread class. 
    2 // 
    3 ////////////////////////////////////////////////////////////////////// 
    4  
    51#pragma once 
    6  
    7  
    8 /** 
    9  * @ingroup NSClientCompat 
    10  * Simple unnamed mutex to handle thread exit wait (used by the Thread class below) 
    11  * 
    12  * @version 1.0 
    13  * first version 
    14  * 
    15  * @date 02-13-2005 
    16  * 
    17  * @author mickem 
    18  * 
    19  * @par license 
    20  * This code is absolutely free to use and modify. The code is provided "as is" with 
    21  * no expressed or implied warranty. The author accepts no liability if it causes 
    22  * any damage to your computer, causes your pet to fall ill, increases baldness 
    23  * 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 status 
    34    * @param owner true if we want to become owner of the mutex 
    35    */ 
    36   UnnamedMutex(bool owner = false) { 
    37     hMutex_ = ::CreateMutex(NULL, owner, NULL); 
    38   } 
    39   /** 
    40    * Default d-tor. 
    41    * Closes the mutex 
    42    */ 
    43   virtual ~UnnamedMutex() { 
    44     CloseHandle(hMutex_); 
    45   } 
    46   /** 
    47    * Wait for the mutex or timeout in dwMilliseconds milliseconds. 
    48    * @param dwMilliseconds The timeout value 
    49    * @return status 
    50    */ 
    51   DWORD wait(DWORD dwMilliseconds = 0L) { 
    52     return ::WaitForSingleObject(hMutex_, dwMilliseconds); 
    53   } 
    54   /** 
    55    * Release the mutex 
    56    * @return status 
    57    */ 
    58   BOOL free() { 
    59     return ::ReleaseMutex(hMutex_); 
    60   } 
    61 }; 
    622 
    633/** 
     
    8929  HANDLE hThread_;    // Thread handle 
    9030  DWORD dwThreadID_;    // Thread ID 
    91   UnnamedMutex endMutext; // mutex to wait for end of thread 
    9231  T* pObject_;      // Wrapped object 
     32  HANDLE hStopEvent_;   // Event to signal that the thread has stopped 
    9333 
    9434  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 
    9838  } thread_param; 
    9939 
     
    10343   * Sets up default values 
    10444   */ 
    105   Thread() : endMutext(false), hThread_(NULL), dwThreadID_(0), pObject_(NULL) {} 
     45  Thread() : hThread_(NULL), dwThreadID_(0), pObject_(NULL), hStopEvent_(NULL) {} 
    10646  /** 
    10747   * Default d-tor. 
     
    11252    if (hThread_) 
    11353      CloseHandle(hThread_); 
     54    if (hStopEvent_) 
     55      CloseHandle(hStopEvent_); 
    11456  } 
    11557 
     
    12567    thread_param* param = static_cast<thread_param*>(lpParameter); 
    12668    T* instance = param->instance; 
    127     Thread *core = param->core; 
     69    Thread *manager = param->manager; 
    12870    LPVOID lpParam = param->lpParam; 
    12971    delete param; 
    130     core->endMutext.wait(); 
     72 
     73    assert(manager->hStopEvent_); 
    13174    DWORD ret = instance->threadProc(lpParam); 
    132     core->endMutext.free(); 
    133     return 0; 
     75    BOOL b = SetEvent(manager->hStopEvent_); 
     76    assert(b); 
     77    return ret; 
    13478  } 
    13579 
     
    14286   * @param lpParam An argument to the thread 
    14387   * @return An instance of the thread object. 
    144    * @throws char 
    14588   * @bug the object return thing is *unsafe* and should be changed (if the thread is terminated that pointer is invalidated without any signal). 
    14689   */ 
    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); 
    15093    pObject_ = new T; 
    15194    thread_param* param = new thread_param; 
    15295    param->instance = pObject_; 
    153     param->core = this; 
     96    param->manager = this; 
    15497    param->lpParam = lpParam; 
     98    hStopEvent_ = CreateEvent(NULL, TRUE, FALSE, NULL); 
    15599    hThread_ = ::CreateThread(NULL,0,threadProc,reinterpret_cast<VOID*>(param),0,&dwThreadID_); 
    156     return pObject_; 
    157100  } 
    158101  /** 
     
    162105   */ 
    163106  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); 
    166109    pObject_->exitThread(); 
    167     DWORD dwWaitResult = endMutext.wait(delay); 
     110 
     111    DWORD dwWaitResult = WaitForSingleObject(hStopEvent_, delay); 
    168112    switch (dwWaitResult) { 
    169113      // The thread got mutex ownership. 
    170114      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        } 
    175124        return true; 
    176         // Cannot get mutex ownership due to time-out. 
     125        // Did not get a signal due to time-out. 
    177126      case WAIT_TIMEOUT:  
    178127        return false;  
    179128 
    180         // Got ownership of the abandoned mutex object. 
     129        // Never got a signal. 
    181130      case WAIT_ABANDONED:  
    182131        return false;  
     
    184133    return false; 
    185134  } 
     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  } 
    186147}; 
    187148 
  • modules/CheckDisk/CheckDisk.vcproj

    r1a5449e r452fd41  
    211211        Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 
    212212    </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> 
    213262  </Configurations> 
    214263  <References> 
     
    250299        <FileConfiguration 
    251300          Name="Debug Dynamic Linkage|Win32"> 
     301          <Tool 
     302            Name="VCCLCompilerTool" 
     303            UsePrecompiledHeader="1"/> 
     304        </FileConfiguration> 
     305        <FileConfiguration 
     306          Name="Distribution|Win32"> 
    252307          <Tool 
    253308            Name="VCCLCompilerTool" 
  • modules/CheckEventLog/CheckEventLog.vcproj

    r1a5449e r452fd41  
    7171        Optimization="0" 
    7272        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" 
    7474        MinimalRebuild="TRUE" 
    7575        BasicRuntimeChecks="3" 
     
    8989        ProgramDatabaseFile="$(OutDir)/CheckEventLog.pdb" 
    9090        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" 
    91141        ImportLibrary="$(OutDir)/CheckEventLog.lib" 
    92142        TargetMachine="1"/> 
     
    144194            UsePrecompiledHeader="1"/> 
    145195        </FileConfiguration> 
     196        <FileConfiguration 
     197          Name="Distribution|Win32"> 
     198          <Tool 
     199            Name="VCCLCompilerTool" 
     200            UsePrecompiledHeader="1"/> 
     201        </FileConfiguration> 
    146202      </File> 
    147203    </Filter> 
  • modules/FileLogger/FileLogger.cpp

    ra0528c4 r452fd41  
    2626} 
    2727std::string FileLogger::getModuleName() { 
    28   return "Simple console logger (used for debug purposes)."; 
     28  return "File logger: " + NSCModuleHelper::getSettingsString("log", "file", "nsclient.log"); 
    2929} 
    3030NSCModuleWrapper::module_version FileLogger::getModuleVersion() { 
  • modules/FileLogger/FileLogger.vcproj

    r1a5449e r452fd41  
    111111        Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 
    112112    </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> 
    113162  </Configurations> 
    114163  <References> 
     
    142191            UsePrecompiledHeader="1"/> 
    143192        </FileConfiguration> 
     193        <FileConfiguration 
     194          Name="Distribution|Win32"> 
     195          <Tool 
     196            Name="VCCLCompilerTool" 
     197            UsePrecompiledHeader="1"/> 
     198        </FileConfiguration> 
    144199      </File> 
    145200    </Filter> 
  • modules/NRPEListener/NRPEListener.cpp

    r1a5449e r452fd41  
    66#include <strEx.h> 
    77#include <time.h> 
     8#include <config.h> 
    89 
    910NRPEListener gNRPEListener; 
     
    2021} 
    2122 
    22 #define DEFAULT_NRPE_PORT 5666 
    2323 
    2424 
    2525bool 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); 
    2828  std::list<std::string>::iterator it; 
    2929  for (it = commands.begin(); it != commands.end(); it++) { 
     
    4040  } 
    4141 
    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  } 
    4449  return true; 
    4550} 
    4651bool 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  } 
    4958  return true; 
    5059} 
     
    7281 
    7382  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) { 
    7584    arrayBuffer::arrayList arr = arrayBuffer::arrayBuffer2list(argLen, char_args); 
    7685    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)); 
    8197    } 
    8298  } 
    8399 
    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); 
    89104  } 
    90105 
  • modules/NRPEListener/NRPEListener.vcproj

    r1a5449e r452fd41  
    113113        Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 
    114114    </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> 
    115165  </Configurations> 
    116166  <References> 
     
    153203            UsePrecompiledHeader="1"/> 
    154204        </FileConfiguration> 
     205        <FileConfiguration 
     206          Name="Distribution|Win32"> 
     207          <Tool 
     208            Name="VCCLCompilerTool" 
     209            UsePrecompiledHeader="1"/> 
     210        </FileConfiguration> 
    155211      </File> 
    156212    </Filter> 
     
    176232      <File 
    177233        RelativePath=".\stdafx.h"> 
     234      </File> 
     235      <File 
     236        RelativePath="..\..\include\thread.h"> 
    178237      </File> 
    179238    </Filter> 
  • modules/NRPEListener/NRPESocket.cpp

    r1a5449e r452fd41  
    130130 
    131131void 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  } 
    132137  simpleSocket::DataBuffer block; 
    133138  client.readAll(block); 
     
    153158  NSC_DEBUG_MSG_STD("Arguments: " + cmd.second); 
    154159 
    155   if (NSCModuleHelper::getSettingsInt("NRPE", "AllowArguments", 0) == 0) { 
     160  if (NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_ARGUMENTS, 0) == 0) { 
    156161    if (!cmd.second.empty()) { 
    157162      NSC_LOG_ERROR("Request contained arguments (not currently allowed)."); 
     
    160165    } 
    161166  } 
    162   if (NSCModuleHelper::getSettingsInt("NRPE", "AllowNastyMetaChars", 0) == 0) { 
     167  if (NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_NASTY_META, 0) == 0) { 
    163168    if (cmd.first.find_first_of(NASTY_METACHARS) != std::string::npos) { 
    164169      NSC_LOG_ERROR("Request command contained illegal metachars!"); 
  • modules/NRPEListener/NRPESocket.h

    r1a5449e r452fd41  
    11#pragma once 
    22#include "resource.h" 
    3 #include <Thread.h> 
    4 #include <Mutex.h> 
    5 #include <WinSock2.h> 
    63#include <Socket.h> 
    7 #include <string.h> 
    84/** 
    95 * @ingroup NSClient++ 
     
    3632class NRPESocket : public simpleSocket::Listener { 
    3733private: 
     34  strEx::splitList allowedHosts_; 
    3835 
    3936public: 
    4037  NRPESocket(); 
    4138  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  } 
    4253 
    4354private: 
  • modules/NRPEListener/stdafx.h

    r2a94f3f r452fd41  
    1414#include <functional> 
    1515 
     16#include <config.h> 
     17 
    1618#include <NSCAPI.h> 
    1719#include <NSCHelper.h> 
  • modules/NSClientCompat/NSClientCompat.cpp

    rc4f6204 r452fd41  
    2626 * @return  
    2727 */ 
    28 NSClientCompat::NSClientCompat() : pdhCollector(NULL) {} 
     28NSClientCompat::NSClientCompat() {} 
    2929/** 
    3030 * Default d-tor 
     
    3838 */ 
    3939bool NSClientCompat::loadModule() { 
    40   pdhCollector = pdhThread.createThread(); 
     40  pdhThread.createThread(); 
    4141  return true; 
    4242} 
     
    110110  std::list<std::string> stl_args; 
    111111  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  } 
    112147 
    113148  int id = atoi(command.c_str()); 
    114   if (id == 0) 
     149  if (id == 0) { 
    115150    return NSCAPI::returnIgnored; 
     151  } 
    116152  switch (id) { 
    117153    case REQ_CLIENTVERSION: 
     
    123159      } 
    124160    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      } 
    128167    case REQ_CPULOAD: 
    129168      { 
     
    135174        while (!stl_args.empty()) { 
    136175          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)); 
    138179          if (v == -1) { 
    139180            msg = "ERROR: We don't collect data that far back."; 
     
    160201 
    161202    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      } 
    164210      return NSCAPI::returnOK; 
    165211 
  • modules/NSClientCompat/NSClientCompat.h

    rd4f294a r452fd41  
    77private: 
    88  PDHCollectorThread pdhThread; 
    9   PDHCollector *pdhCollector; 
    109 
    1110public: 
  • modules/NSClientCompat/NSClientCompat.vcproj

    rc4f6204 r452fd41  
    113113        Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 
    114114    </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> 
    115165  </Configurations> 
    116166  <References> 
     
    156206            UsePrecompiledHeader="1"/> 
    157207        </FileConfiguration> 
     208        <FileConfiguration 
     209          Name="Distribution|Win32"> 
     210          <Tool 
     211            Name="VCCLCompilerTool" 
     212            UsePrecompiledHeader="1"/> 
     213        </FileConfiguration> 
    158214      </File> 
    159215    </Filter> 
  • modules/NSClientCompat/PDHCollector.cpp

    r36c340d r452fd41  
    2222 
    2323 
    24 PDHCollector::PDHCollector() : cpu(BACK_INTERVAL*60/CHECK_INTERVAL), running_(true) { 
     24PDHCollector::PDHCollector() : cpu(BACK_INTERVAL*60/CHECK_INTERVAL), hStopEvent_(NULL) { 
    2525} 
    2626PDHCollector::~PDHCollector()  
    2727{ 
    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_); 
    6330} 
    6431 
     
    9259  } 
    9360 
    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; 
    10965  } 
    11066 
     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; 
    11184  try { 
    11285    pdh.close(); 
     
    11487    NSC_LOG_ERROR_STD("Failed to close performance counters: " + e.str_); 
    11588  } 
    116   NSC_DEBUG_MSG("PDHCollector - shutdown!"); 
    11789  return 0; 
    11890} 
     
    12395 */ 
    12496void 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  } 
    127103} 
    128104/** 
  • modules/NSClientCompat/PDHCollector.h

    ra1e1922 r452fd41  
    2727private: 
    2828  MutexHandler mutexHandler; 
    29   bool running_; 
     29  HANDLE hStopEvent_; 
    3030 
    3131  PDHCollectors::StaticPDHCounterListener memCmtLim; 
  • modules/NSClientListener/NSClientListener.cpp

    r1a5449e r452fd41  
    66#include <strEx.h> 
    77#include <time.h> 
     8#include <config.h> 
    89 
    910NSClientListener gNSClientListener; 
     
    2021} 
    2122 
    22 #define DEFAULT_TCP_PORT 12489 
    23  
    2423bool 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  } 
    2631  return true; 
    2732} 
    2833bool 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  } 
    3040  return true; 
    3141} 
  • modules/NSClientListener/NSClientListener.vcproj

    rc4f6204 r452fd41  
    113113        Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 
    114114    </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> 
    115165  </Configurations> 
    116166  <References> 
     
    150200            UsePrecompiledHeader="1"/> 
    151201        </FileConfiguration> 
     202        <FileConfiguration 
     203          Name="Distribution|Win32"> 
     204          <Tool 
     205            Name="VCCLCompilerTool" 
     206            UsePrecompiledHeader="1"/> 
     207        </FileConfiguration> 
    152208      </File> 
    153209    </Filter> 
  • modules/NSClientListener/NSClientSocket.cpp

    r1a5449e r452fd41  
    1818  strEx::token pwd = strEx::getToken(buffer, '&'); 
    1919  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", "")) ) 
    2121    return "ERROR: Invalid password."; 
    2222  if (pwd.second.empty()) 
     
    4949 
    5050void 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  } 
    5156  simpleSocket::DataBuffer db; 
    5257  client.readAll(db); 
    5358  if (db.getLength() > 0) { 
    54     NSC_DEBUG_MSG_STD("Incoming data length: " + strEx::itos(db.getLength())); 
    5559    std::string incoming(db.getBuffer(), db.getLength()); 
    5660    NSC_DEBUG_MSG_STD("Incoming data: " + incoming); 
  • modules/NSClientListener/NSClientSocket.h

    r1a5449e r452fd41  
    11#pragma once 
    22#include "resource.h" 
    3 #include <Thread.h> 
    4 #include <Mutex.h> 
    5 #include <WinSock2.h> 
    6 #include <strEx.h> 
    7 #include <charEx.h> 
    83#include <Socket.h> 
    94/** 
     
    3328class NSClientSocket : public simpleSocket::Listener { 
    3429private: 
     30  strEx::splitList allowedHosts_; 
    3531 
    3632public: 
     
    4137  virtual void onAccept(simpleSocket::Socket client); 
    4238  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 
     50public: 
     51  void setAllowedHosts(strEx::splitList allowedHosts) { 
     52    allowedHosts_ = allowedHosts; 
     53  } 
     54 
    4355}; 
    4456 
  • modules/SysTray/SysTray.cpp

    r402f042 r452fd41  
    5151 
    5252std::string SysTray::getModuleName() { 
    53   return "This is a nice systray module."; 
     53  return "System Tray icon Module."; 
    5454} 
    5555NSCModuleWrapper::module_version SysTray::getModuleVersion() { 
  • modules/SysTray/SysTray.vcproj

    r1a5449e r452fd41  
    108108        Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 
    109109    </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> 
    110159  </Configurations> 
    111160  <References> 
     
    136185            UsePrecompiledHeader="1"/> 
    137186        </FileConfiguration> 
     187        <FileConfiguration 
     188          Name="Distribution|Win32"> 
     189          <Tool 
     190            Name="VCCLCompilerTool" 
     191            UsePrecompiledHeader="1"/> 
     192        </FileConfiguration> 
    138193      </File> 
    139194      <File 
  • readme.txt

    r36c340d r452fd41  
    11NSClient++ 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 compatible  
     2(and possibly other monitoring tools). It is an attempt to create a NSClient and NRPE compatible  
    33but yet extendable performance service for windows. 
    44 
    5  
    6 This is an initial NSClient++ test release. 
    7  
    8 This version has many of the features from NSClient. 
     5NSClient 
    96The following commands (from check_nt) are supported. 
    107 * CLIENTVERSION 
     
    1613 * PROCSTATE 
    1714 
     15NRPE 
     16All scripts "should" work (haven't actually tried myself though). 
     17Notice that encryption is still missing. 
     18 
    1819Installation: 
    1920To install simply copy all files to directory on the server and run  
    20 the following command: "NSClient++ /install" to uninstall run:  
     21the following command: "NSClient++ /install" to un-install run:  
    2122"NSClient++ /uninstall". 
    2223 
     
    2930    about - Show some info (version et.al.) 
    3031    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. 
    3333 
    3434The directory structure: 
    3535  <install root> 
    3636    - 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 
    3841    <modules> 
    3942      - Various NSClient++ modules available to this instance. 
    4043 
    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. 
     44A 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. 
    5361 
    5462Settings: 
    55 The following things can be changed ion the NSC.ini file. 
     63For details refer to NSC.ini. 
    5664 
    57 [generic] 
    58 password=secret-password 
    59 # The password to use. 
     65About NSClient++ 
     66URL: http://www.sf.net/projects/nscplus 
    6067 
    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 
     68Contact the author: 
     69Michael Medin 
     70EMail: michael <at> medin <dot> name 
     71Address: (feel free to send a postcard if you find this useful :) 
     72Michael Medin 
     73Terapivaegen 6b 3tr 
     74SE-141 55 HUDDINGE 
     75SWEDEN 
Note: See TracChangeset for help on using the changeset viewer.