예제 #1
0
    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
예제 #2
0
    def _test_elements(cls):
        test_sites = [
            (
                "Hamburg",
                "ham",
                (
                    240,  # critical hosts
                    111,  # hosts with unknowns
                    100,  # hosts with warnings
                    50,  # hosts in downtime
                    12335,  # OK
                )),
            ("München", "muc", (
                0,
                1,
                5,
                0,
                100,
            )),
            ("Darmstadt", "dar", (
                305,
                10,
                4445,
                0,
                108908,
            )),
            ("Berlin", "ber", (
                0,
                4500,
                0,
                6000,
                3101101,
            )),
            ("Essen", "ess", (
                40024,
                23,
                99299,
                60,
                2498284,
            )),
            ("Gutstadt", "gut", (
                0,
                0,
                0,
                0,
                668868,
            )),
            ("Schlechtstadt", "sch", (
                548284,
                0,
                0,
                0,
                0,
            )),
        ]
        elements: List[ABCElement] = []
        for site_name, site_id, states in test_sites:
            parts = []
            total = 0
            for title, css_class, count in zip([
                    "Critical hosts",
                    "Hosts with unknowns",
                    "Hosts with warnings",
                    "Hosts in downtime",
                    "OK/UP",
            ], ["critical", "unknown", "warning", "downtime", "ok"], states):
                parts.append(
                    Part(title=title, css_class=css_class, count=count))
                total += count

            total_part = Part(title="Total", css_class="", count=total)

            elements.append(
                SiteElement(
                    title=site_name,
                    url_add_vars={
                        "site": site_id,
                    },
                    parts=parts,
                    total=total_part,
                    tooltip=cls._render_tooltip(site_name, parts, total_part),
                ))

        for state, tooltip in sorted(sites.site_state_titles().items()):
            elements.append(
                IconElement(
                    title="Site: %s" % state,
                    css_class="site_%s" % state,
                    tooltip=tooltip,
                ))

        return elements