Commit 80f1b720 authored by jaywink's avatar jaywink
Browse files

Merge branch 'alert-format' into 'master'

Improve formatting of alerts by using more attributes

Closes #2

See merge request jaywink/matrix-alertmanager!5
parents 30e4461a abc494c5
Pipeline #5118 passed with stage
in 28 seconds
......@@ -23,27 +23,49 @@ const utils = {
Format a single alert into a message string.
*/
let parts = []
//console.log(data)
if (data.status === 'firing') {
if (process.env.MENTION_ROOM === "1") {
parts.push('@room', '<br>')
}
parts.push('<strong><font color=\"#ff0000\">FIRING:</font></strong>')
let color = (function(severity) {
switch(severity) {
case 'warning':
return '#ffc107'; // orange
case 'none':
return '#17a2b8'; // blue
default:
return '#dc3545'; // red
}
})(data.labels.severity);
parts.push('<strong><font color=\"', color, '\">FIRING:</font></strong>')
} else if (data.status === 'resolved') {
parts.push('<strong><font color=\"#33cc33\">RESOLVED:</font></strong>')
} else {
parts.push(data.status.toUpperCase() + ':')
}
// name and location of occurrence
if (data.labels.alertname !== undefined) {
parts.push('<i>', data.labels.alertname, '</i>')
if (data.labels.host !== undefined || data.labels.instance !== undefined) {
parts.push(' at ')
}
}
if (data.labels.host !== undefined) {
parts.push(data.labels.host)
} else {
if (data.labels.instance !== undefined) {
parts.push(data.labels.instance)
}
} else if (data.labels.instance !== undefined) {
parts.push(data.labels.instance)
}
parts.push('<br>', data.annotations.description)
// additional descriptive content
if (data.annotations.message !== undefined) {
parts.push('<br>', data.annotations.message.replace("\n", "<br>"))
}
if (data.annotations.description !== undefined) {
parts.push('<br>', data.annotations.description)
}
parts.push('<br><a href="', data.generatorURL,'">Alert link</a>')
return parts.join(' ')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment