Getting configuration values

When loading configuration values for Monitors, Alerters and Loggers, you can use the get_config_option() function to perform sanity checks on the loaded config.

get_config_option(config_options: dict, key: str[, default=None[, required=False[, required_type="str"[, allowed_values=None[, allow_empty=True[, mininum=None[, maximum=None]]]]]]])

Get a config value out of a dict, and perform basic validation on it.

  • config_options (dict) – The dict to get the value from

  • key (str) – The key to the value in the dict

  • default – The default value to return if the key is not found

  • required (bool) – Throw an exception if the value is not present (and default is None)

  • required_type (str) – One of str, int, float, bool, [int] (list of int), [str] (list of str)

  • allowed_values – A list of allowed values

  • allow_empty (bool) – Allow the empty string when required_type is “str”

  • minimum (integer, float or None) – The minimum allowed value for int and float

  • maximum (integer, float or None) – The maximum allowed value for int and float


the fetched configuration value (or the default)

Note that the return type of the function signature covers all supported types, so you should use typing.cast() to help mypy understand. Do not use assert.