Mercurial > prosody-modules
comparison mod_pubsub_alertmanager/mod_pubsub_alertmanager.lua @ 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 | f7e26c43a9bc |
comparison
equal
deleted
inserted
replaced
| 4620:9b253cce7d88 | 4621:ebc2c099a11b |
|---|---|
| 24 return error_mapping[err] or 500; | 24 return error_mapping[err] or 500; |
| 25 end | 25 end |
| 26 return 202; | 26 return 202; |
| 27 end | 27 end |
| 28 | 28 |
| 29 local node_template = module:get_option_string("alertmanager_node_template", "{path?alerts}"); | |
| 30 | |
| 29 function handle_POST(event, path) | 31 function handle_POST(event, path) |
| 30 local request = event.request; | 32 local request = event.request; |
| 31 | 33 |
| 32 local payload = json.decode(event.request.body); | 34 local payload = json.decode(event.request.body); |
| 33 if type(payload) ~= "table" then return 400; end | 35 if type(payload) ~= "table" then return 400; end |
| 47 end | 49 end |
| 48 if alert.generatorURL then | 50 if alert.generatorURL then |
| 49 item:tag("link", { href=alert.generatorURL }):up(); | 51 item:tag("link", { href=alert.generatorURL }):up(); |
| 50 end | 52 end |
| 51 | 53 |
| 52 local ret = publish_payload(path, request.ip, uuid_generate(), item); | 54 local node = render(node_template, {alert = alert, path = path, payload = payload, request = request}); |
| 55 local ret = publish_payload(node, request.ip, uuid_generate(), item); | |
| 53 if ret ~= 202 then | 56 if ret ~= 202 then |
| 54 return ret | 57 return ret |
| 55 end | 58 end |
| 56 end | 59 end |
| 57 return 202; | 60 return 202; |
| 89 end); | 92 end); |
| 90 | 93 |
| 91 module:provides("http", { | 94 module:provides("http", { |
| 92 route = { | 95 route = { |
| 93 ["POST /*"] = handle_POST; | 96 ["POST /*"] = handle_POST; |
| 97 ["POST"] = handle_POST; | |
| 94 }; | 98 }; |
| 95 }); | 99 }); |
