Mercurial > prosody-modules
comparison mod_audit_status/mod_audit_status.lua @ 5650:0eb2d5ea2428
merge
author | Stephen Paul Weber <singpolyma@singpolyma.net> |
---|---|
date | Sat, 06 May 2023 19:40:23 -0500 |
parents | 14b6397cd6de |
children | 9944c6c3e914 |
comparison
equal
deleted
inserted
replaced
5649:2c69577b28c2 | 5650:0eb2d5ea2428 |
---|---|
1 module:depends("audit"); | |
2 | |
3 local st = require "util.stanza"; | |
4 | |
5 -- Suppress warnings about module:audit() | |
6 -- luacheck: ignore 143/module | |
7 | |
8 local heartbeat_interval = module:get_option_number("audit_status_heartbeat_interval", 60); | |
9 | |
10 local store = module:open_store(nil, "keyval+"); | |
11 | |
12 module:hook_global("server-started", function () | |
13 local recorded_status = store:get(); | |
14 if recorded_status and recorded_status.status == "started" then | |
15 module:audit(nil, "server-crashed", { timestamp = recorded_status.heartbeat }); | |
16 end | |
17 module:audit(nil, "server-started"); | |
18 store:set_key(nil, "status", "started"); | |
19 end); | |
20 | |
21 module:hook_global("server-stopped", function () | |
22 module:audit(nil, "server-stopped", { | |
23 custom = { | |
24 prosody.shutdown_reason and st.stanza("note"):text(prosody.shutdown_reason); | |
25 }; | |
26 }); | |
27 store:set_key(nil, "status", "stopped"); | |
28 end); | |
29 | |
30 if heartbeat_interval then | |
31 module:add_timer(0, function () | |
32 store:set_key(nil, "heartbeat", os.time()); | |
33 return heartbeat_interval; | |
34 end); | |
35 end |