comparison mod_http_host_status_check/mod_http_host_status_check.lua @ 6378:5a76973e4304

mod_http_host_status_check: Switch to prosody.util.time.now() to get the current time
author Link Mauve <linkmauve@linkmauve.fr>
date Fri, 30 Jan 2026 15:04:03 +0100
parents 85cf9a8b4020
children ba68b74ebfb8
comparison
equal deleted inserted replaced
6377:032445730eaa 6378:5a76973e4304
1 local heartbeats = module:shared("/*/host_status_check/heartbeats"); 1 local heartbeats = module:shared("/*/host_status_check/heartbeats");
2 local events = module:shared("/*/host_status_check/connection_events"); 2 local events = module:shared("/*/host_status_check/connection_events");
3 local host_status_ok = module:shared("host_status_ok"); 3 local host_status_ok = module:shared("host_status_ok");
4 4
5 local time = require "socket".gettime; 5 local time = require "prosody.util.time".now;
6 local template = require "util.interpolation".new("%b{}", function (s) return s end) 6 local template = require "util.interpolation".new("%b{}", function (s) return s end)
7 7
8 module:depends "http" 8 module:depends "http"
9 9
10 local threshold = module:get_option_number("status_check_heartbeat_threshold", 10); 10 local threshold = module:get_option_number("status_check_heartbeat_threshold", 10);
37 local all_ok = true; 37 local all_ok = true;
38 local failed_hosts = {}; 38 local failed_hosts = {};
39 39
40 for host in pairs(hosts) do 40 for host in pairs(hosts) do
41 local last_heartbeat_time = heartbeats[host]; 41 local last_heartbeat_time = heartbeats[host];
42 42
43 local ok, status_text = true; 43 local ok, status_text = true;
44 44
45 local is_component = hosts[host].type == "component" and hosts[host].modules.component; 45 local is_component = hosts[host].type == "component" and hosts[host].modules.component;
46 46
47 if is_component then 47 if is_component then
48 local current_status = hosts[host].modules.component.connected; 48 local current_status = hosts[host].modules.component.connected;
49 if events[host] then 49 if events[host] then
50 local tracked_status = events[host].connected; 50 local tracked_status = events[host].connected;
51 if tracked_status == current_status then 51 if tracked_status == current_status then
82 82
83 if not ok then 83 if not ok then
84 all_ok = false; 84 all_ok = false;
85 table.insert(failed_hosts, host); 85 table.insert(failed_hosts, host);
86 end 86 end
87 87
88 if not ok or is_component or last_heartbeat_time then 88 if not ok or is_component or last_heartbeat_time then
89 host_statuses[host] = string_pad(status_text, 20); 89 host_statuses[host] = string_pad(status_text, 20);
90 end 90 end
91 local last_ok = host_status_ok[host]; 91 local last_ok = host_status_ok[host];
92 if last_ok ~= ok then 92 if last_ok ~= ok then