Ejemplo n.º 1
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())
     )
Ejemplo n.º 2
0
def _link_with_uuid(
    host_name: HostName,
    host: CREHost,
    uuid: UUID,
) -> None:
    uuid_link_manager = get_uuid_link_manager()
    uuid_link_manager.create_link(
        host_name,
        uuid,
        create_target_dir=host.effective_attributes().get("cmk_agent_connection") == "push-agent",
    )
Ejemplo n.º 3
0
def page_menu_host_entries(mode_name: str,
                           host: CREHost) -> Iterator[PageMenuEntry]:
    if mode_name != "edit_host":
        yield PageMenuEntry(
            title=_("Properties"),
            icon_name="edit",
            item=make_simple_link(
                watolib.folder_preserving_link([("mode", "edit_host"),
                                                ("host", host.name())])),
        )

    if mode_name != "inventory":
        yield PageMenuEntry(
            title=_("Service configuration"),
            icon_name="services",
            item=make_simple_link(
                watolib.folder_preserving_link([("mode", "inventory"),
                                                ("host", host.name())])),
        )

    if mode_name != "diag_host" and not host.is_cluster():
        yield PageMenuEntry(
            title=_("Connection tests"),
            icon_name="diagnose",
            item=make_simple_link(
                watolib.folder_preserving_link([("mode", "diag_host"),
                                                ("host", host.name())])),
        )

    if mode_name != "object_parameters" and user.may("wato.rulesets"):
        yield PageMenuEntry(
            title=_("Effective parameters"),
            icon_name="rulesets",
            item=make_simple_link(
                watolib.folder_preserving_link([("mode", "object_parameters"),
                                                ("host", host.name())])),
        )

    if mode_name == "object_parameters" or mode_name == "edit_host" and user.may(
            "wato.rulesets"):
        yield PageMenuEntry(
            title=_("Rules"),
            icon_name="rulesets",
            item=make_simple_link(
                makeuri_contextless(
                    request,
                    [
                        ("mode", "rule_search"),
                        ("filled_in", "search"),
                        ("search_p_ruleset_deprecated", "OFF"),
                        ("search_p_rule_host_list_USE", "ON"),
                        ("search_p_rule_host_list", host.name()),
                    ],
                    filename="wato.py",
                )),
        )

    yield make_host_status_link(host_name=host.name(), view_name="hoststatus")

    if user.may("wato.rulesets") and host.is_cluster():
        yield PageMenuEntry(
            title=_("Clustered services"),
            icon_name="rulesets",
            item=make_simple_link(
                watolib.folder_preserving_link([("mode", "edit_ruleset"),
                                                ("varname",
                                                 "clustered_services")])),
        )

    if watolib.has_agent_bakery() and user.may("wato.download_agents"):
        yield PageMenuEntry(
            title=_("Monitoring agent"),
            icon_name="agents",
            item=make_simple_link(
                watolib.folder_preserving_link([("mode", "agent_of_host"),
                                                ("host", host.name())])),
        )

    if mode_name == "edit_host" and not host.locked():
        if user.may("wato.rename_hosts"):
            yield PageMenuEntry(
                title=_("Rename"),
                icon_name="rename_host",
                item=make_simple_link(
                    watolib.folder_preserving_link([("mode", "rename_host"),
                                                    ("host", host.name())])),
            )

        if user.may("wato.manage_hosts") and user.may("wato.clone_hosts"):
            yield PageMenuEntry(
                title=_("Clone"),
                icon_name="insert",
                item=make_simple_link(host.clone_url()),
            )

        yield PageMenuEntry(
            title=_("Delete"),
            icon_name="delete",
            item=make_simple_link(
                make_confirm_link(
                    url=makeactionuri(request, transactions,
                                      [("delete", "1")]),
                    message=_(
                        "Do you really want to delete the host <tt>%s</tt>?") %
                    host.name(),
                )),
        )

        if user.may("wato.auditlog"):
            yield PageMenuEntry(
                title=_("Audit log"),
                icon_name="auditlog",
                item=make_simple_link(
                    make_object_audit_log_url(host.object_ref())),
            )
Ejemplo n.º 4
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,
    )
