Exemple #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 = Boolean(
        description="Add these contact groups to the host.",
        load_default=False,
    )
    use_for_services = 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."
        ),
        load_default=False,
    )
    recurse_use = Boolean(
        description="Add these groups as contacts to all hosts in all sub-folders of this folder.",
        load_default=False,
    )
    recurse_perms = Boolean(
        description="Give these groups also permission on all sub-folders.",
        load_default=False,
    )
Exemple #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 = Constant(
        description="A list of single IPv4 addresses.",
        constant="ip_list",
    )
    addresses = List(
        String(
            validate=ValidateIPv4(),
        )
    )
Exemple #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 = 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."),
    )
Exemple #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.",
        load_default=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 = Boolean(
        data_key="set_ip_address",
        description="When set, the found IPv4 address is set on the discovered host.",
        load_default=True,
    )
    max_parallel_pings = Integer(
        description="Set the maximum number of concurrent pings sent to target IP addresses.",
        required=False,
        minimum=1,
        maximum=200,
        load_default=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)
Exemple #5
0
         "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"
Exemple #6
0
    "Content-Type": String(
        required=True,
        description=(
            "A header specifying which type of content is in the request/response body. "
            "This is required when sending encoded data in a POST/PUT body. When the "
            "request body is empty, this header should not be sent."
        ),
        example="application/json",
    )
}

SERVICE_DESCRIPTION = {
    "service_description": String(
        description="The service description.",
        example="Memory",
    )
}

SITES = List(
    String(),
    description="Restrict the query to this particular site.",
    load_default=[],
)

USERNAME = {
    "username": String(
        description="A username.",
        example="user",
    )
}