more config options: configurable font size, ssl verification

This commit is contained in:
Franzi 2020-12-19 09:08:53 +01:00
parent 6d65637676
commit db36b18ff8
Signed by: kunsi
GPG key ID: 12E3D2136B818350
3 changed files with 80 additions and 38 deletions

View file

@ -4,6 +4,9 @@
"network": "Needs to connect to icinga2 api" "network": "Needs to connect to icinga2 api"
}, },
"options": [{ "options": [{
"title": "Display Options",
"type": "section"
}, {
"title": "Background color", "title": "Background color",
"ui_width": 4, "ui_width": 4,
"name": "background_color", "name": "background_color",
@ -15,18 +18,68 @@
"name": "font", "name": "font",
"type": "font", "type": "font",
"default": "silkscreen.ttf" "default": "silkscreen.ttf"
}, {
"title": "Screen Rotation",
"ui_width": 4,
"name": "rotate",
"type": "select",
"default": 0,
"hint": "Rotation of screen (clockwise)",
"options": [
[0, "0°"],
[90, "90°"],
[180, "180°"],
[270, "270°"]
]
}, {
"title": "Font Size (Headings)",
"ui_width": 4,
"name": "header_size",
"type": "select",
"default": 50,
"hint": "Font size of Host and Service name. Will be reduced to half screen width, if needed.",
"options": [
[20, "20px"],
[30, "30px"],
[40, "40px"],
[50, "50px"],
[60, "60px"]
]
}, {
"title": "Font Size (Output)",
"ui_width": 4,
"name": "output_size",
"type": "select",
"default": 30,
"hint": "Font size of Check Output.",
"options": [
[10, "10px"],
[20, "20px"],
[30, "30px"],
[40, "40px"]
]
}, {
"title": "Connection to icinga2",
"type": "section"
}, { }, {
"title": "icinga2 API user", "title": "icinga2 API user",
"ui_width": 6, "ui_width": 5,
"name": "api_user", "name": "api_user",
"type": "string", "type": "string",
"default": "readonly" "default": "readonly"
}, { }, {
"title": "icinga2 API password", "title": "icinga2 API password",
"ui_width": 6, "ui_width": 5,
"name": "api_password", "name": "api_password",
"type": "string", "type": "string",
"default": "really_secure" "default": "really_secure"
}, {
"title": "Verify Certs",
"ui_width": 2,
"name": "ssl_verify",
"type": "boolean",
"default": true,
"hint": "Verify SSL certificates when doing requests to icinga2?"
}, { }, {
"title": "icinga2 API URL for hosts", "title": "icinga2 API URL for hosts",
"ui_width": 12, "ui_width": 12,
@ -41,18 +94,5 @@
"type": "string", "type": "string",
"default": "https://icinga2/api/v1/objects/services?filter=service.state!=ServiceOK", "default": "https://icinga2/api/v1/objects/services?filter=service.state!=ServiceOK",
"hint": "Full URL to the API endpoint which returns a list of monitored services. Keeping the filter is strongly recommended!" "hint": "Full URL to the API endpoint which returns a list of monitored services. Keeping the filter is strongly recommended!"
}, {
"title": "Screen Rotation",
"ui_width": 4,
"name": "rotate",
"type": "select",
"default": 0,
"hint": "Rotation of screen (clockwise)",
"options": [
[0, "0°"],
[90, "90°"],
[180, "180°"],
[270, "270°"]
]
}] }]
} }

View file

