From 6ed420f3b3bedf9156946d182afc0d0d54139eb7 Mon Sep 17 00:00:00 2001 From: "Costa Tsaousis (ktsaou)" Date: Fri, 9 Sep 2016 00:57:34 +0300 Subject: [PATCH] alarm-notify.sh configuration; alarm-notify.sh support multiple recipients per alarm for pushover --- conf.d/health_alarm_notify.conf | 76 ++++++++++++++++++++++++++------- plugins.d/alarm-notify.sh | 38 +++++++++-------- 2 files changed, 82 insertions(+), 32 deletions(-) diff --git a/conf.d/health_alarm_notify.conf b/conf.d/health_alarm_notify.conf index e4855913..d1c42bd2 100644 --- a/conf.d/health_alarm_notify.conf +++ b/conf.d/health_alarm_notify.conf @@ -2,52 +2,98 @@ # netdata alarms have been categorized to allow different roles to receive # alarms related to their work. +# +# This file defines the addresses for each role. +# This file is a BASH script itself. -# this file defines the email addresses for each role. if a role is not -# defined, the email will be sent to root. +############################################################################### +# external commands needed + +# The full path to the sendmail command. +# If empty, the system $PATH will be searched for it. +sendmail= + +# The full path of the curl command. +# If empty, the system $PATH will be searched for it. +curl= + + +############################################################################### +# sending emails + +# note: multiple recipients can be given like this: +# "admin1@example.com, admin2@example.com, ..." +# note it needs a comma! + +# enable/disable sending emails +SEND_EMAIL="YES" + +# if a role recipient is not configured, an email will be send to +DEFAULT_RECIPIENT_EMAIL="root" -# you can set multiple addresses for each role, like this: -# -# recipients[sysadmin]="admin1@example.com, admin2@example.com" -# -# it is important to add the comma between email addresses. -# This configuration file is a BASH script itself. The 'recipients' variable is -# an associative array. So you can use other variables too, like this one: +############################################################################### +# sending pushover notifications (pushover.com) -default_recipient_for_all_roles="root" +# note: multiple recipients can be given like this: +# "USERTOKEN1 USERTOKEN2 USERTOKEN3 ..." +# enable/disable sending pushover notifications +SEND_PUSHOVER="YES" + +# Login to pushover.com to get your pushover app token +# You need only one for all your netdata servers. +# Without it, netdata cannot send pushover notifications. +PUSHOVER_APP_TOKEN= + +# if a role recipient is not configured, a notification will be send to +# this pushover user token +DEFAULT_RECIPIENT_PUSHOVER= + + +############################################################################### +# RECIPIENTS PER ROLE # ----------------------------------------------------------------------------- # generic system alarms # CPU, disks, entropy, etc -recipients[sysadmin]="${default_recipient_for_all_roles}" +role_recipients_email[sysadmin]="${DEFAULT_RECIPIENT_EMAIL}" + +role_recipients_pushover[sysadmin]="${DEFAULT_RECIPIENT_PUSHOVER}" # ----------------------------------------------------------------------------- # DNS related alarms -recipients[domainadmin]="${default_recipient_for_all_roles}" +role_recipients_email[domainadmin]="${DEFAULT_RECIPIENT_EMAIL}" + +role_recipients_pushover[domainadmin]="${DEFAULT_RECIPIENT_PUSHOVER}" # ----------------------------------------------------------------------------- # database servers alarms # mysql, redis, memcached, etc -recipients[dba]="${default_recipient_for_all_roles}" +role_recipients_email[dba]="${DEFAULT_RECIPIENT_EMAIL}" + +role_recipients_pushover[dba]="${DEFAULT_RECIPIENT_PUSHOVER}" # ----------------------------------------------------------------------------- # web servers alarms # apache, nginx, etc -recipients[webmaster]="${default_recipient_for_all_roles}" +role_recipients_email[webmaster]="${DEFAULT_RECIPIENT_EMAIL}" + +role_recipients_pushover[webmaster]="${DEFAULT_RECIPIENT_PUSHOVER}" # ----------------------------------------------------------------------------- # proxy servers alarms # apache, nginx, etc -recipients[proxyadmin]="${default_recipient_for_all_roles}" +role_recipients_email[proxyadmin]="${DEFAULT_RECIPIENT_EMAIL}" + +role_recipients_pushover[proxyadmin]="${DEFAULT_RECIPIENT_PUSHOVER}" diff --git a/plugins.d/alarm-notify.sh b/plugins.d/alarm-notify.sh index 9188b967..55d149a5 100755 --- a/plugins.d/alarm-notify.sh +++ b/plugins.d/alarm-notify.sh @@ -195,27 +195,31 @@ send_email() { # pushover sender send_pushover() { - local apptoken="${1}" usertoken="${2}" title="${3}" message="${4}" httpcode + local apptoken="${1}" usertoken="${2}" title="${3}" message="${4}" httpcode sent=0 user if [ "${SEND_PUSHOVER}" = "YES" -a ! -z "${apptoken}" -a ! -z "${usertoken}" -a ! -z "${title}" -a ! -z "${message}" ] then - httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null \ - --form-string "token=${apptoken}" \ - --form-string "user=${usertoken}" \ - --form-string "html=1" \ - --form-string "title=${title}" \ - --form-string "message=${message}" \ - https://api.pushover.net/1/messages.json) - - if [ "${httpcode}" == "200" ] - then - echo >&2 "${me}: Sent notification push for ${status} on '${chart}.${name}'" - return 0 - else - echo >&2 "${me}: FAILED to send notification push for ${status} on '${chart}.${name}' with HTTP error code ${httpcode}." - return 1 - fi + for user in ${usertoken//,/ } + do + httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null \ + --form-string "token=${apptoken}" \ + --form-string "user=${user}" \ + --form-string "html=1" \ + --form-string "title=${title}" \ + --form-string "message=${message}" \ + https://api.pushover.net/1/messages.json) + + if [ "${httpcode}" == "200" ] + then + echo >&2 "${me}: Sent notification push for ${status} on '${chart}.${name}' to '${user}'" + sent=$((sent + 1)) + else + echo >&2 "${me}: FAILED to send notification push for ${status} on '${chart}.${name}' to '${user}' with HTTP error code ${httpcode}." + fi + done + + [ ${sent} -gt 0 ] && return 0 fi return 1 -- 2.39.2