File: get-config-values.rst

package info (click to toggle)
simplemonitor 1.15.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,520 kB
  • sloc: python: 8,725; sh: 258; makefile: 74; javascript: 69
file content (25 lines) | stat: -rw-r--r-- 1,511 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
.. _get-config-option-helper:

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.

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

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

    :param dict config_options: The dict to get the value from
    :param str key: The key to the value in the dict
    :param default: The default value to return if the key is not found
    :param bool required: Throw an exception if the value is not present (and default is None)
    :param str required_type: One of str, int, float, bool, [int] (list of int), [str] (list of str)
    :param allowed_values: A list of allowed values
    :param bool allow_empty: Allow the empty string when required_type is "str"
    :param minimum: The minimum allowed value for int and float
    :param maximum: The maximum allowed value for int and float
    :type minimum: integer, float or None
    :type maximum: integer, float or None
    :return: the fetched configuration value (or the default)

    Note that the return type of the function signature covers all supported types, so you should use :py:func:`typing.cast` to help mypy understand. Do not use :ref:`assert<python:assert>`.