def _serialize_folder(folder: CREFolder): uri = constructors.object_href('folder_config', folder.id()) return constructors.domain_object( domain_type='folder_config', identifier=folder.id(), title=folder.title(), members={ 'move': constructors.object_action( name='move', base=uri, parameters=dict([ constructors.action_parameter( action='move', parameter='destination', friendly_name='The destination folder of this move action', optional=False, pattern="[0-9a-fA-F]{32}|root", ), ]), ), }, extensions={ 'attributes': folder.attributes().copy(), }, )
def etag_of_folder(folder: CREFolder) -> ETags: return constructors.etag_of_dict( { "path": folder.path(), "attributes": folder.attributes(), "hosts": folder.host_names(), } )
def _serialize_rule( folder: watolib.CREFolder, index: int, rule: watolib.Rule, ) -> DomainObject: return constructors.domain_object( domain_type="rule", editable=False, identifier=rule.id, title=rule.description(), extensions={ "ruleset": rule.ruleset.name, "folder": "/" + folder.path(), "folder_index": index, "properties": rule.rule_options.to_config(), "value_raw": rule.value, "conditions": denilled( { "host_name": rule.conditions.host_name, "host_tag": rule.conditions.host_tags, "host_label": rule.conditions.host_labels, "service_description": rule.conditions.service_description, "service_label": rule.conditions.service_labels, } ), }, )
def make_folder_breadcrumb(folder: watolib.CREFolder) -> Breadcrumb: return Breadcrumb([ BreadcrumbItem( title=_("Hosts"), url=None, ), ]) + folder.breadcrumb()
def _serialize_folder(folder: CREFolder, show_hosts): links = [] if not folder.is_root(): links.append( constructors.link_rel( rel="cmk/move", href=constructors.object_action_href( "folder_config", folder_slug(folder), action_name="move", ), method="post", title="Move the folder", ) ) rv = constructors.domain_object( domain_type="folder_config", identifier=folder_slug(folder), title=folder.title(), extensions={ "path": "/" + folder.path(), "attributes": folder.attributes().copy(), }, links=links, ) if show_hosts: rv["members"]["hosts"] = constructors.collection_property( name="hosts", base=constructors.object_href("folder_config", folder_slug(folder)), value=[ constructors.collection_item( domain_type="host_config", obj={ "id": host.id(), "title": host.name(), }, ) for host in folder.hosts().values() ], ) return rv
def _serialize_folder(folder: CREFolder, show_hosts): links = [] if not folder.is_root(): links.append( constructors.link_rel( rel='cmk/move', href=constructors.object_action_href( "folder_config", folder_slug(folder), action_name='move', ), method='post', title='Move the folder', )) rv = constructors.domain_object( domain_type='folder_config', identifier=folder_slug(folder), title=folder.title(), extensions={ 'path': '/' + folder.path(), 'attributes': folder.attributes().copy(), }, links=links, ) if show_hosts: rv['members']['hosts'] = constructors.collection_property( name='hosts', base=constructors.object_href('folder_config', folder_slug(folder)), value=[ constructors.collection_item( domain_type='host_config', obj={ 'id': host.id(), 'title': host.name(), }, ) for host in folder.hosts().values() ], ) return rv
def folder_slug(folder: CREFolder) -> str: """Create a tilde separated path identifier to be used in URLs Args: folder: The folder instance for which to generate the URL. Returns: A path looking like this: `~folder~subfolder~leaf_folder` """ return '~' + folder.path().rstrip("/").replace("/", "~")
def _serialize_folder(folder: CREFolder) -> DomainObject: uri = constructors.object_href('folder_config', folder.id()) return constructors.domain_object( domain_type='folder_config', identifier=folder.id(), title=folder.title(), members={ 'hosts': constructors.object_collection( name='hosts', domain_type='host_config', entries=[ constructors.link_rel( rel='.../value', parameters={'collection': "items"}, href=constructors.object_href('host_config', host), ) for host in folder.hosts().values() ], base=uri, ), 'move': constructors.object_action( name='move', base=uri, parameters=dict([ constructors.action_parameter( action='move', parameter='destination', friendly_name= 'The destination folder of this move action', optional=False, pattern="[0-9a-fA-F]{32}|root", ), ]), ), }, extensions={ 'attributes': folder.attributes(), }, )
def make_folder_status_link(folder: watolib.CREFolder, view_name: str) -> PageMenuEntry: return PageMenuEntry( title=_("Status"), icon_name="status", item=make_simple_link( html.makeuri_contextless( [ ("view_name", view_name), ("wato_folder", folder.path()), ], filename="view.py", )), )
def etag_of_folder(folder: CREFolder) -> ETags: return constructors.etag_of_dict({ 'path': folder.path(), 'attributes': folder.attributes(), 'hosts': folder.host_names(), })