comparison mod_pubsub_alertmanager/mod_pubsub_alertmanager.lua @ 4619:b11001bd915d

mod_pubsub_alertmanager: Add a plain text summary
author Kim Alvefur <zash@zash.se>
date Thu, 01 Jul 2021 00:07:27 +0200
parents 48132b6e1b16
children 9b253cce7d88
comparison
equal deleted inserted replaced
4618:48132b6e1b16 4619:b11001bd915d
1 local st = require "util.stanza"; 1 local st = require "util.stanza";
2 local json = require "util.json"; 2 local json = require "util.json";
3 local filters = {};
4 local render = require "util.interpolation".new("%b{}", tostring, filters);
3 local uuid_generate = require "util.uuid".generate; 5 local uuid_generate = require "util.uuid".generate;
4 6
5 module:depends("http"); 7 module:depends("http");
6 8
7 local pubsub_service = module:depends("pubsub").service; 9 local pubsub_service = module:depends("pubsub").service;
53 end 55 end
54 end 56 end
55 return 202; 57 return 202;
56 end 58 end
57 59
60 local template = [[
61 *ALARM!*
62 Status: {status}
63 Starts at: {startsAt}{endsAt&
64 Ends at: {endsAt}}
65 Labels: {labels%
66 {idx}: {item}}
67 Annotations: {annotations%
68 {idx}: {item}}
69 ]]
70
71 module:hook("pubsub-summary/urn:uuid:e3bec775-c607-4e9b-9a3f-94de1316d861:v4", function(event)
72 local payload = event.payload;
73
74 local data = {
75 status = payload.attr.status,
76 annotations = {},
77 labels = {},
78 endsAt = payload:find("ends/@at"),
79 startsAt = payload:find("starts/@at"),
80 };
81 for label in payload:childtags("label") do
82 data.labels[tostring(label.attr.name)] = label:get_text();
83 end
84 for annotation in payload:childtags("annotation") do
85 data.annotations[tostring(annotation.attr.name)] = annotation:get_text();
86 end
87
88 return render(template, data);
89 end);
90
58 module:provides("http", { 91 module:provides("http", {
59 route = { 92 route = {
60 ["POST /*"] = handle_POST; 93 ["POST /*"] = handle_POST;
61 }; 94 };
62 }); 95 });