Ejemplo n.º 1
0
class ConcreteTimePeriod(BaseSchema):
    alias = fields.String(description="The alias of the time period",
                          example="alias")
    active_time_ranges = fields.List(
        fields.Nested(ConcreteTimeRangeActive),
        description="The days for which time ranges were specified",
        example={
            "day": "all",
            "time_ranges": [{
                "start": "12:00",
                "end": "14:00"
            }]
        },
    )
    exceptions = fields.List(
        fields.Nested(ConcreteTimePeriodException),
        description="Specific day exclusions with their list of time ranges",
        example=[{
            "date": "2020-01-01",
            "time_ranges": [{
                "start": "14:00",
                "end": "18:00"
            }]
        }],
    )
    exclude = fields.List(  # type: ignore[assignment]
        fields.String(description="Name of excluding time period",
                      example="holidays"),
        description=
        "The collection of time period aliases whose periods are excluded",
    )
Ejemplo n.º 2
0
class RuleConditions(base.BaseSchema):
    cast_to_dict = True

    host_name = fields.Nested(
        HostOrServiceConditionSchema,
        many=False,
        description=(
            "Here you can enter a list of explicit host names that the rule should or should "
            "not apply to. "
            "Leave this option disabled if you want the rule to apply for all hosts specified "
            "by the given tags. The names that you enter here are compared with case sensitive "
            "exact matching. Alternatively you can use regular expressions if you enter a "
            "tilde `~` as the first character. That regular expression must match the beginning "
            "of the host names in question."
        ),
        example={"match_on": ["host1", "host2"], "operator": "one_of"},
    )
    host_tag = fields.Nested(
        TagConditionSchema,
        many=True,
        description=(
            "The rule will only be applied to hosts fulfilling all the host tag conditions "
            "listed here, even if they appear in the list of explicit host names."
        ),
        example=[{"key": "criticality", "operator": "is", "value": "prod"}],
    )
    host_label = fields.Nested(
        LabelConditionSchema,
        many=True,
        description="Further restrict this rule by applying host label conditions.",
        example=[{"key": "os", "operator": "is", "value": "windows"}],
    )
    service_label = fields.Nested(
        LabelConditionSchema,
        many=True,
        description=(
            "Restrict the application of the rule, by checking against service label conditions."
        ),
        example=[{"key": "os", "operator": "is", "value": "windows"}],
    )
    service_description = fields.Nested(
        HostOrServiceConditionSchema(use_regex="always"),
        many=False,
        description=(
            "Specify a list of service patterns this rule shall apply to.\n"
            " * The patterns must match the beginning of the service in question.\n"
            " * Adding a `$` to the end forces an exact match.\n"
            " * Pattern use regular expressions. e.g. a `.*` will match an arbitrary text.\n"
            " * The text entered here is handled as a regular expression pattern.\n"
            " * The pattern is matched from the beginning.\n"
            " * The match is performed case sensitive.\n"
            "BE AWARE: Depending on the service ruleset the service_description of "
            "the rules is only a check item or a full service description. For "
            "example the check parameters rulesets only use the item, and other "
            "service rulesets like disabled services ruleset use full service"
            "descriptions."
        ),
        example={"match_on": ["foo1", "bar2"], "operator": "none_of"},
    )
Ejemplo n.º 3
0
class FolderMembers(BaseSchema):
    hosts = fields.Nested(
        ObjectCollectionMember(),
        description="A list of links pointing to the actual host-resources.",
    )
    move = fields.Nested(
        ObjectActionMember(),
        description="An action which triggers the move of this folder to another folder.",
    )
Ejemplo n.º 4
0
class HostConfigSchema(DomainObject):
    domainType = fields.Constant(
        "host_config", required=True, description="The domain type of the object."
    )
    members = fields.Nested(HostMembers, description="All the members of the host object.")
    extensions = fields.Nested(
        HostExtensions,
        description="All the data and metadata of this host.",
    )
