Skip to content

Commit

Permalink
Formatting release: use description for summary; allow greater contro…
Browse files Browse the repository at this point in the history
…l over HEX codes used for colors of message text; clean up styling and duplicate info (#15)

* allow changing colors of header line and always use first sentence of description as summary for collapsible

* remove second runbook_url in description

* additional formatting and setting new defaults for colors to be a bit more spacechalk :)

* clean up formatting more

* fix typo

* clean up colors a bit more formatting

* catch typo of missing + in resolved msg formatting

* clean up readme
  • Loading branch information
jessebot authored Jul 16, 2024
1 parent 67d598a commit cf34fd5
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 16 deletions.
8 changes: 8 additions & 0 deletions .env.default
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@ GRAFANA_DATASOURCE="default"

# comment to disable silence link
ALERTMANAGER_URL="https://alertmanager.example.com"

# colors for alert message text. These are HEX codes.
COLOR_CRITICAL="#f2748a" # red
COLOR_ERROR="#f289f9" # orange
COLOR_WARNING="#fdcd36" # yellow
COLOR_INFO="#7aa2f7" # blue
COLOR_RECOVERED="#a8fd57"
COLOR_DEFAULT="#585858" # grey
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ A bot to receive Prometheus Alertmanager webhook events and forward them to chos
* Configurable room per alert receiver
* Automatic joining of configured rooms. Private rooms require an invite
* Secret key authentication with Alertmanager
* HTML formatted messages
* 🎨 HTML formatted messages
* You can now choose the text colors for each severity too!
* Optionally mentions `@room` on firing alerts
* Optionally set the bot user's display name and avatar

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "matrix-alertmanager",
"version": "0.11.2",
"version": "0.12.0",
"description": "Prometheus Alertmanager bot for Matrix",
"main": "src/app.js",
"scripts": {
Expand Down
49 changes: 37 additions & 12 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const utils = {
let parts = []

let summary = ""
if (data.annotations.hasOwnProperty("summary")) {
summary = data.annotations.summary;
if (data.annotations.hasOwnProperty("description")) {
summary = data.annotations.description.split('.')[0];
} else if (data.labels.hasOwnProperty("alertname")) {
summary = data.labels.alertname;
}
Expand All @@ -42,35 +42,60 @@ const utils = {
let color = (function (severity) {
switch (severity) {
case 'critical':
return '#E41227'; // red
if (process.env.COLOR_CRITICAL) {
return process.env.COLOR_CRITICAL;
} else {
return '#f2748a'; // red
}
case 'error':
return '#FF4507'; // orange
if (process.env.COLOR_ERROR) {
return process.env.COLOR_ERROR;
} else {
return '#f289f9'; // magenta
}
case 'warning':
return '#FFE608'; // yellow
if (process.env.COLOR_WARNING) {
return process.env.COLOR_WARNING;
} else {
return '#fdcd36'; // yellow
}
case 'info':
return '#1661B8'; // blue
if (process.env.COLOR_INFO) {
return process.env.COLOR_INFO;
} else {
return '#7aa2f7'; // blue
}
default:
return '#999999'; // grey
if (process.env.COLOR_DEFAULT) {
return process.env.COLOR_DEFAULT;
} else {
return '#7aa2f7'; // grey
}
}
})(data.labels.severity);
parts.push('<summary><strong><font color=\"' + color + '\">FIRING: ' + summary + env + '</font></strong></summary>')
parts.push('<summary><font color=\"' + color + '\"><b>FIRING</b>: ' + summary + env + '</font></summary>')
} else if (data.status === 'resolved') {
parts.push('<summary><strong><font color=\"#33CC33\">RESOLVED: ' + summary + env + '</font></strong></summary>')
if (process.env.COLOR_RECOVERED) {
let resolved_color = process.env.COLOR_RECOVERED
} else {
let resolved_color = "#a8fd57"
}
parts.push('<summary><font color=\"' + resolved_color + '\"><b>RESOLVED</b>: ' + summary + env + '</font></summary>')
} else {
parts.push('<summary>' + data.status.toUpperCase() + ': ' + summary + env + '</summary>')
}

parts.push('<br />\n')

Object.keys(data.labels).forEach((label) => {
parts.push('<b>' + label + '</b>: ' + data.labels[label] + '<br>\n')
parts.push('<font color=\"#bdd8ff\"><b>' + label + '</b></font>: ' + data.labels[label] + '<br>\n')
});

parts.push('<br />\n')

Object.keys(data.annotations).forEach((annotation) => {
if (annotation != "summary" && !annotation.startsWith("logs_")) {
parts.push('<b>' + annotation + '</b>: ' + data.annotations[annotation] + '<br>\n')
if (annotation != "summary" && annotation != "runbook_url" && !annotation.startsWith("logs_")) {
parts.push('<font color=\"#bdd8ff\"><b>' + annotation + '</b></font>: ' + data.annotations[annotation] + '<br>\n')
}
})
parts.push('</details>')
Expand Down

0 comments on commit cf34fd5

Please sign in to comment.