Ejemplo n.º 5
0
def serialize_service_discovery(
    host: CREHost,
    discovered_services: Sequence[CheckPreviewEntry],
    discovery_phases: List[str],
):

    members = {}
    host_name = host.name()
    for entry in discovered_services:
        if _in_phase(entry.check_source, discovery_phases):
            service_phase = _lookup_phase_name(entry.check_source)
            members[
                f"{entry.check_plugin_name}-{entry.item}"] = object_property(
                    name=entry.description,
                    title=f"The service is currently {service_phase!r}",
                    value=service_phase,
                    prop_format="string",
                    linkable=False,
                    extensions={
                        "host_name": host_name,
                        "check_plugin_name": entry.check_plugin_name,
                        "service_name": entry.description,
                        "service_item": entry.item,
                        "service_phase": service_phase,
                    },
                    base="",
                    links=[
                        link_rel(
                            rel="cmk/service.move-monitored",
                            href=update_service_phase.path.format(
                                host_name=host_name),
                            body_params={
                                "target_phase": "monitored",
                                "check_type": entry.check_plugin_name,
                                "service_item": entry.item,
                            },
                            method="put",
                            title="Move the service to monitored",
                        ),
                        link_rel(
                            rel="cmk/service.move-undecided",
                            href=update_service_phase.path.format(
                                host_name=host_name),
                            body_params={
                                "target_phase": "undecided",
                                "check_type": entry.check_plugin_name,
                                "service_item": entry.item,
                            },
                            method="put",
                            title="Move the service to undecided",
                        ),
                        link_rel(
                            rel="cmk/service.move-ignored",
                            href=update_service_phase.path.format(
                                host_name=host_name),
                            body_params={
                                "target_phase": "ignored",
                                "check_type": entry.check_plugin_name,
                                "service_item": entry.item,
                            },
                            method="put",
                            title="Move the service to ignored",
                        ),
                    ],
                )

    return domain_object(
        domain_type="service_discovery",
        identifier=f"{host_name}-services-wato",
        title="Services discovery",
        members=members,
        editable=False,
        deletable=False,
        extensions={},
    )
Ejemplo n.º 6
0
def page_menu_host_entries(mode_name: str, host: CREHost) -> Iterator[PageMenuEntry]:
    if mode_name != "edit_host":
        yield PageMenuEntry(
            title=_("Properties"),
            icon_name="edit",
            item=make_simple_link(
                watolib.folder_preserving_link([("mode", "edit_host"), ("host", host.name())])),
        )

    if mode_name != "inventory":
        yield PageMenuEntry(
            title=_("Service configuration"),
            icon_name="services",
            item=make_simple_link(
                watolib.folder_preserving_link([("mode", "inventory"), ("host", host.name())])),
        )

    if mode_name != "diag_host" and not host.is_cluster():
        yield PageMenuEntry(
            title=_("Connection tests"),
            icon_name="diagnose",
            item=make_simple_link(
                watolib.folder_preserving_link([("mode", "diag_host"), ("host", host.name())])),
        )

    if mode_name != "object_parameters" and config.user.may('wato.rulesets'):
        yield PageMenuEntry(
            title=_("Effective parameters"),
            icon_name="rulesets",
            item=make_simple_link(
                watolib.folder_preserving_link([("mode", "object_parameters"),
                                                ("host", host.name())])),
        )

    yield make_host_status_link(host_name=host.name(), view_name="hoststatus")

    if config.user.may('wato.rulesets') and host.is_cluster():
        yield PageMenuEntry(
            title=_("Clustered services"),
            icon_name="rulesets",
            item=make_simple_link(
                watolib.folder_preserving_link([("mode", "edit_ruleset"),
                                                ("varname", "clustered_services")])),
        )

    if watolib.has_agent_bakery() and config.user.may('wato.download_agents'):
        yield PageMenuEntry(
            title=_("Monitoring agent"),
            icon_name="agents",
            item=make_simple_link(
                watolib.folder_preserving_link([("mode", "agent_of_host"), ("host", host.name())])),
        )

    if mode_name == "edit_host" and not host.locked():
        if config.user.may("wato.rename_hosts"):
            yield PageMenuEntry(
                title=_("Rename"),
                icon_name="rename_host",
                item=make_simple_link(
                    watolib.folder_preserving_link([("mode", "rename_host"),
                                                    ("host", host.name())])),
            )

        if config.user.may("wato.manage_hosts") and config.user.may("wato.clone_hosts"):
            yield PageMenuEntry(
                title=_("Clone"),
                icon_name="insert",
                item=make_simple_link(host.clone_url()),
            )

        yield PageMenuEntry(
            title=_("Delete"),
            icon_name="delete",
            item=make_simple_link(html.makeactionuri([("delete", "1")])),
        )