Ejemplo n.º 5
0
class RuleExtensions(base.BaseSchema):
    """Serializes the 'extensions' part of the Rule Domain Object.

    Examples:

        >>> ext = RuleExtensions()
        >>> from cmk.gui.utils.script_helpers import application_and_request_context
        >>> with application_and_request_context():
        ...     ext.load({
        ...        'folder': '/',
        ...     })
        {'folder': Folder('', 'Main')}

        >>> with application_and_request_context():
        ...     rv = ext.load({
        ...        'folder': '/',
        ...        'conditions': {
        ...            'service_description': {'match_on': ['foo'],
        ...                                               'operator': 'none_of',},
        ...            'host_tag': [{'key': 'criticality', 'operator': 'is', 'value': 'prod'}],
        ...        }
        ...     })
        ...     rv
        {'folder': Folder('', 'Main'), \
'conditions': {\
'host_tag': {'criticality': 'prod'},\
 'service_description': {'$nor': [{'$regex': 'foo'}]}\
}}

        >>> ext.dump(rv)
        {'folder': '/', 'conditions': {\
'host_tag': [{'key': 'criticality', 'operator': 'is', 'value': 'prod'}], \
'service_description': {'match_on': ['foo'], 'operator': 'none_of'}}}

    """

    cast_to_dict = True

    ruleset = fields.String(description="The name of the ruleset.")
    folder = fields.FolderField(required=True, example="~router")
    folder_index = fields.Integer(
        description="The position of this rule in the chain in this folder.",
    )
    properties = fields.Nested(
        RuleProperties,
        description="Property values of this rule.",
        example={},
    )
    value_raw = fields.PythonString(
        description="The raw parameter value for this rule.",
        example='{"ignore_fs_types": ["tmpfs"]}',
    )
    conditions = fields.Nested(
        RuleConditions,
        description="Conditions.",
    )
Ejemplo n.º 6
0
class FolderSchema(Linkable):
    domainType = fields.Constant("folder_config", description="The domain type of the object.")
    id = fields.String(description="The full path of the folder, tilde-separated.")
    title = fields.String(description="The human readable title for this folder.")
    members = fields.Nested(
        FolderMembers(),
        description="Specific collections or actions applicable to this object.",
    )
    extensions = fields.Nested(
        FolderExtensions(),
        description="Data and Meta-Data of this object.",
    )
Ejemplo n.º 7
0
class HostMembers(BaseSchema):
    folder_config = fields.Nested(
        FolderSchema(),
        description="The folder in which this host resides. It is represented by a hexadecimal "
        "identifier which is it's 'primary key'. The folder can be accessed via the "
        "`self`-link provided in the links array.",
    )
Ejemplo n.º 8
0
class ObjectCollectionMember(ObjectMemberBase):
    memberType = fields.Constant("collection")
    value = fields.List(fields.Nested(LinkSchema()))
    name = fields.String(example="important_values")
    title = fields.String(
        description="A human readable title of this object. Can be used for "
        "user interfaces.", )
Ejemplo n.º 9
0
class ActionResultObject(ActionResultBase):
    result = fields.Nested(
        Schema.from_dict(
            {
                "links": fields.List(
                    fields.Nested(LinkSchema),
                    required=True,
                ),
                "value": fields.Dict(
                    required=True,
                    example={"duration": "5 seconds."},
                ),
            },
            name="ActionResultObjectValue",
        ),
        description="The result of the action. In this case, an object.",
    )
Ejemplo n.º 10
0
    def openapi_field(self):
        # FIXME: due to cyclical imports which, when fixed, expose even more cyclical imports.
        from cmk.gui import fields

        return fields.Nested(
            fields.HostContactGroup,
            description=self.help(),
        )
Ejemplo n.º 11
0
class ActionResultScalar(ActionResultBase):
    result = fields.Nested(
        Schema.from_dict(
            {
                "links": fields.List(
                    fields.Nested(LinkSchema),
                    required=True,
                ),
                "value": fields.String(
                    required=True,
                    example="Done.",
                ),
            },
            name="ActionResultScalarValue",
        ),
        description="The scalar result of the action.",
    )
Ejemplo n.º 12
0
class PasswordObject(DomainObject):
    domainType = fields.Constant(
        "password",
        description="The type of the domain-object.",
    )
    extensions = fields.Nested(
        PasswordExtension,
        description="All the attributes of the domain object.",
    )
Ejemplo n.º 13
0
 def openapi_field(self) -> fields.Field:
     return fields.Nested(
         fields.NetworkScan,
         description=(
             "Configuration for automatic network scan. Pings will be"
             "sent to each IP address in the configured ranges to check"
             "if a host is up or down. Each found host will be added to"
             "the folder by it's hostname (if possible) or IP address."),
     )
Ejemplo n.º 14
0
class FolderCollection(DomainObjectCollection):
    domainType = fields.Constant(
        "folder_config",
        description="The domain type of the objects in the collection.",
    )
    value = fields.List(
        fields.Nested(FolderSchema()),
        description="A list of folder objects.",
    )
Ejemplo n.º 15
0
 def openapi_field(self) -> fields.Field:
     return fields.Nested(
         fields.SNMPCredentials,
         description=
         ("The SNMP access configuration. A configured SNMP v1/v2 community here "
          "will have precedence over any configured SNMP community rule. For this "
          "attribute to take effect, the attribute `tag_snmp_ds` needs to be set "
          "first."),
     )
