X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FConfig%2FNix.git;a=blobdiff_plain;f=modules%2Fprivate%2Fmonitoring%2Fstatus%2Fapp.py;fp=modules%2Fprivate%2Fmonitoring%2Fstatus%2Fapp.py;h=ff928914c6d681f15769ea81dd2cfbd95b59b662;hp=b1d419cc1cc88909a265dca4d293a1337a235b9e;hb=2edbb2d889bd9d1787bc1745a75c1b6969d148ab;hpb=b4b5eadc29d2547e181ce60d735a4b943beb2a9a diff --git a/modules/private/monitoring/status/app.py b/modules/private/monitoring/status/app.py index b1d419c..ff92891 100755 --- a/modules/private/monitoring/status/app.py +++ b/modules/private/monitoring/status/app.py @@ -55,33 +55,34 @@ def get_lq(request): return b"".join(chunks).decode() class Host: - def __init__(self, name, alias, status, webname): + def __init__(self, name, alias, status, webname, vhost): self.name = name self.alias = alias self.webname = webname or alias + self.vhost = vhost self.status = status self.services = [] @classmethod - def parse_hosts(cls, payload): - parsed = [cls.parse(p) for p in json.loads(payload)] + def parse_hosts(cls, payload, vhost): + parsed = filter(lambda x: x.vhost == vhost, [cls.parse(p) for p in json.loads(payload)]) return {p.name: p for p in parsed} @classmethod def parse(cls, payload): - return cls(payload[0], payload[1], HOST_STATUS[payload[2]], payload[3].get("WEBSTATUS_NAME")) + return cls(payload[0], payload[1], HOST_STATUS[payload[2]], payload[3].get("WEBSTATUS_NAME"), payload[3].get("WEBSTATUS_VHOST")) def __repr__(self): return "Host {}: {} ({})".format(self.name, self.alias, self.webname) @classmethod - def query(cls): + def query(cls, vhost): answer = get_lq("""GET hosts Filter: groups >= webstatus-hosts Columns: name alias state custom_variables OutputFormat: json """) - return cls.parse_hosts(answer) + return cls.parse_hosts(answer, vhost) def fill_services(self, services): self.services = [service for service in services if service.host == self.name] @@ -110,8 +111,8 @@ OutputFormat: json """) return cls.parse_groups(answer) - def fill_services(self, services): - self.services = [service for service in services if any([group == self.name for group in service.groups])] + def fill_services(self, services, hosts): + self.services = [service for service in services if any([group == self.name for group in service.groups]) and service.host in hosts] def __repr__(self): return "ServiceGroup {}: {}".format(self.name, self.alias) @@ -158,15 +159,15 @@ OutputFormat: json def __repr__(self): return "Service {}: {}".format(self.name, self.webname) -def get_infos(): - hosts = Host.query() +def get_infos(vhost): + hosts = Host.query(vhost) servicegroups = ServiceGroup.query() services = Service.query() for host in hosts: hosts[host].fill_services(services) for group in servicegroups: - servicegroups[group].fill_services(services) + servicegroups[group].fill_services(services, hosts) return (hosts, servicegroups, services) TEMPLATE=''' @@ -254,12 +255,14 @@ TEMPLATE=''' {% endfor %} {%- endfor %} + {%- for group in servicegroups.values() if group.services and group.name != "webstatus-resources" %} + {%- if loop.first %}

Services

- {%- for group in servicegroups.values() if group.services and group.name != "webstatus-resources" %} + {%- endif %}

{{ group.alias }}

- {%- for service in group.services -%} + {%- for service in group.services if service.host in hosts -%} {%- if loop.first %}
- {%- endfor %} + {%- if loop.last %}
+ {% endif %} + {%- endfor %} ''' @@ -307,7 +312,7 @@ def live(): @app.route("/", methods=["GET"]) def get(): - (hosts, servicegroups, services) = get_infos() + (hosts, servicegroups, services) = get_infos(request.host) resp = make_response(render_template_string(TEMPLATE, hosts=hosts, servicegroups=servicegroups)) resp.content_type = "text/html" return resp