show icon instead of [ACK] for acknowledged lines

This commit is contained in:
Franziska Kunsmann 2024-02-13 09:26:30 +01:00
parent 72d6b961d2
commit 5f0d718301
3 changed files with 33 additions and 25 deletions

BIN
ack.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -4,6 +4,7 @@ local json = require "json"
local services = {}
local rotate_before = nil
local transform = nil
local ack_image = resource.load_image("ack.png")
local c_hard = {}
c_hard[0] = resource.create_colored_texture(0, 0.666, 0, 1)
@ -68,6 +69,10 @@ function node.render()
local service_width = CONFIG.header_font:width(serv.service, service_font_size)
local my_height = (#serv.output*CONFIG.output_size*1.5) + margin*3
if serv.ack then
header_width = header_width - margin - host_font_size
end
if host_width + service_width > header_width then
-- two-line output, if possible
while CONFIG.header_font:width(serv.host, host_font_size) > header_width do
@ -89,15 +94,21 @@ function node.render()
y = y + margin
service_x = real_width - margin - CONFIG.header_font:width(serv.service, service_font_size)
local service_x = real_width - margin - CONFIG.header_font:width(serv.service, service_font_size)
local host_x = margin
if serv.ack then
ack_image:draw(host_x, y, host_x + host_font_size, y + host_font_size)
host_x = host_x + host_font_size + margin
end
if host_width + service_width > header_width then
CONFIG.header_font:write(margin, y, serv.host, host_font_size, c_text[serv.state][1],c_text[serv.state][2],c_text[serv.state][2],1)
CONFIG.header_font:write(host_x, y, serv.host, host_font_size, c_text[serv.state][1],c_text[serv.state][2],c_text[serv.state][2],1)
y = y + host_font_size + margin
CONFIG.header_font:write(service_x, y, serv.service, service_font_size, c_text[serv.state][1],c_text[serv.state][2],c_text[serv.state][3],1)
y = y + service_font_size + margin
else
CONFIG.header_font:write(margin, y, serv.host, host_font_size, c_text[serv.state][1],c_text[serv.state][2],c_text[serv.state][2],1)
CONFIG.header_font:write(host_x, y, serv.host, host_font_size, c_text[serv.state][1],c_text[serv.state][2],c_text[serv.state][2],1)
CONFIG.header_font:write(service_x, y, serv.service, service_font_size, c_text[serv.state][1],c_text[serv.state][2],c_text[serv.state][3],1)
y = y + CONFIG.header_size + margin
end

41
service
View file

@ -73,27 +73,25 @@ def regenerate():
if host['attrs']['problem']:
broken_hosts.add(host['attrs']['display_name'])
if host['attrs']['downtime_depth'] > 0:
if (
host['attrs']['downtime_depth'] > 0
or (
host['attrs']['acknowledgement'] > 0
and not CONFIG['show_ack']
)
):
continue
if host['attrs']['acknowledgement'] > 0:
if not CONFIG['show_ack']:
continue
ack = '[ACK] '
else:
ack = ''
if not CONFIG['show_soft'] and int(host['attrs']['state_type']) == 0:
continue
services['services'].append({
'host': ack + host['attrs']['display_name'],
'host': host['attrs']['display_name'],
'service': '-- HOST --',
'state': 2,
'type': int(host['attrs']['state_type']),
'output': limit_output_lines(host['attrs']['last_check_result']['output'].splitlines(), 3),
'ack': ack,
'ack': bool(host['attrs']['acknowledgement'] > 0),
'sort': '{}{}{}{}'.format(
int(host['attrs']['state_type'])*-1,
SORT_ORDER[2],
@ -104,27 +102,26 @@ def regenerate():
for svc in serv['results']:
if svc['attrs']['problem']:
if svc['attrs']['downtime_depth'] > 0 or svc['attrs']['host_name'] in broken_hosts:
if (
svc['attrs']['host_name'] in broken_hosts
or svc['attrs']['downtime_depth'] > 0
or (
svc['attrs']['acknowledgement'] > 0
and not CONFIG['show_ack']
)
):
continue
if svc['attrs']['acknowledgement'] > 0:
if not CONFIG['show_ack']:
continue
ack = ' [ACK]'
else:
ack = ''
if not CONFIG['show_soft'] and int(svc['attrs']['state_type']) == 0:
continue
services['services'].append({
'host': svc['attrs']['host_name'],
'service': svc['attrs']['display_name'] + ack,
'service': svc['attrs']['display_name'],
'state': int(svc['attrs']['state']),
'type': int(svc['attrs']['state_type']),
'output': limit_output_lines(svc['attrs']['last_check_result']['output'].splitlines()),
'ack': ack,
'ack': bool(svc['attrs']['acknowledgement'] > 0),
'sort': '{}{}{}{}'.format(
int(svc['attrs']['state_type'])*-1,
SORT_ORDER[int(svc['attrs']['state'])],