Ejemplo n.º 16
0
class HostConfigCollection(DomainObjectCollection):
    domainType = fields.Constant(
        "host_config",
        description="The domain type of the objects in the collection.",
    )
    value = fields.List(
        fields.Nested(HostConfigSchema()),
        description="A list of host objects.",
    )
Ejemplo n.º 17
0
class RuleCollection(response_schemas.DomainObjectCollection):
    domainType = fields.Constant(
        "rule",
        description="Domain type of this object.",
    )
    value: fields.Field = fields.Nested(
        RuleObject,
        description="The collection itself. Each entry in here is part of the collection.",
        many=True,
    )
Ejemplo n.º 18
0
class ActionResultObject(ActionResultBase):
    result = fields.Nested(
        Schema.from_dict(
            {
                'links':
                fields.List(
                    fields.Nested(LinkSchema),
                    required=True,
                ),
                'value':
                fields.Dict(
                    required=True,
                    example={'duration': '5 seconds.'},
                )
            },
            name='ActionResultObjectValue',
        ),
        description="The result of the action. In this case, an object.",
    )
Ejemplo n.º 19
0
class ConcreteTimePeriodException(BaseSchema):
    date = fields.String(
        example="2020-01-01",
        format="date",
        description="The date of the time period exception." "8601 profile",
    )
    time_ranges = fields.List(
        fields.Nested(ConcreteTimeRange),
        example="[{'start': '14:00', 'end': '18:00'}]",
    )
Ejemplo n.º 20
0
class RulesetObject(response_schemas.DomainObject):
    domainType = fields.Constant(
        "ruleset",
        description="Domain type of this object.",
        example="ruleset",
    )
    extensions = fields.Nested(
        RulesetExtensions,
        description="Specific attributes related to rulesets.",
    )
Ejemplo n.º 21
0
class Version(LinkSchema):
    specVersion = fields.Str(
        description=
        ('The "major.minor" parts of the version of the spec supported by this '
         'implementation, e.g. "1.0"'),
        required=False,
    )
    implVersion = fields.Str(
        description=
        ("(optional) Version of the implementation itself (format is specific to "
         "the implementation)"),
        required=False,
    )
    additionalCapabilities = fields.Nested(VersionCapabilities)
Ejemplo n.º 22
0
class RuleObject(response_schemas.DomainObject):
    """The schema for sending data TO the API client.

    For the schema responsible for receiving data, see `InputRuleObject`.
    """

    domainType = fields.Constant(
        "rule",
        description="Domain type of this object.",
        example="rule",
    )
    extensions = fields.Nested(
        RuleExtensions,
        description="Attributes specific to rule objects.",
    )
Ejemplo n.º 23
0
class DomainObjectCollection(Linkable):
    id = fields.String(
        description="The name of this collection.",
        load_default="all",
    )
    domainType: fields.Field = fields.String(
        description="The domain type of the objects in the collection."
    )
    title = fields.String(
        description="A human readable title of this object. Can be used for " "user interfaces.",
    )
    value: fields.Field = fields.Nested(
        CollectionItem,
        description="The collection itself. Each entry in here is part of the collection.",
        many=True,
    )
    extensions = fields.Dict(description="Additional attributes alongside the collection.")
Ejemplo n.º 24
0
 def openapi_field(self) -> fields.Field:
     return fields.Nested(
         fields.SNMPCredentials,
         description="SNMP credentials",
         allow_none=True,
     )
Ejemplo n.º 25
0
class ConcreteTimeRangeActive(BaseSchema):
    day = fields.String(
        description="The day for which the time ranges are specified",
        pattern=f"{'|'.join(weekday_ids())}",
    )
    time_ranges = fields.List(fields.Nested(ConcreteTimeRange))
Ejemplo n.º 26
0
class ObjectAction(Linkable):
    parameters = fields.Nested(Parameter)
Ejemplo n.º 27
0
class HostConfigSchema(Linkable):
    domainType = fields.Constant("host_config", required=True)
    id = fields.String()
    title = fields.String()
    members = fields.Nested(HostMembers,
                            description="All the members of the host object.")
Ejemplo n.º 28
0
class SiteState(Linkable):
    domainType = fields.Constant("site-state", required=True)
    members = fields.Nested(SiteStateMembers,
                            description="All the members of the host object.")
Ejemplo n.º 29
0
 def openapi_field(self) -> fields.Field:
     return fields.Nested(
         fields.IPMIParameters,
         description="IPMI credentials",
         required=False,
     )
Ejemplo n.º 30
0
class Linkable(BaseSchema):
    links = fields.List(
        fields.Nested(LinkSchema),
        required=True,
        description="list of links to other resources.",
    )