Mercurial > prosody-modules
changeset 3407:26ae3b6a8a57
mod_pubsub_stats: Generate a textual summary for notifications
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 22 Dec 2018 16:34:51 +0100 |
parents | 4cbb1e381431 |
children | b2ce818ec19c |
files | mod_pubsub_stats/mod_pubsub_stats.lua |
diffstat | 1 files changed, 12 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_pubsub_stats/mod_pubsub_stats.lua Tue Dec 18 19:12:52 2018 +0100 +++ b/mod_pubsub_stats/mod_pubsub_stats.lua Sat Dec 22 16:34:51 2018 +0100 @@ -40,3 +40,15 @@ function module.unload() pubsub.service:delete(node, true); end + +module:hook("pubsub-summary/http://jabber.org/protocol/stats", function (event) + local payload = event.payload; + local summary = {}; + for stat in payload:childtags("stat") do + if stat.attr.name and stat.attr.value then + table.insert(summary, string.format("%s: %g %s", stat.attr.name, tonumber(stat.attr.value), stat.attr.units or "")); + end + end + return table.concat(summary, "\n"); +end); +