Mercurial > prosody-modules
annotate mod_admin_notify/mod_admin_notify.lua @ 5787:e79f9dec35c0
mod_c2s_conn_throttle: Reduce log level from error->info
Our general policy is that "error" should never be triggerable by remote
entities, and that it is always about something that requires admin
intervention. This satisfies neither condition.
The "warn" level can be used for unexpected events/behaviour triggered by
remote entities, and this could qualify. However I don't think failed auth
attempts are unexpected enough.
I selected "info" because it is what is also used for other notable session
lifecycle events.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 07 Dec 2023 15:46:50 +0000 |
parents | 44e18454e1e0 |
children |
rev | line source |
---|---|
4238
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local it = require "util.iterators"; |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local jid = require "util.jid"; |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local set = require "util.set"; |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local st = require "util.stanza"; |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local roles_store = module:open_store("roles", "map"); |
4274
44e18454e1e0
mod_admin_notify: Fix traceback when no admins listed in config
Matthew Wild <mwild1@gmail.com>
parents:
4238
diff
changeset
|
7 local config_admins = module:get_option_inherited_set("admins", {}) / jid.prep; |
4238
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local function append_host(username) |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 return username.."@"..module.host; |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 end |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 local function get_admins() |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local role_admins = roles_store:get_all("prosody:admin") or {}; |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local admins = config_admins + (set.new(it.to_array(it.keys(role_admins))) / append_host); |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 return admins; |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 end |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 function notify(text) --luacheck: ignore 131/notify |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 local base_msg = st.message({ from = module.host }) |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 :text_tag("body", text); |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 for admin_jid in get_admins() do |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 local msg = st.clone(base_msg); |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 msg.attr.to = admin_jid; |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 module:send(msg); |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 end |
e97c509fdbe3
mod_admin_notify: New module providing an API to notify host admins
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 end |