示例#1
0
class HostContactGroup(BaseSchema):
    cast_to_dict = True

    groups = List(
        GroupField(
            group_type="contact",
            example="all",
            required=True,
        ),
        required=True,
        description="A list of contact groups.",
    )
    use = _fields.Boolean(
        description="Add these contact groups to the host.",
        missing=False,
    )
    use_for_services = _fields.Boolean(
        description=
        ("<p>Always add host contact groups also to its services.</p>"
         "With this option contact groups that are added to hosts are always being added to "
         "services, as well. This only makes a difference if you have assigned other contact "
         "groups to services via rules in <i>Host & Service Parameters</i>. As long as you do "
         "not have any such rule a service always inherits all contact groups from its host."
         ),
        missing=False,
    )
    recurse_use = _fields.Boolean(
        description=
        "Add these groups as contacts to all hosts in all sub-folders of this folder.",
        missing=False,
    )
    recurse_perms = _fields.Boolean(
        description="Give these groups also permission on all sub-folders.",
        missing=False,
    )
示例#2
0
class IPAddresses(BaseSchema, CheckmkTuple):
    """Represents a list of IPv4 addresses

    >>> schema = IPAddresses()
    >>> rv = schema.dump(('ip_list', ['127.0.0.1', '127.0.0.2']))
    >>> rv
    {'type': 'ip_list', 'addresses': ['127.0.0.1', '127.0.0.2']}

    >>> schema.load(rv)
    ('ip_list', ['127.0.0.1', '127.0.0.2'])

    """
    tuple_fields = ('type', 'addresses')
    cast_to_dict = True

    type = _fields.Constant(
        description="A list of single IPv4 addresses.",
        constant='ip_list',
    )
    addresses = List(String(validate=ValidateIPv4(),))
示例#3
0
class IPRegexp(BaseSchema, CheckmkTuple):
    """

    >>> schema = IPRegexp()
    >>> rv = schema.dump(('ip_regex_list', ['127.0.[0-9].1', '127.0.[0-9].2']))
    >>> schema.load(rv)
    ('ip_regex_list', ['127.0.[0-9].1', '127.0.[0-9].2'])

    """
    tuple_fields = ('type', 'regexp_list')
    cast_to_dict = True

    type = _fields.Constant(
        description="IPv4 addresses which match a regexp pattern",
        constant='ip_regex_list',
    )
    regexp_list = List(
        String(validate=IsValidRegexp()),
        description=("A list of regular expressions which are matched against the found "
                     "IP addresses. The matches will be excluded from the result."),
    )
示例#4
0
class NetworkScan(BaseSchema):
    """

    >>> schema = NetworkScan()
    >>> settings = {
    ...     'exclude_ranges': [('ip_list', ['192.168.0.2']),
    ...                        ('ip_regex_list', ['192.168.[02].*'])],
    ...     'ip_ranges': [('ip_range', ('192.168.0.10', '192.168.0.244')),
    ...                   ('ip_regex_list', ['192.168.[01].*']),
    ...                   ('ip_list', ['192.168.0.2'])],
    ...     'max_parallel_pings': 100,
    ... #   This is disabled, due to "running outside app context", duh.
    ... #   'run_as': 'cmkadmin',
    ...     'scan_interval': 86400,
    ...     'set_ipaddress': True,
    ...     'time_allowed': [((12, 0), (23, 59))],
    ...     'translate_names': {
    ...         'case': 'lower',
    ...         'drop_domain': True,
    ...         'mapping': [('example.com', 'www.example.com')],
    ...         'regex': [('.*', 'mehrfacheregulaere')]}}
    >>> result = schema.dump(settings)
    >>> assert len(result['addresses']) == 3
    >>> assert len(result['exclude_addresses']) == 2
    >>> assert len(result['time_allowed'][0]) == 2
    >>> assert len(result['translate_names']) == 4

    >>> import unittest
    >>> test_case = unittest.TestCase()
    >>> test_case.maxDiff = None
    >>> test_case.assertDictEqual(settings, schema.load(result))

    """

    ip_ranges = List(
        Nested(IPRangeWithRegexp()),
        data_key="addresses",
        required=True,
        description="IPv4 addresses to include.",
    )
    exclude_ranges = List(
        Nested(IPRangeWithRegexp()),
        data_key="exclude_addresses",
        description="IPv4 addresses to exclude.",
    )
    scan_interval = Integer(
        description=
        "Scan interval in seconds. Default is 1 day, minimum is 1 hour.",
        missing=60 * 60 * 24,
        minimum=3600,
    )
    time_allowed = List(
        Nested(TimeAllowedRange()),
        description=
        "Only execute the discovery during this time range each day..",
        required=True,
    )
    set_ipaddress = _fields.Boolean(
        data_key="set_ip_address",
        description=
        "When set, the found IPv4 address is set on the discovered host.",
        missing=True,
    )
    max_parallel_pings = Integer(
        description=
        "Set the maximum number of concurrent pings sent to target IP addresses.",
        required=False,
        minimum=1,
        maximum=200,
        missing=100,
    )
    run_as = String(
        description=
        ("Execute the network scan in the Checkmk user context of the chosen user. "
         "This user needs the permission to add new hosts to this folder."),
        required=False,
        validate=_active_users,
    )
    translate_names = Nested(TranslateNames)
示例#5
0
    drop_domain = _fields.Boolean(description=(
        "Drop the rest of the domain, only keep the hostname. Will not affect "
        "IP addresses.\n\n"
        "Examples:\n\n"
        " * `192.168.0.1` -> `192.168.0.1`\n"
        " * `foobar.example.com` -> `foobar`\n"
        " * `example.com` -> `example`\n"
        " * `example` -> `example`\n\n"
        "This will be executed **after**:\n\n"
        " * `convert_case`\n"), )
    regex = List(
        Nested(RegexpRewrites),
        data_key="regexp_rewrites",
        description=
        ("Rewrite discovered hostnames with multiple regular expressions. The "
         "replacements will be done one after another in the order they appear "
         "in the list. If not anchored at the end by a `$` character, the regexp"
         "will be anchored at the end implicitly by adding a `$` character.\n\n"
         "These will be executed **after**:\n\n"
         " * `convert_case`\n"
         " * `drop_domain`\n"),
    )
    mapping = List(
        Nested(DirectMapping),
        data_key="hostname_replacement",
        description=("Replace one value with another.\n\n"
                     "These will be executed **after**:\n\n"
                     " * `convert_case`\n"
                     " * `drop_domain`\n"
                     " * `regexp_rewrites`\n"),
    )