aboutsummaryrefslogtreecommitdiff
path: root/modules/private/monitoring/status/app.py
diff options
context:
space:
mode:
Diffstat (limited to 'modules/private/monitoring/status/app.py')
-rwxr-xr-xmodules/private/monitoring/status/app.py35
1 files changed, 20 insertions, 15 deletions
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):
55 return b"".join(chunks).decode() 55 return b"".join(chunks).decode()
56 56
57class Host: 57class Host:
58 def __init__(self, name, alias, status, webname): 58 def __init__(self, name, alias, status, webname, vhost):
59 self.name = name 59 self.name = name
60 self.alias = alias 60 self.alias = alias
61 self.webname = webname or alias 61 self.webname = webname or alias
62 self.vhost = vhost
62 self.status = status 63 self.status = status
63 self.services = [] 64 self.services = []
64 65
65 @classmethod 66 @classmethod
66 def parse_hosts(cls, payload): 67 def parse_hosts(cls, payload, vhost):
67 parsed = [cls.parse(p) for p in json.loads(payload)] 68 parsed = filter(lambda x: x.vhost == vhost, [cls.parse(p) for p in json.loads(payload)])
68 return {p.name: p for p in parsed} 69 return {p.name: p for p in parsed}
69 70
70 @classmethod 71 @classmethod
71 def parse(cls, payload): 72 def parse(cls, payload):
72 return cls(payload[0], payload[1], HOST_STATUS[payload[2]], payload[3].get("WEBSTATUS_NAME")) 73 return cls(payload[0], payload[1], HOST_STATUS[payload[2]], payload[3].get("WEBSTATUS_NAME"), payload[3].get("WEBSTATUS_VHOST"))
73 74
74 def __repr__(self): 75 def __repr__(self):
75 return "Host {}: {} ({})".format(self.name, self.alias, self.webname) 76 return "Host {}: {} ({})".format(self.name, self.alias, self.webname)
76 77
77 @classmethod 78 @classmethod
78 def query(cls): 79 def query(cls, vhost):
79 answer = get_lq("""GET hosts 80 answer = get_lq("""GET hosts
80Filter: groups >= webstatus-hosts 81Filter: groups >= webstatus-hosts
81Columns: name alias state custom_variables 82Columns: name alias state custom_variables
82OutputFormat: json 83OutputFormat: json
83""") 84""")
84 return cls.parse_hosts(answer) 85 return cls.parse_hosts(answer, vhost)
85 86
86 def fill_services(self, services): 87 def fill_services(self, services):
87 self.services = [service for service in services if service.host == self.name] 88 self.services = [service for service in services if service.host == self.name]
@@ -110,8 +111,8 @@ OutputFormat: json
110""") 111""")
111 return cls.parse_groups(answer) 112 return cls.parse_groups(answer)
112 113
113 def fill_services(self, services): 114 def fill_services(self, services, hosts):
114 self.services = [service for service in services if any([group == self.name for group in service.groups])] 115 self.services = [service for service in services if any([group == self.name for group in service.groups]) and service.host in hosts]
115 116
116 def __repr__(self): 117 def __repr__(self):
117 return "ServiceGroup {}: {}".format(self.name, self.alias) 118 return "ServiceGroup {}: {}".format(self.name, self.alias)
@@ -158,15 +159,15 @@ OutputFormat: json
158 def __repr__(self): 159 def __repr__(self):
159 return "Service {}: {}".format(self.name, self.webname) 160 return "Service {}: {}".format(self.name, self.webname)
160 161
161def get_infos(): 162def get_infos(vhost):
162 hosts = Host.query() 163 hosts = Host.query(vhost)
163 servicegroups = ServiceGroup.query() 164 servicegroups = ServiceGroup.query()
164 services = Service.query() 165 services = Service.query()
165 166
166 for host in hosts: 167 for host in hosts:
167 hosts[host].fill_services(services) 168 hosts[host].fill_services(services)
168 for group in servicegroups: 169 for group in servicegroups:
169 servicegroups[group].fill_services(services) 170 servicegroups[group].fill_services(services, hosts)
170 return (hosts, servicegroups, services) 171 return (hosts, servicegroups, services)
171 172
172TEMPLATE='''<?xml version="1.0" encoding="UTF-8"?> 173TEMPLATE='''<?xml version="1.0" encoding="UTF-8"?>
@@ -254,12 +255,14 @@ TEMPLATE='''<?xml version="1.0" encoding="UTF-8"?>
254 {% endfor %} 255 {% endfor %}
255 {%- endfor %} 256 {%- endfor %}
256 257
258 {%- for group in servicegroups.values() if group.services and group.name != "webstatus-resources" %}
259 {%- if loop.first %}
257 <h2>Services</h2> 260 <h2>Services</h2>
258 <div id="services"> 261 <div id="services">
259 {%- for group in servicegroups.values() if group.services and group.name != "webstatus-resources" %} 262 {%- endif %}
260 <div class="servicegroup"> 263 <div class="servicegroup">
261 <h3 class="servicegroup_title">{{ group.alias }}</h3> 264 <h3 class="servicegroup_title">{{ group.alias }}</h3>
262 {%- for service in group.services -%} 265 {%- for service in group.services if service.host in hosts -%}
263 {%- if loop.first %} 266 {%- if loop.first %}
264 <ul class="services"> 267 <ul class="services">
265 {% endif %} 268 {% endif %}
@@ -281,8 +284,10 @@ TEMPLATE='''<?xml version="1.0" encoding="UTF-8"?>
281 {% endif %} 284 {% endif %}
282 {%- endfor -%} 285 {%- endfor -%}
283 </div> 286 </div>
284 {%- endfor %} 287 {%- if loop.last %}
285 </div> 288 </div>
289 {% endif %}
290 {%- endfor %}
286 </body> 291 </body>
287</html> 292</html>
288''' 293'''
@@ -307,7 +312,7 @@ def live():
307 312
308@app.route("/", methods=["GET"]) 313@app.route("/", methods=["GET"])
309def get(): 314def get():
310 (hosts, servicegroups, services) = get_infos() 315 (hosts, servicegroups, services) = get_infos(request.host)
311 resp = make_response(render_template_string(TEMPLATE, hosts=hosts, servicegroups=servicegroups)) 316 resp = make_response(render_template_string(TEMPLATE, hosts=hosts, servicegroups=servicegroups))
312 resp.content_type = "text/html" 317 resp.content_type = "text/html"
313 return resp 318 return resp