def _collect_sites_data(cls) -> List[ABCElement]: sites.update_site_states_from_dead_sites() site_states = sites.states() site_state_titles = sites.site_state_titles() site_stats = cls._get_site_stats() elements: List[ABCElement] = [] for site_id, _sitealias in config.sorted_sites(): site_spec = config.site(site_id) site_status = site_states.get(site_id, sites.SiteStatus({})) state: Optional[str] = site_status.get("state") if state is None: state = "missing" if state != "online": elements.append( IconElement( title=site_spec["alias"], css_class="site_%s" % state, tooltip=site_state_titles[state], )) continue stats = site_stats[site_id] parts = [] total = 0 for title, css_class, count in [ (_("hosts are down or have critical services"), "critical", stats.hosts_down_or_have_critical), (_("hosts are unreachable or have unknown services"), "unknown", stats.hosts_unreachable_or_have_unknown), (_("hosts are up but have services in warning state"), "warning", stats.hosts_up_and_have_warning), (_("hosts are in scheduled downtime"), "downtime", stats.hosts_in_downtime), (_("hosts are up and have no service problems"), "ok", stats.hosts_up_without_problem), ]: parts.append(Part(title=title, css_class=css_class, count=count)) total += count total_part = Part(title=_("Total number of hosts"), css_class="", count=total) elements.append( SiteElement( title=site_spec["alias"], url_add_vars={ "name": "site", "site": site_id, }, parts=parts, total=total_part, tooltip=cls._render_tooltip(site_spec["alias"], parts, total_part), )) #return elements + cls._test_elements() return elements
def show(self) -> None: html.open_table(cellspacing="0", class_="sitestate") sites.update_site_states_from_dead_sites() for sitename, _sitealias in user_sites.sorted_sites(): site = site_config.get_site_config(sitename) state = sites.states().get(sitename, sites.SiteStatus({})).get("state") if state is None: state = "missing" switch = "missing" text = escape_to_html(sitename) else: if state == "disabled": switch = "on" text = escape_to_html(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 logfiles_of_host(site, host_name): if site: # Honor site hint if available sites.live().set_only_sites([site]) file_names = sites.live().query_value("GET hosts\n" "Columns: mk_logwatch_files\n" "Filter: name = %s\n" % livestatus.lqencode(host_name)) if site: # Honor site hint if available sites.live().set_only_sites(None) if file_names is None: # Not supported by that Livestatus version raise MKGeneralException( _("The monitoring core of the target site '%s' has the version '%s'. That " "does not support fetching logfile information. Please upgrade " "to a newer version.") % (site, sites.states().get(site, sites.SiteStatus({})).get("program_version", "???"))) return file_names
def _livestatus_get_last_program_start(self, site_id: SiteId) -> int: return sites.states().get(site_id, sites.SiteStatus({})).get( "program_start", 0)