@@ -240,23 +240,23 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
240240 },
241241 {
242242 Title : "Alert" ,
243- Value : data .CommonLabels [ "alertname" ] ,
243+ Value : extractKV ( data .CommonLabels , "alertname" ) ,
244244 },
245245 {
246246 Title : "Summary" ,
247- Value : data .CommonAnnotations [ "summary" ] ,
247+ Value : extractKV ( data .CommonAnnotations , "summary" ) ,
248248 },
249249 {
250250 Title : "Severity" ,
251251 Value : renderSeverity (data .CommonLabels ["severity" ]),
252252 },
253253 {
254254 Title : "In Host" ,
255- Value : data .CommonLabels [ "instance" ] ,
255+ Value : extractKV ( data .CommonLabels , "instance" ) ,
256256 },
257257 {
258258 Title : "Description" ,
259- Value : data .CommonAnnotations [ "description" ] ,
259+ Value : extractKV ( data .CommonAnnotations , "description" ) ,
260260 },
261261 {
262262 Title : "Common Labels" ,
@@ -273,14 +273,16 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
273273 {
274274 Type : "Action.OpenUrl" ,
275275 Title : "View details" ,
276- URL : data .CommonAnnotations [ "runbook_url" ] ,
276+ URL : extractKV ( data .CommonAnnotations , "runbook_url" ) ,
277277 },
278278 },
279279 },
280280 },
281281 },
282282 }
283283
284+ // Check if summary exists in CommonLabels
285+
284286 if err = json .NewEncoder (& payload ).Encode (t ); err != nil {
285287 return false , err
286288 }
@@ -335,3 +337,10 @@ func renderCommonAnnotations(commonLabels template.KV) string {
335337
336338 return commonLabels .Remove (removeList ).String ()
337339}
340+
341+ func extractKV (kv template.KV , key string ) string {
342+ if v , ok := kv [key ]; ok {
343+ return v
344+ }
345+ return ""
346+ }
0 commit comments