@cryptotaxi247 / netdata-1 / commits / 00ed87c2c

Gotify notifications (#12639)

coffeegrind123 committed Apr 20, 2022 at 03:48 UTC 00ed87c2c33930eaa74c1f801a8d102fb3ff41aa
6 files changed +148 -4
docs/monitor/enable-notifications.md
+1 -1
@@ -67,6 +67,7 @@ notification platform.
67 - [**Email**](/health/notifications/email/README.md)
68 - [**Flock**](/health/notifications/flock/README.md)
69 - [**Google Hangouts**](/health/notifications/hangouts/README.md)
70 +- [**Gotify**](/health/notifications/gotify/README.md)
71 - [**IRC**](/health/notifications/irc/README.md)
72 - [**Kavenegar**](/health/notifications/kavenegar/README.md)
73 - [**Matrix**](/health/notifications/matrix/README.md)
@@ -144,4 +145,3 @@ architecture](/docs/store/distributed-data-architecture.md) for the best-in-clas
145 - [Netdata Cloud · Alarm notifications](https://learn.netdata.cloud/docs/cloud/alerts-notifications/notifications)
146 - [Netdata Agent · Notifications](/health/notifications/README.md)
147
147 -
health/notifications/Makefile.am
+1
@@ -31,6 +31,7 @@ include awssns/Makefile.inc
31 include discord/Makefile.inc
32 include email/Makefile.inc
33 include flock/Makefile.inc
34 +include gotify/Makefile.inc
35 include hangouts/Makefile.inc
36 include irc/Makefile.inc
37 include kavenegar/Makefile.inc
health/notifications/alarm-notify.sh.in
+51 -3
@@ -38,6 +38,7 @@
38 # - Dynatrace Event by @illumine
39 # - Stackpulse Event by @thiagoftsm
40 # - Opsgenie by @thiaoftsm #9858
41 +# - Gotify by @coffeegrind123
42
43 # -----------------------------------------------------------------------------
44 # testing notifications
@@ -400,6 +401,10 @@ SEND_DYNATRACE=
401 # stackpulse configs
402 STACKPULSE_WEBHOOK=
403
404 +# gotify configs
405 +GOTIFY_APP_URL=
406 +GOTIFY_APP_TOKEN=
407 +
408 # opsgenie configs
409 OPSGENIE_API_KEY=
410
@@ -589,6 +594,9 @@ filter_recipient_by_criticality() {
594 # check matrix
595 { [ -z "${MATRIX_HOMESERVER}" ] || [ -z "${MATRIX_ACCESSTOKEN}" ]; } && SEND_MATRIX="NO"
596
597 +# check gotify
598 +{ [ -z "${GOTIFY_APP_TOKEN}" ] || [ -z "${GOTIFY_APP_URL}" ]; } && SEND_GOTIFY="NO"
599 +
600 # check stackpulse
601 [ -z "${STACKPULSE_WEBHOOK}" ] && SEND_STACKPULSE="NO"
602
@@ -626,7 +634,8 @@ if [ "${SEND_PUSHOVER}" = "YES" ] ||
634 [ "${SEND_MSTEAMS}" = "YES" ] ||
635 [ "${SEND_DYNATRACE}" = "YES" ] ||
636 [ "${SEND_STACKPULSE}" = "YES" ] ||
629 - [ "${SEND_OPSGENIE}" = "YES" ]; then
637 + [ "${SEND_OPSGENIE}" = "YES" ] ||
638 + [ "${SEND_GOTIFY}" = "YES" ]; then
639 # if we need curl, check for the curl command
640 if [ -z "${curl}" ]; then
641 curl="$(command -v curl 2>/dev/null)"
@@ -656,6 +665,7 @@ if [ "${SEND_PUSHOVER}" = "YES" ] ||
665 SEND_DYNATRACE="NO"
666 SEND_STACKPULSE="NO"
667 SEND_OPSGENIE="NO"
668 + SEND_GOTIFY="NO"
669 fi
670 fi
671
@@ -795,7 +805,8 @@ for method in "${SEND_EMAIL}" \
805 "${SEND_MSTEAMS}" \
806 "${SEND_DYNATRACE}" \
807 "${SEND_STACKPULSE}" \
798 - "${SEND_OPSGENIE}" ; do
808 + "${SEND_OPSGENIE}" \
809 + "${SEND_GOTIFY}" ; do
810
811 if [ "${method}" == "YES" ]; then
812 proceed=1
@@ -2277,6 +2288,37 @@ EOF
2288 return 0
2289 }
2290
2291 +# -----------------------------------------------------------------------------
2292 +# Gotify sender
2293 +
2294 +send_gotify() {
2295 + local payload httpcode
2296 + [ "${SEND_GOTIFY}" != "YES" ] && return 1
2297 +
2298 + if [ -z "${GOTIFY_APP_TOKEN}" ] ; then
2299 + info "Can't send Gotify notification, because GOTIFY_APP_TOKEN is not defined"
2300 + return 1
2301 + fi
2302 +
2303 + payload=$(cat <<EOF
2304 + {
2305 + "title" : "${status}, ${name} = ${value_string}, on ${host}",
2306 + "message" : "${date}: ${chart} ${value_string}"
2307 + }
2308 +EOF
2309 +)
2310 +
2311 + httpcode=$(docurl -X POST -H "Content-Type: application/json" -d "${payload}" "${GOTIFY_APP_URL}/message?token=${GOTIFY_APP_TOKEN}")
2312 + if [ "${httpcode}" = "200" ]; then
2313 + info "sent gotify notification for: ${host} ${chart}.${name} is ${status}"
2314 + else
2315 + error "failed to send gotify notification for: ${host} ${chart}.${name} is ${status}, with HTTP error code ${httpcode}."
2316 + return 1
2317 + fi
2318 +
2319 + return 0
2320 +}
2321 +
2322 # -----------------------------------------------------------------------------
2323 # prepare the content of the notification
2324
@@ -3466,6 +3508,11 @@ SENT_STACKPULSE=$?
3508 send_opsgenie
3509 SENT_OPSGENIE=$?
3510
3511 +# -----------------------------------------------------------------------------
3512 +# send messages to Gotify
3513 +send_gotify
3514 +SENT_GOTIFY=$?
3515 +
3516 # -----------------------------------------------------------------------------
3517 # let netdata know
3518 for state in "${SENT_EMAIL}" \
@@ -3495,7 +3542,8 @@ for state in "${SENT_EMAIL}" \
3542 "${SENT_MSTEAMS}" \
3543 "${SENT_DYNATRACE}" \
3544 "${SENT_STACKPULSE}" \
3498 - "${SENT_OPSGENIE}"; do
3545 + "${SENT_OPSGENIE}" \
3546 + "${SENT_GOTIFY}"; do
3547 if [ "${state}" -eq 0 ]; then
3548 # we sent something
3549 exit 0
health/notifications/gotify/Makefile.inc new
+11
@@ -0,0 +1,11 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +# THIS IS NOT A COMPLETE Makefile
4 +# IT IS INCLUDED BY ITS PARENT'S Makefile.am
5 +# IT IS REQUIRED TO REFERENCE ALL FILES RELATIVE TO THE PARENT
6 +
7 +# install these files
8 +dist_noinst_DATA += \
9 + gotify/README.md \
10 + gotify/Makefile.inc \
11 + $(NULL)
health/notifications/gotify/README.md new
+62
@@ -0,0 +1,62 @@
1 +<!--
2 +title: "Send notifications to Gotify"
3 +description: "Send alerts to your Gotify instance when an alert gets triggered in Netdata."
4 +sidebar_label: "Gotify"
5 +custom_edit_url: https://github.com/netdata/netdata/edit/master/health/notifications/gotify/README.md
6 +-->
7 +
8 +# Send notifications to Gotify
9 +
10 +[Gotify](https://gotify.net/) is a self-hosted push notification service created for sending and receiving messages in real time.
11 +
12 +## Configuring Gotify
13 +
14 +### Prerequisites
15 +
16 +To use Gotify as your notification service, you need an application token.
17 +You can generate a new token in the Gotify Web UI.
18 +
19 +### Configuration
20 +
21 +To set up Gotify in Netdata:
22 +
23 +1. Switch to your [config
24 +directory](/docs/configure/nodes.md) and edit the file `health_alarm_notify.conf` using the edit config script.
25 +
26 + ```bash
27 + ./edit-config health_alarm_notify.conf
28 + ```
29 +
30 +2. Change the variable `GOTIFY_APP_TOKEN` to the application token you generated in the Gotify Web UI. Change
31 +`GOTIFY_APP_URL` to point to your Gotify instance.
32 +
33 + ```conf
34 + SEND_GOTIFY="YES"
35 +
36 + # Application token
37 + # Gotify instance url
38 + GOTIFY_APP_TOKEN=XXXXXXXXXXXXXXX
39 + GOTIFY_APP_URL=https://push.example.de/
40 + ```
41 +
42 + Changes to `health_alarm_notify.conf` do not require a Netdata restart.
43 +
44 +3. Test your Gotify notifications configuration by running the following commands, replacing `ROLE` with your preferred role:
45 +
46 + ```sh
47 + # become user netdata
48 + sudo su -s /bin/bash netdata
49 +
50 + # send a test alarm
51 + /usr/libexec/netdata/plugins.d/alarm-notify.sh test ROLE
52 + ```
53 +
54 + 🟢 If everything works, you'll see alarms in Gotify:
55 +
56 + ![Example alarm notifications in Gotify](https://user-images.githubusercontent.com/103264516/162509205-1e88e5d9-96b6-4f7f-9426-182776158128.png)
57 +
58 + 🔴 If sending the test notifications fails, check `/var/log/netdata/error.log` to find the relevant error message:
59 +
60 + ```log
61 + 2020-09-03 23:07:00: alarm-notify.sh: ERROR: failed to send Gotify notification for: hades test.chart.test_alarm is CRITICAL, with HTTP error code 401.
62 + ```
health/notifications/health_alarm_notify.conf
+22
@@ -278,6 +278,16 @@ STACKPULSE_WEBHOOK=""
278
279 DEFAULT_RECIPIENT_STACKPULSE=""
280
281 +#------------------------------------------------------------------------------
282 +# gotify global notification options
283 +SEND_GOTIFY="YES"
284 +
285 +# App token and url
286 +GOTIFY_APP_TOKEN=""
287 +GOTIFY_APP_URL=""
288 +
289 +DEFAULT_RECIPIENT_GOTIFY=""
290 +
291 #------------------------------------------------------------------------------
292 # opsgenie global notification options
293 SEND_OPSGENIE="YES"
@@ -971,6 +981,8 @@ role_recipients_matrix[sysadmin]="${DEFAULT_RECIPIENT_MATRIX}"
981
982 role_recipients_stackpulse[sysadmin]="${DEFAULT_RECIPIENT_STACKPULSE}"
983
984 +role_recipients_gotify[sysadmin]="${DEFAULT_RECIPIENT_GOTIFY}"
985 +
986 # -----------------------------------------------------------------------------
987 # DNS related alarms
988
@@ -1028,6 +1040,8 @@ role_recipients_matrix[domainadmin]="${DEFAULT_RECIPIENT_MATRIX}"
1040
1041 role_recipients_stackpulse[domainadmin]="${DEFAULT_RECIPIENT_STACKPULSE}"
1042
1043 +role_recipients_gotify[domainadmin]="${DEFAULT_RECIPIENT_GOTIFY}"
1044 +
1045 # -----------------------------------------------------------------------------
1046 # database servers alarms
1047 # mysql, redis, memcached, postgres, etc
@@ -1086,6 +1100,8 @@ role_recipients_matrix[dba]="${DEFAULT_RECIPIENT_MATRIX}"
1100
1101 role_recipients_stackpulse[dba]="${DEFAULT_RECIPIENT_STACKPULSE}"
1102
1103 +role_recipients_gotify[dba]="${DEFAULT_RECIPIENT_GOTIFY}"
1104 +
1105 # -----------------------------------------------------------------------------
1106 # web servers alarms
1107 # apache, nginx, lighttpd, etc
@@ -1144,6 +1160,8 @@ role_recipients_matrix[webmaster]="${DEFAULT_RECIPIENT_MATRIX}"
1160
1161 role_recipients_stackpulse[webmaster]="${DEFAULT_RECIPIENT_STACKPULSE}"
1162
1163 +role_recipients_gotify[webmaster]="${DEFAULT_RECIPIENT_GOTIFY}"
1164 +
1165 # -----------------------------------------------------------------------------
1166 # proxy servers alarms
1167 # squid, etc
@@ -1202,6 +1220,8 @@ role_recipients_matrix[proxyadmin]="${DEFAULT_RECIPIENT_MATRIX}"
1220
1221 role_recipients_stackpulse[proxyadmin]="${DEFAULT_RECIPIENT_STACKPULSE}"
1222
1223 +role_recipients_gotify[proxyadmin]="${DEFAULT_RECIPIENT_GOTIFY}"
1224 +
1225 # -----------------------------------------------------------------------------
1226 # peripheral devices
1227 # UPS, photovoltaics, etc
@@ -1257,3 +1277,5 @@ role_recipients_opsgenie[sitemgr]="${DEFAULT_RECIPIENT_OPSGENIE}"
1277 role_recipients_matrix[sitemgr]="${DEFAULT_RECIPIENT_MATRIX}"
1278
1279 role_recipients_stackpulse[sitemgr]="${DEFAULT_RECIPIENT_STACKPULSE}"
1280 +
1281 +role_recipients_gotify[sitemgr]="${DEFAULT_RECIPIENT_GOTIFY}"