Changeset 6533c1a in nscp
- Timestamp:
- 04/17/12 17:56:20 (14 months ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- 308ae18
- Parents:
- 682ccd2
- Files:
-
- 14 edited
-
changelog (modified) (1 diff)
-
include/nsclient/base_logger_impl.hpp (modified) (2 diffs)
-
include/settings/client/settings_client.hpp (modified) (5 diffs)
-
include/settings/settings_handler_impl.hpp (modified) (1 diff)
-
include/settings/settings_interface_impl.hpp (modified) (2 diffs)
-
modules/CheckExternalScripts/CheckExternalScripts.cpp (modified) (1 diff)
-
modules/NSClientServer/NSClientServer.cpp (modified) (2 diffs)
-
modules/SyslogClient/SyslogClient.cpp (modified) (1 diff)
-
modules/SyslogClient/SyslogClient.h (modified) (2 diffs)
-
service/cli_parser.hpp (modified) (3 diffs)
-
service/logger_impl.cpp (modified) (8 diffs)
-
service/settings_client.hpp (modified) (3 diffs)
-
version.hpp (modified) (1 diff)
-
version.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
changelog
r682ccd2 r6533c1a 4 4 * Fixa dependonservice LanManWorkStation (old win) 5 5 * Fix RtlStringFromGUID problem on NT4 6 7 2012-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) 6 10 7 11 2012-04-10 MickeM -
include/nsclient/base_logger_impl.hpp
r440c0cb r6533c1a 16 16 NSCAPI::log_level::level level_; 17 17 bool console_log_; 18 bool is_running_; 18 19 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() {} 20 22 21 23 … … 66 68 virtual void do_log(const std::string &data) = 0; 67 69 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 70 83 }; 71 84 typedef boost::shared_ptr<nsclient::logging::logging_interface_impl> log_impl_type; -
include/settings/client/settings_client.hpp
r83c2453 r6533c1a 65 65 std::wstring data = core_->get_string(path, key, dummy); 66 66 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 } 69 73 } 70 74 } … … 78 82 data = core_->get_string(path, key, dummy); 79 83 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 } 82 90 } 83 91 } … … 96 104 std::wstring data = core_->get_string(path, key, dummy); 97 105 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 } 100 112 } 101 113 } … … 109 121 data = core_->get_string(path, key, dummy); 110 122 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 } 113 129 } 114 130 } … … 676 692 if (v->key) { 677 693 //std::wcout << _T("Setting: ") << v->key_name << _T(" ===> ") << v->parent << std::endl; 678 std::wstring desc = v->description.description;679 694 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); 682 700 } 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);684 701 } 685 702 } -
include/settings/settings_handler_impl.hpp
r8d89d7a r6533c1a 125 125 else if (desc.type == key_bool) 126 126 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 130 134 get_logger()->error(__FILE__, __LINE__, _T("Unknown keytype for: ") + path + _T(".") + key); 131 135 } else { -
include/settings/settings_interface_impl.hpp
r8d89d7a r6533c1a 68 68 } 69 69 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 } 77 81 } 78 82 bool get_bool() const { … … 388 392 virtual string_list get_sections(std::wstring path) { 389 393 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); 391 395 string_list ret; 392 396 get_cached_sections_unsafe(path, ret); -
modules/CheckExternalScripts/CheckExternalScripts.cpp
r8d89d7a r6533c1a 240 240 } 241 241 } else { 242 NSC_DEBUG_MSG(_T("---> ") + cd.to_wstring());243 242 std::wstring message, perf; 244 243 process::exec_arguments args(root_, cd.command + _T(" ") + xargs, timeout); -
modules/NSClientServer/NSClientServer.cpp
r682ccd2 r6533c1a 76 76 77 77 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() 79 79 80 80 (_T("bind to"), sh::string_key(&info_.address), … … 89 89 (_T("timeout"), sh::uint_key(&info_.timeout, 30), 90 90 _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()95 91 96 92 (_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 347 347 boost::asio::io_service io_service; 348 348 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)); 350 350 ip::udp::endpoint receiver_endpoint = *resolver.resolve(query); 351 351 -
modules/SyslogClient/SyslogClient.h
r84cdb9b r6533c1a 103 103 std::string message_syntax; 104 104 std::string host; 105 std::stringport;105 int port; 106 106 std::string ok_severity, warn_severity, crit_severity, unknown_severity; 107 107 … … 125 125 std::wstringstream ss; 126 126 ss << _T("host: ") << utf8::cvt<std::wstring>(host); 127 ss << _T(", port: ") << utf8::cvt<std::wstring>(port);127 ss << _T(", port: ") << port; 128 128 ss << _T(", severity: ") << utf8::cvt<std::wstring>(severity); 129 129 ss << _T(", facility: ") << utf8::cvt<std::wstring>(facility); -
service/cli_parser.hpp
r682ccd2 r6533c1a 226 226 client.start(log_level); 227 227 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"; 230 230 return 1; 231 231 } … … 247 247 bool load_all = vm.count("load-all")==1; 248 248 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); 259 250 int ret = -1; 260 251 … … 274 265 client.switch_context(vm["switch"].as<std::wstring>()); 275 266 ret = 0; 276 } else if (vm.count("settings")) {277 client.set_current(vm["settings"].as<std::wstring>());278 ret = 0;279 267 } else { 280 268 std::cout << all << std::endl; 281 269 return 1; 282 270 } 283 client.exit();284 271 285 272 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"; 288 275 return 1; 289 276 } -
service/logger_impl.cpp
r682ccd2 r6533c1a 73 73 ss << _T(" -- "); 74 74 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) 76 76 << _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; 78 79 } 79 80 return ss.str(); … … 206 207 } 207 208 } 208 bool startup() { return true; }209 bool shutdown() { return true; }210 209 }; 211 210 … … 215 214 std::string format_; 216 215 public: 217 simple_console_logger() : format_("%Y-%m-%d %H:%M:%S") { 218 } 216 simple_console_logger() : format_("%Y-%m-%d %H:%M:%S") {} 219 217 220 218 void do_log(const std::string &data) { 221 219 if (get_console_log()) { 222 std::wcout << render_console_message(data) << std::endl;220 std::wcout << render_console_message(data); 223 221 } 224 222 } … … 251 249 } 252 250 } 253 bool startup() { return true; }254 bool shutdown() { return true; }255 251 }; 256 252 … … 269 265 270 266 log_impl_type background_logger_; 271 bool running_;272 267 273 268 public: 274 269 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) {} 276 271 ~threaded_logger() { 277 272 shutdown(); … … 280 275 void do_log(const std::string &data) { 281 276 if (get_console_log()) { 282 std::wcout << render_console_message(data) << std::endl;277 std::wcout << render_console_message(data); 283 278 } 284 279 push(data); … … 315 310 } 316 311 bool startup() { 312 if (nsclient::logging::logging_interface_impl::is_started()) 313 return true; 317 314 thread_ = boost::thread(boost::bind(&threaded_logger::thread_proc, this)); 318 running_ = true; 319 return true; 315 return nsclient::logging::logging_interface_impl::startup(); 320 316 } 321 317 bool shutdown() { 322 if (! running_)318 if (!nsclient::logging::logging_interface_impl::is_started()) 323 319 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; 331 333 } 332 334 … … 363 365 tmp->set_console_log(old->get_console_log()); 364 366 tmp->set_log_level(old->get_log_level()); 367 if (old->is_started()) 368 tmp->startup(); 365 369 } 366 370 logger_impl_ = tmp; 371 logger_impl_->debug(__FILE__, __LINE__, _T("Creating logger: ") + utf8::to_unicode(backend)); 367 372 delete old; 368 373 old = NULL; -
service/settings_client.hpp
r440c0cb r6533c1a 7 7 class settings_client { 8 8 NSClient* core_; 9 std::wstring current_;10 9 bool default_; 11 10 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 } 12 18 13 19 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(); 19 22 } 20 23 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_)) { 25 28 std::wcout << _T("boot::init failed") << std::endl; 26 29 return; … … 41 44 settings_manager::get_core()->update_defaults(); 42 45 } 46 started_ = true; 43 47 } 44 48 45 void exit() { 49 void terminate() { 50 if (!started_) 51 return; 46 52 core_->stop_unload_plugins_pre(); 47 53 core_->stop_exit_pre(); 48 54 core_->stop_exit_post(); 55 started_ = false; 49 56 } 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; }54 57 55 58 int migrate_from(std::wstring src) { … … 166 169 } 167 170 int show(std::wstring path, std::wstring key) { 168 //core_->load_all_plugins(NSCAPI::dontStart);169 171 std::wcout << settings_manager::get_core()->get()->get_string(path, key); 170 172 return 0; 171 173 } 172 174 int list(std::wstring path) { 173 174 175 try { 175 176 dump_path(path); -
version.hpp
r682ccd2 r6533c1a 1 1 #ifndef VERSION_HPP 2 2 #define VERSION_HPP 3 #define PRODUCTVER 0,4,0,1 594 #define STRPRODUCTVER "0,4,0,1 59"5 #define STRPRODUCTDATE "2012-04-1 1"3 #define PRODUCTVER 0,4,0,163 4 #define STRPRODUCTVER "0,4,0,163" 5 #define STRPRODUCTDATE "2012-04-14" 6 6 #endif // VERSION_HPP -
version.txt
r682ccd2 r6533c1a 1 1 version=0.4.0 2 build=1 593 date=2012-04-1 12 build=163 3 date=2012-04-14
Note: See TracChangeset
for help on using the changeset viewer.








