Changeset 89838be in nscp


Ignore:
Timestamp:
01/16/12 22:22:59 (16 months ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
ffa6a59
Parents:
35254d1
Message:
  • Added option to both execute and query item (with a reload in the middle for installing/running unittests)
  • Fixed issue in python unittest framework to handle "unload" (ie. reload)
  • Fixed NRPE certificate path lookup issue
  • Fixed some minor issues here and there
  • Fixed issue in loader to allow loading dummy as dummy (and not only dummy://)
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • changelog

    r35254d1 r89838be  
    55 * Fixa dependonservice LanManWorkStation (old win) 
    66 * Fix RtlStringFromGUID problem on NT4 
     7 
     82012-01-16 MickeM 
     9 * Added option to both execute and query item (with a reload in the middle for installing/running unittests) 
     10 * Fixed issue in python unittest framework to handle "unload" (ie. reload) 
     11 * Fixed NRPE certificate path lookup issue 
     12 * Fixed some minor issues here and there 
     13 * Fixed issue in loader to allow loading dummy as dummy (and not only dummy://) 
    714 
    8152012-01-15 MickeM 
  • helpers/settings_manager/settings_manager_impl.cpp

    rba63b95 r89838be  
    119119    if (key == _T("ini")) 
    120120      return DEFAULT_CONF_INI_LOCATION; 
     121    if (key == _T("dummy")) 
     122      return _T("dummy://"); 
    121123    return key; 
    122124  } 
     
    124126  bool NSCSettingsImpl::context_exists(std::wstring key) { 
    125127    net::wurl url = net::parse(key); 
     128    if (url.protocol.empty()) 
     129      url = net::parse(expand_context(key)); 
    126130#ifdef WIN32 
    127131    if (url.protocol == _T("old")) 
  • modules/NRPEClient/NRPEClient.cpp

    ra87ce04 r89838be  
    152152    nscapi::target_handler::target t = targets.add(get_settings_proxy(), target_path , key, arg); 
    153153    if (t.has_option(_T("certificate"))) { 
    154       boost::filesystem::wpath p = t.options[_T("certificate")]; 
     154      std::wstring value = t.options[_T("certificate")]; 
     155      boost::filesystem::wpath p = value; 
    155156      if (!boost::filesystem::is_regular(p)) { 
    156157        p = get_core()->getBasePath() / p; 
    157         t.options[_T("certificate")] = utf8::cvt<std::wstring>(p.string()); 
     158        if (boost::filesystem::is_regular(p)) { 
     159          value = p.string(); 
     160        } else { 
     161          value = get_core()->expand_path(value); 
     162        } 
     163        t.options[_T("certificate")] = value; 
    158164        targets.add(t); 
    159165      } 
     
    164170      } 
    165171    } 
     172  } catch (const std::exception &e) { 
     173    NSC_LOG_ERROR_STD(_T("Failed to add target: ") + key + _T(", ") + utf8::to_unicode(e.what())); 
    166174  } catch (...) { 
    167175    NSC_LOG_ERROR_STD(_T("Failed to add target: ") + key); 
  • scripts/python/lib/test_helper.py

    rba63b95 r89838be  
    1616 
    1717def shutdown_testcases(): 
    18   get_test_manager().shutdown() 
     18  if get_test_manager(): 
     19    get_test_manager().shutdown() 
     20  destroy_test_manager() 
    1921 
    2022def get_test_manager(): 
     
    2224  return test_manager 
    2325 
     26def destroy_test_manager(): 
     27  global test_manager 
     28  test_manager = None 
     29 
    2430def create_test_manager(plugin_id = 0, plugin_alias = '', script_alias = ''): 
    2531  global test_manager 
    2632  if not test_manager: 
     33    log('=== Creating new Test manager ===') 
    2734    test_manager = TestManager(plugin_id, plugin_alias, script_alias) 
    2835     
     
    3441 
    3542    reg.simple_function('py_unittest', run_tests, 'Run python unit test suite') 
     43  else: 
     44    log('=== Reusing existing testmanager ===') 
    3645   
    3746  return test_manager 
     
    284293 
    285294    #core = Core.get() 
     295    #core.reload('service') 
    286296    #(code, msg, perf) = core.simple_query('py_unittest', []) 
    287297     
  • scripts/python/test_nrpe.py

    rba63b95 r89838be  
    188188      return r1 
    189189    result = TestResult() 
    190     result.add_message(True, '*FAILED* to send message with %s (retrying)'%encryption) 
     190    result.add_message(True, '*FAILED* to send message with %s (retrying)'%tag) 
    191191    r2 = self.submit_payload('%s/%s'%(ssl, length), ssl, length, '%ssrc%s'%(tag, tag), state, '%smsg%s'%(tag, tag), '') 
    192192    if r2: 
    193193      result.add(r2) 
    194194      return result 
    195     result.add_message(False, 'Failed to send message with: %s%%s'%(ssl, length)) 
     195    result.add_message(False, 'Failed to send message with: %s/%s'%(ssl, length)) 
    196196    return result 
    197197 
  • scripts/python/test_python.py

    rba63b95 r89838be  
    4444    start = time() 
    4545    while self.stress_count < install_checks*10: 
    46       log('Waiting for 100: %d/%d'%(self.stress_count, self.noop_count)) 
     46      log('Waiting for %d: %d/%d'%(install_checks*10, self.stress_count, self.noop_count)) 
    4747      old_stress_count = self.stress_count 
    4848      old_noop_count = self.noop_count 
  • service/NSClient++.cpp

    r35254d1 r89838be  
    793793} 
    794794 
    795 bool NSClientT::exitCore(bool boot) { 
    796   LOG_DEBUG_CORE(_T("Attempting to stop")); 
     795bool NSClientT::stop_unload_plugins_pre() { 
     796  LOG_DEBUG_CORE(_T("Attempting to stop all plugins")); 
    797797  try { 
    798798    LOG_DEBUG_CORE(_T("Stopping: NON Message Handling Plugins")); 
     
    803803    LOG_ERROR_CORE_STD(_T("Unknown exception raised when unloading non msg plugins")); 
    804804  } 
     805  return true; 
     806} 
     807bool NSClientT::stop_exit_pre() { 
    805808#ifdef WIN32 
    806809  LOG_DEBUG_CORE(_T("Stopping: COM helper")); 
     
    845848    LOG_ERROR_CORE_STD(_T("UNknown exception raised: When closing shared session")); 
    846849  } 
     850  return true; 
     851} 
     852bool NSClientT::stop_unload_plugins_post() { 
    847853  try { 
    848854    LOG_DEBUG_CORE(_T("Stopping: Message handling Plugins")); 
     
    853859    LOG_ERROR_CORE_STD(_T("UNknown exception raised: When stopping message plguins")); 
    854860  } 
    855   LOG_INFO_CORE(_T("Stopped succcessfully")); 
    856   logger_master_.stop_slave(); 
    857861  return true; 
    858862} 
     863bool NSClientT::stop_exit_post() { 
     864  try { 
     865    logger_master_.stop_slave(); 
     866  } catch(...) { 
     867    LOG_ERROR_CORE_STD(_T("UNknown exception raised: When closing shared session")); 
     868  } 
     869  return true; 
     870} 
     871 
    859872void NSClientT::service_on_session_changed(unsigned long dwSessionId, bool logon, unsigned long dwEventType) { 
    860873//  if (shared_server_.get() == NULL) { 
     
    937950} 
    938951 
    939 NSCAPI::errorReturn NSClientT::reload(const wchar_t *module) { 
     952NSCAPI::errorReturn NSClientT::reload(const std::wstring module) { 
    940953  if (module == _T("service")) { 
    941     boot_start_plugins() 
    942  
     954    try { 
     955      stop_unload_plugins_pre(); 
     956      stop_unload_plugins_post(); 
     957 
     958      boot_load_all_plugins(); 
     959      boot_start_plugins(true); 
     960      return NSCAPI::isSuccess; 
     961    } catch(const std::exception &e) { 
     962      LOG_ERROR_CORE_STD(_T("Exception raised when reloading: ") + utf8::to_unicode(e.what())); 
     963    } catch(...) { 
     964      LOG_ERROR_CORE_STD(_T("Exception raised when reloading: UNKNOWN")); 
     965    } 
    943966  } else { 
    944     std::wstring m = module; 
    945967    boost::unique_lock<boost::shared_mutex> writeLock(m_mutexRW, boost::get_system_time() + boost::posix_time::seconds(10)); 
    946968    if (!writeLock.owns_lock()) { 
     
    950972 
    951973    BOOST_FOREACH(plugin_type &p, plugins_) { 
    952       if (p->get_alias() == m) { 
    953         LOG_DEBUG_CORE_STD(_T("Found module: ") + m + _T(", reloading...")); 
     974      if (p->get_alias() == module) { 
     975        LOG_DEBUG_CORE_STD(_T("Found module: ") + module + _T(", reloading...")); 
    954976        p->unload_plugin(); 
    955977        p->load_plugin(NSCAPI::normalStart); 
     
    15221544} 
    15231545void NSClientT::handle_shutdown(std::wstring service_name) { 
    1524   exitCore(true); 
     1546  stop_unload_plugins_pre(); 
     1547  stop_exit_pre(); 
     1548  stop_unload_plugins_post(); 
     1549  stop_exit_post(); 
    15251550} 
    15261551 
  • service/NSClient++.h

    r9c06054 r89838be  
    135135  bool boot_load_plugin(std::wstring plugin); 
    136136  bool boot_start_plugins(bool boot); 
    137   bool exitCore(bool boot); 
     137 
     138  bool stop_unload_plugins_pre(); 
     139  bool stop_exit_pre(); 
     140  bool stop_exit_post(); 
     141  bool stop_unload_plugins_post(); 
     142  //bool exitCore(); 
    138143  void set_settings_context(std::wstring context) { context_ = context; } 
    139144#ifdef WIN32x 
     
    179184  NSCAPI::errorReturn register_routing_listener(unsigned int plugin_id, const wchar_t* channel); 
    180185 
    181   NSCAPI::errorReturn reload(const wchar_t *module); 
     186  NSCAPI::errorReturn reload(const std::wstring module); 
    182187 
    183188  struct service_controller { 
  • service/cli_parser.hpp

    r35254d1 r89838be  
    341341        return 1; 
    342342 
    343       std::wstring command; 
    344       enum modes { exec, query, submit, none}; 
     343      std::wstring command, combined_query; 
     344      enum modes { exec, query, submit, none, combined}; 
    345345      modes mode = none; 
    346346 
     
    348348        command = vm["exec"].as<std::wstring>(); 
    349349        mode = exec; 
    350       } 
    351       if (vm.count("query")) { 
     350        if (vm.count("query")) { 
     351          combined_query = vm["query"].as<std::wstring>(); 
     352          mode = combined; 
     353        } 
     354      } else if (vm.count("query")) { 
    352355        command = vm["query"].as<std::wstring>(); 
    353356        mode = query; 
    354       } 
    355       if (vm.count("submit")) { 
     357      } else if (vm.count("submit")) { 
    356358        command = vm["submit"].as<std::wstring>(); 
    357359        mode = submit; 
     
    422424      if (mode == query) { 
    423425        ret = mainClient.simple_query(module, command, arguments, resp); 
    424       } else if (mode == exec) { 
     426      } else if (mode == exec || mode == combined) { 
    425427        ret = mainClient.simple_exec(module, command, arguments, resp); 
    426428        if (ret == NSCAPI::returnIgnored) { 
    427429          ret = 1; 
    428430          std::wcout << _T("Command not found (by module): ") << command << std::endl; 
     431          resp.push_back(_T("Command not found: ") + command); 
    429432          mainClient.simple_exec(module, _T("help"), arguments, resp); 
     433        } else if (mode == combined) { 
     434          mainClient.reload(_T("service")); 
     435          ret = mainClient.simple_query(module, combined_query, arguments, resp); 
    430436        } 
    431437      } else if (mode == submit) { 
     
    434440        std::wcerr << _T("Need to specify one of --exec, --query or --submit") << std::endl; 
    435441      } 
    436       mainClient.exitCore(boot); 
     442      mainClient.stop_unload_plugins_pre(); 
     443      mainClient.stop_exit_pre(); 
     444      mainClient.stop_unload_plugins_post(); 
     445      mainClient.stop_exit_post(); 
    437446 
    438447      BOOST_FOREACH(std::wstring r, resp) { 
  • service/settings_client.hpp

    r35254d1 r89838be  
    4141 
    4242    void exit() { 
    43       core_->exitCore(true); 
     43      core_->stop_unload_plugins_pre(); 
     44      core_->stop_exit_pre(); 
     45      core_->stop_unload_plugins_post(); 
     46      core_->stop_exit_post(); 
    4447    } 
    4548 
  • service/simple_client.hpp

    r9c06054 r89838be  
    9292        } 
    9393      } 
    94       core_->exitCore(true); 
     94      core_->stop_unload_plugins_pre(); 
     95      core_->stop_exit_pre(); 
     96      core_->stop_unload_plugins_post(); 
     97      core_->stop_exit_post(); 
    9598    } 
    9699  }; 
  • version.hpp

    rba63b95 r89838be  
    11#ifndef VERSION_HPP 
    22#define VERSION_HPP 
    3 #define PRODUCTVER     0,4,0,121 
    4 #define STRPRODUCTVER  "0,4,0,121" 
    5 #define STRPRODUCTDATE "2012-01-12" 
     3#define PRODUCTVER     0,4,0,123 
     4#define STRPRODUCTVER  "0,4,0,123" 
     5#define STRPRODUCTDATE "2012-01-16" 
    66#endif // VERSION_HPP 
  • version.txt

    rba63b95 r89838be  
    11version=0.4.0 
    2 build=121 
    3 date=2012-01-12 
     2build=123 
     3date=2012-01-16 
Note: See TracChangeset for help on using the changeset viewer.