view mod_stats39/mod_stats39.lua @ 3843:c065b7670c89

mod_rest: Return a friendly message for parse errors And details in the error context that should be included thanks to previous commit.
author Kim Alvefur <zash@zash.se>
date Wed, 15 Jan 2020 21:41:42 +0100
parents 054898e84a04
children 3941768916f1
line wrap: on
line source

local statsman = require "core.statsmanager";
local st = require "util.stanza";

module:hook("iq/host/http://jabber.org/protocol/stats:query", function (event)
	local origin, stanza = event.origin, event.stanza;
	local stats, _, extra = statsman.get_stats();
	local reply = st.reply(stanza);
	reply:tag("query", { xmlns = "http://jabber.org/protocol/stats" });
	for stat, value in pairs(stats) do
		local unit = extra[stat] and extra[stat].units;
		reply:tag("stat", { name = stat, unit = unit, value = tostring(value) }):up();
	end
	origin.send(reply);
	return true;
end)