@ -2,8 +2,6 @@ util.init_hosted()
local json = require "json" local json = require "json"
local services = {} local services = {}
local host_width = 0
local time_width = 0
local rotate_before = nil local rotate_before = nil
local transform = nil local transform = nil
@ -28,13 +26,6 @@ gl.setup(NATIVE_WIDTH, NATIVE_HEIGHT)
util.file_watch("services.json", function(content) util.file_watch("services.json", function(content)
services = json.decode(content) services = json.decode(content)
host_width = 0
for idx, service in ipairs(services.services) do
host_width = math.max(host_width, CONFIG.font:width(service.host, 50))
end
time_width = CONFIG.font:width(services.prettytime, 30)
end) end)
local white = resource.create_colored_texture(1,1,1,1) local white = resource.create_colored_texture(1,1,1,1)
@ -54,20 +45,31 @@ function node.render()
end end
end end
local time_width = CONFIG.font:width(services.prettytime, CONFIG.output_size)
local host_width = 0
transform() transform()
CONFIG.background_color.clear() CONFIG.background_color.clear()
CONFIG.font:write(real_width/2-time_width/2, 10, services.prettytime, 30, 1,1,1,1) CONFIG.font:write(real_width/2-time_width/2, CONFIG.output_size*0.5, services.prettytime, CONFIG.output_size, 1,1,1,1)
local y = 50 for idx, service in ipairs(services.services) do
for idx, serv in ipairs(services.services) do host_width = math.max(host_width, CONFIG.font:width(service.host, CONFIG.header_size))
my_height = (#serv.output*40)+90
my_font_size = 50
while CONFIG.font:width(serv.host, my_font_size) > real_width/2 do
my_font_size = my_font_size - 2
end end
indent = math.min(host_width, real_width/2) local y = CONFIG.output_size*2
for idx, serv in ipairs(services.services) do
my_height = (#serv.output*CONFIG.output_size*1.5)+40+CONFIG.header_size
host_size = CONFIG.header_size
svc_size = CONFIG.header_size
while CONFIG.font:width(serv.host, host_size) > real_width/2-20 do
host_size = host_size - 2
end
while CONFIG.font:width(serv.service, svc_size) > real_width/2-50 do
svc_size = svc_size - 2
end
indent = math.min(host_width, real_width/2)+40
if serv.type == 0 then if serv.type == 0 then
c_soft[serv.state]:draw(0, y, NATIVE_WIDTH, y+my_height) c_soft[serv.state]:draw(0, y, NATIVE_WIDTH, y+my_height)
@ -77,17 +79,17 @@ function node.render()
y = y+20 y = y+20
CONFIG.font:write(10, y, serv.host, my_font_size, c_text[serv.state][1],c_text[serv.state][2],c_text[serv.state][2],1) CONFIG.font:write(10, y, serv.host, host_size, c_text[serv.state][1],c_text[serv.state][2],c_text[serv.state][2],1)
CONFIG.font:write(indent+40, y, serv.service, 50, c_text[serv.state][1],c_text[serv.state][2],c_text[serv.state][3],1) CONFIG.font:write(indent, y, serv.service, svc_size, c_text[serv.state][1],c_text[serv.state][2],c_text[serv.state][3],1)
y = y+60 y = y+CONFIG.header_size+10
--debug output --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) --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, y, line, CONFIG.output_size, c_text[serv.state][1],c_text[serv.state][2],c_text[serv.state][3],1)
y = y+40 y = y+CONFIG.output_size*1.5
end end
y = y+12 y = y+12

View file

@ -38,8 +38,8 @@ def regenerate():
try: try:
broken_hosts = set() broken_hosts = set()
hosts = requests.get(CONFIG["url_hosts"], auth=(CONFIG["api_user"], CONFIG["api_password"]), verify=False).json() hosts = requests.get(CONFIG["url_hosts"], auth=(CONFIG["api_user"], CONFIG["api_password"]), verify=CONFIG["ssl_verify"]).json()
serv = requests.get(CONFIG["url_services"], auth=(CONFIG["api_user"], CONFIG["api_password"]), verify=False).json() serv = requests.get(CONFIG["url_services"], auth=(CONFIG["api_user"], CONFIG["api_password"]), verify=CONFIG["ssl_verify"]).json()
if 'results' not in hosts: if 'results' not in hosts:
raise KeyError('API call for hosts did not return any results') raise KeyError('API call for hosts did not return any results')