From 00151562145df50cc65e9902d52d5fa77f89fe50 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 9 Jun 2022 06:52:47 +0200 Subject: Merging upstream version 1.35.0. Signed-off-by: Daniel Baumann --- health/notifications/Makefile.am | 1 + health/notifications/alarm-notify.sh.in | 69 +++++++++++++++++++++++++-- health/notifications/gotify/Makefile.inc | 11 +++++ health/notifications/gotify/README.md | 62 ++++++++++++++++++++++++ health/notifications/health_alarm_notify.conf | 22 +++++++++ 5 files changed, 161 insertions(+), 4 deletions(-) create mode 100644 health/notifications/gotify/Makefile.inc create mode 100644 health/notifications/gotify/README.md (limited to 'health/notifications') diff --git a/health/notifications/Makefile.am b/health/notifications/Makefile.am index 46a6e472c..f026171a7 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 287cabfef..38a69a0f3 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 @@ -243,6 +244,7 @@ else total_crit_alarms="${26}" # List of alarms in critical state classification="${27}" # The class field from .conf files edit_command_line="${28}" # The command to edit the alarm, with the line number + child_machine_guid="${29}" # If populated, the notification is sent for a child fi # ----------------------------------------------------------------------------- @@ -400,6 +402,10 @@ SEND_DYNATRACE= # stackpulse configs STACKPULSE_WEBHOOK= +# gotify configs +GOTIFY_APP_URL= +GOTIFY_APP_TOKEN= + # opsgenie configs OPSGENIE_API_KEY= @@ -589,6 +595,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 +635,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 +666,7 @@ if [ "${SEND_PUSHOVER}" = "YES" ] || SEND_DYNATRACE="NO" SEND_STACKPULSE="NO" SEND_OPSGENIE="NO" + SEND_GOTIFY="NO" fi fi @@ -795,7 +806,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 @@ -2277,6 +2289,45 @@ EOF return 0 } +# ----------------------------------------------------------------------------- +# Gotify sender + +send_gotify() { + local payload httpcode priority + [ "${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 + + # priority for Gotify Android app + case "${status}" in + CRITICAL) priority=10 ;; # sound + vibration + WARNING) priority=4 ;; # sound + *) priority=1 ;; # notification only + esac + + payload=$(cat < + +# 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 873c7c353..b69c6d538 100755 --- a/health/notifications/health_alarm_notify.conf +++ b/health/notifications/health_alarm_notify.conf @@ -278,6 +278,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}" -- cgit v1.2.3