🐛 Bug fix
42
README.md
|
@ -12,6 +12,11 @@
|
|||
- [Docker compose](#docker-compose)
|
||||
- [Variables](#variables)
|
||||
- [Grafana configuration](#grafana-configuration)
|
||||
- [Setup a Grafana rule](#setup-a-grafana-rule)
|
||||
- [Title](#title)
|
||||
- [Description](#description)
|
||||
- [Tags](#tags)
|
||||
- [Dashboard button](#dashboard-button)
|
||||
|
||||
## Example
|
||||
|
||||
|
@ -54,4 +59,39 @@ services:
|
|||
|
||||
You just need to add a webhook contact point as below:
|
||||
|
||||
<img src="/docs/static/img/grafana-config.png" alt="Grafana webhook contact point">
|
||||
<img src="/docs/static/img/grafana-config.png" alt="Grafana">
|
||||
|
||||
## Setup a Grafana rule
|
||||
|
||||
### Title
|
||||
|
||||
The title is the name of the Grafana alert.
|
||||
|
||||
<img src="/docs/static/img/grafana-config/ntfy-title.jpg" alt="Grafana">
|
||||
|
||||
<img src="/docs/static/img/grafana-config/grafana-title.png" alt="Grafana">
|
||||
|
||||
### Description
|
||||
|
||||
The description is based on the Grafana summary.
|
||||
|
||||
<img src="/docs/static/img/grafana-config/ntfy-summary.jpg" alt="Grafana">
|
||||
|
||||
<img src="/docs/static/img/grafana-config/grafana-summary.png" alt="Grafana">
|
||||
|
||||
### Tags
|
||||
|
||||
Tags are the name of the alert, the name of the folder and the labels.
|
||||
|
||||
<img src="/docs/static/img/grafana-config/ntfy-tags.jpg" alt="Grafana">
|
||||
|
||||
<img src="/docs/static/img/grafana-config/grafana-tags-1.png" alt="Grafana">
|
||||
<img src="/docs/static/img/grafana-config/grafana-tags-2.png" alt="Grafana">
|
||||
|
||||
### Dashboard button
|
||||
|
||||
The "Dashboard" button corresponds to a Grafana dashboard.
|
||||
|
||||
<img src="/docs/static/img/grafana-config/ntfy-dashboard.jpg" alt="Grafana">
|
||||
|
||||
<img src="/docs/static/img/grafana-config/grafana-dashboard.png" alt="Grafana">
|
||||
|
|
BIN
docs/static/img/demo.png
vendored
Before Width: | Height: | Size: 119 KiB After Width: | Height: | Size: 70 KiB |
BIN
docs/static/img/grafana-config/grafana-dashboard.png
vendored
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
docs/static/img/grafana-config/grafana-summary.png
vendored
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
docs/static/img/grafana-config/grafana-tags-1.png
vendored
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
docs/static/img/grafana-config/grafana-tags-2.png
vendored
Normal file
After Width: | Height: | Size: 9.4 KiB |
BIN
docs/static/img/grafana-config/grafana-title.png
vendored
Normal file
After Width: | Height: | Size: 8.1 KiB |
BIN
docs/static/img/grafana-config/ntfy-dashboard.jpg
vendored
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
docs/static/img/grafana-config/ntfy-summary.jpg
vendored
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
docs/static/img/grafana-config/ntfy-tags.jpg
vendored
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
docs/static/img/grafana-config/ntfy-title.jpg
vendored
Normal file
After Width: | Height: | Size: 18 KiB |
1635
package-lock.json
generated
|
@ -26,15 +26,14 @@
|
|||
"homepage": "https://gitlab.com/Saibe1111/grafana-to-ntfy#readme",
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.17",
|
||||
"@types/node-fetch": "^2.6.4",
|
||||
"prettier": "^2.8.8",
|
||||
"ts-node-dev": "^2.0.0",
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.4.0",
|
||||
"dotenv": "^16.3.1",
|
||||
"express": "^4.18.2",
|
||||
"node-fetch": "^2.6.1",
|
||||
"tslib": "^2.6.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { Headers, Response } from 'node-fetch';
|
||||
import fetch from 'node-fetch';
|
||||
import { MessageHeader } from '../interface/MessageHeader';
|
||||
import { Priority } from '../enum/priority';
|
||||
import axios, { AxiosResponse } from 'axios';
|
||||
|
||||
export class NtfyMessage {
|
||||
private header: MessageHeader;
|
||||
|
@ -27,11 +26,9 @@ export class NtfyMessage {
|
|||
this.server = (process.env['NTFY_SERVER'] as string) || 'https://ntfy.sh';
|
||||
}
|
||||
|
||||
public async publish(): Promise<Response> {
|
||||
const response = await fetch(this.server + '/' + this.topic, {
|
||||
method: 'POST',
|
||||
body: this.message,
|
||||
headers: new Headers(this.transformMessageHeaderToObj(this.header))
|
||||
public async publish(): Promise<AxiosResponse> {
|
||||
const response = await axios.post(this.server + '/' + this.topic, this.message, {
|
||||
headers: this.transformMessageHeaderToObj(this.header)
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
|
|
@ -5,13 +5,13 @@ import { Priority } from '../enum/priority';
|
|||
export class GrafanaService {
|
||||
public async postAlert(req: Request): Promise<void> {
|
||||
const messagePriotity = getPriority(req.body.status);
|
||||
const messageTitle = req.body.commonAnnotations.summary;
|
||||
const messageDescription = req.body.commonAnnotations.description;
|
||||
const messageTitle = req.body.commonLabels.alertname;
|
||||
const messageDescription = req.body.commonAnnotations.summary;
|
||||
const messageTags = getTags(req.body.commonLabels, req.body.status);
|
||||
const messageActions = getActions(req.body.alerts[0].silenceURL, req.body.alerts[0].dashboardURL);
|
||||
const message = new NtfyMessage(messageTitle, messageDescription, messagePriotity, messageTags, messageActions);
|
||||
const response = await message.publish();
|
||||
if (!response.ok) {
|
||||
if (response.status != 200) {
|
||||
if (response.status == 403) {
|
||||
throw new Error('Forbidden');
|
||||
}
|
||||
|
|