Changeset fb7e36a in nscp
- Timestamp:
- 09/03/11 21:17:11 (21 months ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- a78a985
- Parents:
- 4cac39f
- Files:
-
- 16 edited
-
changelog (modified) (1 diff)
-
files/old-settings.map (modified) (1 diff)
-
helpers/installers/installer/Product.wxs (modified) (3 diffs)
-
helpers/settings_manager/settings_manager_impl.cpp (modified) (2 diffs)
-
include/settings/settings_core.hpp (modified) (1 diff)
-
include/settings/settings_handler_impl.hpp (modified) (1 diff)
-
include/settings/settings_ini.hpp (modified) (2 diffs)
-
include/simpleini/simpleini.h (modified) (2 diffs)
-
modules/PythonScript/PythonScript.cpp (modified) (5 diffs)
-
modules/PythonScript/PythonScript.h (modified) (1 diff)
-
scripts/python/test.py (modified) (3 diffs)
-
service/NSClient++.cpp (modified) (6 diffs)
-
service/NSClient++.h (modified) (1 diff)
-
service/cli_parser.hpp (modified) (3 diffs)
-
service/settings_client.hpp (modified) (2 diffs)
-
service/simple_client.hpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
changelog
r4cac39f rfb7e36a 10 10 * Upgraded to new version of simpleinin class 11 11 * Added new component for python protocol buffer library to installer 12 * Added installer for unittests to test.py run like so: 13 nscp --client --module PythonScript --command execute-and-load-python --script test.py 14 * Fixed so settings are created if not existing 15 * Fixed so plugins are not loaded in client mode 16 * Fixed so core is booting correctly in client mode 17 * Added new option --settings --switch <context> to allow switching context without migrating data 18 * Fixed unicode error on linux (settings file) 12 19 13 20 2011-09-02 MickeM -
files/old-settings.map
re11d494 rfb7e36a 18 18 modules/CheckTaskSched.dll=/modules/CheckTaskSched 19 19 modules/Scheduler.dll=/modules/Scheduler 20 21 modules=/modules 20 22 21 23 # Crash section -
helpers/installers/installer/Product.wxs
r4cac39f rfb7e36a 174 174 175 175 <Directory Id="INSTALLLOCATION_SCRIPTS_PYTHON_LIB1" Name="lib"> 176 <Component Id="PythonScriptsPBLib1" Guid=" 8820A304-C697-4393-B72F-$(var.Postfix.GUID)" Win64="$(var.Win64)">176 <Component Id="PythonScriptsPBLib1" Guid="555165B3-5CBF-4204-A349-6AD7CCEF14EB" Win64="$(var.Win64)"> 177 177 <File Id="p_script_lib_001" Name="__init__.py" DiskId="1" Source="$(var.Source)/scripts/python/lib/__init__.py" Vital="no" /> 178 178 </Component> 179 179 <Directory Id="INSTALLLOCATION_SCRIPTS_PYTHON_LIB2" Name="google"> 180 <Component Id="PythonScriptsPBLib2" Guid=" 8820A304-C697-4393-B72F-$(var.Postfix.GUID)" Win64="$(var.Win64)">180 <Component Id="PythonScriptsPBLib2" Guid="555165B3-5CBF-4204-A349-6AD7CCEF14E1" Win64="$(var.Win64)"> 181 181 <File Id="p_script_lib_002" Name="__init__.py" DiskId="1" Source="$(var.Source)/scripts/python/lib/google/__init__.py" Vital="no" /> 182 182 </Component> 183 183 <Directory Id="INSTALLLOCATION_SCRIPTS_PYTHON_LIB3" Name="protobuf"> 184 <Component Id="PythonScriptsPBLib3" Guid=" 8820A304-C697-4393-B72F-$(var.Postfix.GUID)" Win64="$(var.Win64)">184 <Component Id="PythonScriptsPBLib3" Guid="555165B3-5CBF-4204-A349-6AD7CCEF14E2" Win64="$(var.Win64)"> 185 185 <File Id="p_script_lib_003" Name="descriptor.py" DiskId="1" Source="$(var.Source)/scripts/python/lib/google/protobuf/descriptor.py" Vital="no" /> 186 186 <File Id="p_script_lib_004" Name="descriptor_pb2.py" DiskId="1" Source="$(var.Source)/scripts/python/lib/google/protobuf/descriptor_pb2.py" Vital="no" /> … … 193 193 </Component> 194 194 <Directory Id="INSTALLLOCATION_SCRIPTS_PYTHON_LIB4" Name="compiler"> 195 <Component Id="PythonScriptsPBLib4" Guid=" 8820A304-C697-4393-B72F-$(var.Postfix.GUID)" Win64="$(var.Win64)">195 <Component Id="PythonScriptsPBLib4" Guid="555165B3-5CBF-4204-A349-6AD7CCEF14E3" Win64="$(var.Win64)"> 196 196 <File Id="p_script_lib_011" Name="plugin_pb2.py" DiskId="1" Source="$(var.Source)/scripts/python/lib/google/protobuf/compiler/plugin_pb2.py" Vital="no" /> 197 197 </Component> 198 198 </Directory> 199 199 <Directory Id="INSTALLLOCATION_SCRIPTS_PYTHON_LIB5" Name="internal"> 200 <Component Id="PythonScriptsPBLib5" Guid=" 8820A304-C697-4393-B72F-$(var.Postfix.GUID)" Win64="$(var.Win64)">200 <Component Id="PythonScriptsPBLib5" Guid="555165B3-5CBF-4204-A349-6AD7CCEF14E4" Win64="$(var.Win64)"> 201 201 <File Id="p_script_lib_012" Name="api_implementation.py" DiskId="1" Source="$(var.Source)/scripts/python/lib/google/protobuf/internal/api_implementation.py" Vital="no" /> 202 202 <File Id="p_script_lib_013" Name="containers.py" DiskId="1" Source="$(var.Source)/scripts/python/lib/google/protobuf/internal/containers.py" Vital="no" /> … … 214 214 </Directory> 215 215 </Directory> 216 217 218 216 </Directory> 219 217 </Directory> -
helpers/settings_manager/settings_manager_impl.cpp
re11d494 rfb7e36a 175 175 set_instance(key); 176 176 return; 177 } 178 177 } 178 179 get_logger()->debug(__FILE__, __LINE__, _T("No valid settings found (tried): ") + boot_order); 180 181 std::wstring tgt = get_boot_string(_T("main"), _T("write"), _T("")); 182 if (!tgt.empty()) { 183 get_logger()->debug(__FILE__, __LINE__, _T("Creating new settings file: ") + tgt); 184 set_instance(tgt); 185 return; 186 } 179 187 get_logger()->err(__FILE__, __LINE__, _T("No valid settings found (tried): ") + boot_order); 180 188 } … … 195 203 set_boot_string(_T("settings"), strEx::itos(i++), k); 196 204 } 205 set_boot_string(_T("main"), _T("write"), key); 197 206 } 198 207 -
include/settings/settings_core.hpp
rb7d17f8 rfb7e36a 230 230 virtual void migrate_from(std::wstring from) = 0; 231 231 232 virtual void set_primary(std::wstring context) = 0; 233 232 234 ////////////////////////////////////////////////////////////////////////// 233 235 /// Overwrite the (current) settings store with default values. -
include/settings/settings_handler_impl.hpp
re11d494 rfb7e36a 195 195 migrate(ifrom, ito); 196 196 } 197 virtual void set_primary(std::wstring key) = 0;198 197 199 198 ////////////////////////////////////////////////////////////////////////// -
include/settings/settings_ini.hpp
r4cac39f rfb7e36a 9 9 #include <settings/settings_core.hpp> 10 10 #include <settings/settings_core_impl.hpp> 11 //#define SI_CONVERT_ICU 11 12 #include <simpleini/simpleini.h> 12 13 #include <error.hpp> … … 226 227 } 227 228 std::wstring f = get_file_name(); 229 ini.SetUnicode(); 228 230 get_core()->get_logger()->debug(__FILE__, __LINE__, _T("Loading: ") + f + _T(" from ") + get_context()); 229 231 SI_Error rc = ini.LoadFile(f.c_str()); -
include/simpleini/simpleini.h
r4cac39f rfb7e36a 1333 1333 return rc; 1334 1334 #else // !_WIN32 (therefore SI_CONVERT_ICU) 1335 #if SI_CONVERT_ICU1335 #ifdef SI_CONVERT_ICU 1336 1336 char szFile[256]; 1337 1337 u_austrncpy(szFile, a_pwszFile, sizeof(szFile)); … … 1689 1689 ) const 1690 1690 { 1691 return (a_c == '\n' || a_c == '\r' );1691 return (a_c == '\n' || a_c == '\r' || a_c == 0); 1692 1692 } 1693 1693 -
modules/PythonScript/PythonScript.cpp
ra14aa07 rfb7e36a 21 21 #include "stdafx.h" 22 22 #include "PythonScript.h" 23 #include <strEx.h>24 23 #include <time.h> 25 24 #include <error.hpp> 25 26 #include <boost/python.hpp> 27 #include <boost/program_options.hpp> 28 29 #include <strEx.h> 26 30 #include <file_helpers.hpp> 27 28 #include <boost/python.hpp>29 30 31 #include <settings/client/settings_client.hpp> 31 32 #include <nscapi/functions.hpp> … … 39 40 40 41 namespace sh = nscapi::settings_helper; 42 namespace po = boost::program_options; 41 43 42 44 bool PythonScript::loadModule() { … … 102 104 103 105 python_script::python_script(unsigned int plugin_id, const std::string alias, const script_container& script) : alias(alias), plugin_id(plugin_id) { 106 NSC_DEBUG_MSG_STD(_T("Loading python script: ") + script.script.string()); 107 std::wcout << script.script.string() << std::endl;; 104 108 _exec(utf8::cvt<std::string>(script.script.string())); 105 109 callFunction("init", plugin_id, alias, utf8::cvt<std::string>(script.alias)); … … 213 217 NSC_LOG_ERROR(_T("Script not found: ") + file); 214 218 return boost::optional<boost::filesystem::wpath>(); 219 } 220 221 NSCAPI::nagiosReturn PythonScript::execute_and_load_python(std::list<std::wstring> args) { 222 try { 223 po::options_description desc; 224 boost::program_options::variables_map vm; 225 std::wstring file; 226 desc.add_options() 227 ("script", po::wvalue<std::wstring>(&file), "The script to run") 228 ("file", po::wvalue<std::wstring>(&file), "The script to run") 229 ; 230 231 std::vector<std::wstring> vargs(args.begin(), args.end()); 232 po::wparsed_options parsed = po::basic_command_line_parser<wchar_t>(vargs).options(desc).run(); 233 po::store(parsed, vm); 234 po::notify(vm); 235 236 boost::optional<boost::filesystem::wpath> ofile = find_file(file); 237 if (!ofile) 238 return false; 239 script_container sc(*ofile); 240 python_script script(get_id(), "", sc); 241 script.callFunction("__main__"); 242 } catch (const std::exception &e) { 243 NSC_LOG_ERROR_STD(_T("Failed to execute script ") + utf8::cvt<std::wstring>(e.what())); 244 } catch (...) { 245 NSC_LOG_ERROR_STD(_T("Failed to execute script...")); 246 } 215 247 } 216 248 … … 275 307 276 308 NSCAPI::nagiosReturn PythonScript::commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &response) { 309 std::wstring command = char_command; 310 if (command == _T("execute-and-load-python")) { 311 nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_exec_request(char_command, request); 312 return execute_and_load_python(data.args); 313 } 277 314 boost::shared_ptr<script_wrapper::function_wrapper> inst = script_wrapper::function_wrapper::create(get_id()); 278 315 std::string cmd = utf8::cvt<std::string>(char_command); -
modules/PythonScript/PythonScript.h
ra44cb15 rfb7e36a 88 88 NSCAPI::nagiosReturn handleRAWNotification(const std::wstring &channel, const std::wstring &command, std::string &request); 89 89 90 NSCAPI::nagiosReturn execute_and_load_python(std::list<std::wstring> args); 90 91 //NSCAPI::nagiosReturn RunLUA(const unsigned int argLen, wchar_t **char_args, std::wstring &message, std::wstring &perf); 91 92 //NSCAPI::nagiosReturn extract_return(Lua_State &L, int arg_count, std::wstring &message, std::wstring &perf); -
scripts/python/test.py
r4cac39f rfb7e36a 202 202 return (status.CRITICAL, 'Tests failed %d of %d'%(all_failed, all_count)) 203 203 204 204 def install_test(arguments): 205 log('-+---==(TEST INSTALLER)==---------------------------------------------------+-') 206 log(' | Setup nessecary configuration for running test |') 207 log(' | This includes: Loading the PythonScript module at startup |') 208 log(' | To use this please run nsclient++ in "test mode" like so: |') 209 log(' | nscp --test |') 210 log(' | Then start the pytest_test command by typing it and press enter like so: |') 211 log(' | pytest_test |') 212 log(' | Lastly exit by typing exit like so: |') 213 log(' | exit |') 214 log('-+--------------------------------------------------------==(DAS ENDE!)==---+-') 215 conf = Settings.get() 216 conf.set_string('/modules', 'pytest', 'PythonScript') 217 conf.set_string('/settings/pytest/scripts', 'pytest', 'test.py') 218 conf.save() 219 220 def __main__(): 221 install_test([]) 222 205 223 def init(pid, plugin_alias, script_alias): 206 224 global prefix … … 210 228 prefix = '%s_'%script_alias 211 229 212 log('Script: test.py with alias: %s (%s:%d)'%(script_alias, plugin_alias, plugin_id))213 214 230 conf = Settings.get() 215 val = conf.get_string('/modules', 'PythonScript', 'foo')216 217 log('Got it: %s'%val)231 #val = conf.get_string('/modules', 'PythonScript', 'foo') 232 233 #log('Got it: %s'%val) 218 234 219 235 log('Testing to register a function') 220 236 reg = Registry.get(plugin_id) 221 237 222 #reg.simple_cmdline('help', get_help)223 #reg.simple_cmdline('%stest'%prefix, test_cmd)238 reg.simple_cmdline('help', get_help) 239 reg.simple_cmdline('install_python_test', install_test) 224 240 225 241 reg.simple_function('%stest'%prefix, test, 'Run python unittest') … … 228 244 #core.simple_submit('test', 'test.py', status.WARNING, 'hello', '') 229 245 230 (ret, list) = core.simple_exec('%stest'%prefix, ['a', 'b', 'c'])231 for l in list:232 log('-- %s --'%l)233 234 log('Testing to register settings keys')235 conf.register_path('hello', 'PYTHON SETTINGS', 'This is stuff for python')236 conf.register_key('hello', 'python', 'int', 'KEY', 'This is a key', '42')237 238 log('Testing to get key (nonexistant): %d' % conf.get_int('hello', 'python', -1))239 conf.set_int('hello', 'python', 4)240 log('Testing to get it (after setting it): %d' % conf.get_int('hello', 'python', -1))241 242 log('Saving configuration...')246 #(ret, list) = core.simple_exec('%stest'%prefix, ['a', 'b', 'c']) 247 #for l in list: 248 # log('-- %s --'%l) 249 250 #log('Testing to register settings keys') 251 #conf.register_path('hello', 'PYTHON SETTINGS', 'This is stuff for python') 252 #conf.register_key('hello', 'python', 'int', 'KEY', 'This is a key', '42') 253 254 #log('Testing to get key (nonexistant): %d' % conf.get_int('hello', 'python', -1)) 255 #conf.set_int('hello', 'python', 4) 256 #log('Testing to get it (after setting it): %d' % conf.get_int('hello', 'python', -1)) 257 258 #log('Saving configuration...') 243 259 #conf.save() 244 260 -
service/NSClient++.cpp
ra44cb15 rfb7e36a 533 533 * @author mickem 534 534 */ 535 bool NSClientT:: initCore(bool boot) {536 LOG_INFO_CORE( _T("Attempting to start"));535 bool NSClientT::boot_init() { 536 LOG_INFO_CORE(SERVICE_NAME _T(" booting...")); 537 537 538 538 if (!settings_manager::init_settings(&provider, context_)) { … … 627 627 628 628 if (enable_shared_session_) { 629 LOG_ DEBUG_CORE(_T("Enabling shared session..."));630 if (boot) {631 LOG_INFO_CORE(_T("shared session not ported yet!..."));629 LOG_INFO_CORE(_T("shared session not ported yet!...")); 630 // if (boot) { 631 // LOG_INFO_CORE(_T("shared session not ported yet!...")); 632 632 // try { 633 633 // shared_server_.reset(new nsclient_session::shared_server_session(this)); … … 645 645 // shared_server_.reset(NULL); 646 646 // } 647 } else {648 LOG_INFO_CORE(_T("shared session not ported yet!..."));647 // } else { 648 // LOG_INFO_CORE(_T("shared session not ported yet!...")); 649 649 // try { 650 650 // std::wstring id = _T("_attached_") + strEx::itos(GetCurrentProcessId()) + _T("_"); … … 663 663 // shared_client_.reset(NULL); 664 664 // } 665 }665 // } 666 666 } 667 667 #ifdef WIN32 … … 676 676 } 677 677 #endif 678 return true; 679 } 680 bool NSClientT::boot_load_plugins(bool boot) { 681 LOG_DEBUG_CORE(_T("booting::loading plugins")); 678 682 try { 679 683 boost::filesystem::wpath pluginPath = expand_path(_T("${module-path}")); … … 1379 1383 void NSClientT::handle_startup(std::wstring service_name) { 1380 1384 service_name_ = service_name; 1381 initCore(true); 1385 boot_init(); 1386 boot_load_plugins(true); 1382 1387 /* 1383 1388 DWORD dwSessionId = remote_processes::getActiveSessionId(); -
service/NSClient++.h
ra44cb15 rfb7e36a 131 131 132 132 // Service helper functions 133 bool initCore(bool boot); 133 bool boot_init(); 134 bool boot_load_plugins(bool boot); 134 135 bool exitCore(bool boot); 135 136 void set_settings_context(std::wstring context) { context_ = context; } -
service/cli_parser.hpp
rd7e265d rfb7e36a 58 58 ("key", po::value<std::wstring>()->default_value(_T("")), "Key to work with.") 59 59 ("set", po::value<std::wstring>(), "Set a key and path to a given value.") 60 ("switch", po::value<std::wstring>(), "Set default context to use (similar to migrate but does NOT copy values)") 60 61 ("show", "Set a value given a key and path.") 61 62 ("list", "Set all keys below the path (or root).") … … 210 211 if (vm.count("show")) { 211 212 ret = client.show(vm["path"].as<std::wstring>(), vm["key"].as<std::wstring>()); 213 } 214 if (vm.count("switch")) { 215 client.switch_context(vm["switch"].as<std::wstring>()); 216 ret = 0; 212 217 } 213 218 client.exit(); … … 335 340 mainClient.log_info(__FILE__, __LINE__, _T("Arguments: ") + args); 336 341 } 342 core_->boot_init(); 337 343 if (module.empty()) { 338 core_-> initCore(false);344 core_->boot_load_plugins(false); 339 345 } 340 346 int ret = 0; -
service/settings_client.hpp
r7e54a5f rfb7e36a 21 21 if (!current_.empty()) 22 22 core_->set_settings_context(current_); 23 if (!core_->initCore(false)) { 24 std::wcout << _T("Service *NOT* started!") << std::endl; 23 if (!core_->boot_init()) { 24 std::wcout << _T("boot::init failed") << std::endl; 25 return; 26 } 27 if (!core_->boot_load_plugins(false)) { 28 std::wcout << _T("boot::load_plugins failed!") << std::endl; 25 29 return; 26 30 } … … 126 130 127 131 132 void switch_context(std::wstring contect) { 133 settings_manager::get_core()->set_primary(contect); 134 } 135 128 136 int set(std::wstring path, std::wstring key, std::wstring val) { 129 137 core_->load_all_plugins(NSCAPI::dontStart); -
service/simple_client.hpp
r4b1e6fe rfb7e36a 15 15 void start() { 16 16 core_->enableDebug(true); 17 if (!core_->initCore(true)) { 18 core_->log_error(__FILE__, __LINE__, _T("Service failed to start")); 17 if (!core_->boot_init()) { 18 core_->log_error(__FILE__, __LINE__, _T("Service failed to init")); 19 return; 20 } 21 if (!core_->boot_load_plugins(true)) { 22 core_->log_error(__FILE__, __LINE__, _T("Service failed to load plugin")); 19 23 return; 20 24 }
Note: See TracChangeset
for help on using the changeset viewer.








