Changeset 393a00f in nscp


Ignore:
Timestamp:
07/08/12 10:45:05 (11 months ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.2
Children:
77c0100
Parents:
9fdde88
Message:
  • Improved settings API with new protocolbuffers command (available from python)
  • Improved registration API with new protocolbuffers command (available from python)
  • Created new python documentation module docs.py
  • Improved command line syntax so executable commands now take an optional module prefix
Files:
3 added
23 edited

Legend:

Unmodified
Added
Removed
  • CMakeLists.txt

    rc6a974c r393a00f  
    107107ENDIF (TINYXML2_FOUND) 
    108108 
     109FIND_PACKAGE(JSON_SPIRIT) 
     110IF (JSON_SPIRIT_FOUND) 
     111  MESSAGE(STATUS "Found json spirit in: ${JSON_SPIRIT_INCLUDE_DIR}") 
     112ENDIF (JSON_SPIRIT_FOUND) 
    109113 
    110114FIND_PACKAGE(ZeroMQ) 
  • build.cmake

    rc6a974c r393a00f  
    88  SET(INC_PSDK_2003 "C:/Program Files/Microsoft Platform SDK/") 
    99  SET(TINYXML2_DIR "D:/source/libraries/tinyxml2") 
     10  SET(JSON_SPRIT_DIR "D:/source/libraries/json_spirit_v4.05") 
    1011 
    1112  if(CMAKE_CL_64) 
  • changelog

    r9fdde88 r393a00f  
    44 * Fix dependonservice LanManWorkStation (old win) 
    55 * Fix RtlStringFromGUID problem on NT4 
     6 
     72012-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 
    612 
    7132012-06-21 MickeM 
  • include/NSCAPI.h

    r9fdde88 r393a00f  
    173173    typedef NSCAPI::errorReturn (*lpNSAPISettingsRegKey)(unsigned int, const wchar_t*, const wchar_t*, int, const wchar_t*, const wchar_t*, const wchar_t*, int); 
    174174    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 *); 
    175176    typedef NSCAPI::errorReturn (*lpNSAPIGetPluginList)(int *len, NSCAPI::plugin_info *list[]); 
    176177    typedef NSCAPI::errorReturn (*lpNSAPIReleasePluginList)(int len, NSCAPI::plugin_info *list[]); 
     
    180181    typedef NSCAPI::errorReturn (*lpNSAPIReload)(const wchar_t* module); 
    181182    typedef NSCAPI::log_level::level (*lpNSAPIGetLoglevel)(); 
     183    typedef NSCAPI::errorReturn (*lpNSAPIRegistryQuery)(const char *, const unsigned int, char **, unsigned int *); 
    182184 
    183185  } 
  • include/nscapi/nscapi_core_wrapper.cpp

    r9fdde88 r393a00f  
    328328  fNSAPISettingsRegPath(plugin_id, path.c_str(), title.c_str(), description.c_str(), advanced); 
    329329} 
    330  
     330NSCAPI::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} 
     335NSCAPI::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} 
    331345 
    332346void nscapi::core_wrapper::settings_save() { 
     
    334348    throw nscapi::nscapi_exception("NSCore has not been initiated..."); 
    335349  fNSAPISettingsSave(); 
     350} 
     351 
     352 
     353NSCAPI::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} 
     358NSCAPI::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; 
    336367} 
    337368 
     
    579610 
    580611  fNSAPISettingsSave = (nscapi::core_api::lpNSAPISettingsSave)f(_T("NSAPISettingsSave")); 
     612  fNSAPISettingsQuery = (nscapi::core_api::lpNSAPISettingsQuery)f(_T("NSAPISettingsQuery")); 
    581613 
    582614  fNSAPIExpandPath = (nscapi::core_api::lpNSAPIExpandPath)f(_T("NSAPIExpandPath")); 
     
    585617  fNSAPIRegisterRoutingListener = (nscapi::core_api::lpNSAPIRegisterRoutingListener)f(_T("NSAPIRegisterRoutingListener")); 
    586618  fNSAPIGetLoglevel = (nscapi::core_api::lpNSAPIGetLoglevel)f(_T("NSAPIGetLoglevel")); 
     619  fNSAPIRegistryQuery = (nscapi::core_api::lpNSAPIRegistryQuery)f(_T("NSAPIRegistryQuery")); 
    587620 
    588621  return true; 
  • include/nscapi/nscapi_core_wrapper.hpp

    r9fdde88 r393a00f  
    6262    nscapi::core_api::lpNSAPISettingsRegKey fNSAPISettingsRegKey; 
    6363    nscapi::core_api::lpNSAPISettingsRegPath fNSAPISettingsRegPath; 
     64    nscapi::core_api::lpNSAPISettingsQuery fNSAPISettingsQuery; 
    6465    nscapi::core_api::lpNSAPIGetPluginList fNSAPIGetPluginList; 
    6566    nscapi::core_api::lpNSAPIReleasePluginList fNSAPIReleasePluginList; 
     
    6970    nscapi::core_api::lpNSAPIRegisterSubmissionListener fNSAPIRegisterSubmissionListener; 
    7071    nscapi::core_api::lpNSAPIRegisterRoutingListener fNSAPIRegisterRoutingListener; 
     72    nscapi::core_api::lpNSAPIRegistryQuery fNSAPIRegistryQuery; 
    7173 
    7274  public: 
     
    113115      , fNSAPISettingsRegKey(NULL) 
    114116      , fNSAPISettingsRegPath(NULL) 
     117      , fNSAPISettingsQuery(NULL) 
    115118      , fNSAPIGetPluginList(NULL) 
    116119      , fNSAPIReleasePluginList(NULL) 
     
    120123      , fNSAPIRegisterSubmissionListener(NULL) 
    121124      , fNSAPIRegisterRoutingListener(NULL) 
     125      , fNSAPIRegistryQuery(NULL) 
    122126    {} 
    123127 
     
    133137    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); 
    134138    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); 
    135141    void settings_save(); 
    136142 
     
    168174    void registerRoutingListener(unsigned int id, std::wstring channel); 
    169175 
     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 
    170179    bool load_endpoints(nscapi::core_api::lpNSAPILoader f); 
    171180    void set_alias(const std::wstring default_alias, const std::wstring alias); 
  • include/nscapi/nscapi_protobuf_functions.hpp

    r308ae18 r393a00f  
    5959      static Plugin::Common::Status::StatusType status_to_gpb(int ret) { 
    6060        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; 
    6363      } 
    6464      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) 
    6666          return NSCAPI::isSuccess; 
    6767        return NSCAPI::hasFailed; 
    6868      } 
    6969      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) 
    7171          return Plugin::Common_ResultCode_OK; 
    7272        return Plugin::Common_ResultCode_UNKNOWN; 
     
    7474      static Plugin::Common::Status::StatusType gbp_to_nagios_gbp_status(Plugin::Common::ResultCode ret) { 
    7575        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; 
    7878      } 
    7979       
  • include/settings/settings_core.hpp

    r9fdde88 r393a00f  
    3636 
    3737 
    38   class settings_exception : std::exception { 
     38  class settings_exception : public std::exception { 
    3939    std::string error_; 
    4040  public: 
     
    162162    virtual key_description get_registred_key(std::wstring path, std::wstring key) = 0; 
    163163 
    164     virtual settings_core::path_description get_registred_path(std::wstring path) = 0; 
     164    virtual settings_core::path_description get_registred_path(const std::wstring &path) = 0; 
    165165 
    166166    ////////////////////////////////////////////////////////////////////////// 
  • include/settings/settings_handler_impl.hpp

    r9fdde88 r393a00f  
    244244      throw KeyNotFoundException(path, key); 
    245245    } 
    246     settings_core::path_description get_registred_path(std::wstring path) { 
     246    settings_core::path_description get_registred_path(const std::wstring &path) { 
    247247      reg_paths_type::const_iterator cit = registred_paths_.find(path); 
    248248      if (cit != registred_paths_.end()) { 
  • libs/protobuf/plugin.proto

    r8d89d7a r393a00f  
    1313  enum DataType { 
    1414    INT = 1; 
    15     STRING = 1; 
    16     FLOAT = 1; 
    17     BOOL = 1; 
     15    STRING = 2; 
     16    FLOAT = 3; 
     17    BOOL = 4; 
     18    LIST = 5; 
    1819  }; 
    1920   
     
    2425    optional double float_data = 4; 
    2526    optional bool bool_data = 5; 
     27    repeated string list_data = 6; 
    2628  } 
    2729 
     
    115117   
    116118    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; 
    122123    }; 
    123124   
     
    250251} 
    251252 
     253 
     254// // // // // // // // // // // // // // // // // // // // // // // //  
     255// 
     256// plugins and registration 
     257// 
     258// // // // // // // // // // // // // // // // // // // // // // // //  
     259message 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 
     282message 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}; 
     313message 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 
    252335// // // // // // // // // // // // // // // // // // // // // // // //  
    253336// 
     
    258341message Settings { 
    259342  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 
     365message SettingsRequestMessage { 
    270366  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    }; 
    271395    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; 
    279403  }; 
    280404  required Common.Header header = 1; 
    281405  repeated Request payload = 2; 
    282 } 
    283 message QuerySettingsResponseMessage { 
     406}; 
     407message SettingsResponseMessage { 
    284408  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    }; 
    288421    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 
    300429  required Common.Header header = 1; 
    301430  repeated Response payload = 2; 
    302 } 
     431}; 
    303432 
    304433 
  • modules/DotnetPlugins/DotnetPlugins.cpp

    r9fdde88 r393a00f  
    4343  try { 
    4444    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); 
    4646 
    4747    std::list<std::wstring> keys = get_core()->getSettingsSection(settings_path); 
    4848    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); 
    5050    } 
    5151    if (mode == NSCAPI::normalStart) { 
  • modules/PythonScript/PythonScript.cpp

    r0382c02 r393a00f  
    6464    .def("register_path", &script_wrapper::settings_wrapper::settings_register_path) 
    6565    .def("register_key", &script_wrapper::settings_wrapper::settings_register_key) 
     66    .def("query", &script_wrapper::settings_wrapper::query) 
    6667    ; 
    6768  class_<script_wrapper::function_wrapper, boost::shared_ptr<script_wrapper::function_wrapper> >("Registry", no_init) 
     
    7677    .def("subscription", &script_wrapper::function_wrapper::subscribe_function) 
    7778    .def("simple_subscription", &script_wrapper::function_wrapper::subscribe_simple_function) 
     79    .def("query", &script_wrapper::function_wrapper::query) 
    7880    ; 
    7981  class_<script_wrapper::command_wrapper, boost::shared_ptr<script_wrapper::command_wrapper> >("Core", init<>()) 
     
    142144  } 
    143145} 
     146bool 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} 
    144165bool python_script::callFunction(const std::string& functionName, unsigned int i1, const std::string &s1, const std::string &s2){ 
    145166  try { 
     
    286307 
    287308    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(); 
    289310    po::store(parsed, vm); 
    290311    po::notify(vm); 
     
    296317      return NSCAPI::returnUNKNOWN; 
    297318    } 
     319    std::vector<std::wstring> py_args = po::collect_unrecognized(parsed.options, po::include_positional); 
    298320 
    299321    boost::optional<boost::filesystem::wpath> ofile = find_file(file); 
     
    302324    script_container sc(*ofile); 
    303325    python_script script(get_id(), "", sc); 
    304     if (!script.callFunction("__main__")) { 
     326    if (!script.callFunction("__main__", py_args)) { 
    305327      message = _T("Failed to execute script: __main__"); 
    306328      return NSCAPI::returnUNKNOWN; 
  • modules/PythonScript/PythonScript.h

    ra48fd4c r393a00f  
    4141  bool callFunction(const std::string& functionName); 
    4242  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); 
    4344  void _exec(const std::string &scriptfile); 
    4445}; 
  • modules/PythonScript/script_wrapper.cpp

    r9fdde88 r393a00f  
    101101py::list script_wrapper::convert(std::list<std::wstring> lst) { 
    102102  py::list ret; 
    103   BOOST_FOREACH(std::wstring s, lst) { 
     103  BOOST_FOREACH(const std::wstring &s, lst) { 
    104104    ret.append(utf8::cvt<std::string>(s)); 
     105  } 
     106  return ret; 
     107} 
     108py::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); 
    105112  } 
    106113  return ret; 
     
    220227  } 
    221228} 
     229 
     230tuple 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 
    222244int script_wrapper::function_wrapper::handle_query(const std::string cmd, const std::string &request, std::string &response) const { 
    223245  try { 
     
    622644  core->settings_register_path(plugin_id, utf8::cvt<std::wstring>(path), utf8::cvt<std::wstring>(title), utf8::cvt<std::wstring>(description), false); 
    623645} 
     646tuple 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  
    6767  std::list<std::wstring> convert(boost::python::list lst); 
    6868  boost::python::list convert(std::list<std::wstring> lst); 
     69  boost::python::list convert(const std::vector<std::wstring> &lst); 
    6970 
    7071 
     
    134135 
    135136    std::wstring get_commands(); 
     137    tuple query(std::string request); 
    136138  }; 
    137139  struct command_wrapper { 
     
    192194    void settings_register_key(std::string path, std::string key, std::string stype, std::string title, std::string description, std::string defaultValue); 
    193195    void settings_register_path(std::string path, std::string title, std::string description); 
     196    tuple query(std::string request); 
    194197  }; 
    195198 
  • service/CMakeLists.txt

    r8d89d7a r393a00f  
    55PROJECT(service) 
    66INCLUDE_DIRECTORIES(${BOOST_INCLUDE_DIRS}) 
     7INCLUDE_DIRECTORIES(${JSON_SPIRIT_INCLUDE_DIR}) 
    78LINK_DIRECTORIES(${BOOST_LIB_DIRS}) 
    89 
     
    6869 
    6970   
    70 # SET( 
    71 #   CMAKE_LINKER_FLAGS  
    72 #   /MANIFEST  
    73 #   /MANIFESTFILE:"${CMAKE_CURRENT_SOURCE_DIR}/NSClient++.manifest" 
    74 # ) 
    75 # SET( 
    76 #   CMAKE_MODULE_LINKER_FLAG  
    77 #   /MANIFEST  
    78 #   /MANIFESTFILE:"${CMAKE_CURRENT_SOURCE_DIR}/NSClient++.manifest" 
    79 # ) 
    80  
    8171ENDIF(WIN32) 
    8272IF(BREAKPAD_FOUND) 
     
    10191  ${NSCP_DEF_PLUGIN_LIB} 
    10292  ${EXTRA_LIBS} 
     93  json_spirit_static 
    10394  settings_manager 
    10495) 
  • service/NSClient++.cpp

    r9fdde88 r393a00f  
    870870 
    871871std::wstring NSClientT::describeCommand(std::wstring command) { 
    872   return commands_.describe(command); 
     872  return commands_.describe(command).description; 
    873873} 
    874874std::list<std::wstring> NSClientT::getAllCommandNames() { 
     
    10231023} 
    10241024 
    1025 int NSClientT::simple_exec(std::wstring module, std::wstring command, std::vector<std::wstring> arguments, std::list<std::wstring> &resp) { 
     1025int NSClientT::simple_exec(std::wstring command, std::vector<std::wstring> arguments, std::list<std::wstring> &resp) { 
    10261026  std::string request; 
    10271027  std::list<std::string> responses; 
    10281028  std::list<std::wstring> errors; 
    10291029  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  } 
    10301036  int ret = load_and_run(module, boost::bind(&exec_helper, _1, command, arguments, request, &responses), errors); 
    10311037 
     
    12301236  BOOST_FOREACH(plugin_type plugin, plugins_) { 
    12311237    if (plugin->get_id() == plugin_id) 
    1232       return plugin->getFilename(); 
     1238      return plugin->getModule(); 
    12331239  } 
    12341240  return _T(""); 
     
    14331439} 
    14341440 
     1441typedef std::map<unsigned int, std::string> modules_type; 
     1442 
     1443inline 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 
     1455void 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 
     1461NSCAPI::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 
     1570NSCAPI::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 
    14351635#ifdef _WIN32 
    14361636void NSClientT::handle_session_change(unsigned long dwSessionId, bool logon) { 
  • service/NSClient++.h

    r9fdde88 r393a00f  
    135135  NSCAPI::nagiosReturn inject(std::wstring command, std::wstring arguments, std::wstring &msg, std::wstring & perf); 
    136136  std::wstring execute(std::wstring password, std::wstring cmd, std::list<std::wstring> args); 
    137   int simple_exec(std::wstring module, std::wstring command, 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); 
    138138  int simple_query(std::wstring module, std::wstring command, std::vector<std::wstring> arguments, std::list<std::wstring> &resp); 
    139139  NSCAPI::nagiosReturn exec_command(const wchar_t* target, const wchar_t* raw_command, std::string &request, std::string &response); 
    140140  NSCAPI::errorReturn register_submission_listener(unsigned int plugin_id, const wchar_t* channel); 
    141141  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); 
    142144 
    143145  NSCAPI::errorReturn reload(const std::wstring module); 
  • service/cli_parser.hpp

    r9fdde88 r393a00f  
    8888 
    8989    client.add_options() 
     90      ("load-all", "Load all plugins.") 
    9091      ("exec,e", po::value<std::wstring>()->implicit_value(_T("")), "Run a command (execute)") 
    9192      ("boot,b", "Boot the client before executing command (similar as running the command from test)") 
     
    354355    modes mode; 
    355356    bool boot; 
    356     client_arguments() : mode(none), boot(false) {} 
     357    bool load_all; 
     358    client_arguments() : mode(none), boot(false), load_all(false) {} 
    357359 
    358360    void debug() { 
     
    363365        info(__LINE__, _T("Mode: ") + strEx::itos(mode)); 
    364366        info(__LINE__, _T("Boot: ") + strEx::itos(boot)); 
     367        info(__LINE__, _T("Load All: ") + strEx::itos(load_all)); 
    365368        if (!module.empty() && boot) 
    366369          info(__LINE__, _T("Warning module and boot specified only THAT module will be loaded")); 
     
    408411        args.mode = client_arguments::submit; 
    409412      } 
     413 
     414      args.load_all = vm.count("load-all")==1; 
    410415 
    411416      if (vm.count("module")) 
     
    532537 
    533538      core_->boot_init(log_level); 
     539      if (args.load_all) 
     540        core_->preboot_load_all_plugin_files(); 
    534541      if (args.module.empty()) 
    535542        core_->boot_load_all_plugins(); 
     
    546553        ret = mainClient.simple_query(args.module, args.command, args.arguments, resp); 
    547554      } 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); 
    549556        if (ret == NSCAPI::returnIgnored) { 
    550557          ret = 1; 
    551558          std::wcout << _T("Command not found (by module): ") << args.command << std::endl; 
    552559          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); 
    554561        } else if (args.mode == client_arguments::combined) { 
    555562          if (ret == NSCAPI::returnOK) { 
  • service/commands.hpp

    r0382c02 r393a00f  
    2424 
    2525    }; 
     26    struct command_info { 
     27      std::wstring description; 
     28      unsigned int plugin_id; 
     29      std::wstring name; 
     30    }; 
    2631 
    2732    typedef boost::shared_ptr<NSCPlugin> plugin_type; 
    2833    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; 
    3035    typedef std::map<std::wstring,plugin_type> command_list_type; 
    3136 
     
    9297      if (!have_plugin(plugin_id)) 
    9398        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; 
    95102      commands_[lc] = plugins_[plugin_id]; 
    96103    } 
     
    110117 
    111118public: 
    112     std::wstring describe(std::wstring command) { 
     119    command_info describe(std::wstring command) { 
    113120      boost::shared_lock<boost::shared_mutex> readLock(mutex_, boost::get_system_time() + boost::posix_time::seconds(5)); 
    114121      if (!readLock.owns_lock()) { 
    115122        log_error(__FILE__, __LINE__, _T("Failed to get mutex: ") + command); 
    116         return _T("error: ") + command; 
     123        return command_info(); 
    117124      } 
    118125      std::wstring lc = make_key(command); 
    119126      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      } 
    122132      return (*cit).second; 
    123133    } 
     
    130140        return lst; 
    131141      } 
    132       std::pair<std::wstring,std::wstring> cit; 
    133       BOOST_FOREACH(cit, descriptions_) { 
     142      BOOST_FOREACH(description_list_type::value_type cit, descriptions_) { 
    134143        lst.push_back(cit.first); 
    135144      } 
  • service/core_api.cpp

    r9fdde88 r393a00f  
    364364} 
    365365 
     366NSCAPI::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} 
     369NSCAPI::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 
    366373 
    367374NSCAPI::errorReturn NSAPISettingsRegPath(unsigned int plugin_id, const wchar_t* path, const wchar_t* title, const wchar_t* description, int advanced) { 
     
    435442  return NSCAPI::isSuccess; 
    436443} 
    437  
    438  
    439444 
    440445 
     
    516521  if (wcscasecmp(buffer, _T("NSAPIGetLoglevel")) == 0) 
    517522    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); 
    518527 
    519528  LOG_ERROR_STD(_T("Function not found: ") + buffer); 
  • service/core_api.h

    r9fdde88 r393a00f  
    6969NSCAPI::errorReturn NSAPIReload(const wchar_t*); 
    7070NSCAPI::log_level::level NSAPIGetLoglevel(); 
     71NSCAPI::errorReturn NSAPISettingsQuery(const char *request_buffer, const unsigned int request_buffer_len, char **response_buffer, unsigned int *response_buffer_len); 
     72NSCAPI::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  
    22#include <settings/settings_core.hpp> 
    33#include <nsclient/logger.hpp> 
     4#include <json_spirit.h> 
    45 
    56class NSClientT; 
     
    9394    } 
    9495 
     96    bool match_filter(std::wstring name) { 
     97      return filter_.empty() || name.find(filter_) != std::wstring::npos;  
     98    } 
     99 
    95100 
    96101    int generate(std::wstring target) { 
     
    107112            BOOST_FOREACH(unsigned int i, desc.plugins) { 
    108113              std::wstring name = core_->get_plugin_module_name(i); 
    109               if (name.find(filter_) != std::wstring::npos) 
     114              if (match_filter(name)) 
    110115                include = true; 
    111116              if (!plugins.empty()) 
     
    147152            } 
    148153          } 
     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); 
    149246        } else { 
    150247          //settings_manager::get_core()->update_defaults(); 
Note: See TracChangeset for help on using the changeset viewer.