Mercurial > prosody-modules
annotate mod_admin_probe/mod_admin_probe.lua @ 5668:ecfd7aece33b
mod_measure_modules: Report module statuses via OpenMetrics
Someone in the chat asked about a health check endpoint, which reminded
me of mod_http_status, which provides access to module statuses with
full details. After that, this idea came about, which seems natural.
As noted in the README, it could be used to monitor that critical
modules are in fact loaded correctly.
As more modules use the status API, the more useful this module and
mod_http_status becomes.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 06 Oct 2023 18:34:39 +0200 |
parents | f78661861e98 |
children |
rev | line source |
---|---|
1281
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
1 -- Prosody IM |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
2 -- Copyright (C) 2014 Florian Zeitz |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
3 -- |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
4 -- This project is MIT/X11 licensed. Please see the |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
5 -- COPYING file in the source package for more information. |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
6 -- |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
7 |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
8 local presence = module:depends("presence"); |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
9 local send_presence_of_available_resources = presence.send_presence_of_available_resources; |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
10 |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
11 local hosts = prosody.hosts; |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
12 local core_post_stanza = prosody.core_post_stanza; |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
13 |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
14 local st = require "util.stanza"; |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
15 local is_admin = require "core.usermanager".is_admin; |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
16 local jid_split = require "util.jid".split; |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
17 |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
18 module:hook("presence/bare", function(data) |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
19 local origin, stanza = data.origin, data.stanza; |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
20 local to, from, type = stanza.attr.to, stanza.attr.from, stanza.attr.type; |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
21 local node, host = jid_split(to); |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
22 |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
23 if type ~= "probe" then return; end |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
24 if not is_admin(from, module.host) then return; end |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
25 |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
26 if 0 == send_presence_of_available_resources(node, host, from, origin) then |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
27 core_post_stanza(hosts[host], st.presence({from=to, to=from, type="unavailable"}), true); |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
28 end |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
29 return true; |
f78661861e98
mod_admin_probe: Module allowing server administrators to probe any user
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
30 end, 10); |