Ejemplo n.º 1
0
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,
                }
            ),
        },
    )
Ejemplo n.º 2
0
def etag_of_folder(folder: CREFolder) -> ETags:
    return constructors.etag_of_dict(
        {
            "path": folder.path(),
            "attributes": folder.attributes(),
            "hosts": folder.host_names(),
        }
    )
Ejemplo n.º 3
0
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("/", "~")
Ejemplo n.º 4
0
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",
            )),
    )
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
def etag_of_folder(folder: CREFolder) -> ETags:
    return constructors.etag_of_dict({
        'path': folder.path(),
        'attributes': folder.attributes(),
        'hosts': folder.host_names(),
    })