diff options
-rwxr-xr-x | conf.d/health_alarm_notify.conf | 42 | ||||
-rwxr-xr-x | plugins.d/alarm-notify.sh | 68 |
2 files changed, 109 insertions, 1 deletions
diff --git a/conf.d/health_alarm_notify.conf b/conf.d/health_alarm_notify.conf index 890b189930..9e72aac4dc 100755 --- a/conf.d/health_alarm_notify.conf +++ b/conf.d/health_alarm_notify.conf @@ -14,6 +14,7 @@ # - sms messages to your cell phone or any sms enabled device (twilio.com) # - sms messages to your cell phone or any sms enabled device (messagebird.com) # - notifications to users on pagerduty.com +# - notifications to Amazon SNS topics (aws.amazon.com) # - messages to your irc channel on your selected network # - messages to a local or remote syslog daemon # - message to Microsoft Team (thru webhook) @@ -85,6 +86,11 @@ nc="" # If not found, syslog notifications will be silently disabled. logger="" +# The full path of the aws command. +# If empty, the system $PATH will be searched for it. +# If not found, Amazon SNS notifications will be silently disabled. +aws="" + #------------------------------------------------------------------------------ # extra options for external commands # @@ -619,6 +625,28 @@ SYSLOG_FACILITY='' DEFAULT_RECIPIENT_SYSLOG="netdata" #------------------------------------------------------------------------------ +# Amazon SNS notifications +# +# This method requires potentially complex manual configuration. See the +# netdata wiki for information on what is needed. + +# enable/disable sending Amazon SNS notifications +SEND_AWSSNS="YES" + +# Specify a template for the Amazon SNS notifications. This supports +# the same set of variables that are usable in the `custom_sender()` +# function in the custom notification configuration below. +# +AWSSNS_MESSAGE_FORMAT="${status} on ${host} at ${date}: ${chart} ${value_string}" + +# If a role's recipients are not configured, use the following. +# (empty = do not send a notification for unconfigured roles) +# +# Recipients for AWS SNS notifications are specified as topic ARN's. +# +DEFAULT_RECIPIENT_AWSSNS="" + +#------------------------------------------------------------------------------ # custom notifications # @@ -719,6 +747,8 @@ role_recipients_irc[sysadmin]="${DEFAULT_RECIPIENT_IRC}" role_recipients_syslog[sysadmin]="${DEFAULT_RECIPIENT_SYSLOG}" +role_recipients_awssns[sysadmin]="${DEFAULT_RECIPIENT_AWSSNS}" + role_recipients_custom[sysadmin]="${DEFAULT_RECIPIENT_CUSTOM}" role_recipients_msteam[sysadmin]="${DEFAULT_RECIPIENT_MSTEAM}" @@ -758,6 +788,8 @@ role_recipients_irc[domainadmin]="${DEFAULT_RECIPIENT_IRC}" role_recipients_syslog[domainadmin]="${DEFAULT_RECIPIENT_SYSLOG}" +role_recipients_awssns[domainadmin]="${DEFAULT_RECIPIENT_AWSSNS}" + role_recipients_custom[domainadmin]="${DEFAULT_RECIPIENT_CUSTOM}" role_recipients_msteam[domainadmin]="${DEFAULT_RECIPIENT_MSTEAM}" @@ -798,6 +830,8 @@ role_recipients_irc[dba]="${DEFAULT_RECIPIENT_IRC}" role_recipients_syslog[dba]="${DEFAULT_RECIPIENT_SYSLOG}" +role_recipients_awssns[dba]="${DEFAULT_RECIPIENT_AWSSNS}" + role_recipients_custom[dba]="${DEFAULT_RECIPIENT_CUSTOM}" role_recipients_msteam[dba]="${DEFAULT_RECIPIENT_MSTEAM}" @@ -838,6 +872,8 @@ role_recipients_irc[webmaster]="${DEFAULT_RECIPIENT_IRC}" role_recipients_syslog[webmaster]="${DEFAULT_RECIPIENT_SYSLOG}" +role_recipients_awssns[webmaster]="${DEFAULT_RECIPIENT_AWSSNS}" + role_recipients_custom[webmaster]="${DEFAULT_RECIPIENT_CUSTOM}" role_recipients_msteam[webmaster]="${DEFAULT_RECIPIENT_MSTEAM}" @@ -878,6 +914,8 @@ role_recipients_irc[proxyadmin]="${DEFAULT_RECIPIENT_IRC}" role_recipients_syslog[proxyadmin]="${DEFAULT_RECIPIENT_SYSLOG}" +role_recipients_awssns[porxyadmin]="${DEFAULT_RECIPIENT_AWSSNS}" + role_recipients_custom[proxyadmin]="${DEFAULT_RECIPIENT_CUSTOM}" role_recipients_msteam[proxyadmin]="${DEFAULT_RECIPIENT_MSTEAM}" @@ -916,6 +954,8 @@ role_recipients_fleep[sitemgr]="${DEFAULT_RECIPIENT_FLEEP}" role_recipients_syslog[sitemgr]="${DEFAULT_RECIPIENT_SYSLOG}" +role_recipients_awssns[sitemgr]="${DEFAULT_RECIPIENT_AWSSNS}" + role_recipients_custom[sitemgr]="${DEFAULT_RECIPIENT_CUSTOM}" -role_recipients_msteam[sitemgr]="${DEFAULT_RECIPIENT_MSTEAM}"
\ No newline at end of file +role_recipients_msteam[sitemgr]="${DEFAULT_RECIPIENT_MSTEAM}" diff --git a/plugins.d/alarm-notify.sh b/plugins.d/alarm-notify.sh index cf1f9978ae..b37e9bfbd9 100755 --- a/plugins.d/alarm-notify.sh +++ b/plugins.d/alarm-notify.sh @@ -245,6 +245,7 @@ SEND_KAFKA="YES" SEND_PD="YES" SEND_FLEEP="YES" SEND_IRC="YES" +SEND_AWSSNS="YES" SEND_SYSLOG="NO" SEND_CUSTOM="YES" @@ -334,6 +335,11 @@ FLEEP_SENDER="${host}" DEFAULT_RECIPIENT_FLEEP= declare -A role_recipients_fleep=() +# Amazon SNS configs +DEFAULT_RECIPIENT_AWSSNS= +AWSSNS_MESSAGE_FORMAT= +declare -A role_recipients_awssns=() + # syslog configs SYSLOG_FACILITY= declare -A role_recipients_syslog=() @@ -452,6 +458,7 @@ declare -A arr_kavenegar=() declare -A arr_fleep=() declare -A arr_irc=() declare -A arr_syslog=() +declare -A arr_awssns=() # netdata may call us with multiple roles, and roles may have multiple but # overlapping recipients - so, here we find the unique recipients. @@ -597,6 +604,14 @@ do [ "${r}" != "disabled" ] && filter_recipient_by_criticality irc "${r}" && arr_irc[${r/|*/}]="1" done + # amazon sns + a="${role_recipients_awssns[${x}]}" + [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_AWSSNS}" + for r in ${a//,/ } + do + [ "${r}" != "disabled" ] && filter_recipient_by_criticality awssns "${r}" && arr_awssns[${r/|*/}]="1" + done + # syslog a="${role_recipients_syslog[${x}]}" [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_SYSLOG}" @@ -692,6 +707,10 @@ done to_irc="${!arr_irc[*]}" [ -z "${to_irc}" ] && SEND_IRC="NO" +# build the list of awssns recipients (facilities, servers, and prefixes) +to_awssns="${!arr_awssns[*]}" +[ -z "${to_awssns}" ] && SEND_AWSSNS="NO" + # build the list of syslog recipients (facilities, servers, and prefixes) to_syslog="${!arr_syslog[*]}" [ -z "${to_syslog}" ] && SEND_SYSLOG="NO" @@ -822,6 +841,17 @@ if [ "${SEND_SYSLOG}" = "YES" -a -z "${logger}" ] fi fi +# if we need aws, check for the aws command +if [ "${SEND_AWSSNS}" = "YES" -a -z "${aws}" ] + then + aws="$(which aws 2>/dev/null || command -v aws 2>/dev/null)" + if [ -z "${aws}" ] + then + debug "Cannot find aws command in the system path. Disabling Amazon SNS notifications." + SEND_AWSSNS="NO" + fi +fi + # check that we have at least a method enabled if [ "${SEND_EMAIL}" != "YES" \ -a "${SEND_PUSHOVER}" != "YES" \ @@ -841,6 +871,7 @@ if [ "${SEND_EMAIL}" != "YES" \ -a "${SEND_FLEEP}" != "YES" \ -a "${SEND_CUSTOM}" != "YES" \ -a "${SEND_IRC}" != "YES" \ + -a "${SEND_AWSSNS}" != "YES" \ -a "${SEND_SYSLOG}" != "YES" \ -a "${SEND_MSTEAM}" != "YES" \ ] @@ -1786,6 +1817,34 @@ send_irc() { } # ----------------------------------------------------------------------------- +# Amazon SNS sender + +send_awssns() { + local targets="${1}" message='' sent=0 region='' + local default_format="${status} on ${host} at ${date}: ${chart} ${value_string}" + + [ "${SEND_AWSSNS}" = "YES" ] || return 1 + + message=${AWSSNS_MESSAGE_FORMAT:-${default_format}} + + for target in ${targets} ; do + # Extract the region from the target ARN. We need to explicitly specify the region so that it matches up correctly. + region="$(echo ${target} | cut -f 4 -d ':')" + ${aws} sns publish --region "${region}" --subject "${host} ${status_message} - ${name//_/ } - ${chart}" --message "${message}" --target-arn ${target} &>/dev/null + if [ $? = 0 ]; then + info "sent Amazon SNS notification for: ${host} ${chart}.${name} is ${status} to '${target}'" + sent=$((sent + 1)) + else + error "failed to send Amazon SNS notification for: ${host} ${chart}.${name} is ${status} to '${target}'" + fi + done + + [ ${sent} -gt 0 ] && return 0 + + return 1 +} + +# ----------------------------------------------------------------------------- # syslog sender send_syslog() { @@ -2140,6 +2199,14 @@ SENT_HIPCHAT=$? # ----------------------------------------------------------------------------- +# send the Amazon SNS message + +send_awssns ${to_awssns} + +SENT_AWSSNS=$? + + +# ----------------------------------------------------------------------------- # send the syslog message send_syslog ${to_syslog} @@ -2291,6 +2358,7 @@ if [ ${SENT_EMAIL} -eq 0 \ -o ${SENT_PD} -eq 0 \ -o ${SENT_FLEEP} -eq 0 \ -o ${SENT_IRC} -eq 0 \ + -o ${SENT_AWSSNS} -eq 0 \ -o ${SENT_CUSTOM} -eq 0 \ -o ${SENT_SYSLOG} -eq 0 \ ] |