Changeset 22d2739 in nscp


Ignore:
Timestamp:
11/06/07 21:26:06 (6 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
3ece2bd
Parents:
b749b8d
Message:

2007-11-06 MickeM

+ Added CLI interface to CheckWMI to check queries

Files:
12 edited

Legend:

Unmodified
Added
Removed
  • AutoBuild.h

    rb749b8d r22d2739  
    33// change the FALSE to TRUE for autoincrement of build number 
    44#define INCREMENT_VERSION TRUE 
    5 #define FILEVER        0,2,7,42 
    6 #define PRODUCTVER     0,2,7,140 
    7 #define STRFILEVER     "0.2.7.42" 
    8 #define STRPRODUCTVER  "0.2.7.140" 
    9 #define STRPRODUCTDATE  "2007-11-04" 
     5#define FILEVER        0,2,7,44 
     6#define PRODUCTVER     0,2,7,142 
     7#define STRFILEVER     "0.2.7.44" 
     8#define STRPRODUCTVER  "0.2.7.142" 
     9#define STRPRODUCTDATE  "2007-11-06" 
    1010#endif // AUTOBUILD_H 
  • NSCPlugin.h

    rdc65e35 r22d2739  
    153153  std::string getCongifurationMeta(); 
    154154  int commandLineExec(const char* command, const unsigned int argLen, char **arguments); 
     155  std::string getModule() { 
     156    if (file_.empty()) 
     157      return ""; 
     158    std::string ret = file_; 
     159    int pos = ret.find_last_of("\\"); 
     160    if (pos != std::string::npos && ++pos < ret.length()) { 
     161      ret = ret.substr(pos); 
     162    } 
     163    pos = ret.find_last_of("."); 
     164    if (pos != std::string::npos) { 
     165      ret = ret.substr(0, pos); 
     166    } 
     167    return ret; 
     168  } 
    155169 
    156170private: 
  • NSClient++.cpp

    rb749b8d r22d2739  
    241241    return -1; 
    242242  } 
     243  std::string moduleList = ""; 
    243244  for (pluginList::size_type i=0;i<plugins_.size();++i) { 
    244245    NSCPlugin *p = plugins_[i]; 
    245     if (p->getName() == sModule) { 
     246    if (!moduleList.empty()) 
     247      moduleList += ", "; 
     248    moduleList += p->getModule(); 
     249    if (p->getModule() == sModule) { 
    246250      LOG_DEBUG_STD("Found module: " + p->getName() + "..."); 
    247251      try { 
     
    249253      } catch (NSPluginException e) { 
    250254        LOG_ERROR_STD("Could not execute command: " + e.error_ + " in " + e.file_); 
    251       } 
    252     } 
    253   } 
    254   LOG_ERROR("Module not found."); 
     255        return -1; 
     256      } 
     257    } 
     258  } 
     259  LOG_ERROR_STD("Module not found: " + module + " available modules are: " + moduleList); 
    255260  return 0; 
    256261} 
  • NSClient++.vcproj

    r12edcec r22d2739  
    418418      <Tool 
    419419        Name="VCPreBuildEventTool" 
    420         CommandLine="XAutobuild.exe -f $(ProjectDir)" 
     420        CommandLine="XAutobuild.exe -f &quot;$(ProjectDir)&quot;" 
    421421      /> 
    422422      <Tool 
    423423        Name="VCCustomBuildTool" 
    424         CommandLine="echo Copying dependency DLLs&#x0D;&#x0A;cmd /c &quot;xcopy /Q /Y $(InputDir)\dist_dll\*.dll $(InputDir)\Dist\&quot;&#x0D;&#x0A;echo Removing old archive&#x0D;&#x0A;cmd /c &quot;del $(InputDir)\Dist\modules\*.pdb&quot;&#x0D;&#x0A;cmd /c &quot;del $(InputDir)\Dist\*.zip&quot;&#x0D;&#x0A;echo Making archive&#x0D;&#x0A;7z.exe a -r -tzip -bd $(TargetDir)\$(InputName)-$(PlatformName).zip $(TargetDir)\*&#x0D;&#x0A;echo Renaming archive&#x0D;&#x0A;postbuild.pl &quot;$(TargetDir)\$(InputName)-$(PlatformName).zip&quot;&#x0D;&#x0A;echo Sending to server&#x0D;&#x0A;echo pscp.exe $(TargetDir)\*.zip mickem@ssl.nakednuns.org:/var/www/files/nightly/&#x0D;&#x0A;pscp.exe $(TargetDir)\*.zip mickem@ssl.nakednuns.org:/var/www/files/nightly/&#x0D;&#x0A;" 
     424        CommandLine="echo Copying dependency DLLs&#x0D;&#x0A;cmd /c &quot;xcopy /Q /Y $(InputDir)\dist_dll\*.dll $(InputDir)\Dist\&quot;&#x0D;&#x0A;echo Removing old archive&#x0D;&#x0A;cmd /c &quot;del &quot;$(InputDir)\Dist\modules\*.pdb&quot;&quot;&#x0D;&#x0A;cmd /c &quot;del &quot;$(InputDir)\Dist\*.zip&quot;&quot;&#x0D;&#x0A;echo Making archive: 7z.exe a -r -tzip -bd &quot;$(TargetDir)\$(InputName)-$(PlatformName).zip&quot; &quot;$(TargetDir)\*&quot;&#x0D;&#x0A;7z.exe a -r -tzip -bd &quot;$(TargetDir)\$(InputName)-$(PlatformName).zip&quot; &quot;$(TargetDir)\*&quot;&#x0D;&#x0A;echo Renaming archive&#x0D;&#x0A;postbuild.pl &quot;$(TargetDir)\$(InputName)-$(PlatformName).zip&quot;&#x0D;&#x0A;echo Sending to server&#x0D;&#x0A;echo pscp.exe &quot;$(TargetDir)\*.zip&quot; mickem@ssl.nakednuns.org:/var/www/files/nightly/&#x0D;&#x0A;pscp.exe &quot;$(TargetDir)\*.zip&quot; mickem@ssl.nakednuns.org:/var/www/files/nightly/&#x0D;&#x0A;" 
    425425        Outputs="$(InputDir)\Dist\$(ProjectName).zip" 
    426426      /> 
     
    13911391          <Tool 
    13921392            Name="VCCustomBuildTool" 
     1393            CommandLine="echo Copying $(InputFileName)...&#x0D;&#x0A;cmd /c &quot;copy &quot;$(InputDir)\$(InputName)&quot; &quot;$(InputDir)\Dist\&quot;&quot;&#x0D;&#x0A;" 
     1394            Outputs="$(InputDir)\Dist\$(InputFileName)" 
     1395          /> 
     1396        </FileConfiguration> 
     1397        <FileConfiguration 
     1398          Name="Distribution|x64" 
     1399          > 
     1400          <Tool 
     1401            Name="VCCustomBuildTool" 
    13931402            CommandLine="echo Copying $(InputFileName)...&#x0D;&#x0A;cmd /c &quot;copy $(InputDir)\$(InputName) $(InputDir)\Dist\&quot;&#x0D;&#x0A;" 
    13941403            Outputs="$(InputDir)\Dist\$(InputFileName)" 
     
    13961405        </FileConfiguration> 
    13971406        <FileConfiguration 
    1398           Name="Distribution|x64" 
     1407          Name="Nightly|Win32" 
     1408          > 
     1409          <Tool 
     1410            Name="VCCustomBuildTool" 
     1411            CommandLine="echo Copying $(InputFileName)...&#x0D;&#x0A;cmd /c &quot;copy &quot;$(InputDir)\$(InputName)&quot; &quot;$(InputDir)\Dist\&quot;&quot;&#x0D;&#x0A;" 
     1412            Outputs="$(InputDir)\Dist\$(InputFileName)" 
     1413          /> 
     1414        </FileConfiguration> 
     1415        <FileConfiguration 
     1416          Name="Nightly|x64" 
    13991417          > 
    14001418          <Tool 
     
    14041422          /> 
    14051423        </FileConfiguration> 
    1406         <FileConfiguration 
    1407           Name="Nightly|Win32" 
    1408           > 
    1409           <Tool 
    1410             Name="VCCustomBuildTool" 
    1411             CommandLine="echo Copying $(InputFileName)...&#x0D;&#x0A;cmd /c &quot;copy &quot;$(InputDir)\$(InputName)&quot; &quot;$(InputDir)\Dist\&quot;&quot;&#x0D;&#x0A;" 
    1412             Outputs="$(InputDir)\Dist\$(InputFileName)" 
    1413           /> 
    1414         </FileConfiguration> 
    1415         <FileConfiguration 
    1416           Name="Nightly|x64" 
    1417           > 
    1418           <Tool 
    1419             Name="VCCustomBuildTool" 
    1420             CommandLine="echo Copying $(InputFileName)...&#x0D;&#x0A;cmd /c &quot;copy $(InputDir)\$(InputName) $(InputDir)\Dist\&quot;&#x0D;&#x0A;" 
    1421             Outputs="$(InputDir)\Dist\$(InputFileName)" 
    1422           /> 
    1423         </FileConfiguration> 
    14241424      </File> 
    14251425      <File 
     
    14671467          <Tool 
    14681468            Name="VCCustomBuildTool" 
     1469            CommandLine="echo Copying $(InputFileName)...&#x0D;&#x0A;cmd /c &quot;copy &quot;$(InputDir)\$(InputFileName)&quot; &quot;$(TargetDir)&quot;&quot;&#x0D;&#x0A;" 
     1470            Outputs="$(TargetDir)$(InputFileName)" 
     1471          /> 
     1472        </FileConfiguration> 
     1473        <FileConfiguration 
     1474          Name="Distribution|x64" 
     1475          > 
     1476          <Tool 
     1477            Name="VCCustomBuildTool" 
    14691478            CommandLine="echo Copying $(InputFileName)...&#x0D;&#x0A;cmd /c &quot;copy $(InputDir)\$(InputFileName) $(TargetDir)&quot;&#x0D;&#x0A;" 
    14701479            Outputs="$(TargetDir)$(InputFileName)" 
     
    14721481        </FileConfiguration> 
    14731482        <FileConfiguration 
    1474           Name="Distribution|x64" 
     1483          Name="Nightly|Win32" 
     1484          > 
     1485          <Tool 
     1486            Name="VCCustomBuildTool" 
     1487            CommandLine="echo Copying $(InputFileName)...&#x0D;&#x0A;cmd /c &quot;copy &quot;$(InputDir)\$(InputFileName)&quot; &quot;$(TargetDir)&quot;&quot;&#x0D;&#x0A;" 
     1488            Outputs="$(TargetDir)$(InputFileName)" 
     1489          /> 
     1490        </FileConfiguration> 
     1491        <FileConfiguration 
     1492          Name="Nightly|x64" 
    14751493          > 
    14761494          <Tool 
     
    14801498          /> 
    14811499        </FileConfiguration> 
    1482         <FileConfiguration 
    1483           Name="Nightly|Win32" 
    1484           > 
    1485           <Tool 
    1486             Name="VCCustomBuildTool" 
    1487             CommandLine="echo Copying $(InputFileName)...&#x0D;&#x0A;cmd /c &quot;copy &quot;$(InputDir)\$(InputFileName)&quot; &quot;$(TargetDir)&quot;&quot;&#x0D;&#x0A;" 
    1488             Outputs="$(TargetDir)$(InputFileName)" 
    1489           /> 
    1490         </FileConfiguration> 
    1491         <FileConfiguration 
    1492           Name="Nightly|x64" 
    1493           > 
    1494           <Tool 
    1495             Name="VCCustomBuildTool" 
    1496             CommandLine="echo Copying $(InputFileName)...&#x0D;&#x0A;cmd /c &quot;copy $(InputDir)\$(InputFileName) $(TargetDir)&quot;&#x0D;&#x0A;" 
    1497             Outputs="$(TargetDir)$(InputFileName)" 
    1498           /> 
    1499         </FileConfiguration> 
    15001500      </File> 
    15011501      <File 
     
    15891589          <Tool 
    15901590            Name="VCCustomBuildTool" 
     1591            CommandLine="echo Copying $(InputFileName)...&#x0D;&#x0A;cmd /c &quot;copy &quot;$(InputDir)\$(InputFileName)&quot; &quot;$(TargetDir)&quot;&quot;&#x0D;&#x0A;" 
     1592            Outputs="$(TargetDir)\$(InputFileName) " 
     1593          /> 
     1594        </FileConfiguration> 
     1595        <FileConfiguration 
     1596          Name="Distribution|x64" 
     1597          > 
     1598          <Tool 
     1599            Name="VCCustomBuildTool" 
    15911600            CommandLine="echo Copying $(InputFileName)...&#x0D;&#x0A;cmd /c &quot;copy $(InputDir)\$(InputFileName) $(TargetDir)&quot;&#x0D;&#x0A;" 
    15921601            Outputs="$(TargetDir)\$(InputFileName) " 
     
    15941603        </FileConfiguration> 
    15951604        <FileConfiguration 
    1596           Name="Distribution|x64" 
     1605          Name="Nightly|Win32" 
     1606          > 
     1607          <Tool 
     1608            Name="VCCustomBuildTool" 
     1609            CommandLine="echo Copying $(InputFileName)...&#x0D;&#x0A;cmd /c &quot;copy &quot;$(InputDir)\$(InputFileName)&quot; &quot;$(TargetDir)&quot;&quot;&#x0D;&#x0A;" 
     1610            Outputs="$(TargetDir)\$(InputFileName) " 
     1611          /> 
     1612        </FileConfiguration> 
     1613        <FileConfiguration 
     1614          Name="Nightly|x64" 
    15971615          > 
    15981616          <Tool 
     
    16021620          /> 
    16031621        </FileConfiguration> 
    1604         <FileConfiguration 
    1605           Name="Nightly|Win32" 
    1606           > 
    1607           <Tool 
    1608             Name="VCCustomBuildTool" 
    1609             CommandLine="echo Copying $(InputFileName)...&#x0D;&#x0A;cmd /c &quot;copy &quot;$(InputDir)\$(InputFileName)&quot; &quot;$(TargetDir)&quot;&quot;&#x0D;&#x0A;" 
    1610             Outputs="$(TargetDir)\$(InputFileName) " 
    1611           /> 
    1612         </FileConfiguration> 
    1613         <FileConfiguration 
    1614           Name="Nightly|x64" 
    1615           > 
    1616           <Tool 
    1617             Name="VCCustomBuildTool" 
    1618             CommandLine="echo Copying $(InputFileName)...&#x0D;&#x0A;cmd /c &quot;copy $(InputDir)\$(InputFileName) $(TargetDir)&quot;&#x0D;&#x0A;" 
    1619             Outputs="$(TargetDir)\$(InputFileName) " 
    1620           /> 
    1621         </FileConfiguration> 
    16221622      </File> 
    16231623      <File 
     
    16291629          <Tool 
    16301630            Name="VCCustomBuildTool" 
    1631             CommandLine="echo Copying $(InputFileName)...&#x0D;&#x0A;cmd /c &quot;copy $(InputDir)\$(InputFileName) $(InputDir)\Dist\$(InputName).ini&quot;&#x0D;&#x0A;" 
     1631            CommandLine="echo Copying $(InputFileName)...&#x0D;&#x0A;cmd /c &quot;copy &quot;$(InputDir)\$(InputFileName)&quot; &quot;$(InputDir)\Dist\$(InputName).ini&quot;&quot;&#x0D;&#x0A;" 
    16321632            Outputs="$(InputDir)\Dist\$(InputName).ini" 
    16331633          /> 
     
    16891689          <Tool 
    16901690            Name="VCCustomBuildTool" 
    1691             CommandLine="echo Copying $(InputFileName)...&#x0D;&#x0A;cmd /c &quot;copy &quot;$(InputDir)\$(InputFileName)&quot; &quot;$(InputDir)\$(OutDir)&quot;&quot;" 
     1691            CommandLine="echo Copying $(InputFileName)...&#x0D;&#x0A;cmd /c &quot;copy &quot;$(InputDir)\$(InputFileName)&quot; &quot;$(InputDir)\$(OutDir)&quot;&quot;&#x0D;&#x0A;" 
    16921692            Outputs="$(InputDir)\$(OutDir)\$(InputFileName)" 
    16931693          /> 
     
    16981698          <Tool 
    16991699            Name="VCCustomBuildTool" 
    1700             CommandLine="echo Copying $(InputFileName)...&#x0D;&#x0A;cmd /c &quot;copy &quot;$(InputDir)\$(InputFileName)&quot; &quot;$(InputDir)\$(OutDir)&quot;&quot;" 
     1700            CommandLine="echo Copying $(InputFileName)...&#x0D;&#x0A;cmd /c &quot;copy &quot;$(InputDir)\$(InputFileName)&quot; &quot;$(InputDir)\$(OutDir)&quot;&quot;&#x0D;&#x0A;" 
    17011701            Outputs="$(InputDir)\$(OutDir)\$(InputFileName)" 
    17021702          /> 
  • changelog

    rb749b8d r22d2739  
    44 * Fix installer (after configuration UI) 
    55 * Add module for relaying events 
    6  * Add filtering to WMI module 
    76 * Fix WMI module 
    87 * Fix PDH problems 
    98 * Add API for rehashing the daemon (or implement it the API is there but does nothing) 
     9 
     102007-11-06 MickeM 
     11 + Added CLI interface to CheckWMI to check queries 
    1012 
    11132007-11-04 MickeM 
  • include/NSCHelper.cpp

    r478588b r22d2739  
    156156    if ((msgType == NSCAPI::debug) && (!logDebug())) 
    157157      return; 
     158    std::string::size_type pos = file.find_last_of("\\"); 
     159    if (pos != std::string::npos) 
     160      file = file.substr(pos); 
    158161    return fNSAPIMessage(msgType, file.c_str(), line, message.c_str()); 
    159162  } 
  • modules/CheckWMI/CheckWMI.cpp

    rb749b8d r22d2739  
    2525#include <time.h> 
    2626#include <map> 
     27#include <vector> 
    2728 
    2829 
     
    155156  return NSCAPI::returnIgnored; 
    156157} 
     158int CheckWMI::commandLineExec(const char* command, const unsigned int argLen, char** char_args) { 
     159  //WMIQuery wmiQuery; 
     160  std::string query = command; 
     161  query += " " + arrayBuffer::arrayBuffer2string(char_args, argLen, " "); 
     162  WMIQuery::result_type rows; 
     163  try { 
     164    rows = wmiQuery.execute(query); 
     165  } catch (WMIException e) { 
     166    std::cout << "WMIQuery failed: " + e.getMessage() << std::endl; 
     167    return -1; 
     168  } 
     169  std::vector<int> widths; 
     170  for (WMIQuery::result_type::iterator citRow = rows.begin(); citRow != rows.end(); ++citRow) { 
     171    const WMIQuery::wmi_row vals = *citRow; 
     172    if (citRow == rows.begin()) { 
     173      for (WMIQuery::wmi_row::list_type::const_iterator citCol = vals.results.begin(); citCol != vals.results.end(); ++citCol) { 
     174        widths.push_back( (*citCol).first.length()+1 ); 
     175      } 
     176    } 
     177    int i=0; 
     178    for (WMIQuery::wmi_row::list_type::const_iterator citCol = vals.results.begin(); citCol != vals.results.end(); ++citCol, i++) { 
     179      widths[i] = max(widths[i], (*citCol).second.string.length()+1); 
     180    } 
     181  } 
     182 
     183  std::string row2 = "|"; 
     184  for (WMIQuery::result_type::iterator citRow = rows.begin(); citRow != rows.end(); ++citRow) { 
     185    const WMIQuery::wmi_row vals = *citRow; 
     186    if (citRow == rows.begin()) { 
     187      int i=0; 
     188      std::string row1 = "|"; 
     189      for (WMIQuery::wmi_row::list_type::const_iterator citCol = vals.results.begin(); citCol != vals.results.end(); ++citCol, i++) { 
     190        int w = widths[i]-(*citCol).first.length(); 
     191        if (w<0) w=0; 
     192        row1 += std::string(w, ' ') + (*citCol).first + " |"; 
     193        row2 += std::string(widths[i], '-') + "-+"; 
     194 
     195      } 
     196      NSC_LOG_MESSAGE(row2); 
     197      NSC_LOG_MESSAGE(row1); 
     198      NSC_LOG_MESSAGE(row2); 
     199    } 
     200    int i=0; 
     201    std::string row = "|"; 
     202    for (WMIQuery::wmi_row::list_type::const_iterator citCol = vals.results.begin(); citCol != vals.results.end(); ++citCol, i++) { 
     203      int w = widths[i]-(*citCol).second.string.length(); 
     204      if (w<0) w=0; 
     205      row += std::string(w, ' ') + (*citCol).second.string + " |"; 
     206    } 
     207    NSC_LOG_MESSAGE(row); 
     208  } 
     209  NSC_LOG_MESSAGE(row2); 
     210  return 0; 
     211} 
    157212 
    158213 
     
    160215NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    161216NSC_WRAPPERS_HANDLE_CMD_DEF(gCheckWMI); 
     217NSC_WRAPPERS_CLI_DEF(gCheckWMI); 
  • modules/CheckWMI/CheckWMI.def

    r1b7ae3d r22d2739  
    1212  NSUnloadModule 
    1313  NSGetModuleDescription 
     14  NSCommandLineExec 
    1415 
  • modules/CheckWMI/CheckWMI.h

    rb749b8d r22d2739  
    2020***************************************************************************/ 
    2121NSC_WRAPPERS_MAIN(); 
     22NSC_WRAPPERS_CLI(); 
     23 
    2224#include <config.h> 
    2325#include <strEx.h> 
     
    3840 
    3941  std::string getModuleName() { 
    40     return "CheckWMI Various Disk related checks."; 
     42    return "CheckWMI"; 
    4143  } 
    4244  std::string getModuleDescription() { 
     
    5153  bool hasMessageHandler(); 
    5254  NSCAPI::nagiosReturn handleCommand(const strEx::blindstr command, const unsigned int argLen, char **char_args, std::string &message, std::string &perf); 
     55  int CheckWMI::commandLineExec(const char* command,const unsigned int argLen,char** args); 
    5356 
    5457  // Check commands 
  • modules/CheckWMI/CheckWMI.vcproj

    rb749b8d r22d2739  
    758758      </File> 
    759759      <File 
     760        RelativePath=".\CheckWMI.def" 
     761        > 
     762      </File> 
     763      <File 
    760764        RelativePath="..\..\include\NSCHelper.cpp" 
    761765        > 
  • modules/CheckWMI/WMIQuery.cpp

    rb749b8d r22d2739  
    6262} 
    6363 
     64std::string WMIQuery::sanitize_string(LPTSTR in) { 
     65  TCHAR *p = in; 
     66  while (*p) { 
     67    if (p[0] < ' ' || p[0] > '}') 
     68      p[0] = '.'; 
     69    p++; 
     70  }  
     71  return in; 
     72} 
    6473 
    6574WMIQuery::result_type WMIQuery::execute(std::string query) 
  • modules/CheckWMI/WMIQuery.h

    rb749b8d r22d2739  
    152152 
    153153  result_type  execute(std::string query); 
     154  std::string sanitize_string(LPTSTR in); 
    154155 
    155156  bool initialize(); 
Note: See TracChangeset for help on using the changeset viewer.