# HG changeset patch # User Matthew Wild # Date 1684867238 -3600 # Node ID 67190744b1eb0030bf2e8bceafb32f378bb2414b # Parent bb083e9f78dd4cad7ebcdd9c5ff749808c1a5413 mod_pubsub_alertmanager: Support for per-path config overrides diff -r bb083e9f78dd -r 67190744b1eb mod_pubsub_alertmanager/README.md --- a/mod_pubsub_alertmanager/README.md Thu May 18 21:11:13 2023 +0200 +++ b/mod_pubsub_alertmanager/README.md Tue May 23 19:40:38 2023 +0100 @@ -93,3 +93,21 @@ `alertmanager_node_template` : Template for the pubsub node name, defaults to `"{path?alerts}"` + +`alertmanager_path_configs` +: Per-path configuration variables (see below). + +### Per-path configuration + +It's possible to override configuration options based on the path suffix. For +example, if a request is made to `http://prosody/pubsub_alertmanager/foo` the +path suffix is `foo`. You can then supply the following configuration: + +``` lua +alertmanager_path_configs = { + foo = { + node_template = "alerts/{alert.labels.severity}"; + publisher = "user@example.net"; + }; +} +``` diff -r bb083e9f78dd -r 67190744b1eb mod_pubsub_alertmanager/mod_pubsub_alertmanager.lua --- a/mod_pubsub_alertmanager/mod_pubsub_alertmanager.lua Thu May 18 21:11:13 2023 +0200 +++ b/mod_pubsub_alertmanager/mod_pubsub_alertmanager.lua Tue May 23 19:40:38 2023 +0100 @@ -29,11 +29,16 @@ return 202; end -local node_template = module:get_option_string("alertmanager_node_template", "{path?alerts}"); +local global_node_template = module:get_option_string("alertmanager_node_template", "{path?alerts}"); +local path_configs = module:get_option("alertmanager_path_configs", {}); function handle_POST(event, path) local request = event.request; + local config = path_configs[path] or {}; + local node_template = config.node_template or global_node_template; + local publisher = config.publisher or request.ip; + local payload = json.decode(event.request.body); if type(payload) ~= "table" then return 400; end if payload.version ~= "4" then return 501; end @@ -55,7 +60,7 @@ end local node = render(node_template, {alert = alert, path = path, payload = payload, request = request}); - local ret = publish_payload(node, request.ip, uuid_generate(), item); + local ret = publish_payload(node, publisher, uuid_generate(), item); if ret ~= 202 then return ret end