From 7ff165a6f7b367edf5fd4d476f9154c2da39b421 Mon Sep 17 00:00:00 2001 From: Alex Kelly Date: Tue, 29 Nov 2022 22:12:42 -0500 Subject: [PATCH] add crowdsec formatter --- matrix_webhook/formatters/crowdsec.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 matrix_webhook/formatters/crowdsec.py diff --git a/matrix_webhook/formatters/crowdsec.py b/matrix_webhook/formatters/crowdsec.py new file mode 100644 index 0000000..7bd1eab --- /dev/null +++ b/matrix_webhook/formatters/crowdsec.py @@ -0,0 +1,11 @@ +def formatter(data, headers): + """ format a message sent with crowdsec http endpoints""" + data_out = "" + for row in data["body"]: + if "crowdsecurity" in row['scenario']: + source, scenario, *_ = row['scenario'].split('/') + row['scenario'] = f"[{scenario}](https://hub.crowdsec.net/author/crowdsecurity/configurations/{scenario})" + data_out += f"{row['host']} has been banned {row['duration']} due to {row['scenario']}\n\n[AbuseIPDB](https://www.abuseipdb.com/check{row['host'])" + data["body"] = data_out + return data +