From 47c1365347f65c5e300571e3af7bfe3248b75261 Mon Sep 17 00:00:00 2001 From: "Costa Tsaousis (ktsaou)" Date: Fri, 21 Jul 2017 00:41:18 +0300 Subject: alarm-notify.sh now enables debug mode when NETDATA_ALARM_NOTIFY_DEBUG=1 --- plugins.d/alarm-notify.sh | 66 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 16 deletions(-) (limited to 'plugins.d') diff --git a/plugins.d/alarm-notify.sh b/plugins.d/alarm-notify.sh index 4f619091f1..65e0594077 100755 --- a/plugins.d/alarm-notify.sh +++ b/plugins.d/alarm-notify.sh @@ -99,11 +99,41 @@ fatal() { exit 1 } -debug=0 +debug=${NETDATA_ALARM_NOTIFY_DEBUG-0} debug() { - [ ${debug} -eq 1 ] && log DEBUG "${@}" + [ "${debug}" = "1" ] && log DEBUG "${@}" } +docurl() { + if [ -z "${curl}" ] + then + error "\${curl} is unset." + return 1 + fi + + if [ "${debug}" = "1" ] + then + echo >&2 "--- BEGIN curl command ---" + printf >&2 "%q " ${curl} "${@}" + echo >&2 + echo >&2 "--- END curl command ---" + + local out=$(mktemp /tmp/netdata-health-alarm-notify-XXXXXXXX) + local code=$(${curl} --write-out %{http_code} --output "${out}" --silent --show-error "${@}") + local ret=$? + echo >&2 "--- BEGIN received response ---" + cat >&2 "${out}" + echo >&2 + echo >&2 "--- END received response ---" + echo >&2 "RECEIVED HTTP RESPONSE CODE: ${code}" + rm "${out}" + echo "${code}" + return ${ret} + fi + + ${curl} --write-out %{http_code} --output /dev/null --silent --show-error "${@}" + return $? +} # ----------------------------------------------------------------------------- # this is to be overwritten by the config file @@ -266,6 +296,8 @@ declare -A role_recipients_email=() if [ -f "${NETDATA_CONFIG_DIR}/health_alarm_notify.conf" ] then source "${NETDATA_CONFIG_DIR}/health_alarm_notify.conf" +else + error "Cannot find file ${NETDATA_CONFIG_DIR}/health_alarm_notify.conf. Using internal defaults." fi # ----------------------------------------------------------------------------- @@ -508,8 +540,7 @@ if [ "${SEND_PD}" = "YES" ] pd_send="$(which pd-send 2>/dev/null || command -v pd-send 2>/dev/null)" if [ -z "${pd_send}" ] then - # no pd-send available - # disable pagerduty.com + error "Cannot find pd-send command in the system path. Disabling pagerduty.com notifications." SEND_PD="NO" fi fi @@ -530,8 +561,7 @@ if [ \( \ curl="$(which curl 2>/dev/null || command -v curl 2>/dev/null)" if [ -z "${curl}" ] then - # no curl available - # disable all curl based methods + error "Cannot find curl command in the system path. Disabling all curl based notifications." SEND_PUSHOVER="NO" SEND_PUSHBULLET="NO" SEND_TELEGRAM="NO" @@ -548,7 +578,11 @@ fi if [ "${SEND_EMAIL}" = "YES" -a -z "${sendmail}" ] then sendmail="$(which sendmail 2>/dev/null || command -v sendmail 2>/dev/null)" - [ -z "${sendmail}" ] && SEND_EMAIL="NO" + if [ -z "${sendmail}" ] + then + debug "Cannot find sendmail command in the system path. Disabling email notifications." + SEND_EMAIL="NO" + fi fi # check that we have at least a method enabled @@ -699,7 +733,7 @@ send_pushover() { for user in ${usertokens} do - httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null \ + httpcode=$(docurl \ --form-string "token=${apptoken}" \ --form-string "user=${user}" \ --form-string "html=1" \ @@ -736,7 +770,7 @@ send_pushbullet() { #https://docs.pushbullet.com/#create-push for user in ${recipients} do - httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null \ + httpcode=$(docurl \ --header 'Access-Token: '${userapikey}'' \ --header 'Content-Type: application/json' \ --data-binary @<(cat <