comparison mod_audit_status/mod_audit_status.lua @ 5320:c450dbf6c0fa

mod_audit_status: New module to log server status to audit log
author Matthew Wild <mwild1@gmail.com>
date Fri, 07 Apr 2023 12:09:21 +0100
parents
children 18fd615c2733
comparison
equal deleted inserted replaced
5319:5043108b14f4 5320:c450dbf6c0fa
1 module:depends("audit");
2
3 -- Suppress warnings about module:audit()
4 -- luacheck: ignore 143/module
5
6 local heartbeat_interval = module:get_option_number("audit_status_heartbeat_interval", 60);
7
8 local store = module:open_store(nil, "keyval+");
9
10 module:hook_global("server-started", function ()
11 local recorded_status = store:get();
12 if recorded_status.status == "started" then
13 module:audit(nil, "server-crashed", { timestamp = recorded_status.heartbeat });
14 end
15 module:audit(nil, "server-started");
16 store:set_key(nil, "status", "started");
17 end);
18
19 module:hook_global("server-stopped", function ()
20 module:audit(nil, "server-stopped");
21 store:set_key(nil, "status", "stopped");
22 end);
23
24 if heartbeat_interval then
25 module:add_timer(0, function ()
26 store:set_key(nil, "heartbeat", os.time());
27 return heartbeat_interval;
28 end);
29 end