diff options
author | coffeegrind123 <103264516+coffeegrind123@users.noreply.github.com> | 2022-04-20 03:48:17 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-20 00:48:17 +0000 |
commit | 00ed87c2c33930eaa74c1f801a8d102fb3ff41aa (patch) | |
tree | 8cb0b9cd0b968c28820acb7f8e740be63c35019c /health | |
parent | 7f5b4f40fe2a55845e847d6de535c3f0ae61c38e (diff) |
Gotify notifications (#12639)
Diffstat (limited to 'health')
-rw-r--r-- | health/notifications/Makefile.am | 1 | ||||
-rwxr-xr-x | health/notifications/alarm-notify.sh.in | 54 | ||||
-rw-r--r-- | health/notifications/gotify/Makefile.inc | 11 | ||||
-rw-r--r-- | health/notifications/gotify/README.md | 62 | ||||
-rwxr-xr-x | health/notifications/health_alarm_notify.conf | 22 |
5 files changed, 147 insertions, 3 deletions
diff --git a/health/notifications/Makefile.am b/health/notifications/Makefile.am index 46a6e472ca..f026171a7e 100644 --- a/health/notifications/Makefile.am +++ b/health/notifications/Makefile.am @@ -31,6 +31,7 @@ include awssns/Makefile.inc include discord/Makefile.inc include email/Makefile.inc include flock/Makefile.inc +include gotify/Makefile.inc include hangouts/Makefile.inc include irc/Makefile.inc include kavenegar/Makefile.inc diff --git a/health/notifications/alarm-notify.sh.in b/health/notifications/alarm-notify.sh.in index 287cabfef1..cfa5577b6e 100755 --- a/health/notifications/alarm-notify.sh.in +++ b/health/notifications/alarm-notify.sh.in @@ -38,6 +38,7 @@ # - Dynatrace Event by @illumine # - Stackpulse Event by @thiagoftsm # - Opsgenie by @thiaoftsm #9858 +# - Gotify by @coffeegrind123 # ----------------------------------------------------------------------------- # testing notifications @@ -400,6 +401,10 @@ SEND_DYNATRACE= # stackpulse configs STACKPULSE_WEBHOOK= +# gotify configs +GOTIFY_APP_URL= +GOTIFY_APP_TOKEN= + # opsgenie configs OPSGENIE_API_KEY= @@ -589,6 +594,9 @@ filter_recipient_by_criticality() { # check matrix { [ -z "${MATRIX_HOMESERVER}" ] || [ -z "${MATRIX_ACCESSTOKEN}" ]; } && SEND_MATRIX="NO" +# check gotify +{ [ -z "${GOTIFY_APP_TOKEN}" ] || [ -z "${GOTIFY_APP_URL}" ]; } && SEND_GOTIFY="NO" + # check stackpulse [ -z "${STACKPULSE_WEBHOOK}" ] && SEND_STACKPULSE="NO" @@ -626,7 +634,8 @@ if [ "${SEND_PUSHOVER}" = "YES" ] || [ "${SEND_MSTEAMS}" = "YES" ] || [ "${SEND_DYNATRACE}" = "YES" ] || [ "${SEND_STACKPULSE}" = "YES" ] || - [ "${SEND_OPSGENIE}" = "YES" ]; then + [ "${SEND_OPSGENIE}" = "YES" ] || + [ "${SEND_GOTIFY}" = "YES" ]; then # if we need curl, check for the curl command if [ -z "${curl}" ]; then curl="$(command -v curl 2>/dev/null)" @@ -656,6 +665,7 @@ if [ "${SEND_PUSHOVER}" = "YES" ] || SEND_DYNATRACE="NO" SEND_STACKPULSE="NO" SEND_OPSGENIE="NO" + SEND_GOTIFY="NO" fi fi @@ -795,7 +805,8 @@ for method in "${SEND_EMAIL}" \ "${SEND_MSTEAMS}" \ "${SEND_DYNATRACE}" \ "${SEND_STACKPULSE}" \ - "${SEND_OPSGENIE}" ; do + "${SEND_OPSGENIE}" \ + "${SEND_GOTIFY}" ; do if [ "${method}" == "YES" ]; then proceed=1 @@ -2278,6 +2289,37 @@ EOF } # ----------------------------------------------------------------------------- +# Gotify sender + +send_gotify() { + local payload httpcode + [ "${SEND_GOTIFY}" != "YES" ] && return 1 + + if [ -z "${GOTIFY_APP_TOKEN}" ] ; then + info "Can't send Gotify notification, because GOTIFY_APP_TOKEN is not defined" + return 1 + fi + + payload=$(cat <<EOF + { + "title" : "${status}, ${name} = ${value_string}, on ${host}", + "message" : "${date}: ${chart} ${value_string}" + } +EOF +) + + httpcode=$(docurl -X POST -H "Content-Type: application/json" -d "${payload}" "${GOTIFY_APP_URL}/message?token=${GOTIFY_APP_TOKEN}") + if [ "${httpcode}" = "200" ]; then + info "sent gotify notification for: ${host} ${chart}.${name} is ${status}" + else + error "failed to send gotify notification for: ${host} ${chart}.${name} is ${status}, with HTTP error code ${httpcode}." + return 1 + fi + + return 0 +} + +# ----------------------------------------------------------------------------- # prepare the content of the notification # the url to send the user on click @@ -3467,6 +3509,11 @@ send_opsgenie SENT_OPSGENIE=$? # ----------------------------------------------------------------------------- +# send messages to Gotify +send_gotify +SENT_GOTIFY=$? + +# ----------------------------------------------------------------------------- # let netdata know for state in "${SENT_EMAIL}" \ "${SENT_PUSHOVER}" \ @@ -3495,7 +3542,8 @@ for state in "${SENT_EMAIL}" \ "${SENT_MSTEAMS}" \ "${SENT_DYNATRACE}" \ "${SENT_STACKPULSE}" \ - "${SENT_OPSGENIE}"; do + "${SENT_OPSGENIE}" \ + "${SENT_GOTIFY}"; do if [ "${state}" -eq 0 ]; then # we sent something exit 0 diff --git a/health/notifications/gotify/Makefile.inc b/health/notifications/gotify/Makefile.inc new file mode 100644 index 0000000000..782559125c --- /dev/null +++ b/health/notifications/gotify/Makefile.inc @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-3.0-or-later + +# THIS IS NOT A COMPLETE Makefile +# IT IS INCLUDED BY ITS PARENT'S Makefile.am +# IT IS REQUIRED TO REFERENCE ALL FILES RELATIVE TO THE PARENT + +# install these files +dist_noinst_DATA += \ + gotify/README.md \ + gotify/Makefile.inc \ + $(NULL) diff --git a/health/notifications/gotify/README.md b/health/notifications/gotify/README.md new file mode 100644 index 0000000000..c253c845c7 --- /dev/null +++ b/health/notifications/gotify/README.md @@ -0,0 +1,62 @@ +<!-- +title: "Send notifications to Gotify" +description: "Send alerts to your Gotify instance when an alert gets triggered in Netdata." +sidebar_label: "Gotify" +custom_edit_url: https://github.com/netdata/netdata/edit/master/health/notifications/gotify/README.md +--> + +# Send notifications to Gotify + +[Gotify](https://gotify.net/) is a self-hosted push notification service created for sending and receiving messages in real time. + +## Configuring Gotify + +### Prerequisites + +To use Gotify as your notification service, you need an application token. +You can generate a new token in the Gotify Web UI. + +### Configuration + +To set up Gotify in Netdata: + +1. Switch to your [config +directory](/docs/configure/nodes.md) and edit the file `health_alarm_notify.conf` using the edit config script. + + ```bash + ./edit-config health_alarm_notify.conf + ``` + +2. Change the variable `GOTIFY_APP_TOKEN` to the application token you generated in the Gotify Web UI. Change +`GOTIFY_APP_URL` to point to your Gotify instance. + + ```conf + SEND_GOTIFY="YES" + + # Application token + # Gotify instance url + GOTIFY_APP_TOKEN=XXXXXXXXXXXXXXX + GOTIFY_APP_URL=https://push.example.de/ + ``` + + Changes to `health_alarm_notify.conf` do not require a Netdata restart. + +3. Test your Gotify notifications configuration by running the following commands, replacing `ROLE` with your preferred role: + + ```sh + # become user netdata + sudo su -s /bin/bash netdata + + # send a test alarm + /usr/libexec/netdata/plugins.d/alarm-notify.sh test ROLE + ``` + + 🟢 If everything works, you'll see alarms in Gotify: + + ![Example alarm notifications in Gotify](https://user-images.githubusercontent.com/103264516/162509205-1e88e5d9-96b6-4f7f-9426-182776158128.png) + + 🔴 If sending the test notifications fails, check `/var/log/netdata/error.log` to find the relevant error message: + + ```log + 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. + ``` diff --git a/health/notifications/health_alarm_notify.conf b/health/notifications/health_alarm_notify.conf index 873c7c353f..b69c6d538a 100755 --- a/health/notifications/health_alarm_notify.conf +++ b/health/notifications/health_alarm_notify.conf @@ -279,6 +279,16 @@ STACKPULSE_WEBHOOK="" DEFAULT_RECIPIENT_STACKPULSE="" #------------------------------------------------------------------------------ +# gotify global notification options +SEND_GOTIFY="YES" + +# App token and url +GOTIFY_APP_TOKEN="" +GOTIFY_APP_URL="" + +DEFAULT_RECIPIENT_GOTIFY="" + +#------------------------------------------------------------------------------ # opsgenie global notification options SEND_OPSGENIE="YES" @@ -971,6 +981,8 @@ role_recipients_matrix[sysadmin]="${DEFAULT_RECIPIENT_MATRIX}" role_recipients_stackpulse[sysadmin]="${DEFAULT_RECIPIENT_STACKPULSE}" +role_recipients_gotify[sysadmin]="${DEFAULT_RECIPIENT_GOTIFY}" + # ----------------------------------------------------------------------------- # DNS related alarms @@ -1028,6 +1040,8 @@ role_recipients_matrix[domainadmin]="${DEFAULT_RECIPIENT_MATRIX}" role_recipients_stackpulse[domainadmin]="${DEFAULT_RECIPIENT_STACKPULSE}" +role_recipients_gotify[domainadmin]="${DEFAULT_RECIPIENT_GOTIFY}" + # ----------------------------------------------------------------------------- # database servers alarms # mysql, redis, memcached, postgres, etc @@ -1086,6 +1100,8 @@ role_recipients_matrix[dba]="${DEFAULT_RECIPIENT_MATRIX}" role_recipients_stackpulse[dba]="${DEFAULT_RECIPIENT_STACKPULSE}" +role_recipients_gotify[dba]="${DEFAULT_RECIPIENT_GOTIFY}" + # ----------------------------------------------------------------------------- # web servers alarms # apache, nginx, lighttpd, etc @@ -1144,6 +1160,8 @@ role_recipients_matrix[webmaster]="${DEFAULT_RECIPIENT_MATRIX}" role_recipients_stackpulse[webmaster]="${DEFAULT_RECIPIENT_STACKPULSE}" +role_recipients_gotify[webmaster]="${DEFAULT_RECIPIENT_GOTIFY}" + # ----------------------------------------------------------------------------- # proxy servers alarms # squid, etc @@ -1202,6 +1220,8 @@ role_recipients_matrix[proxyadmin]="${DEFAULT_RECIPIENT_MATRIX}" role_recipients_stackpulse[proxyadmin]="${DEFAULT_RECIPIENT_STACKPULSE}" +role_recipients_gotify[proxyadmin]="${DEFAULT_RECIPIENT_GOTIFY}" + # ----------------------------------------------------------------------------- # peripheral devices # UPS, photovoltaics, etc @@ -1257,3 +1277,5 @@ role_recipients_opsgenie[sitemgr]="${DEFAULT_RECIPIENT_OPSGENIE}" role_recipients_matrix[sitemgr]="${DEFAULT_RECIPIENT_MATRIX}" role_recipients_stackpulse[sitemgr]="${DEFAULT_RECIPIENT_STACKPULSE}" + +role_recipients_gotify[sitemgr]="${DEFAULT_RECIPIENT_GOTIFY}" |