コード例 #1
0
ファイル: master_control.py プロジェクト: gradecke/checkmk
    def show(self) -> None:
        items = self._core_toggles()
        sites.update_site_states_from_dead_sites()

        site_status_info: Dict[sites.SiteId, List] = {}
        try:
            sites.live().set_prepend_site(True)
            for row in sites.live().query(
                "GET status\nColumns: %s" % " ".join([i[0] for i in items])
            ):
                site_id, values = row[0], row[1:]
                site_status_info[site_id] = values
        finally:
            sites.live().set_prepend_site(False)

        for site_id, site_alias in sites.sorted_sites():
            container: ContextManager[bool] = (
                foldable_container(
                    treename="master_control",
                    id_=site_id,
                    isopen=True,
                    title=site_alias,
                    icon="foldable_sidebar",
                )
                if not sites.is_single_local_site()
                else nullcontext(False)
            )
            with container:
                try:
                    self._show_master_control_site(site_id, site_status_info, items)
                except Exception as e:
                    logger.exception("error rendering master control for site %s", site_id)
                    write_snapin_exception(e)
コード例 #2
0
ファイル: site_status.py プロジェクト: troelsarvin/checkmk
    def show(self) -> None:
        html.open_table(cellspacing="0", class_="sitestate")

        sites.update_site_states_from_dead_sites()

        for sitename, _sitealias in sites.sorted_sites():
            site = sites.get_site_config(sitename)

            state = sites.states().get(sitename,
                                       sites.SiteStatus({})).get("state")

            if state is None:
                state = "missing"
                switch = "missing"
                text = escape_html_permissive(sitename)

            else:
                if state == "disabled":
                    switch = "on"
                    text = escape_html_permissive(site["alias"])
                else:
                    switch = "off"
                    text = render_link(
                        site["alias"],
                        "view.py?view_name=sitehosts&site=%s" % sitename)

            html.open_tr()
            html.td(text, class_="left")
            html.open_td(class_="state")
            if switch == "missing":
                html.status_label(content=state,
                                  status=state,
                                  title=_("Site is missing"))
            else:
                url = makeactionuri_contextless(
                    request,
                    transactions,
                    [
                        ("_site_switch", "%s:%s" % (sitename, switch)),
                    ],
                    filename="switch_site.py",
                )
                html.status_label_button(
                    content=state,
                    status=state,
                    title=_("enable this site")
                    if state == "disabled" else _("disable this site"),
                    onclick="cmk.sidebar.switch_site(%s)" % (json.dumps(url)),
                )
            html.close_tr()
        html.close_table()
コード例 #3
0
ファイル: test_sites.py プロジェクト: troelsarvin/checkmk
def test_sorted_sites(with_user_login, mocker):
    mocker.patch.object(
        user,
        "authorized_sites",
        return_value={
            "site1": {"alias": "Site 1"},
            "site3": {"alias": "Site 3"},
            "site5": {"alias": "Site 5"},
            "site23": {"alias": "Site 23"},
            "site6": {"alias": "Site 6"},
            "site12": {"alias": "Site 12"},
        },
    )
    expected = [
        ("site1", "Site 1"),
        ("site12", "Site 12"),
        ("site23", "Site 23"),
        ("site3", "Site 3"),
        ("site5", "Site 5"),
        ("site6", "Site 6"),
    ]
    assert sites.sorted_sites() == expected
    mocker.stopall()
コード例 #4
0
ファイル: grafana.py プロジェクト: troelsarvin/checkmk
 def _get_user_sites(self, request):
     return sites.sorted_sites()