Changeset 6533c1a in nscp


Ignore:
Timestamp:
04/17/12 17:56:20 (14 months ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
308ae18
Parents:
682ccd2
Message:
  • Fixed so keys with parents are advanced (in favour of the parent)
  • Fixed so NSClientServer uses the correct default path for its parents (ie. /settings/default)
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • changelog

    r682ccd2 r6533c1a  
    44 * Fixa dependonservice LanManWorkStation (old win) 
    55 * Fix RtlStringFromGUID problem on NT4 
     6 
     72012-04-12 MickeM 
     8 * Fixed so keys with parents are advanced (in favour of the parent) 
     9 * Fixed so NSClientServer uses the correct default path for its parents (ie. /settings/default) 
    610 
    7112012-04-10 MickeM 
  • include/nsclient/base_logger_impl.hpp

    r440c0cb r6533c1a  
    1616      NSCAPI::log_level::level level_; 
    1717      bool console_log_; 
     18      bool is_running_; 
    1819    public: 
    19       logging_interface_impl() : level_(NSCAPI::log_level::info), console_log_(false) {} 
     20      logging_interface_impl() : level_(NSCAPI::log_level::info), console_log_(false), is_running_(false) {} 
     21      virtual ~logging_interface_impl() {} 
    2022 
    2123 
     
    6668      virtual void do_log(const std::string &data) = 0; 
    6769      virtual void configure() = 0; 
    68       virtual bool shutdown() = 0; 
    69       virtual bool startup() = 0; 
     70      virtual bool shutdown() { 
     71        is_running_ = false; 
     72        return true; 
     73      } 
     74      virtual bool startup() { 
     75        is_running_ = true; 
     76        return true; 
     77      } 
     78 
     79      bool is_started() const { 
     80        return is_running_; 
     81      } 
     82       
    7083    }; 
    7184    typedef boost::shared_ptr<nsclient::logging::logging_interface_impl> log_impl_type; 
  • include/settings/client/settings_client.hpp

    r83c2453 r6533c1a  
    6565        std::wstring data = core_->get_string(path, key, dummy); 
    6666        if (typed_key<T>::has_default_ || data != dummy) { 
    67           T value = boost::lexical_cast<T>(data); 
    68           update_target(&value); 
     67          try { 
     68            T value = boost::lexical_cast<T>(data); 
     69            update_target(&value); 
     70          } catch (const std::exception &e) { 
     71            core_->err(__FILE__, __LINE__, _T("Failed to parse key: ") + path + _T("/") + key + _T(": ") + utf8::to_unicode(e.what())); 
     72          } 
    6973        } 
    7074      } 
     
    7882        data = core_->get_string(path, key, dummy); 
    7983        if (typed_key<T>::has_default_ || data != dummy) { 
    80           T value = boost::lexical_cast<T>(data); 
    81           update_target(&value); 
     84          try { 
     85            T value = boost::lexical_cast<T>(data); 
     86            update_target(&value); 
     87          } catch (const std::exception &e) { 
     88            core_->err(__FILE__, __LINE__, _T("Failed to parse key: ") + path + _T("/") + key + _T(": ") + utf8::to_unicode(e.what())); 
     89          } 
    8290        } 
    8391      } 
     
    96104        std::wstring data = core_->get_string(path, key, dummy); 
    97105        if (typed_key<T>::has_default_ || data != dummy) { 
    98           T value = boost::lexical_cast<T>(core_->expand_path(data)); 
    99           update_target(&value); 
     106          try { 
     107            T value = boost::lexical_cast<T>(core_->expand_path(data)); 
     108            update_target(&value); 
     109          } catch (const std::exception &e) { 
     110            core_->err(__FILE__, __LINE__, _T("Failed to parse key: ") + path + _T("/") + key + _T(": ") + utf8::to_unicode(e.what())); 
     111          } 
    100112        } 
    101113      } 
     
    109121        data = core_->get_string(path, key, dummy); 
    110122        if (typed_key<T>::has_default_ || data != dummy) { 
    111           T value = boost::lexical_cast<T>(core_->expand_path(data)); 
    112           update_target(&value); 
     123          try { 
     124            T value = boost::lexical_cast<T>(core_->expand_path(data)); 
     125            update_target(&value); 
     126          } catch (const std::exception &e) { 
     127            core_->err(__FILE__, __LINE__, _T("Failed to parse key: ") + path + _T("/") + key + _T(": ") + utf8::to_unicode(e.what())); 
     128          } 
    113129        } 
    114130      } 
     
    676692          if (v->key) { 
    677693            //std::wcout << _T("Setting: ") << v->key_name << _T(" ===> ") << v->parent << std::endl; 
    678             std::wstring desc = v->description.description; 
    679694            if (v->has_parent()) { 
    680               desc += _T(" Parent element can be found under: ") + v->parent; 
    681               core_->register_key(v->parent, v->key_name, v->key->get_type(), v->description.title, desc, v->key->get_default_as_string(), v->description.advanced); 
     695              core_->register_key(v->parent, v->key_name, v->key->get_type(), v->description.title, v->description.description, v->key->get_default_as_string(), v->description.advanced); 
     696              std::wstring desc = v->description.description + _T(" parent for this key is found under: ") + v->parent + _T(" this is marked as advanced in favour of the parent."); 
     697              core_->register_key(v->path, v->key_name, v->key->get_type(), v->description.title, desc, v->key->get_default_as_string(), true); 
     698            } else { 
     699              core_->register_key(v->path, v->key_name, v->key->get_type(), v->description.title, v->description.description, v->key->get_default_as_string(), v->description.advanced); 
    682700            } 
    683             core_->register_key(v->path, v->key_name, v->key->get_type(), v->description.title, desc, v->key->get_default_as_string(), v->description.advanced); 
    684701          } 
    685702        } 
  • include/settings/settings_handler_impl.hpp

    r8d89d7a r6533c1a  
    125125              else if (desc.type == key_bool) 
    126126                get()->set_bool(path, key, settings::settings_interface::string_to_bool(desc.defValue)); 
    127               else if (desc.type == key_integer) 
    128                 get()->set_int(path, key, strEx::stoi(desc.defValue)); 
    129               else 
     127              else if (desc.type == key_integer) { 
     128                try { 
     129                  get()->set_int(path, key, strEx::stoi(desc.defValue)); 
     130                } catch (const std::exception &e) { 
     131                  get_logger()->error(__FILE__, __LINE__, _T("invalid default value for: ") + path + _T(".") + key); 
     132                } 
     133              } else 
    130134                get_logger()->error(__FILE__, __LINE__, _T("Unknown keytype for: ") + path + _T(".") + key); 
    131135            } else { 
  • include/settings/settings_interface_impl.hpp

    r8d89d7a r6533c1a  
    6868      } 
    6969      int get_int() const { 
    70         if (type==settings_core::key_string) 
    71           return strEx::stoi(string_val); 
    72         if (type==settings_core::key_integer) 
    73           return int_val; 
    74         if (type==settings_core::key_bool) 
    75           return int_val==1?1:0; 
    76         return -1; 
     70        try { 
     71          if (type==settings_core::key_string) 
     72            return strEx::stoi(string_val); 
     73          if (type==settings_core::key_integer) 
     74            return int_val; 
     75          if (type==settings_core::key_bool) 
     76            return int_val==1?1:0; 
     77          return -1; 
     78        } catch (std::exception &e) { 
     79          return -1; 
     80        } 
    7781      } 
    7882      bool get_bool() const { 
     
    388392    virtual string_list get_sections(std::wstring path) { 
    389393      MUTEX_GUARD(); 
    390       nsclient::logging::logger::get_logger()->debug(__FILE__, __LINE__, std::wstring(_T("Get sections for: ")) + path); 
     394      //nsclient::logging::logger::get_logger()->debug(__FILE__, __LINE__, std::wstring(_T("Get sections for: ")) + path); 
    391395      string_list ret; 
    392396      get_cached_sections_unsafe(path, ret); 
  • modules/CheckExternalScripts/CheckExternalScripts.cpp

    r8d89d7a r6533c1a  
    240240    } 
    241241  } else { 
    242     NSC_DEBUG_MSG(_T("---> ") + cd.to_wstring()); 
    243242    std::wstring message, perf; 
    244243    process::exec_arguments args(root_, cd.command + _T(" ") + xargs, timeout); 
  • modules/NSClientServer/NSClientServer.cpp

    r682ccd2 r6533c1a  
    7676 
    7777 
    78     settings.alias().add_parent(_T("/settings/default/socket")).add_key_to_settings() 
     78    settings.alias().add_parent(_T("/settings/default")).add_key_to_settings() 
    7979 
    8080      (_T("bind to"), sh::string_key(&info_.address), 
     
    8989      (_T("timeout"), sh::uint_key(&info_.timeout, 30), 
    9090      _T("TIMEOUT"), _T("Timeout when reading packets on incoming sockets. If the data has not arrived within this time we will bail out.")) 
    91  
    92       ; 
    93  
    94     settings.alias().add_parent(_T("/settings/default")).add_key_to_settings() 
    9591 
    9692      (_T("password"), sh::string_fun_key<std::wstring>(boost::bind(&check_nt::server::handler::set_password, info_.request_handler, _1), _T("")), 
  • modules/SyslogClient/SyslogClient.cpp

    r8d89d7a r6533c1a  
    347347    boost::asio::io_service io_service; 
    348348    ip::udp::resolver resolver(io_service); 
    349     ip::udp::resolver::query query(ip::udp::v4(), con.host, con.port); 
     349    ip::udp::resolver::query query(ip::udp::v4(), con.host, strEx::s::itos(con.port)); 
    350350    ip::udp::endpoint receiver_endpoint = *resolver.resolve(query); 
    351351 
  • modules/SyslogClient/SyslogClient.h

    r84cdb9b r6533c1a  
    103103    std::string message_syntax; 
    104104    std::string host; 
    105     std::string port; 
     105    int port; 
    106106    std::string ok_severity, warn_severity, crit_severity, unknown_severity; 
    107107 
     
    125125      std::wstringstream ss; 
    126126      ss << _T("host: ") << utf8::cvt<std::wstring>(host); 
    127       ss << _T(", port: ") << utf8::cvt<std::wstring>(port); 
     127      ss << _T(", port: ") << port; 
    128128      ss << _T(", severity: ") << utf8::cvt<std::wstring>(severity); 
    129129      ss << _T(", facility: ") << utf8::cvt<std::wstring>(facility); 
  • service/cli_parser.hpp

    r682ccd2 r6533c1a  
    226226      client.start(log_level); 
    227227      return 0; 
    228     } catch(std::exception & e) { 
    229       get_logger()->error(__FILE__, __LINE__, std::wstring(_T("Unable to parse command line (settings): ")) + utf8::to_unicode(e.what())); 
     228    } catch(const std::exception & e) { 
     229      std::cerr << std::string("Unable to parse command line (test): ") << e.what() << "\n"; 
    230230      return 1; 
    231231    } 
     
    247247      bool load_all = vm.count("load-all")==1; 
    248248 
    249       nsclient::settings_client client(core_); 
    250  
    251       std::wstring current = _T(""); //client.get_source(); 
    252  
    253  
    254       client.set_current(current); 
    255       client.set_update_defaults(def); 
    256       client.set_load_all_files(load_all); 
    257  
    258       client.boot(log_level); 
     249      nsclient::settings_client client(core_, log_level, def, load_all); 
    259250      int ret = -1; 
    260251 
     
    274265        client.switch_context(vm["switch"].as<std::wstring>()); 
    275266        ret = 0; 
    276       } else if (vm.count("settings")) { 
    277         client.set_current(vm["settings"].as<std::wstring>()); 
    278         ret = 0; 
    279267      } else { 
    280268        std::cout << all << std::endl; 
    281269        return 1; 
    282270      } 
    283       client.exit(); 
    284271 
    285272      return ret; 
    286     } catch(std::exception & e) { 
    287       get_logger()->error(__FILE__, __LINE__, std::wstring(_T("Unable to parse command line (settings): ")) + utf8::to_unicode(e.what())); 
     273    } catch(const std::exception & e) { 
     274      std::cerr << std::string("Unable to parse command line (settings): ") << e.what() << "\n"; 
    288275      return 1; 
    289276    } 
  • service/logger_impl.cpp

    r682ccd2 r6533c1a  
    7373        ss << _T(" -- "); 
    7474      ss << render_log_level_short(msg.level()) 
    75         << _T(" ") << rpad(utf8::cvt<std::wstring>(msg.file()), 40) 
     75        << _T(" ") << rpad(utf8::cvt<std::wstring>(msg.file()), 20) 
    7676        << _T(":") << lpad(utf8::cvt<std::wstring>(strEx::itos(msg.line())),4)  
    77         << _T(" ") + utf8::cvt<std::wstring>(msg.message()); 
     77        << _T(" ") + utf8::cvt<std::wstring>(msg.message()) 
     78        << std::endl; 
    7879    } 
    7980    return ss.str(); 
     
    206207    } 
    207208  } 
    208   bool startup() { return true; } 
    209   bool shutdown() { return true; } 
    210209}; 
    211210 
     
    215214  std::string format_; 
    216215public: 
    217   simple_console_logger() : format_("%Y-%m-%d %H:%M:%S") { 
    218   } 
     216  simple_console_logger() : format_("%Y-%m-%d %H:%M:%S") {} 
    219217 
    220218  void do_log(const std::string &data) { 
    221219    if (get_console_log()) { 
    222       std::wcout << render_console_message(data) << std::endl; 
     220      std::wcout << render_console_message(data); 
    223221    } 
    224222  } 
     
    251249    } 
    252250  } 
    253   bool startup() { return true; } 
    254   bool shutdown() { return true; } 
    255251}; 
    256252 
     
    269265 
    270266  log_impl_type background_logger_; 
    271   bool running_; 
    272267 
    273268public: 
    274269 
    275   threaded_logger(log_impl_type background_logger) : background_logger_(background_logger), running_(false) {} 
     270  threaded_logger(log_impl_type background_logger) : background_logger_(background_logger) {} 
    276271  ~threaded_logger() { 
    277272    shutdown(); 
     
    280275  void do_log(const std::string &data) { 
    281276    if (get_console_log()) { 
    282       std::wcout << render_console_message(data) << std::endl; 
     277      std::wcout << render_console_message(data); 
    283278    } 
    284279    push(data); 
     
    315310  } 
    316311  bool startup() { 
     312    if (nsclient::logging::logging_interface_impl::is_started()) 
     313      return true; 
    317314    thread_ = boost::thread(boost::bind(&threaded_logger::thread_proc, this)); 
    318     running_ = true; 
    319     return true; 
     315    return nsclient::logging::logging_interface_impl::startup(); 
    320316  } 
    321317  bool shutdown() { 
    322     if (!running_) 
     318    if (!nsclient::logging::logging_interface_impl::is_started()) 
    323319      return true; 
    324     push(QUIT_MESSAGE); 
    325     if (!thread_.timed_join(boost::posix_time::seconds(5))) { 
    326       log_fatal("Failed to exit log slave!"); 
    327       return false; 
    328     } 
    329     running_ = false; 
    330     return true; 
     320    try { 
     321      push(QUIT_MESSAGE); 
     322      if (!thread_.timed_join(boost::posix_time::seconds(5))) { 
     323        log_fatal("Failed to exit log slave!"); 
     324        return false; 
     325      } 
     326      return nsclient::logging::logging_interface_impl::shutdown(); 
     327    } catch (const std::exception &e) { 
     328      log_fatal(std::string("Failed to exit log slave: ") + e.what()); 
     329    } catch (...) { 
     330      log_fatal("Failed to exit log slave"); 
     331    } 
     332    return false; 
    331333  } 
    332334 
     
    363365    tmp->set_console_log(old->get_console_log()); 
    364366    tmp->set_log_level(old->get_log_level()); 
     367    if (old->is_started()) 
     368      tmp->startup(); 
    365369  } 
    366370  logger_impl_ = tmp; 
     371  logger_impl_->debug(__FILE__, __LINE__, _T("Creating logger: ") + utf8::to_unicode(backend)); 
    367372  delete old; 
    368373  old = NULL; 
  • service/settings_client.hpp

    r440c0cb r6533c1a  
    77  class settings_client { 
    88    NSClient* core_; 
    9     std::wstring current_; 
    109    bool default_; 
    1110    bool load_all_; 
     11    bool started_; 
     12    std::wstring log_; 
     13 
     14  public: 
     15    settings_client(NSClient* core, std::wstring log, bool update_defaults, bool load_all) : started_(false), core_(core), log_(log), default_(update_defaults), load_all_(load_all) { 
     16      startup(); 
     17    } 
    1218 
    1319 
    14   public: 
    15     settings_client(NSClient* core) : core_(core), default_(false), load_all_(false) {} 
    16  
    17     std::wstring get_source() { 
    18       settings_manager::get_core()->get()->get_context(); 
     20    ~settings_client() { 
     21      terminate(); 
    1922    } 
    2023 
    21     void boot(std::wstring log) { 
    22       if (!current_.empty()) 
    23         core_->set_settings_context(current_); 
    24       if (!core_->boot_init(log)) { 
     24    void startup() { 
     25      if (started_) 
     26        return; 
     27      if (!core_->boot_init(log_)) { 
    2528        std::wcout << _T("boot::init failed") << std::endl; 
    2629        return; 
     
    4144        settings_manager::get_core()->update_defaults(); 
    4245      } 
     46      started_ = true; 
    4347    } 
    4448 
    45     void exit() { 
     49    void terminate() { 
     50      if (!started_) 
     51        return; 
    4652      core_->stop_unload_plugins_pre(); 
    4753      core_->stop_exit_pre(); 
    4854      core_->stop_exit_post(); 
     55      started_ = false; 
    4956    } 
    50  
    51     void set_current(std::wstring current) { current_ = current; } 
    52     void set_update_defaults(bool def) { default_ = def; } 
    53     void set_load_all_files(bool def) { load_all_ = def; } 
    5457 
    5558    int migrate_from(std::wstring src) { 
     
    166169    } 
    167170    int show(std::wstring path, std::wstring key) { 
    168       //core_->load_all_plugins(NSCAPI::dontStart); 
    169171      std::wcout << settings_manager::get_core()->get()->get_string(path, key); 
    170172      return 0; 
    171173    } 
    172174    int list(std::wstring path) { 
    173  
    174175      try { 
    175176        dump_path(path); 
  • version.hpp

    r682ccd2 r6533c1a  
    11#ifndef VERSION_HPP 
    22#define VERSION_HPP 
    3 #define PRODUCTVER     0,4,0,159 
    4 #define STRPRODUCTVER  "0,4,0,159" 
    5 #define STRPRODUCTDATE "2012-04-11" 
     3#define PRODUCTVER     0,4,0,163 
     4#define STRPRODUCTVER  "0,4,0,163" 
     5#define STRPRODUCTDATE "2012-04-14" 
    66#endif // VERSION_HPP 
  • version.txt

    r682ccd2 r6533c1a  
    11version=0.4.0 
    2 build=159 
    3 date=2012-04-11 
     2build=163 
     3date=2012-04-14 
Note: See TracChangeset for help on using the changeset viewer.