class HostExtensions(BaseSchema): folder = gui_fields.FolderField( description="The folder, in which this host resides.", ) attributes = gui_fields.attributes_field( "host", "view", description="Attributes of this host.", example={"ipaddress": "192.168.0.123"}, ) effective_attributes = fields.Dict( description="All attributes of this host and all parent folders. Format may change!", allow_none=True, example={"tag_snmp_ds": None}, ) is_cluster = fields.Boolean( description="If this is a cluster host, i.e. a container for other hosts.", ) is_offline = fields.Boolean( description="Whether the host is offline", ) cluster_nodes = fields.List( gui_fields.HostField(), allow_none=True, load_default=None, description="In the case this is a cluster host, these are the cluster nodes.", )
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 = gui_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 = gui_fields.PythonString( description="The raw parameter value for this rule.", example='{"ignore_fs_types": ["tmpfs"]}', ) conditions = fields.Nested( RuleConditions, description="Conditions.", )
class RulesetExtensions(base.BaseSchema): name = fields.String( description="The name of the ruleset", example="host_groups", ) folder = fields.FolderField(required=True, example="~router") number_of_rules = fields.Integer( description="The number of rules of this ruleset.", example=5, )
class RulesetSearchOptions(base.BaseSchema): """ search_options = { "fulltext": None, "ruleset_deprecated": False, "ruleset_used": False, "ruleset_group": False, "ruleset_name": False, "ruleset_title": False, "ruleset_help": False, } """ cast_to_dict = True fulltext = fields.String(description=( "Search all keys (like `name`, `title`, `help`, etc.) for this text. " "Regex allowed."), ) folder = gui_fields.FolderField( description="The folder in which to search for rules.", ) deprecated = fields.String( attribute="ruleset_deprecated", description="Also show deprecated rulesets. Defaults to False.", ) used = fields.String( attribute="ruleset_used", description="Only show used rulesets. Defaults to True.", ) group = fields.String( attribute="ruleset_group", description="The specific group to search for rules in.", ) name = fields.String( attribute="ruleset_name", description="A regex of the name.", )
from cmk.gui.plugins.openapi.endpoints.utils import folder_slug from cmk.gui.plugins.openapi.restful_objects import ( constructors, Endpoint, request_schemas, response_schemas, ) from cmk.gui.plugins.openapi.utils import problem, ProblemException from cmk.gui.watolib import CREFolder PATH_FOLDER_FIELD = { "folder": fields.FolderField( description= ("The path of the folder being requested. Please be aware that slashes can't " "be used in the URL. Also, escaping the slashes via %2f will not work. Please " "replace the path delimiters with the tilde character `~`."), example="~my~fine~folder", required=True, ) } @Endpoint( constructors.collection_href("folder_config"), "cmk/create", method="post", etag="output", response_schema=response_schemas.FolderSchema, request_schema=request_schemas.CreateFolder, ) def create(params):
class InputRuleObject(base.BaseSchema): """A schema to validate the values coming from the API clients. Examples: >>> s = InputRuleObject() >>> from cmk.gui.utils.script_helpers import application_and_request_context >>> with application_and_request_context(): ... rv = s.load({ ... 'folder': '~', ... 'ruleset': 'host', ... 'properties': {'disabled': False}, ... 'conditions': { ... 'host_name': { ... 'match_on': ['example.com', 'heute'], ... 'operator': 'one_of', ... }, ... 'host_labels': [ ... {'key': 'os', 'operator': 'is', 'value': 'windows'}, ... {'key': 'foo', 'operator': 'is_not', 'value': 'bar'}, ... ], ... 'host_tags': [ ... {'key': 'criticality', 'operator': 'is_not', 'value': 'prod'}, ... {'key': 'foo', 'operator': 'is_not', 'value': 'testing'}, ... ], ... } ... }) >>> rv {'ruleset': 'host', 'folder': Folder('', 'Main'), 'properties': {'disabled': False}, \ 'conditions': {\ 'host_name': ['example.com', 'heute'], \ 'host_tags': {'criticality': {'$ne': 'prod'}, 'foo': {'$ne': 'testing'}}, \ 'host_labels': {'os': 'windows', 'foo': {'$ne': 'bar'}}}} >>> rv['folder'].path() '' >>> s.dump(rv) {'ruleset': 'host', 'folder': '/', 'properties': {'disabled': False}, \ 'conditions': {\ 'host_name': {'match_on': ['example.com', 'heute'], 'operator': 'one_of'}, \ 'host_tags': [{'key': 'criticality', 'operator': 'is_not', 'value': 'prod'}, {'key': 'foo', 'operator': 'is_not', 'value': 'testing'}], \ 'host_labels': [{'key': 'os', 'operator': 'is', 'value': 'windows'}, {'key': 'foo', 'operator': 'is_not', 'value': 'bar'}]}} """ cast_to_dict = True ruleset = fields.String( description="Name of rule set.", example="host_config", required=True, ) folder = gui_fields.FolderField(required=True, example="~router") properties = fields.Nested( RuleProperties, description="Configuration values for rules.", example={"disabled": False}, ) value_raw = gui_fields.PythonString( description= ("The raw parameter value for this rule. To create the correct structure, for now use " "the 'export for API' menu item in the Rule Editor of the GUI. The value is expected " "to be a valid Python type."), example='{"ignore_fs_types": ["tmpfs"]}', ) conditions = fields.Nested( RuleConditions, description="Conditions.", example={}, )
class MoveToFolder(base.BaseSchema): cast_to_dict = True position = fields.String(description="The type of position to move to.", example="top_of_folder") folder = gui_fields.FolderField(example="/")