annotate mod_support_contact/mod_support_contact.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 7dbde05b48a9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
1 -- mod_support_contact.lua
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
2 --
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
3 -- Config options:
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
4 -- support_contact = "support@hostname"; -- a JID
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
5 -- support_contact_nick = "Support!"; -- roster nick
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
6 -- support_contact_group = "Users being supported!"; -- the roster group in the support contact's roster
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
7
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
8 local host = module:get_host();
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
9
986
8b1250df82e8 mod_support_contact: Use module:get_option_string()
Kim Alvefur <zash@zash.se>
parents: 777
diff changeset
10 local support_contact = module:get_option_string("support_contact", "support@"..host);
8b1250df82e8 mod_support_contact: Use module:get_option_string()
Kim Alvefur <zash@zash.se>
parents: 777
diff changeset
11 local support_contact_nick = module:get_option_string("support_contact_nick", "Support");
8b1250df82e8 mod_support_contact: Use module:get_option_string()
Kim Alvefur <zash@zash.se>
parents: 777
diff changeset
12 local support_contact_group = module:get_option_string("support_contact_group", "Users");
1
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
13
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
14 if not(support_contact and support_contact_nick) then return; end
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16 local rostermanager = require "core.rostermanager";
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
17 local jid_split = require "util.jid".split;
100
999a4b3e699b mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents: 1
diff changeset
18 local st = require "util.stanza";
1
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
19
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
20 module:hook("user-registered", function(event)
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21 module:log("debug", "Adding support contact");
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
22
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
23 local groups = support_contact_group and {[support_contact_group] = true;} or {};
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
24
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
25 local node, host = event.username, event.host;
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
26 local jid = node and (node..'@'..host) or host;
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
27 local roster;
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28
100
999a4b3e699b mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents: 1
diff changeset
29 roster = rostermanager.load_roster(node, host);
999a4b3e699b mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents: 1
diff changeset
30 if hosts[host] then
999a4b3e699b mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents: 1
diff changeset
31 roster[support_contact] = {subscription = "both", name = support_contact_nick, groups = {}};
999a4b3e699b mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents: 1
diff changeset
32 else
999a4b3e699b mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents: 1
diff changeset
33 roster[support_contact] = {subscription = "from", ask = "subscribe", name = support_contact_nick, groups = {}};
999a4b3e699b mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents: 1
diff changeset
34 end
999a4b3e699b mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents: 1
diff changeset
35 rostermanager.save_roster(node, host, roster);
1
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
36
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
37 node, host = jid_split(support_contact);
1343
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 986
diff changeset
38
100
999a4b3e699b mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents: 1
diff changeset
39 if hosts[host] then
999a4b3e699b mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents: 1
diff changeset
40 roster = rostermanager.load_roster(node, host);
999a4b3e699b mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents: 1
diff changeset
41 roster[jid] = {subscription = "both", groups = groups};
999a4b3e699b mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents: 1
diff changeset
42 rostermanager.save_roster(node, host, roster);
999a4b3e699b mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents: 1
diff changeset
43 rostermanager.roster_push(node, host, jid);
999a4b3e699b mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents: 1
diff changeset
44 else
777
e5413b66aeec mod_support_contact: Use module:send()
Matthew Wild <mwild1@gmail.com>
parents: 100
diff changeset
45 module:send(st.presence({from=jid, to=support_contact, type="subscribe"}));
100
999a4b3e699b mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents: 1
diff changeset
46 end
1
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
47 end);