fix sorting (should be CRITICAL, UNKNOWN, WARNING)
This commit is contained in:
parent
07c733e4d0
commit
4d8812e657
2 changed files with 26 additions and 6 deletions
3
node.lua
3
node.lua
|
@ -82,6 +82,9 @@ function node.render()
|
||||||
|
|
||||||
y = y+60
|
y = y+60
|
||||||
|
|
||||||
|
--debug output
|
||||||
|
--CONFIG.font:write(10, y, serv.sort, 10, c_text[serv.state][1],c_text[serv.state][2],c_text[serv.state][2],1)
|
||||||
|
|
||||||
for idx, line in ipairs(serv.output) do
|
for idx, line in ipairs(serv.output) do
|
||||||
CONFIG.font:write(indent+40, y, line, 30, c_text[serv.state][1],c_text[serv.state][2],c_text[serv.state][3],1)
|
CONFIG.font:write(indent+40, y, line, 30, c_text[serv.state][1],c_text[serv.state][2],c_text[serv.state][3],1)
|
||||||
y = y+40
|
y = y+40
|
||||||
|
|
29
service
29
service
|
@ -13,6 +13,8 @@ from hosted import CONFIG, NODE
|
||||||
|
|
||||||
CONFIG.restart_on_update()
|
CONFIG.restart_on_update()
|
||||||
|
|
||||||
|
SORT_ORDER = [0, 1, 3, 2]
|
||||||
|
|
||||||
def current_time():
|
def current_time():
|
||||||
timezone = pytz.timezone("Europe/Berlin")
|
timezone = pytz.timezone("Europe/Berlin")
|
||||||
now = datetime.utcnow()
|
now = datetime.utcnow()
|
||||||
|
@ -51,8 +53,14 @@ def regenerate():
|
||||||
'host': host['attrs']['display_name'],
|
'host': host['attrs']['display_name'],
|
||||||
'service': '-- HOST --',
|
'service': '-- HOST --',
|
||||||
'state': 2,
|
'state': 2,
|
||||||
'type': host['attrs']['state_type'],
|
'type': int(host['attrs']['state_type']),
|
||||||
'output': host['attrs']['last_check_result']['output'].splitlines(),
|
'output': host['attrs']['last_check_result']['output'].splitlines(),
|
||||||
|
'sort': '{}{}{}{}'.format(
|
||||||
|
int(host['attrs']['state_type']),
|
||||||
|
SORT_ORDER[2],
|
||||||
|
host['attrs']['display_name'],
|
||||||
|
'--',
|
||||||
|
),
|
||||||
})
|
})
|
||||||
|
|
||||||
for svc in serv['results']:
|
for svc in serv['results']:
|
||||||
|
@ -63,19 +71,24 @@ def regenerate():
|
||||||
services['services'].append({
|
services['services'].append({
|
||||||
'host': svc['attrs']['host_name'],
|
'host': svc['attrs']['host_name'],
|
||||||
'service': svc['attrs']['display_name'],
|
'service': svc['attrs']['display_name'],
|
||||||
'state': svc['attrs']['state'],
|
'state': int(svc['attrs']['state']),
|
||||||
'type': svc['attrs']['state_type'],
|
'type': int(svc['attrs']['state_type']),
|
||||||
'output': svc['attrs']['last_check_result']['output'].splitlines(),
|
'output': svc['attrs']['last_check_result']['output'].splitlines(),
|
||||||
|
'sort': '{}{}{}{}'.format(
|
||||||
|
int(svc['attrs']['state_type']),
|
||||||
|
SORT_ORDER[int(svc['attrs']['state'])],
|
||||||
|
svc['attrs']['host_name'],
|
||||||
|
svc['attrs']['display_name'],
|
||||||
|
),
|
||||||
})
|
})
|
||||||
|
|
||||||
services['services'].sort(key=lambda x: str(x['type'])+str(x['state'])+x['host']+x['service'])
|
|
||||||
services['services'].reverse()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
services['services'].append({
|
services['services'].append({
|
||||||
'host': 'icinga2beamer',
|
'host': 'icinga2beamer',
|
||||||
'service': 'INTERNAL',
|
'service': 'INTERNAL',
|
||||||
'state': 2,
|
'state': 2,
|
||||||
|
'type': 1,
|
||||||
'output': [repr(e)],
|
'output': [repr(e)],
|
||||||
|
'sort': 1000,
|
||||||
})
|
})
|
||||||
|
|
||||||
if len(services['services']) == 0:
|
if len(services['services']) == 0:
|
||||||
|
@ -83,9 +96,13 @@ def regenerate():
|
||||||
'host': '',
|
'host': '',
|
||||||
'service': 'icinga2',
|
'service': 'icinga2',
|
||||||
'state': 0,
|
'state': 0,
|
||||||
|
'type': 1,
|
||||||
'output': ['Everything is fine. Go get some coffee.'],
|
'output': ['Everything is fine. Go get some coffee.'],
|
||||||
|
'sort': 1000,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
services['services'].sort(key=lambda x: x['sort'], reverse=True)
|
||||||
|
|
||||||
with file("services.json", "wb") as f:
|
with file("services.json", "wb") as f:
|
||||||
f.write(json.dumps(services, ensure_ascii=False).encode("utf8"))
|
f.write(json.dumps(services, ensure_ascii=False).encode("utf8"))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue