def resolve_paramstring(check_plugin_name, parameters_unresolved): # type: (str, str) -> CheckParameters """Translates a parameter string (read from autochecks) to it's final value (according to the current configuration)""" check_context = config.get_check_context(check_plugin_name) # TODO: Can't we simply access check_context[paramstring]? return eval(parameters_unresolved, check_context, check_context)
def resolve_paramstring(check_plugin_name, parameters_unresolved): # type: (CheckPluginName, CheckParameters) -> CheckParameters """Translates a parameter string (read from autochecks) to it's final value (according to the current configuration). Values of other types are kept""" if not isinstance(parameters_unresolved, str): return parameters_unresolved check_context = config.get_check_context(check_plugin_name) # TODO: Can't we simply access check_context[paramstring]? return eval(parameters_unresolved, check_context, check_context)
def _resolve_string_parameters(params_unresolved: Any, check_name: str) -> Any: if not isinstance(params_unresolved, str): return params_unresolved try: context = config.get_check_context(check_name) # string may look like '{"foo": bar}', in the worst case. return eval(params_unresolved, context, context) except Exception: raise ValueError("Invalid check parameter string '%s' found in discovered service %r" % (params_unresolved, check_name))
def _create_wrapped_parameters(check_plugin_name: str, check_info_dict: Dict[str, Any]) -> Optional[Dict[str, Any]]: """compute default parameters and wrap them in a dictionary""" default_parameters = get_default_parameters( check_info_dict, config.factory_settings, config.get_check_context(check_plugin_name), ) if default_parameters is None: return {} if check_info_dict.get("group") else None if isinstance(default_parameters, dict): return default_parameters return wrap_parameters(default_parameters)
def _create_wrapped_parameters(check_plugin_name, check_info_dict): # type: (str, Dict[str, Any]) -> Optional[Dict[str, Any]] """compute default parameters and wrap them in a dictionary""" var_name = check_info_dict.get("default_levels_variable") if var_name is None: return {} if check_info_dict.get("group") else None # look in factory settings parameters = config.factory_settings.get(var_name) if isinstance(parameters, dict): return parameters if parameters is not None: return wrap_parameters(parameters) # look in check context parameters = config.get_check_context(check_plugin_name).get(var_name) if isinstance(parameters, dict): return parameters if parameters is not None: return wrap_parameters(parameters) raise ValueError("[%s]: default levels variable %r is undefined" % (check_plugin_name, var_name))