changeset 4621:ebc2c099a11b

mod_pubsub_alertmanager: Allow templating the pubsub node to publish to Allows e.g. using a pubsub node per alert severity, or per some other category.
author Kim Alvefur <zash@zash.se>
date Fri, 16 Jul 2021 12:27:34 +0200
parents 9b253cce7d88
children 61ce3394fe8b
files mod_pubsub_alertmanager/mod_pubsub_alertmanager.lua
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mod_pubsub_alertmanager/mod_pubsub_alertmanager.lua	Fri Jul 16 12:26:55 2021 +0200
+++ b/mod_pubsub_alertmanager/mod_pubsub_alertmanager.lua	Fri Jul 16 12:27:34 2021 +0200
@@ -26,6 +26,8 @@
 	return 202;
 end
 
+local node_template = module:get_option_string("alertmanager_node_template", "{path?alerts}");
+
 function handle_POST(event, path)
 	local request = event.request;
 
@@ -49,7 +51,8 @@
 			item:tag("link", { href=alert.generatorURL }):up();
 		end
 
-		local ret = publish_payload(path, request.ip, uuid_generate(), item);
+		local node = render(node_template, {alert = alert, path = path, payload = payload, request = request});
+		local ret = publish_payload(node, request.ip, uuid_generate(), item);
 		if ret ~= 202 then
 			return ret
 		end
@@ -91,5 +94,6 @@
 module:provides("http", {
 	route = {
 		["POST /*"] = handle_POST;
+		["POST"] = handle_POST;
 	};
 });