Exemple #1
0
def serialize_host(host: CREHost, effective_attributes: bool):
    extensions = {
        "folder":
        host.folder().path(),
        "attributes":
        host.attributes(),
        "effective_attributes":
        host.effective_attributes() if effective_attributes else None,
        "is_cluster":
        host.is_cluster(),
        "is_offline":
        host.is_offline(),
        "cluster_nodes":
        host.cluster_nodes(),
    }

    agent_links = []
    if not cmk_version.is_raw_edition():
        import cmk.gui.cee.agent_bakery as agent_bakery  # pylint: disable=no-name-in-module

        for agent_type in sorted(agent_bakery.agent_package_types().keys()):
            agent_links.append(
                constructors.link_rel(
                    rel="cmk/download",
                    href="{}?{}".format(
                        constructors.domain_type_action_href(
                            "agent", "download"),
                        urlencode({
                            "os_type": agent_type,
                            "host_name": host.id()
                        }),
                    ),
                    method="get",
                    title=f"Download the {agent_type} agent of the host.",
                ))

    return constructors.domain_object(
        domain_type="host_config",
        identifier=host.id(),
        title=host.alias() or host.name(),
        links=[
            constructors.link_rel(
                rel="cmk/folder_config",
                href=constructors.object_href("folder_config",
                                              folder_slug(host.folder())),
                method="get",
                title="The folder config of the host.",
            ),
        ] + agent_links,
        extensions=extensions,
    )
Exemple #2
0
 def is_discovery_rule_of(self, host: CREHost) -> bool:
     return (
         self.conditions.host_name == [host.name()]
         and self.conditions.host_tags == {}
         and self.conditions.has_only_explicit_service_conditions()
         and self.folder.is_transitive_parent_of(host.folder())
     )