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()
def show(self): html.open_table(cellspacing=0, class_="sitestate") sites.update_site_states_from_dead_sites() for sitename, _sitealias in config.sorted_sites(): site = config.site(sitename) state = sites.states().get(sitename, {}).get("state") if state is None: state = "missing" switch = "missing" text = sitename else: if state == "disabled": switch = "on" text = site["alias"] else: switch = "off" text = render_link( site["alias"], "view.py?view_name=sitehosts&site=%s" % sitename) html.open_tr() html.open_td(class_="left") html.write(text) html.close_td() html.open_td(class_="state") if switch == "missing": html.status_label(content=state, status=state, title=_("Site is missing")) else: url = html.makeactionuri_contextless([ ("_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()
def _activation_status(self): with table_element("site-status", searchable=False, sortable=False, css="activation") as table: for site_id, site in sort_sites( cmk.gui.watolib.changes.activation_sites()): table.row() site_status, status = self._get_site_status(site_id, site) is_online = self._site_is_online(status) is_logged_in = self._site_is_logged_in(site_id, site) has_foreign = self._site_has_foreign_changes(site_id) can_activate_all = not has_foreign or config.user.may( "wato.activateforeign") # Disable actions for offline sites and not logged in sites if not is_online or not is_logged_in: can_activate_all = False need_restart = self._is_activate_needed(site_id) need_sync = self.is_sync_needed(site_id) need_action = need_restart or need_sync # Activation checkbox table.cell("", css="buttons") if can_activate_all and need_action: html.checkbox("site_%s" % site_id, cssclass="site_checkbox") # Iconbuttons table.cell(_("Actions"), css="buttons") if config.user.may("wato.sites"): edit_url = watolib.folder_preserving_link([ ("mode", "edit_site"), ("edit", site_id) ]) html.icon_button(edit_url, _("Edit the properties of this site"), "edit") # State if can_activate_all and need_sync: html.icon_button( url="javascript:void(0)", id_="activate_%s" % site_id, cssclass="activate_site", title= _("This site is not update and needs a replication. Start it now." ), icon="need_replicate", onclick= "cmk.activation.activate_changes(\"site\", \"%s\")" % site_id) if can_activate_all and need_restart: html.icon_button( url="javascript:void(0)", id_="activate_%s" % site_id, cssclass="activate_site", title= _("This site needs a restart for activating the changes. Start it now." ), icon="need_restart", onclick= "cmk.activation.activate_changes(\"site\", \"%s\")" % site_id) if can_activate_all and not need_action: html.icon(_("This site is up-to-date."), "siteuptodate") site_url = site.get("multisiteurl") if site_url: html.icon_button( site_url, _("Open this site's local web user interface"), "url", target="_blank") table.text_cell(_("Site"), site.get("alias", site_id)) # Livestatus table.cell(_("Status"), css="narrow nobr") html.status_label(content=status, status=status, title=_("This site is %s") % status) # Livestatus-/Check_MK-Version table.cell(_("Version"), site_status.get("livestatus_version", ""), css="narrow nobr") table.cell(_("Changes"), "%d" % len(self._changes_of_site(site_id)), css="number narrow nobr") table.cell(_("Progress"), css="repprogress") html.open_div(id_="site_%s_status" % site_id, class_=["msg"]) html.close_div() html.open_div(id_="site_%s_progress" % site_id, class_=["progress"]) html.close_div() # Hidden on initial rendering and shown on activation start table.cell(_("Details"), css="details") html.open_div(id_="site_%s_details" % site_id) # Shown on initial rendering and hidden on activation start table.cell(_("Last result"), css="last_result") last_state = self._last_activation_state(site_id) if not is_logged_in: html.write_text(_("Is not logged in.") + " ") if not last_state: html.write_text(_("Has never been activated")) else: html.write_text("%s: %s. " % (_("State"), last_state["_status_text"])) if last_state["_status_details"]: html.write(last_state["_status_details"])
def _activation_status(self): with table_element("site-status", searchable=False, sortable=False, css="activation") as table: for site_id, site in sort_sites(activation_sites()): table.row() site_status, status = self._get_site_status(site_id, site) is_online = self._site_is_online(status) is_logged_in = self._site_is_logged_in(site_id, site) has_foreign = self._site_has_foreign_changes(site_id) can_activate_all = not has_foreign or user.may( "wato.activateforeign") # Disable actions for offline sites and not logged in sites if not is_online or not is_logged_in: can_activate_all = False need_restart = self._is_activate_needed(site_id) need_sync = self.is_sync_needed(site_id) need_action = need_restart or need_sync nr_changes = len(self._changes_of_site(site_id)) # Activation checkbox table.cell("", css="buttons") if can_activate_all and nr_changes: html.checkbox("site_%s" % site_id, need_action, cssclass="site_checkbox") # Iconbuttons table.cell(_("Actions"), css="buttons") if user.may("wato.sites"): edit_url = watolib.folder_preserving_link([ ("mode", "edit_site"), ("site", site_id) ]) html.icon_button(edit_url, _("Edit the properties of this site"), "edit") # State if can_activate_all and need_sync: html.icon_button( url="javascript:void(0)", id_="activate_%s" % site_id, cssclass="activate_site", title= _("This site is not update and needs a replication. Start it now." ), icon="need_replicate", onclick='cmk.activation.activate_changes("site", "%s")' % site_id, ) if can_activate_all and need_restart: html.icon_button( url="javascript:void(0)", id_="activate_%s" % site_id, cssclass="activate_site", title= _("This site needs a restart for activating the changes. Start it now." ), icon="need_restart", onclick='cmk.activation.activate_changes("site", "%s")' % site_id, ) if can_activate_all and not need_action: html.icon("siteuptodate", _("This site is up-to-date.")) site_url = site.get("multisiteurl") if site_url: html.icon_button( site_url, _("Open this site's local web user interface"), "url", target="_blank", ) table.cell(_("Site"), site.get("alias", site_id), css="narrow nobr") # Livestatus table.cell(_("Status"), css="narrow nobr") html.status_label(content=status, status=status, title=_("This site is %s") % status) # Livestatus-/Checkmk-Version table.cell(_("Version"), site_status.get("livestatus_version", ""), css="narrow nobr") table.cell(_("Changes"), "%d" % nr_changes, css="number narrow nobr") table.cell(_("Progress"), css="repprogress") html.open_div(id_="site_%s_status" % site_id, class_=["msg"]) html.close_div() html.open_div(id_="site_%s_progress" % site_id, class_=["progress"]) html.close_div() table.cell(_("Details"), css="details") html.open_div(id_="site_%s_details" % site_id) last_state = self._last_activation_state(site_id) if not is_logged_in: html.write_text(_("Is not logged in.") + " ") if not last_state: html.write_text(_("Has never been activated")) elif (need_action and last_state["_state"] == cmk.gui.watolib.activate_changes.STATE_SUCCESS): html.write_text(_("Activation needed")) else: html.javascript( "cmk.activation.update_site_activation_state(%s);" % json.dumps(last_state)) html.close_div()