def show(self): # type: () -> None items = self._core_toggles() sites.update_site_states_from_dead_sites() site_status_info = {} # type: 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 config.sorted_sites(): if not config.is_single_local_site(): html.begin_foldable_container("master_control", site_id, True, site_alias) 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) finally: if not config.is_single_local_site(): html.end_foldable_container()
def _verify_slave_site_config(self, site_id): # type: (str) -> None if not site_id: raise MKGeneralException(_("Missing variable siteid")) our_id = config.omd_site() if not config.is_single_local_site(): raise MKGeneralException( _("Configuration error. You treat us as " "a <b>remote</b>, but we have an own distributed WATO configuration!" )) if our_id is not None and our_id != site_id: raise MKGeneralException( _("Site ID mismatch. Our ID is '%s', but you are saying we are '%s'." ) % (our_id, site_id)) # Make sure there are no local changes we would lose! changes = ActivateChanges() changes.load() pending = list(reversed(changes.grouped_changes())) if pending: message = _( "There are %d pending changes that would get lost. The most recent are: " ) % len(pending) message += ", ".join(change["text"] for _change_id, change in pending[:10]) raise MKGeneralException(message)
def generate_response_data(cls, properties, context, settings): if config.is_single_local_site(): site_id: Optional[SiteId] = config.omd_site() else: site_filter = context.get("site", {}).get("site") site_id = SiteId(site_filter) if site_filter else None render_mode = "hosts" if site_id else "sites" if render_mode == "hosts": assert site_id is not None elements = cls._collect_hosts_data(site_id) elif render_mode == "sites": elements = cls._collect_sites_data() else: raise NotImplementedError() return { # TODO: Get the correct dashlet title. This needs to use the general dashlet title # calculation. We somehow have to get the title from # cmk.gui.dashboard._render_dashlet_title. "title": _("Site overview"), "render_mode": render_mode, "plot_definitions": [], "data": [e.serialize() for e in elements], }
def generate_response_data(cls, properties, context, settings): if config.is_single_local_site(): site_id: Optional[SiteId] = config.omd_site() else: site_filter = context.get("site", {}).get("site") site_id = SiteId(site_filter) if site_filter else None render_mode = "hosts" if site_id else "sites" if render_mode == "hosts": assert site_id is not None elements = cls._collect_hosts_data(site_id) default_title = _("Host overview") elif render_mode == "sites": elements = cls._collect_sites_data() default_title = _("Site overview") else: raise NotImplementedError() return { # TODO: This should all be done inside the dashlet class once it is instantiated by the # ajax call "title": render_title_with_macros_string( context, settings["single_infos"], settings.get("title", default_title), default_title, ), "render_mode": render_mode, "plot_definitions": [], "data": [e.serialize() for e in elements], }
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 config.sorted_sites(): container: ContextManager[bool] = foldable_container( treename="master_control", id_=site_id, isopen=True, title=site_alias, icon="foldable_sidebar" ) if not config.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)
def show(self): items = [ ("enable_notifications", _("Notifications")), ("execute_service_checks", _("Service checks")), ("execute_host_checks", _("Host checks")), ("enable_flap_detection", _("Flap Detection")), ("enable_event_handlers", _("Event handlers")), ("process_performance_data", _("Performance data")), ("enable_event_handlers", _("Alert handlers")), ] sites.update_site_states_from_dead_sites() site_status_info = {} 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) def _render_master_control_site(site_id): site_state = sites.states().get(site_id) if site_state["state"] == "dead": html.show_error(site_state["exception"]) elif site_state["state"] == "disabled": html.show_message(_("Site is disabled")) elif site_state["state"] == "unknown": if site_state.get("exception"): html.show_error(site_state["exception"]) else: html.show_error(_("Site state is unknown")) else: is_cmc = site_state["program_version"].startswith("Check_MK ") try: site_info = site_status_info[site_id] except KeyError: site_info = None html.open_table(class_="master_control") for i, (colname, title) in enumerate(items): # Do not show event handlers on Check_MK Micro Core if is_cmc and title == _("Event handlers"): continue elif not is_cmc and title == _("Alert handlers"): continue colvalue = site_info[i] url = html.makeactionuri_contextless( [ ("site", site_id), ("switch", colname), ("state", "%d" % (1 - colvalue)), ], filename="switch_master_state.py") onclick = "cmk.ajax.get_url('%s', cmk.utils.update_contents, 'snapin_master_control')" % url html.open_tr() html.td(title, class_="left") html.open_td() html.toggle_switch( enabled=colvalue, help_txt=_("Switch '%s' to '%s'") % (title, _("off") if colvalue else _("on")), onclick=onclick, ) html.close_td() html.close_tr() html.close_table() for site_id, site_alias in config.sorted_sites(): if not config.is_single_local_site(): html.begin_foldable_container("master_control", site_id, True, site_alias) try: _render_master_control_site(site_id) except Exception as e: logger.exception("error rendering master control for site %s", site_id) write_snapin_exception(e) finally: if not config.is_single_local_site(): html.end_foldable_container()