Changeset 393a00f in nscp
- Timestamp:
- 07/08/12 10:45:05 (11 months ago)
- Branches:
- master, 0.4.2
- Children:
- 77c0100
- Parents:
- 9fdde88
- Files:
-
- 3 added
- 23 edited
-
CMakeLists.txt (modified) (1 diff)
-
build.cmake (modified) (1 diff)
-
build/cmake/FindJson_Spirit.cmake (added)
-
changelog (modified) (1 diff)
-
include/NSCAPI.h (modified) (2 diffs)
-
include/nscapi/nscapi_core_wrapper.cpp (modified) (4 diffs)
-
include/nscapi/nscapi_core_wrapper.hpp (modified) (6 diffs)
-
include/nscapi/nscapi_protobuf_functions.hpp (modified) (2 diffs)
-
include/settings/settings_core.hpp (modified) (2 diffs)
-
include/settings/settings_handler_impl.hpp (modified) (1 diff)
-
libs/json_spirit/CMakeLists.txt (added)
-
libs/protobuf/plugin.proto (modified) (5 diffs)
-
modules/DotnetPlugins/DotnetPlugins.cpp (modified) (1 diff)
-
modules/PythonScript/PythonScript.cpp (modified) (6 diffs)
-
modules/PythonScript/PythonScript.h (modified) (1 diff)
-
modules/PythonScript/script_wrapper.cpp (modified) (3 diffs)
-
modules/PythonScript/script_wrapper.hpp (modified) (3 diffs)
-
scripts/python/docs.py (added)
-
service/CMakeLists.txt (modified) (3 diffs)
-
service/NSClient++.cpp (modified) (4 diffs)
-
service/NSClient++.h (modified) (1 diff)
-
service/cli_parser.hpp (modified) (6 diffs)
-
service/commands.hpp (modified) (4 diffs)
-
service/core_api.cpp (modified) (3 diffs)
-
service/core_api.h (modified) (1 diff)
-
service/settings_client.hpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
CMakeLists.txt
rc6a974c r393a00f 107 107 ENDIF (TINYXML2_FOUND) 108 108 109 FIND_PACKAGE(JSON_SPIRIT) 110 IF (JSON_SPIRIT_FOUND) 111 MESSAGE(STATUS "Found json spirit in: ${JSON_SPIRIT_INCLUDE_DIR}") 112 ENDIF (JSON_SPIRIT_FOUND) 109 113 110 114 FIND_PACKAGE(ZeroMQ) -
build.cmake
rc6a974c r393a00f 8 8 SET(INC_PSDK_2003 "C:/Program Files/Microsoft Platform SDK/") 9 9 SET(TINYXML2_DIR "D:/source/libraries/tinyxml2") 10 SET(JSON_SPRIT_DIR "D:/source/libraries/json_spirit_v4.05") 10 11 11 12 if(CMAKE_CL_64) -
changelog
r9fdde88 r393a00f 4 4 * Fix dependonservice LanManWorkStation (old win) 5 5 * Fix RtlStringFromGUID problem on NT4 6 7 2012-07-03 MickeM 8 * Improved settings API with new protoclbuffers commad (avalible from python) 9 * Improved registration API with new protoclbuffers commad (avalible from python) 10 * Created new python documentation module docs.py 11 * Improved command line syntax so executable commands now take an optional module prefix 6 12 7 13 2012-06-21 MickeM -
include/NSCAPI.h
r9fdde88 r393a00f 173 173 typedef NSCAPI::errorReturn (*lpNSAPISettingsRegKey)(unsigned int, const wchar_t*, const wchar_t*, int, const wchar_t*, const wchar_t*, const wchar_t*, int); 174 174 typedef NSCAPI::errorReturn (*lpNSAPISettingsRegPath)(unsigned int, const wchar_t*, const wchar_t*, const wchar_t*, int); 175 typedef NSCAPI::errorReturn (*lpNSAPISettingsQuery)(const char *, const unsigned int, char **, unsigned int *); 175 176 typedef NSCAPI::errorReturn (*lpNSAPIGetPluginList)(int *len, NSCAPI::plugin_info *list[]); 176 177 typedef NSCAPI::errorReturn (*lpNSAPIReleasePluginList)(int len, NSCAPI::plugin_info *list[]); … … 180 181 typedef NSCAPI::errorReturn (*lpNSAPIReload)(const wchar_t* module); 181 182 typedef NSCAPI::log_level::level (*lpNSAPIGetLoglevel)(); 183 typedef NSCAPI::errorReturn (*lpNSAPIRegistryQuery)(const char *, const unsigned int, char **, unsigned int *); 182 184 183 185 } -
include/nscapi/nscapi_core_wrapper.cpp
r9fdde88 r393a00f 328 328 fNSAPISettingsRegPath(plugin_id, path.c_str(), title.c_str(), description.c_str(), advanced); 329 329 } 330 330 NSCAPI::errorReturn nscapi::core_wrapper::settings_query(const char *request, const unsigned int request_len, char **response, unsigned int *response_len) { 331 if (!fNSAPISettingsQuery) 332 throw nscapi::nscapi_exception("NSCore has not been initiated..."); 333 fNSAPISettingsQuery(request, request_len, response, response_len); 334 } 335 NSCAPI::errorReturn nscapi::core_wrapper::settings_query(const std::string request, std::string &response) { 336 char *buffer = NULL; 337 unsigned int buffer_size = 0; 338 NSCAPI::errorReturn retC = settings_query(request.c_str(), request.size(), &buffer, &buffer_size); 339 if (buffer_size > 0 && buffer != NULL) { 340 response = std::string(buffer, buffer_size); 341 } 342 DestroyBuffer(&buffer); 343 return retC; 344 } 331 345 332 346 void nscapi::core_wrapper::settings_save() { … … 334 348 throw nscapi::nscapi_exception("NSCore has not been initiated..."); 335 349 fNSAPISettingsSave(); 350 } 351 352 353 NSCAPI::errorReturn nscapi::core_wrapper::registry_query(const char *request, const unsigned int request_len, char **response, unsigned int *response_len) { 354 if (!fNSAPIRegistryQuery) 355 throw nscapi::nscapi_exception("NSCore has not been initiated..."); 356 fNSAPIRegistryQuery(request, request_len, response, response_len); 357 } 358 NSCAPI::errorReturn nscapi::core_wrapper::registry_query(const std::string request, std::string &response) { 359 char *buffer = NULL; 360 unsigned int buffer_size = 0; 361 NSCAPI::errorReturn retC = registry_query(request.c_str(), request.size(), &buffer, &buffer_size); 362 if (buffer_size > 0 && buffer != NULL) { 363 response = std::string(buffer, buffer_size); 364 } 365 DestroyBuffer(&buffer); 366 return retC; 336 367 } 337 368 … … 579 610 580 611 fNSAPISettingsSave = (nscapi::core_api::lpNSAPISettingsSave)f(_T("NSAPISettingsSave")); 612 fNSAPISettingsQuery = (nscapi::core_api::lpNSAPISettingsQuery)f(_T("NSAPISettingsQuery")); 581 613 582 614 fNSAPIExpandPath = (nscapi::core_api::lpNSAPIExpandPath)f(_T("NSAPIExpandPath")); … … 585 617 fNSAPIRegisterRoutingListener = (nscapi::core_api::lpNSAPIRegisterRoutingListener)f(_T("NSAPIRegisterRoutingListener")); 586 618 fNSAPIGetLoglevel = (nscapi::core_api::lpNSAPIGetLoglevel)f(_T("NSAPIGetLoglevel")); 619 fNSAPIRegistryQuery = (nscapi::core_api::lpNSAPIRegistryQuery)f(_T("NSAPIRegistryQuery")); 587 620 588 621 return true; -
include/nscapi/nscapi_core_wrapper.hpp
r9fdde88 r393a00f 62 62 nscapi::core_api::lpNSAPISettingsRegKey fNSAPISettingsRegKey; 63 63 nscapi::core_api::lpNSAPISettingsRegPath fNSAPISettingsRegPath; 64 nscapi::core_api::lpNSAPISettingsQuery fNSAPISettingsQuery; 64 65 nscapi::core_api::lpNSAPIGetPluginList fNSAPIGetPluginList; 65 66 nscapi::core_api::lpNSAPIReleasePluginList fNSAPIReleasePluginList; … … 69 70 nscapi::core_api::lpNSAPIRegisterSubmissionListener fNSAPIRegisterSubmissionListener; 70 71 nscapi::core_api::lpNSAPIRegisterRoutingListener fNSAPIRegisterRoutingListener; 72 nscapi::core_api::lpNSAPIRegistryQuery fNSAPIRegistryQuery; 71 73 72 74 public: … … 113 115 , fNSAPISettingsRegKey(NULL) 114 116 , fNSAPISettingsRegPath(NULL) 117 , fNSAPISettingsQuery(NULL) 115 118 , fNSAPIGetPluginList(NULL) 116 119 , fNSAPIReleasePluginList(NULL) … … 120 123 , fNSAPIRegisterSubmissionListener(NULL) 121 124 , fNSAPIRegisterRoutingListener(NULL) 125 , fNSAPIRegistryQuery(NULL) 122 126 {} 123 127 … … 133 137 void settings_register_key(unsigned int plugin_id, std::wstring path, std::wstring key, NSCAPI::settings_type type, std::wstring title, std::wstring description, std::wstring defaultValue, bool advanced); 134 138 void settings_register_path(unsigned int plugin_id, std::wstring path, std::wstring title, std::wstring description, bool advanced); 139 NSCAPI::errorReturn settings_query(const char *request, const unsigned int request_len, char **response, unsigned int *response_len); 140 NSCAPI::errorReturn settings_query(const std::string request, std::string &response); 135 141 void settings_save(); 136 142 … … 168 174 void registerRoutingListener(unsigned int id, std::wstring channel); 169 175 176 NSCAPI::errorReturn registry_query(const char *request, const unsigned int request_len, char **response, unsigned int *response_len); 177 NSCAPI::errorReturn registry_query(const std::string request, std::string &response); 178 170 179 bool load_endpoints(nscapi::core_api::lpNSAPILoader f); 171 180 void set_alias(const std::wstring default_alias, const std::wstring alias); -
include/nscapi/nscapi_protobuf_functions.hpp
r308ae18 r393a00f 59 59 static Plugin::Common::Status::StatusType status_to_gpb(int ret) { 60 60 if (ret == NSCAPI::isSuccess) 61 return Plugin::Common_Status_StatusType_ OK;62 return Plugin::Common_Status_StatusType_ PROBLEM;61 return Plugin::Common_Status_StatusType_STATUS_OK; 62 return Plugin::Common_Status_StatusType_STATUS_ERROR; 63 63 } 64 64 static int gbp_to_status(Plugin::Common::Status::StatusType ret) { 65 if (ret == Plugin::Common_Status_StatusType_ OK)65 if (ret == Plugin::Common_Status_StatusType_STATUS_OK) 66 66 return NSCAPI::isSuccess; 67 67 return NSCAPI::hasFailed; 68 68 } 69 69 static Plugin::Common::ResultCode gbp_status_to_gbp_nagios(Plugin::Common::Status::StatusType ret) { 70 if (ret == Plugin::Common_Status_StatusType_ OK)70 if (ret == Plugin::Common_Status_StatusType_STATUS_OK) 71 71 return Plugin::Common_ResultCode_OK; 72 72 return Plugin::Common_ResultCode_UNKNOWN; … … 74 74 static Plugin::Common::Status::StatusType gbp_to_nagios_gbp_status(Plugin::Common::ResultCode ret) { 75 75 if (ret == Plugin::Common_ResultCode_UNKNOWN||ret == Plugin::Common_ResultCode_WARNING||ret == Plugin::Common_ResultCode_CRITCAL) 76 return Plugin::Common_Status_StatusType_ CRITICAL;77 return Plugin::Common_Status_StatusType_ OK;76 return Plugin::Common_Status_StatusType_STATUS_ERROR; 77 return Plugin::Common_Status_StatusType_STATUS_OK; 78 78 } 79 79 -
include/settings/settings_core.hpp
r9fdde88 r393a00f 36 36 37 37 38 class settings_exception : std::exception {38 class settings_exception : public std::exception { 39 39 std::string error_; 40 40 public: … … 162 162 virtual key_description get_registred_key(std::wstring path, std::wstring key) = 0; 163 163 164 virtual settings_core::path_description get_registred_path( std::wstringpath) = 0;164 virtual settings_core::path_description get_registred_path(const std::wstring &path) = 0; 165 165 166 166 ////////////////////////////////////////////////////////////////////////// -
include/settings/settings_handler_impl.hpp
r9fdde88 r393a00f 244 244 throw KeyNotFoundException(path, key); 245 245 } 246 settings_core::path_description get_registred_path( std::wstringpath) {246 settings_core::path_description get_registred_path(const std::wstring &path) { 247 247 reg_paths_type::const_iterator cit = registred_paths_.find(path); 248 248 if (cit != registred_paths_.end()) { -
libs/protobuf/plugin.proto
r8d89d7a r393a00f 13 13 enum DataType { 14 14 INT = 1; 15 STRING = 1; 16 FLOAT = 1; 17 BOOL = 1; 15 STRING = 2; 16 FLOAT = 3; 17 BOOL = 4; 18 LIST = 5; 18 19 }; 19 20 … … 24 25 optional double float_data = 4; 25 26 optional bool bool_data = 5; 27 repeated string list_data = 6; 26 28 } 27 29 … … 115 117 116 118 enum StatusType { 117 OK = 0; 118 WARNING = 1; 119 PROBLEM = 2; 120 CRITICAL = 3; 121 UNKNOWN = 10; 119 STATUS_OK = 0; 120 STATUS_WARNING = 1; 121 STATUS_ERROR = 2; 122 STATUS_DELAYED = 3; 122 123 }; 123 124 … … 250 251 } 251 252 253 254 // // // // // // // // // // // // // // // // // // // // // // // // 255 // 256 // plugins and registration 257 // 258 // // // // // // // // // // // // // // // // // // // // // // // // 259 message Registry { 260 enum ItemType { 261 QUERY = 1; 262 COMMAND = 2; 263 HANDLER = 3; 264 PLUGIN = 4; 265 ALL = 99; 266 }; 267 message Query { 268 optional string expression = 1; 269 }; 270 message Information { 271 optional string title = 1; 272 optional string description = 2; 273 274 optional string minVersion = 5; 275 optional string maxVersion = 6; 276 277 optional bool advanced = 8; 278 repeated string plugin = 9; 279 }; 280 }; 281 282 message RegistryRequestMessage { 283 message Request { 284 enum ActionType { 285 REGISTRATION = 1; 286 INVENTORY = 2; 287 }; 288 message Registration { 289 optional int32 plugin_id = 1; 290 required Registry.ItemType type = 2; 291 required string name = 3; 292 optional Registry.Information info = 4; 293 294 repeated string alias = 9; 295 }; 296 message Inventory { 297 optional string plugin = 1; 298 repeated Registry.ItemType type = 2; 299 optional string name = 3; 300 optional Registry.Information info = 4; 301 302 optional bool fetch_all = 6; 303 optional bool fetch_information = 7; 304 }; 305 optional int64 id = 1; 306 required ActionType type = 2; 307 optional Registration registration = 3; 308 optional Inventory inventory = 4; 309 }; 310 required Common.Header header = 1; 311 repeated Request payload = 2; 312 }; 313 message RegistryResponseMessage { 314 message Response { 315 enum ActionType { 316 INVENTORY = 2; 317 }; 318 message Inventory { 319 repeated string plugin = 1; 320 required Registry.ItemType type = 2; 321 required string name = 3; 322 optional Registry.Information info = 4; 323 }; 324 optional int64 id = 1; 325 required Common.Status result = 2; 326 required ActionType type = 3; 327 328 repeated Inventory inventory = 4; 329 }; 330 331 required Common.Header header = 1; 332 repeated Response payload = 2; 333 }; 334 252 335 // // // // // // // // // // // // // // // // // // // // // // // // 253 336 // … … 258 341 message Settings { 259 342 message Node { 260 message Path { 261 required string path = 1; 262 optional string key = 2; 263 } 264 optional Path path = 1; 265 optional string expression = 2; 266 }; 267 }; 268 269 message QuerySettingsRequestMessage { 343 required string path = 1; 344 optional string key = 2; 345 }; 346 message Query { 347 optional string expression = 1; 348 }; 349 message Value { 350 optional Common.AnyDataType value = 1; 351 optional Common.DataType type = 2; 352 }; 353 message Information { 354 optional string title = 1; 355 optional string description = 2; 356 optional string default_value = 3; 357 optional string min_version = 4; 358 optional string max_version = 5; 359 optional bool advanced = 6; 360 optional string sample = 7; 361 repeated string plugin = 9; 362 }; 363 }; 364 365 message SettingsRequestMessage { 270 366 message Request { 367 enum ActionType { 368 REGISTRATION = 1; 369 QUERY = 2; 370 UPDATE = 3; 371 INVENTORY = 4; 372 }; 373 message Registration { 374 optional Settings.Node node = 1; 375 optional Settings.Information info = 2; 376 }; 377 message Query { 378 optional Settings.Node node = 1; 379 optional Settings.Query query = 4; 380 optional bool recursive = 2; 381 optional Common.DataType type = 3; 382 }; 383 message Inventory { 384 optional Settings.Node node = 1; 385 optional Settings.Query query = 10; 386 optional bool recursive_fetch = 2; 387 optional bool fetch_keys = 3; 388 optional bool fetch_paths = 4; 389 optional bool descriptions = 5; 390 }; 391 message Update { 392 optional Settings.Node node = 1; 393 optional Settings.Value value = 2; 394 }; 271 395 optional int64 id = 1; 272 required Settings node = 2;273 274 optional string default = 3;275 optional bool fetch_descriptions = 4;276 277 optional Common.DataType return_type = 17;278 396 required ActionType type = 2; 397 required int32 plugin_id = 3; 398 399 optional Registration registration = 10; 400 optional Query query = 11; 401 optional Update update = 12; 402 optional Inventory inventory = 13; 279 403 }; 280 404 required Common.Header header = 1; 281 405 repeated Request payload = 2; 282 } 283 message QuerySettingsResponseMessage {406 }; 407 message SettingsResponseMessage { 284 408 message Response { 285 message SectionKeys { 286 repeated string key = 1; 287 } 409 enum ActionType { 410 QUERY = 2; 411 INVENTORY = 4; 412 }; 413 message Query { 414 required Settings.Node node = 1; 415 required Settings.Value value = 2; 416 }; 417 message Inventory { 418 required Settings.Node node = 1; 419 required Settings.Information info = 2; 420 }; 288 421 optional int64 id = 1; 289 required Settings node = 2; 290 291 optional Common.AnyDataType value = 4; 292 optional SectionKeys keys = 5; 293 294 optional string title = 6; 295 optional string description = 7; 296 297 optional Common.DataType required_type = 17; 298 299 }; 422 required Common.Status result = 2; 423 required ActionType type = 3; 424 425 repeated Query query = 4; 426 repeated Inventory inventory = 5; 427 }; 428 300 429 required Common.Header header = 1; 301 430 repeated Response payload = 2; 302 } 431 }; 303 432 304 433 -
modules/DotnetPlugins/DotnetPlugins.cpp
r9fdde88 r393a00f 43 43 try { 44 44 root_path = get_core()->expand_path(module_path); 45 get_core()->settings_register_path( settings_path, _T("DOTNET MODULES"), _T("List all dot net modules loaded by the DotNetplugins module here"), false);45 get_core()->settings_register_path(get_id(), settings_path, _T("DOTNET MODULES"), _T("List all dot net modules loaded by the DotNetplugins module here"), false); 46 46 47 47 std::list<std::wstring> keys = get_core()->getSettingsSection(settings_path); 48 48 BOOST_FOREACH(std::wstring key, keys) { 49 get_core()->settings_register_key( settings_path + _T("/") + key, factory_key, NSCAPI::key_string, _T("DOTNET FACTORY"), _T("The class to instasitate in the dot-net plugin"), factory_default, true);49 get_core()->settings_register_key(get_id(), settings_path + _T("/") + key, factory_key, NSCAPI::key_string, _T("DOTNET FACTORY"), _T("The class to instasitate in the dot-net plugin"), factory_default, true); 50 50 } 51 51 if (mode == NSCAPI::normalStart) { -
modules/PythonScript/PythonScript.cpp
r0382c02 r393a00f 64 64 .def("register_path", &script_wrapper::settings_wrapper::settings_register_path) 65 65 .def("register_key", &script_wrapper::settings_wrapper::settings_register_key) 66 .def("query", &script_wrapper::settings_wrapper::query) 66 67 ; 67 68 class_<script_wrapper::function_wrapper, boost::shared_ptr<script_wrapper::function_wrapper> >("Registry", no_init) … … 76 77 .def("subscription", &script_wrapper::function_wrapper::subscribe_function) 77 78 .def("simple_subscription", &script_wrapper::function_wrapper::subscribe_simple_function) 79 .def("query", &script_wrapper::function_wrapper::query) 78 80 ; 79 81 class_<script_wrapper::command_wrapper, boost::shared_ptr<script_wrapper::command_wrapper> >("Core", init<>()) … … 142 144 } 143 145 } 146 bool python_script::callFunction(const std::string& functionName, const std::vector<std::wstring> args) { 147 try { 148 script_wrapper::thread_locker locker; 149 try { 150 if (!localDict.has_key(functionName)) 151 return true; 152 object scriptFunction = extract<object>(localDict[functionName]); 153 if (scriptFunction) 154 scriptFunction(script_wrapper::convert(args)); 155 return true; 156 } catch( error_already_set e) { 157 script_wrapper::log_exception(); 158 return false; 159 } 160 } catch (...) { 161 NSC_LOG_ERROR(_T("Unknown exception")); 162 return false; 163 } 164 } 144 165 bool python_script::callFunction(const std::string& functionName, unsigned int i1, const std::string &s1, const std::string &s2){ 145 166 try { … … 286 307 287 308 std::vector<std::wstring> vargs(args.begin(), args.end()); 288 po::wparsed_options parsed = po::basic_command_line_parser<wchar_t>(vargs).options(desc). run();309 po::wparsed_options parsed = po::basic_command_line_parser<wchar_t>(vargs).options(desc).allow_unregistered().run(); 289 310 po::store(parsed, vm); 290 311 po::notify(vm); … … 296 317 return NSCAPI::returnUNKNOWN; 297 318 } 319 std::vector<std::wstring> py_args = po::collect_unrecognized(parsed.options, po::include_positional); 298 320 299 321 boost::optional<boost::filesystem::wpath> ofile = find_file(file); … … 302 324 script_container sc(*ofile); 303 325 python_script script(get_id(), "", sc); 304 if (!script.callFunction("__main__" )) {326 if (!script.callFunction("__main__", py_args)) { 305 327 message = _T("Failed to execute script: __main__"); 306 328 return NSCAPI::returnUNKNOWN; -
modules/PythonScript/PythonScript.h
ra48fd4c r393a00f 41 41 bool callFunction(const std::string& functionName); 42 42 bool callFunction(const std::string& functionName, unsigned int i1, const std::string &s1, const std::string &s2); 43 bool callFunction(const std::string& functionName, const std::vector<std::wstring> args); 43 44 void _exec(const std::string &scriptfile); 44 45 }; -
modules/PythonScript/script_wrapper.cpp
r9fdde88 r393a00f 101 101 py::list script_wrapper::convert(std::list<std::wstring> lst) { 102 102 py::list ret; 103 BOOST_FOREACH( std::wstrings, lst) {103 BOOST_FOREACH(const std::wstring &s, lst) { 104 104 ret.append(utf8::cvt<std::string>(s)); 105 } 106 return ret; 107 } 108 py::list script_wrapper::convert(const std::vector<std::wstring> &lst) { 109 py::list ret; 110 BOOST_FOREACH(const std::wstring &s, lst) { 111 ret.append(s); 105 112 } 106 113 return ret; … … 220 227 } 221 228 } 229 230 tuple script_wrapper::function_wrapper::query(std::string request) { 231 try { 232 std::string response; 233 NSCAPI::errorReturn ret = core->registry_query(request, response); 234 return make_tuple(ret, response); 235 } catch (const std::exception &e) { 236 NSC_LOG_ERROR_STD(_T("Query failed: ") + utf8::cvt<std::wstring>(e.what())); 237 return make_tuple(false,utf8::cvt<std::wstring>(e.what())); 238 } catch (...) { 239 NSC_LOG_ERROR_STD(_T("Query failed")); 240 return make_tuple(false,_T("")); 241 } 242 } 243 222 244 int script_wrapper::function_wrapper::handle_query(const std::string cmd, const std::string &request, std::string &response) const { 223 245 try { … … 622 644 core->settings_register_path(plugin_id, utf8::cvt<std::wstring>(path), utf8::cvt<std::wstring>(title), utf8::cvt<std::wstring>(description), false); 623 645 } 646 tuple script_wrapper::settings_wrapper::query(std::string request) { 647 try { 648 std::string response; 649 NSCAPI::errorReturn ret = core->settings_query(request, response); 650 return make_tuple(ret, response); 651 } catch (const std::exception &e) { 652 NSC_LOG_ERROR_STD(_T("Query failed: ") + utf8::cvt<std::wstring>(e.what())); 653 return make_tuple(false,utf8::cvt<std::wstring>(e.what())); 654 } catch (...) { 655 NSC_LOG_ERROR_STD(_T("Query failed")); 656 return make_tuple(false,_T("")); 657 } 658 } -
modules/PythonScript/script_wrapper.hpp
r9fdde88 r393a00f 67 67 std::list<std::wstring> convert(boost::python::list lst); 68 68 boost::python::list convert(std::list<std::wstring> lst); 69 boost::python::list convert(const std::vector<std::wstring> &lst); 69 70 70 71 … … 134 135 135 136 std::wstring get_commands(); 137 tuple query(std::string request); 136 138 }; 137 139 struct command_wrapper { … … 192 194 void settings_register_key(std::string path, std::string key, std::string stype, std::string title, std::string description, std::string defaultValue); 193 195 void settings_register_path(std::string path, std::string title, std::string description); 196 tuple query(std::string request); 194 197 }; 195 198 -
service/CMakeLists.txt
r8d89d7a r393a00f 5 5 PROJECT(service) 6 6 INCLUDE_DIRECTORIES(${BOOST_INCLUDE_DIRS}) 7 INCLUDE_DIRECTORIES(${JSON_SPIRIT_INCLUDE_DIR}) 7 8 LINK_DIRECTORIES(${BOOST_LIB_DIRS}) 8 9 … … 68 69 69 70 70 # SET(71 # CMAKE_LINKER_FLAGS72 # /MANIFEST73 # /MANIFESTFILE:"${CMAKE_CURRENT_SOURCE_DIR}/NSClient++.manifest"74 # )75 # SET(76 # CMAKE_MODULE_LINKER_FLAG77 # /MANIFEST78 # /MANIFESTFILE:"${CMAKE_CURRENT_SOURCE_DIR}/NSClient++.manifest"79 # )80 81 71 ENDIF(WIN32) 82 72 IF(BREAKPAD_FOUND) … … 101 91 ${NSCP_DEF_PLUGIN_LIB} 102 92 ${EXTRA_LIBS} 93 json_spirit_static 103 94 settings_manager 104 95 ) -
service/NSClient++.cpp
r9fdde88 r393a00f 870 870 871 871 std::wstring NSClientT::describeCommand(std::wstring command) { 872 return commands_.describe(command) ;872 return commands_.describe(command).description; 873 873 } 874 874 std::list<std::wstring> NSClientT::getAllCommandNames() { … … 1023 1023 } 1024 1024 1025 int NSClientT::simple_exec(std::wstring module, std::wstringcommand, std::vector<std::wstring> arguments, std::list<std::wstring> &resp) {1025 int NSClientT::simple_exec(std::wstring command, std::vector<std::wstring> arguments, std::list<std::wstring> &resp) { 1026 1026 std::string request; 1027 1027 std::list<std::string> responses; 1028 1028 std::list<std::wstring> errors; 1029 1029 nscapi::functions::create_simple_exec_request(command, arguments, request); 1030 std::wstring module; 1031 std::wstring::size_type pos = command.find(L'.'); 1032 if (pos != std::wstring::npos) { 1033 module = command.substr(0, pos); 1034 command = command.substr(pos+1); 1035 } 1030 1036 int ret = load_and_run(module, boost::bind(&exec_helper, _1, command, arguments, request, &responses), errors); 1031 1037 … … 1230 1236 BOOST_FOREACH(plugin_type plugin, plugins_) { 1231 1237 if (plugin->get_id() == plugin_id) 1232 return plugin->get Filename();1238 return plugin->getModule(); 1233 1239 } 1234 1240 return _T(""); … … 1433 1439 } 1434 1440 1441 typedef std::map<unsigned int, std::string> modules_type; 1442 1443 inline std::string add_plugin_data(modules_type module_cache, unsigned int plugin_id, NSClientT *instance) { 1444 modules_type::const_iterator it = module_cache.find(plugin_id); 1445 std::string module; 1446 if (it == module_cache.end()) { 1447 module = utf8::cvt<std::string>(instance->get_plugin_module_name(plugin_id)); 1448 module_cache[plugin_id] = module; 1449 return module; 1450 } else { 1451 return it->second; 1452 } 1453 } 1454 1455 void settings_add_plugin_data(const std::set<unsigned int> &plugins, modules_type module_cache, ::Plugin::Settings_Information* info, NSClientT *instance) { 1456 BOOST_FOREACH(unsigned int i, plugins) { 1457 info->add_plugin(add_plugin_data(module_cache, i, instance)); 1458 } 1459 } 1460 1461 NSCAPI::errorReturn NSClientT::settings_query(const char *request_buffer, const unsigned int request_buffer_len, char **response_buffer, unsigned int *response_buffer_len) { 1462 try { 1463 std::string response_string; 1464 Plugin::SettingsRequestMessage request; 1465 Plugin::SettingsResponseMessage response; 1466 nscapi::functions::create_simple_header(response.mutable_header()); 1467 modules_type module_cache; 1468 request.ParseFromArray(request_buffer, request_buffer_len); 1469 for (int i=0;i<request.payload_size();i++) { 1470 const Plugin::SettingsRequestMessage::Request &r = request.payload(i); 1471 if (r.type() == Plugin::SettingsRequestMessage_Request_ActionType_INVENTORY) { 1472 const Plugin::SettingsRequestMessage::Request::Inventory &q = r.inventory(); 1473 Plugin::SettingsResponseMessage::Response* rp = response.add_payload(); 1474 if (q.node().has_key()) { 1475 settings::settings_core::key_description desc = settings_manager::get_core()->get_registred_key(utf8::cvt<std::wstring>(q.node().path()), utf8::cvt<std::wstring>(q.node().key())); 1476 Plugin::SettingsResponseMessage::Response::Inventory *rpp = rp->add_inventory(); 1477 rpp->mutable_node()->CopyFrom(q.node()); 1478 rpp->mutable_info()->set_title(utf8::cvt<std::string>(desc.title)); 1479 rpp->mutable_info()->set_description(utf8::cvt<std::string>(desc.description)); 1480 } else { 1481 if (q.recursive_fetch()) { 1482 BOOST_FOREACH(const std::wstring &path, settings_manager::get_core()->get_reg_sections()) { 1483 if (q.fetch_paths()) { 1484 settings::settings_core::path_description desc = settings_manager::get_core()->get_registred_path(path); 1485 Plugin::SettingsResponseMessage::Response::Inventory *rpp = rp->add_inventory(); 1486 rpp->mutable_node()->set_path(utf8::cvt<std::string>(path)); 1487 rpp->mutable_info()->set_title(utf8::cvt<std::string>(desc.title)); 1488 rpp->mutable_info()->set_description(utf8::cvt<std::string>(desc.description)); 1489 rpp->mutable_info()->set_advanced(desc.advanced); 1490 settings_add_plugin_data(desc.plugins, module_cache, rpp->mutable_info(), this); 1491 } 1492 if (q.fetch_keys()) { 1493 BOOST_FOREACH(const std::wstring &key, settings_manager::get_core()->get_reg_keys(path)) { 1494 settings::settings_core::key_description desc = settings_manager::get_core()->get_registred_key(path, key); 1495 Plugin::SettingsResponseMessage::Response::Inventory *rpp = rp->add_inventory(); 1496 rpp->mutable_node()->set_path(utf8::cvt<std::string>(path)); 1497 rpp->mutable_node()->set_key(utf8::cvt<std::string>(key)); 1498 rpp->mutable_info()->set_title(utf8::cvt<std::string>(desc.title)); 1499 rpp->mutable_info()->set_description(utf8::cvt<std::string>(desc.description)); 1500 rpp->mutable_info()->set_advanced(desc.advanced); 1501 rpp->mutable_info()->set_default_value(utf8::cvt<std::string>(desc.defValue)); 1502 settings_add_plugin_data(desc.plugins, module_cache, rpp->mutable_info(), this); 1503 } 1504 } 1505 } 1506 } else { 1507 std::wstring path = utf8::cvt<std::wstring>(q.node().path()); 1508 if (q.fetch_paths()) { 1509 settings::settings_core::path_description desc = settings_manager::get_core()->get_registred_path(path); 1510 Plugin::SettingsResponseMessage::Response::Inventory *rpp = rp->add_inventory(); 1511 rpp->mutable_node()->set_path(utf8::cvt<std::string>(path)); 1512 rpp->mutable_info()->set_title(utf8::cvt<std::string>(desc.title)); 1513 rpp->mutable_info()->set_description(utf8::cvt<std::string>(desc.description)); 1514 rpp->mutable_info()->set_advanced(desc.advanced); 1515 settings_add_plugin_data(desc.plugins, module_cache, rpp->mutable_info(), this); 1516 } 1517 if (q.fetch_keys()) { 1518 BOOST_FOREACH(const std::wstring &key, settings_manager::get_core()->get_reg_keys(path)) { 1519 settings::settings_core::key_description desc = settings_manager::get_core()->get_registred_key(path, key); 1520 Plugin::SettingsResponseMessage::Response::Inventory *rpp = rp->add_inventory(); 1521 rpp->mutable_node()->set_path(q.node().path()); 1522 rpp->mutable_node()->set_key(utf8::cvt<std::string>(key)); 1523 rpp->mutable_info()->set_title(utf8::cvt<std::string>(desc.title)); 1524 rpp->mutable_info()->set_description(utf8::cvt<std::string>(desc.description)); 1525 rpp->mutable_info()->set_advanced(desc.advanced); 1526 rpp->mutable_info()->set_default_value(utf8::cvt<std::string>(desc.defValue)); 1527 settings_add_plugin_data(desc.plugins, module_cache, rpp->mutable_info(), this); 1528 } 1529 } 1530 } 1531 rp->mutable_result()->set_status(Plugin::Common_Status_StatusType_STATUS_OK); 1532 rp->set_type(Plugin::SettingsResponseMessage_Response_ActionType_INVENTORY); 1533 } 1534 } else if (r.type() == Plugin::SettingsRequestMessage_Request_ActionType_QUERY) { 1535 const Plugin::SettingsRequestMessage::Request::Query &q = r.query(); 1536 Plugin::SettingsResponseMessage::Response* rp = response.add_payload(); 1537 Plugin::SettingsResponseMessage::Response::Query *rpp = rp->add_query(); 1538 rpp->mutable_node()->CopyFrom(q.node()); 1539 if (q.node().has_key()) { 1540 if (q.type() == Plugin::Common_DataType_STRING) { 1541 rpp->mutable_value()->mutable_value()->set_string_data(utf8::cvt<std::string>(settings_manager::get_settings()->get_string(utf8::cvt<std::wstring>(q.node().path()), utf8::cvt<std::wstring>(q.node().key())))); 1542 } else { 1543 LOG_ERROR_CORE_STD(_T("Invalid type")); 1544 } 1545 } else { 1546 BOOST_FOREACH(const std::wstring &key, settings_manager::get_settings()->get_keys(utf8::cvt<std::wstring>(q.node().path()))) { 1547 rpp->mutable_value()->mutable_value()->add_list_data(utf8::cvt<std::string>(key)); 1548 } 1549 } 1550 } else { 1551 LOG_ERROR_CORE_STD(_T("Invalid action")); 1552 } 1553 } 1554 *response_buffer_len = response.ByteSize(); 1555 *response_buffer = new char[*response_buffer_len + 10]; 1556 response.SerializeToArray(*response_buffer, *response_buffer_len); 1557 } catch (settings::settings_exception e) { 1558 LOG_ERROR_CORE_STD(_T("Failed query key: ") + e.getMessage()); 1559 return NSCAPI::hasFailed; 1560 } catch (const std::exception &e) { 1561 LOG_ERROR_CORE_STD(_T("Failed query key: ") + utf8::to_unicode(e.what())); 1562 return NSCAPI::hasFailed; 1563 } catch (...) { 1564 LOG_ERROR_CORE_STD(_T("Failed query key")); 1565 return NSCAPI::hasFailed; 1566 } 1567 return NSCAPI::isSuccess; 1568 } 1569 1570 NSCAPI::errorReturn NSClientT::registry_query(const char *request_buffer, const unsigned int request_buffer_len, char **response_buffer, unsigned int *response_buffer_len) { 1571 try { 1572 std::string response_string; 1573 Plugin::RegistryRequestMessage request; 1574 Plugin::RegistryResponseMessage response; 1575 nscapi::functions::create_simple_header(response.mutable_header()); 1576 modules_type module_cache; 1577 request.ParseFromArray(request_buffer, request_buffer_len); 1578 for (int i=0;i<request.payload_size();i++) { 1579 const Plugin::RegistryRequestMessage::Request &r = request.payload(i); 1580 if (r.type() == Plugin::RegistryRequestMessage_Request_ActionType_INVENTORY) { 1581 const Plugin::RegistryRequestMessage::Request::Inventory &q = r.inventory(); 1582 Plugin::RegistryResponseMessage::Response* rp = response.add_payload(); 1583 for (int i=0;i<q.type_size();i++) { 1584 Plugin::Registry_ItemType type = q.type(i); 1585 if (type == Plugin::Registry_ItemType_QUERY || type == Plugin::Registry_ItemType_ALL) { 1586 BOOST_FOREACH(const std::wstring &command, commands_.list()) { 1587 nsclient::commands::command_info info = commands_.describe(command); 1588 Plugin::RegistryResponseMessage::Response::Inventory *rpp = rp->add_inventory(); 1589 rpp->set_name(utf8::cvt<std::string>(command)); 1590 rpp->set_type(Plugin::Registry_ItemType_COMMAND); 1591 rpp->mutable_info()->add_plugin(add_plugin_data(module_cache, info.plugin_id, this)); 1592 rpp->mutable_info()->set_title(utf8::cvt<std::string>(info.name)); 1593 rpp->mutable_info()->set_description(utf8::cvt<std::string>(info.description)); 1594 } 1595 } 1596 if (type == Plugin::Registry_ItemType_PLUGIN || type == Plugin::Registry_ItemType_ALL) { 1597 boost::shared_lock<boost::shared_mutex> readLock(m_mutexRW, boost::get_system_time() + boost::posix_time::milliseconds(5000)); 1598 if (readLock.owns_lock()) { 1599 BOOST_FOREACH(plugin_type plugin, plugins_) { 1600 Plugin::RegistryResponseMessage::Response::Inventory *rpp = rp->add_inventory(); 1601 rpp->set_name(utf8::cvt<std::string>(plugin->getModule())); 1602 rpp->set_type(Plugin::Registry_ItemType_COMMAND); 1603 rpp->mutable_info()->add_plugin(utf8::cvt<std::string>(plugin->getModule())); 1604 rpp->mutable_info()->set_title(utf8::cvt<std::string>(plugin->getName())); 1605 rpp->mutable_info()->set_description(utf8::cvt<std::string>(plugin->getDescription())); 1606 } 1607 } else { 1608 LOG_ERROR_CORE(_T("FATAL ERROR: Could not get read-mutex (010).")); 1609 } 1610 } 1611 } 1612 rp->mutable_result()->set_status(Plugin::Common_Status_StatusType_STATUS_OK); 1613 rp->set_type(Plugin::RegistryResponseMessage_Response_ActionType_INVENTORY); 1614 } else { 1615 LOG_ERROR_CORE_STD(_T("Invalid action")); 1616 } 1617 } 1618 *response_buffer_len = response.ByteSize(); 1619 *response_buffer = new char[*response_buffer_len + 10]; 1620 response.SerializeToArray(*response_buffer, *response_buffer_len); 1621 } catch (settings::settings_exception e) { 1622 LOG_ERROR_CORE_STD(_T("Failed query: ") + e.getMessage()); 1623 return NSCAPI::hasFailed; 1624 } catch (const std::exception &e) { 1625 LOG_ERROR_CORE_STD(_T("Failed query: ") + utf8::to_unicode(e.what())); 1626 return NSCAPI::hasFailed; 1627 } catch (...) { 1628 LOG_ERROR_CORE_STD(_T("Failed query")); 1629 return NSCAPI::hasFailed; 1630 } 1631 return NSCAPI::isSuccess; 1632 } 1633 1634 1435 1635 #ifdef _WIN32 1436 1636 void NSClientT::handle_session_change(unsigned long dwSessionId, bool logon) { -
service/NSClient++.h
r9fdde88 r393a00f 135 135 NSCAPI::nagiosReturn inject(std::wstring command, std::wstring arguments, std::wstring &msg, std::wstring & perf); 136 136 std::wstring execute(std::wstring password, std::wstring cmd, std::list<std::wstring> args); 137 int simple_exec(std::wstring module, std::wstringcommand, std::vector<std::wstring> arguments, std::list<std::wstring> &resp);137 int simple_exec(std::wstring command, std::vector<std::wstring> arguments, std::list<std::wstring> &resp); 138 138 int simple_query(std::wstring module, std::wstring command, std::vector<std::wstring> arguments, std::list<std::wstring> &resp); 139 139 NSCAPI::nagiosReturn exec_command(const wchar_t* target, const wchar_t* raw_command, std::string &request, std::string &response); 140 140 NSCAPI::errorReturn register_submission_listener(unsigned int plugin_id, const wchar_t* channel); 141 141 NSCAPI::errorReturn register_routing_listener(unsigned int plugin_id, const wchar_t* channel); 142 NSCAPI::errorReturn settings_query(const char *request_buffer, const unsigned int request_buffer_len, char **response_buffer, unsigned int *response_buffer_len); 143 NSCAPI::errorReturn registry_query(const char *request_buffer, const unsigned int request_buffer_len, char **response_buffer, unsigned int *response_buffer_len); 142 144 143 145 NSCAPI::errorReturn reload(const std::wstring module); -
service/cli_parser.hpp
r9fdde88 r393a00f 88 88 89 89 client.add_options() 90 ("load-all", "Load all plugins.") 90 91 ("exec,e", po::value<std::wstring>()->implicit_value(_T("")), "Run a command (execute)") 91 92 ("boot,b", "Boot the client before executing command (similar as running the command from test)") … … 354 355 modes mode; 355 356 bool boot; 356 client_arguments() : mode(none), boot(false) {} 357 bool load_all; 358 client_arguments() : mode(none), boot(false), load_all(false) {} 357 359 358 360 void debug() { … … 363 365 info(__LINE__, _T("Mode: ") + strEx::itos(mode)); 364 366 info(__LINE__, _T("Boot: ") + strEx::itos(boot)); 367 info(__LINE__, _T("Load All: ") + strEx::itos(load_all)); 365 368 if (!module.empty() && boot) 366 369 info(__LINE__, _T("Warning module and boot specified only THAT module will be loaded")); … … 408 411 args.mode = client_arguments::submit; 409 412 } 413 414 args.load_all = vm.count("load-all")==1; 410 415 411 416 if (vm.count("module")) … … 532 537 533 538 core_->boot_init(log_level); 539 if (args.load_all) 540 core_->preboot_load_all_plugin_files(); 534 541 if (args.module.empty()) 535 542 core_->boot_load_all_plugins(); … … 546 553 ret = mainClient.simple_query(args.module, args.command, args.arguments, resp); 547 554 } else if (args.mode == client_arguments::exec || args.mode == client_arguments::combined) { 548 ret = mainClient.simple_exec(args. module, args.command, args.arguments, resp);555 ret = mainClient.simple_exec(args.command, args.arguments, resp); 549 556 if (ret == NSCAPI::returnIgnored) { 550 557 ret = 1; 551 558 std::wcout << _T("Command not found (by module): ") << args.command << std::endl; 552 559 resp.push_back(_T("Command not found: ") + args.command); 553 mainClient.simple_exec( args.module,_T("help"), args.arguments, resp);560 mainClient.simple_exec(_T("help"), args.arguments, resp); 554 561 } else if (args.mode == client_arguments::combined) { 555 562 if (ret == NSCAPI::returnOK) { -
service/commands.hpp
r0382c02 r393a00f 24 24 25 25 }; 26 struct command_info { 27 std::wstring description; 28 unsigned int plugin_id; 29 std::wstring name; 30 }; 26 31 27 32 typedef boost::shared_ptr<NSCPlugin> plugin_type; 28 33 typedef std::map<unsigned long,plugin_type> plugin_list_type; 29 typedef std::map<std::wstring, std::wstring> description_list_type;34 typedef std::map<std::wstring,command_info> description_list_type; 30 35 typedef std::map<std::wstring,plugin_type> command_list_type; 31 36 … … 92 97 if (!have_plugin(plugin_id)) 93 98 throw command_exception("Failed to find plugin: " + ::to_string(plugin_id) + " {" + unsafe_get_all_plugin_ids() + "}"); 94 descriptions_[lc] = desc; 99 descriptions_[lc].description = desc; 100 descriptions_[lc].plugin_id = plugin_id; 101 descriptions_[lc].name = cmd; 95 102 commands_[lc] = plugins_[plugin_id]; 96 103 } … … 110 117 111 118 public: 112 std::wstringdescribe(std::wstring command) {119 command_info describe(std::wstring command) { 113 120 boost::shared_lock<boost::shared_mutex> readLock(mutex_, boost::get_system_time() + boost::posix_time::seconds(5)); 114 121 if (!readLock.owns_lock()) { 115 122 log_error(__FILE__, __LINE__, _T("Failed to get mutex: ") + command); 116 return _T("error: ") + command;123 return command_info(); 117 124 } 118 125 std::wstring lc = make_key(command); 119 126 description_list_type::const_iterator cit = descriptions_.find(lc); 120 if (cit == descriptions_.end()) 121 return _T("Command not found: ") + command; 127 if (cit == descriptions_.end()) { 128 command_info info; 129 info.description = _T("Command not found: ") + command; 130 return info; 131 } 122 132 return (*cit).second; 123 133 } … … 130 140 return lst; 131 141 } 132 std::pair<std::wstring,std::wstring> cit; 133 BOOST_FOREACH(cit, descriptions_) { 142 BOOST_FOREACH(description_list_type::value_type cit, descriptions_) { 134 143 lst.push_back(cit.first); 135 144 } -
service/core_api.cpp
r9fdde88 r393a00f 364 364 } 365 365 366 NSCAPI::errorReturn NSAPISettingsQuery(const char *request_buffer, const unsigned int request_buffer_len, char **response_buffer, unsigned int *response_buffer_len) { 367 return mainClient.settings_query(request_buffer, request_buffer_len, response_buffer, response_buffer_len); 368 } 369 NSCAPI::errorReturn NSAPIRegistryQuery(const char *request_buffer, const unsigned int request_buffer_len, char **response_buffer, unsigned int *response_buffer_len) { 370 return mainClient.registry_query(request_buffer, request_buffer_len, response_buffer, response_buffer_len); 371 } 372 366 373 367 374 NSCAPI::errorReturn NSAPISettingsRegPath(unsigned int plugin_id, const wchar_t* path, const wchar_t* title, const wchar_t* description, int advanced) { … … 435 442 return NSCAPI::isSuccess; 436 443 } 437 438 439 444 440 445 … … 516 521 if (wcscasecmp(buffer, _T("NSAPIGetLoglevel")) == 0) 517 522 return reinterpret_cast<LPVOID>(&NSAPIGetLoglevel); 523 if (wcscasecmp(buffer, _T("NSAPISettingsQuery")) == 0) 524 return reinterpret_cast<LPVOID>(&NSAPISettingsQuery); 525 if (wcscasecmp(buffer, _T("NSAPIRegistryQuery")) == 0) 526 return reinterpret_cast<LPVOID>(&NSAPIRegistryQuery); 518 527 519 528 LOG_ERROR_STD(_T("Function not found: ") + buffer); -
service/core_api.h
r9fdde88 r393a00f 69 69 NSCAPI::errorReturn NSAPIReload(const wchar_t*); 70 70 NSCAPI::log_level::level NSAPIGetLoglevel(); 71 NSCAPI::errorReturn NSAPISettingsQuery(const char *request_buffer, const unsigned int request_buffer_len, char **response_buffer, unsigned int *response_buffer_len); 72 NSCAPI::errorReturn NSAPIRegistryQuery(const char *request_buffer, const unsigned int request_buffer_len, char **response_buffer, unsigned int *response_buffer_len); -
service/settings_client.hpp
r9fdde88 r393a00f 2 2 #include <settings/settings_core.hpp> 3 3 #include <nsclient/logger.hpp> 4 #include <json_spirit.h> 4 5 5 6 class NSClientT; … … 93 94 } 94 95 96 bool match_filter(std::wstring name) { 97 return filter_.empty() || name.find(filter_) != std::wstring::npos; 98 } 99 95 100 96 101 int generate(std::wstring target) { … … 107 112 BOOST_FOREACH(unsigned int i, desc.plugins) { 108 113 std::wstring name = core_->get_plugin_module_name(i); 109 if ( name.find(filter_) != std::wstring::npos)114 if (match_filter(name)) 110 115 include = true; 111 116 if (!plugins.empty()) … … 147 152 } 148 153 } 154 } else if (target == _T("doc")) { 155 settings::string_list s = settings_manager::get_core()->get_reg_sections(); 156 BOOST_FOREACH(std::wstring path, s) { 157 158 settings::settings_core::path_description desc = settings_manager::get_core()->get_registred_path(path); 159 std::wstring plugins; 160 bool include = filter_.empty(); 161 BOOST_FOREACH(unsigned int i, desc.plugins) { 162 std::wstring name = core_->get_plugin_module_name(i); 163 if (match_filter(name)) 164 include = true; 165 if (!plugins.empty()) 166 plugins += _T(", "); 167 plugins += name; 168 } 169 170 if (!include) 171 continue; 172 173 std::wcout << path << std::endl; 174 strEx::replace(desc.description, _T("\n"), _T("\n\t")); 175 std::wcout << _T("\t") << desc.description << std::endl; 176 std::wcout << _T("\tUsed by: ") << plugins << std::endl; 177 std::wcout << std::endl; 178 settings::string_list k = settings_manager::get_core()->get_reg_keys(path); 179 bool first = true; 180 BOOST_FOREACH(std::wstring key, k) { 181 settings::settings_core::key_description desc = settings_manager::get_core()->get_registred_key(path, key); 182 if (!desc.advanced) { 183 if (first) 184 std::wcout << _T("\tKeys:") << std::endl; 185 first = false; 186 std::wcout << _T("\t") << key << _T(" (=") << desc.defValue << _T(")") << std::endl; 187 strEx::replace(desc.description, _T("\n"), _T("\n\t\t")); 188 std::wcout << _T("\t\t") << desc.title << std::endl; 189 std::wcout << _T("\t\t") << desc.description << std::endl; 190 } 191 } 192 first = true; 193 BOOST_FOREACH(std::wstring key, k) { 194 settings::settings_core::key_description desc = settings_manager::get_core()->get_registred_key(path, key); 195 if (desc.advanced) { 196 if (first) 197 std::wcout << _T("\tAdvanced keys:") << std::endl; 198 first = false; 199 std::wcout << _T("\t") << key << _T(" (=") << desc.defValue << _T(")") << std::endl; 200 strEx::replace(desc.description, _T("\n"), _T("\n\t\t")); 201 std::wcout << _T("\t\t") << desc.title << std::endl; 202 std::wcout << _T("\t\t") << desc.description << std::endl; 203 } 204 } 205 } 206 } else if (target == _T("json") || target == _T("json-compact")) { 207 json_spirit::wObject json_root; 208 settings::string_list s = settings_manager::get_core()->get_reg_sections(); 209 BOOST_FOREACH(std::wstring path, s) { 210 211 settings::settings_core::path_description desc = settings_manager::get_core()->get_registred_path(path); 212 bool include = filter_.empty(); 213 json_spirit::wObject json_plugins; 214 BOOST_FOREACH(unsigned int i, desc.plugins) { 215 std::wstring name = core_->get_plugin_module_name(i); 216 if (match_filter(name)) 217 include = true; 218 json_plugins.push_back(json_spirit::wPair(strEx::itos(i), name)); 219 } 220 if (!include) 221 continue; 222 223 json_spirit::wObject json_path; 224 json_path.push_back(json_spirit::wPair(_T("path"), path)); 225 json_path.push_back(json_spirit::wPair(_T("title"), desc.title)); 226 json_path.push_back(json_spirit::wPair(_T("description"), desc.description)); 227 json_path.push_back(json_spirit::wPair(_T("plugins"), json_plugins)); 228 229 json_spirit::wObject json_keys; 230 BOOST_FOREACH(std::wstring key, settings_manager::get_core()->get_reg_keys(path)) { 231 settings::settings_core::key_description desc = settings_manager::get_core()->get_registred_key(path, key); 232 json_spirit::wObject json_key; 233 json_key.push_back(json_spirit::wPair(_T("key"), key)); 234 json_key.push_back(json_spirit::wPair(_T("title"), desc.title)); 235 json_key.push_back(json_spirit::wPair(_T("description"), desc.description)); 236 json_key.push_back(json_spirit::wPair(_T("default value"), desc.defValue)); 237 json_keys.push_back(json_spirit::wPair(key, json_key)); 238 } 239 json_path.push_back(json_spirit::wPair(_T("keys"), json_keys)); 240 json_root.push_back(json_spirit::wPair(path, json_path)); 241 } 242 if (target == _T("json-compact")) 243 write(json_root, std::wcout); 244 else 245 write(json_root, std::wcout, json_spirit::pretty_print); 149 246 } else { 150 247 //settings_manager::get_core()->update_defaults();
Note: See TracChangeset
for help on using the changeset viewer.








