comparison mod_spam_reporting/mod_spam_reporting.lua @ 6113:83adef4f7d2e

mod_spam_reporting: Add a metric
author Kim Alvefur <zash@zash.se>
date Wed, 08 Jan 2025 09:20:56 +0100
parents a357c3e3bd32
children
comparison
equal deleted inserted replaced
6112:476717ab3cd9 6113:83adef4f7d2e
2 -- Copyright (C) 2016-2021 Kim Alvefur 2 -- Copyright (C) 2016-2021 Kim Alvefur
3 -- 3 --
4 -- This file is MIT/X11 licensed. 4 -- This file is MIT/X11 licensed.
5 5
6 local jid_prep = require "util.jid".prep; 6 local jid_prep = require "util.jid".prep;
7
8 local count_report = module:metric("counter", "received", "reports", "Number of spam and abuse reports submitted by users.", { "report_type" });
7 9
8 module:depends("blocklist"); 10 module:depends("blocklist");
9 11
10 module:add_feature("urn:xmpp:reporting:0"); 12 module:add_feature("urn:xmpp:reporting:0");
11 module:add_feature("urn:xmpp:reporting:reason:spam:0"); 13 module:add_feature("urn:xmpp:reporting:reason:spam:0");
31 end 33 end
32 reason = report:get_child_text("text"); 34 reason = report:get_child_text("text");
33 end 35 end
34 36
35 if report_type then 37 if report_type then
38 count_report:with_labels(report_type):add(1);
36 module:log("warn", "Received report of %s from JID '%s', %s", report_type, jid, reason or "no reason given"); 39 module:log("warn", "Received report of %s from JID '%s', %s", report_type, jid, reason or "no reason given");
37 module:fire_event(module.name.."/"..report_type.."-report", { 40 module:fire_event(module.name.."/"..report_type.."-report", {
38 origin = event.origin, stanza = event.stanza, jid = jid, 41 origin = event.origin, stanza = event.stanza, jid = jid,
39 item = item, report = report, reason = reason, }); 42 item = item, report = report, reason = reason, });
40 end 43 end