Changeset c88cf98 in nscp


Ignore:
Timestamp:
03/12/12 07:40:24 (15 months ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
74e060a
Parents:
fb8241a
Message:
  • Fixed a lot of issues with the installer
  • Added so the installer can generate a config file for you
  • Fixed so installer uses the correct path for password and allowed hosts
  • Added sample python WMI script to list all classes in all namespaces
  • Fixed so if python scripts does not expose init and shutdown they will not be called
  • Added new option --simple to CheckWMI wmi commands to return a simple list without formatting.
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • changelog

    rfb8241a rc88cf98  
    55 * Fix RtlStringFromGUID problem on NT4 
    66 
     72012-03-11 MickeM 
     8 * Fixed a lot of issues with the installer 
     9 * Added so the installer can generate a config file for you 
     10 * Fixed so installer uses the correct path for password and allowed hosts 
     11 
    7122012-03-08 MickeM 
    813 * Major improvments to the WMI command line syntax. 
     
    1015   Means you can use NSCLient++ as a almost full featured WMI command line client. 
    1116   For details use: nscp wmi --help 
     17 * Added sample python WMI script to list all classes in all namespaces 
     18 * Fixed so if python scripts does not expose init and shutdown they will not be called 
     19 * Added new option --simple to CheckWMI wmi commands to return a simple list without formatting. 
    1220   
    13212012-03-06 MickeM 
  • helpers/installer-dlls/main_dll/main_dll.cpp

    r441a022 rc88cf98  
    313313    } 
    314314 
    315     std::wstring defpath = _T("/settings/default/"); 
     315    std::wstring defpath = _T("/settings/default"); 
    316316    write_changed_key(h, data, _T("ALLOWED_HOSTS"), defpath, _T("allowed hosts")); 
    317317    write_changed_key(h, data, _T("NSCLIENT_PWD"), defpath, _T("password")); 
  • helpers/installers/installer/Product.wxs

    r523576e rc88cf98  
    3030 
    3131    <?if "$(var.arch)" = "x64"?> 
    32       <Condition Message="x64 bit version not supported (by installer) on Win32 bit platform (get Win32 bit version instead)">NOT VersionNT64</Condition> 
     32      <Condition Message="x64 bit version not supported on Win32 bit platform (get Win32 instead)">VersionNT64</Condition> 
    3333    <?endif?> 
    3434    <Media Id="1" Cabinet="Product.cab" EmbedCab="yes" CompressionLevel="high" /> 
     
    4444              <fire:FirewallException Id="FWX1" Name="NSClient++ Monitoring Agent" Scope="any" IgnoreFailure="yes" /> 
    4545            </File> 
     46            <RemoveFile Id="PurgeLogFiles" Name="*.log" On="uninstall" /> 
    4647            <ServiceInstall Id="SWCNSCP" 
    4748              Name="[SERVICE_NAME]" DisplayName="$(var.App.Title) ($(var.arch))" 
     
    4950              Description="Monitoring agent for nagios (and others) used to respond to status queries" 
    5051              Arguments="service --run --name [SERVICE_NAME]"> 
    51         <ServiceDependency Id="Tcpip" /> 
    52       </ServiceInstall> 
     52              <ServiceDependency Id="Tcpip" /> 
     53            </ServiceInstall> 
    5354            <ServiceControl Id="StartSWCNSCP" Name="[SERVICE_NAME]" Start="install" Stop="both" Wait="yes" Remove="uninstall" /> 
    5455            <RemoveFolder Id="RemoveMenuShortcuts" Directory="ProgramMenuDir" On="uninstall" /> 
     
    7778            --> 
    7879            <File Id="ErrorReporter" Name="reporter.exe" DiskId="1" Source="$(var.Source)/reporter.exe" Vital="yes" /> 
    79             <!-- 
    80               <File Id="NSClientINI" Name="NSC.ini" LongName="NSC.ini" DiskId="1" Source="$(var.Path.ini)/NSC.ini" Vital="yes"/> 
    81             --> 
     80          </Component> 
     81          <Component Id="SampleConfigUser" Guid="AA636DB0-A0B9-4dd2-B74C-$(var.Postfix.GUID)" Win64="$(var.Win64)"> 
     82            <File Id="NSClientINIUser" Name="nsclient.ini" DiskId="1" Source="$(var.Path.ini)/nsclient.dist" Vital="no" PatchIgnore="yes"> 
     83              <Permission User="Everyone" GenericRead="yes" Read="yes" GenericWrite="yes" Write="yes"/> 
     84            </File> 
     85            <RemoveFile Id="PurgeConfigFilesUser" Name="*.ini" On="uninstall" /> 
     86            <Condition>INSTALL_SAMPLE_CONFIG AND USER_WRITABLE_CONFIG</Condition> 
     87          </Component> 
     88          <Component Id="SampleConfig" Guid="AAA36DB0-A0B9-4dd2-B74C-$(var.Postfix.GUID)" Win64="$(var.Win64)"> 
     89            <File Id="NSClientINI" Name="nsclient.ini" DiskId="1" Source="$(var.Path.ini)/nsclient.dist" Vital="no" PatchIgnore="yes" /> 
     90            <RemoveFile Id="PurgeConfigFiles" Name="*.ini" On="uninstall" /> 
     91            <Condition>INSTALL_SAMPLE_CONFIG AND NOT USER_WRITABLE_CONFIG</Condition> 
    8292          </Component> 
    8393          <Component Id="RandomFiles" Guid="B4636DB0-A0B9-4dd2-B74C-$(var.Postfix.GUID)" Win64="$(var.Win64)"> 
     
    236246        <ComponentRef Id="Shortcuts" /> 
    237247        <ComponentRef Id="Helpers" /> 
    238         <ComponentRef Id="RandomFiles" /> 
    239       </Feature> 
     248        <ComponentRef Id="RandomFiles" /> 
     249        <ComponentRef Id="SampleConfigUser" /> 
     250        <ComponentRef Id="SampleConfig" /> 
     251      </Feature> 
    240252      <Feature Id="Documentation" Title="Documentation (pdf)" Description="Documentation for NSClient++ and how to use it from Nagios" Level="1"> 
    241253        <ComponentRef Id="NagiosDocumentation" /> 
     
    279291    <CustomAction Id='ImportConfig'     BinaryKey='InstallerHelper' DllEntry='ImportConfig'     Impersonate='yes' Execute="immediate" Return="check" /> 
    280292    <CustomAction Id='ScheduleWriteConfig'  BinaryKey='InstallerHelper' DllEntry='ScheduleWriteConfig'  Impersonate='yes' Execute="immediate" Return="check" /> 
    281     <CustomAction Id="ExecWriteConfig"    BinaryKey="InstallerHelper" DllEntry="ExecWriteConfig"    Impersonate="no" Execute="deferred" Return="check"  /> 
    282  
    283     <CustomAction Id='NeedUninstall'    BinaryKey='InstallerHelper' DllEntry='NeedUninstall'    Impersonate='yes' Execute="immediate" Return="check" /> 
     293    <CustomAction Id="ExecWriteConfig"    BinaryKey="InstallerHelper" DllEntry="ExecWriteConfig"  Impersonate="no" Execute="deferred" Return="check"  /> 
     294 
     295    <CustomAction Id='NeedUninstall'    BinaryKey='InstallerHelper' DllEntry='NeedUninstall'  Impersonate='yes' Execute="immediate" Return="check" /> 
    284296    <CustomAction Id="PreventDowngrading" Error="Newer version already installed." /> 
    285297 
     298 
     299    <CustomAction Id="GenConfig.Command" Property="GenConfig" Value="&quot;[#NSClientEXE]&quot; settings --generate ini"/> 
     300    <CustomAction Id="GenConfig" BinaryKey="WixCA" DllEntry="CAQuietExec" Impersonate="no" Return="ignore" Execute="deferred"/> 
     301 
    286302    <Binary Id='InstallerHelper' SourceFile='$(var.Helpers)/main_dll.dll' /> 
    287303 
    288     <InstallExecuteSequence> 
     304    <InstallExecuteSequence> 
    289305      <RemoveExistingProducts After='InstallInitialize'/> 
    290306      <Custom Action="PreventDowngrading" After="FindRelatedProducts">NEWAPPFOUND</Custom> 
    291       <Custom Action="ScheduleWriteConfig" After='InstallFiles' /> 
     307      <Custom Action="ScheduleWriteConfig" After="InstallFiles">NOT REMOVE</Custom> 
     308      <Custom Action="GenConfig.Command" After="ScheduleWriteConfig">NOT REMOVE AND INSTALL_SAMPLE_CONFIG = 1</Custom> 
     309      <Custom Action="GenConfig" After="GenConfig.Command">NOT REMOVE AND INSTALL_SAMPLE_CONFIG = 1</Custom> 
    292310    </InstallExecuteSequence> 
    293311 
    294312    <InstallUISequence> 
    295313      <Custom Action="PreventDowngrading" After="FindRelatedProducts">NEWAPPFOUND</Custom> 
    296       <Custom Action="NeedUninstall" After="FindRelatedProducts" >1</Custom> 
    297       <Custom Action="ImportConfig" After="CostFinalize" >1</Custom> 
     314      <Custom Action="NeedUninstall" After="FindRelatedProducts">1</Custom> 
     315      <Custom Action="ImportConfig" After="CostFinalize">NOT REMOVE</Custom> 
    298316    </InstallUISequence> 
    299317 
  • helpers/installers/installer/properties.wxs

    rb7d17f8 rc88cf98  
    1919  <Property Id="NSCLIENT_PWD_DEFAULT"></Property> 
    2020   --> 
    21   <Property Id="CONFIGURATION_TYPE_DEFAULT">ini://${shared-path}/nsclient.ini</Property> 
     21  <Property Id="CONFIGURATION_TYPE_DEFAULT">ini://${exe-path}/nsclient.ini</Property> 
    2222 
    2323  <!-- CONFIGURE INITAL VALUES IN CONFIG UI --> 
     
    3030  <Property Id="ALLOWED_HOSTS"></Property> 
    3131  <Property Id="NSCLIENT_PWD"></Property> 
     32  <Property Id="CONFIGURATION_TYPE">ini://${shared-path}/nsclient.ini</Property> 
    3233   --> 
    33   <Property Id="CONFIGURATION_TYPE">ini://${shared-path}/nsclient.ini</Property> 
     34  <Property Id="CONFIGURATION_TYPE">ini://${exe-path}/nsclient.ini</Property> 
     35  <Property Id="INSTALL_SAMPLE_CONFIG">1</Property> 
    3436 
    3537  <!-- CONFIGURE THE INSTALLER --> 
  • helpers/installers/ui/SelectConfigurationDlg.wxs

    re11d494 rc88cf98  
    1515        </Control> 
    1616 
    17         <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="&amp;Back"> 
     17        <Control Id="generateConfig" Type="CheckBox" X="45" Y="73" Width="260" Height="20" Property="INSTALL_SAMPLE_CONFIG" Text="Install sample configuration" CheckBoxValue="1"> 
     18          <Condition Action="enable">CONFIGURATION_TYPE = "ini://${exe-path}/nsclient.ini"</Condition> 
     19          <Condition Action="disable"><![CDATA[CONFIGURATION_TYPE <> "ini://${exe-path}/nsclient.ini"]]></Condition> 
     20        </Control> 
     21        <Control Id="userWriteConfig" Type="CheckBox" X="60"  Y="88" Width="260" Height="20" Property="USER_WRITABLE_CONFIG" Text="Allow Everyone to write config file" CheckBoxValue="1"> 
     22          <Condition Action="enable">CONFIGURATION_TYPE = "ini://${exe-path}/nsclient.ini" AND INSTALL_SAMPLE_CONFIG</Condition> 
     23          <Condition Action="disable"><![CDATA[CONFIGURATION_TYPE <> "ini://${exe-path}/nsclient.ini" OR NOT INSTALL_SAMPLE_CONFIG]]></Condition> 
     24        </Control> 
     25 
     26        <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="&amp;Back"> 
    1827        </Control> 
    1928        <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="&amp;Next"> 
  • modules/CheckWMI/CheckWMI.cpp

    rfb8241a rc88cf98  
    405405 
    406406}; 
    407 void print_results(WMIQuery::result_type &rows, int limit, std::wstring & result)  
     407void print_pretty_results(WMIQuery::result_type &rows, int limit, std::wstring & result)  
    408408{ 
    409409  pad_handler padder; 
    410410  NSC_DEBUG_MSG_STD(_T("Query returned: ") + strEx::itos(rows.size()) + _T(" rows.")); 
    411   std::vector<std::wstring::size_type> widths; 
    412411  int rownum=0; 
    413412  BOOST_FOREACH(const WMIQuery::wmi_row &row, rows) { 
     
    441440    if (limit != -1 && rownum > limit) 
    442441      break; 
    443     int i=0; 
    444442    std::wstring row1 = _T("|"); 
    445443    padder.reset_index(); 
     
    450448  } 
    451449} 
     450 
     451void print_simple_results(WMIQuery::result_type &rows, int limit, std::wstring & result)  
     452{ 
     453  int rownum=0; 
     454  BOOST_FOREACH(const WMIQuery::wmi_row &row, rows) { 
     455    if (limit != -1 && rownum > limit) 
     456      break; 
     457    bool first = true; 
     458    BOOST_FOREACH(const WMIQuery::wmi_row::list_type::value_type &val, row.results) { 
     459      if (first)  
     460        first = false; 
     461      else 
     462        result += _T(","); 
     463      result += val.second.string; 
     464    } 
     465    result += _T("\n"); 
     466  } 
     467} 
     468void print_results(WMIQuery::result_type &rows, int limit, std::wstring & result, bool simple)  { 
     469  if (simple) 
     470    print_simple_results(rows, limit, result); 
     471  else 
     472    print_pretty_results(rows, limit, result); 
     473} 
     474 
    452475 
    453476NSCAPI::nagiosReturn CheckWMI::handleCommand(const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf) { 
     
    485508 
    486509      std::wstring query, ns, computer, user, password, list_cls, list_inst; 
     510      bool simple; 
    487511      int limit = -1; 
    488512      po::options_description desc("Allowed options"); 
     
    490514        ("help,h", "Show help screen") 
    491515        ("select,s", po::wvalue<std::wstring>(&query), "Execute a query") 
     516        ("simple", "Use simple format") 
    492517        ("list-classes", po::wvalue<std::wstring>(&list_cls)->implicit_value(_T("")), "list all classes of a given type") 
    493518        ("list-instances", po::wvalue<std::wstring>(&list_inst)->implicit_value(_T("")), "list all instances of a given type") 
     
    523548        return NSCAPI::isSuccess; 
    524549      } 
     550      simple = vm.count("simple") > 0; 
    525551 
    526552      ns = build_namespace(ns, computer); 
     
    541567          return NSCAPI::isSuccess; 
    542568        } else { 
    543           print_results(rows, limit, result); 
     569          print_results(rows, limit, result, simple); 
    544570        } 
    545571      } else if (vm.count("list-classes")) { 
     
    547573          WMIQuery wmiQuery; 
    548574          rows = wmiQuery.get_classes(ns, list_cls, user, password); 
    549           print_results(rows, limit, result); 
     575          print_results(rows, limit, result, simple); 
    550576        } catch (WMIException e) { 
    551577          NSC_LOG_ERROR_STD(_T("WMIQuery failed: ") + e.getMessage()); 
     
    557583          WMIQuery wmiQuery; 
    558584          rows = wmiQuery.get_instances(ns, list_inst, user, password); 
    559           print_results(rows, limit, result); 
     585          print_results(rows, limit, result, simple); 
    560586        } catch (WMIException e) { 
    561587          NSC_LOG_ERROR_STD(_T("WMIQuery failed: ") + e.getMessage()); 
     
    567593          WMIQuery wmiQuery; 
    568594          rows = wmiQuery.get_instances(ns, _T("__Namespace"), user, password); 
    569           print_results(rows, limit, result); 
     595          print_results(rows, limit, result, simple); 
    570596        } catch (WMIException e) { 
    571597          NSC_LOG_ERROR_STD(_T("WMIQuery failed: ") + e.getMessage()); 
  • modules/CheckWMI/WMIQuery.cpp

    rfb8241a rc88cf98  
    120120  set_proxy_blanket(service, user, password); 
    121121 
    122 //  if (! (user.empty() && password.empty())) { 
    123 //    std::wstring error; 
    124 //    boost::optional<identidy_container> auth = get_identity(user, password, error); 
    125 //    if (auth) { 
    126 //    //hr = CoSetProxyBlanket(service, RPC_C_AUTHN_DEFAULT, RPC_C_AUTHZ_DEFAULT, COLE_DEFAULT_PRINCIPAL, RPC_C_AUTHN_LEVEL_DEFAULT,  
    127 //    //  RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE ); 
    128 //      hr = CoSetProxyBlanket(service, RPC_C_AUTHN_DEFAULT, RPC_C_AUTHZ_DEFAULT, COLE_DEFAULT_PRINCIPAL, RPC_C_AUTHN_LEVEL_DEFAULT,  
    129 //      RPC_C_IMP_LEVEL_IMPERSONATE, &(*auth).auth_identity, EOAC_NONE ); 
    130 //      //hr = CoSetProxyBlanket(service, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_CALL,  
    131 //      //  RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE ); 
    132 //      if (FAILED(hr)) 
    133 //        throw WMIException(_T("CoSetProxyBlanket failed: ") + ComError::getComError(ComError::getWMIError(hr))); 
    134 //    } 
    135 //  } 
    136122  return service; 
    137123} 
  • modules/PythonScript/PythonScript.cpp

    r836e9cd rc88cf98  
    125125    script_wrapper::thread_locker locker; 
    126126    try { 
     127      if (!localDict.has_key(functionName)) 
     128        return true; 
    127129      object scriptFunction = extract<object>(localDict[functionName]); 
    128130      if( scriptFunction ) 
     
    142144    script_wrapper::thread_locker locker; 
    143145    try { 
     146      if (!localDict.has_key(functionName)) 
     147        return true; 
    144148      object scriptFunction = extract<object>(localDict[functionName]); 
    145149      if(scriptFunction) 
  • scripts/python/lib/test_helper.py

    r8013c0c rc88cf98  
    263263    else: 
    264264      self.add_message(s1 in s2 or s2 in s1, msg, '"%s" (contains) "%s"'%(s1, s2)) 
     265 
     266  def assert_not_contains(self, s1, s2, msg): 
     267    if s1 == s2: 
     268      self.add_message(False, msg, '"%s" (equals) "%s"'%(s1, s2)) 
     269    elif s1 == None or s2 == None: 
     270      self.add_message(True, msg, '"%s" (is null?) "%s"'%(s1, s2)) 
     271    else: 
     272      self.add_message(not (s1 in s2 or s2 in s1), msg, '"%s" (does not contains) "%s"'%(s1, s2)) 
    265273 
    266274  def add_entry(self, e): 
  • scripts/python/test_all.py

    r836e9cd rc88cf98  
    1616  from test_w32_system import Win32SystemTest 
    1717  from test_w32_file import Win32FileTest 
    18   all_tests.extend([EventLogTest, Win32SystemTest, Win32FileTest]) 
     18  from test_w32_wmi import Win32WMITest 
     19  all_tests.extend([EventLogTest, Win32SystemTest, Win32FileTest, Win32WMITest]) 
    1920 
    2021def __main__(): 
  • scripts/python/test_w32_file.py

    r836e9cd rc88cf98  
    157157  def install(self, arguments): 
    158158    conf = Settings.get() 
    159     conf.set_string('/modules', 'test_system', 'CheckDisk') 
     159    conf.set_string('/modules', 'test_disk', 'CheckDisk') 
    160160    conf.set_string('/modules', 'pytest', 'PythonScript') 
    161161    conf.set_string('/settings/pytest/scripts', 'test_w32sys', 'test_w32_file.py') 
Note: See TracChangeset for help on using the changeset viewer.