From db36b18ff8f7e9cf17147739ea9fce6cd0d73be2 Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Sat, 19 Dec 2020 09:08:53 +0100 Subject: [PATCH] more config options: configurable font size, ssl verification --- node.json | 70 +++++++++++++++++++++++++++++++++++++++++++------------ node.lua | 44 +++++++++++++++++----------------- service | 4 ++-- 3 files changed, 80 insertions(+), 38 deletions(-) diff --git a/node.json b/node.json index b4e185e..95e7de8 100644 --- a/node.json +++ b/node.json @@ -4,6 +4,9 @@ "network": "Needs to connect to icinga2 api" }, "options": [{ + "title": "Display Options", + "type": "section" + }, { "title": "Background color", "ui_width": 4, "name": "background_color", @@ -15,18 +18,68 @@ "name": "font", "type": "font", "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", - "ui_width": 6, + "ui_width": 5, "name": "api_user", "type": "string", "default": "readonly" }, { "title": "icinga2 API password", - "ui_width": 6, + "ui_width": 5, "name": "api_password", "type": "string", "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", "ui_width": 12, @@ -41,18 +94,5 @@ "type": "string", "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!" - }, { - "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°"] - ] }] } diff --git a/node.lua b/node.lua index f6a41a2..70f8e2a 100644 --- a/node.lua +++ b/node.lua @@ -2,8 +2,6 @@ util.init_hosted() local json = require "json" local services = {} -local host_width = 0 -local time_width = 0 local rotate_before = nil local transform = nil @@ -28,13 +26,6 @@ gl.setup(NATIVE_WIDTH, NATIVE_HEIGHT) util.file_watch("services.json", function(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) local white = resource.create_colored_texture(1,1,1,1) @@ -54,20 +45,31 @@ function node.render() end end + local time_width = CONFIG.font:width(services.prettytime, CONFIG.output_size) + local host_width = 0 + transform() 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 + host_width = math.max(host_width, CONFIG.font:width(service.host, CONFIG.header_size)) + end + + local y = CONFIG.output_size*2 for idx, serv in ipairs(services.services) do - my_height = (#serv.output*40)+90 - my_font_size = 50 + 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, my_font_size) > real_width/2 do - my_font_size = my_font_size - 2 + 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) + indent = math.min(host_width, real_width/2)+40 if serv.type == 0 then c_soft[serv.state]:draw(0, y, NATIVE_WIDTH, y+my_height) @@ -77,17 +79,17 @@ function node.render() 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(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(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, 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 --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 - 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 + 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+CONFIG.output_size*1.5 end y = y+12 diff --git a/service b/service index f05e99d..243cc47 100755 --- a/service +++ b/service @@ -38,8 +38,8 @@ def regenerate(): try: broken_hosts = set() - hosts = requests.get(CONFIG["url_hosts"], auth=(CONFIG["api_user"], CONFIG["api_password"]), verify=False).json() - serv = requests.get(CONFIG["url_services"], 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=CONFIG["ssl_verify"]).json() if 'results' not in hosts: raise KeyError('API call for hosts did not return any results')