X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=plugins.d%2Falarm-email.sh;h=df083c6559e8d0f14cda37c25218630e397683e0;hb=f5fef72a72cfc1c799b7a9b37ff2dfa25e731420;hp=e90aa0d4ef7db745db166a1b9e2a9db67988b782;hpb=f14cf74f118c2d362fa05fc28c33190984ee691f;p=netdata.git diff --git a/plugins.d/alarm-email.sh b/plugins.d/alarm-email.sh index e90aa0d4..df083c65 100755 --- a/plugins.d/alarm-email.sh +++ b/plugins.d/alarm-email.sh @@ -1,284 +1,6 @@ #!/usr/bin/env bash -me="${0}" +# OBSOLETE - REPLACED WITH +# alarm-notify.sh -sendmail="$(which sendmail 2>/dev/null || command -v sendmail 2>/dev/null)" -if [ -z "${sendmail}" ] -then - echo >&2 "I cannot send emails - there is no sendmail command available." - exit 1 -fi - -default_recipient_for_all_roles="root" -declare -A recipients=() -if [ -f "${NETDATA_CONFIG_DIR}/health_email_recipients.conf" ] - then - source "${NETDATA_CONFIG_DIR}/health_email_recipients.conf" -fi - -sendmail_from_pipe() { - "${sendmail}" -t - - if [ $? -eq 0 ] - then - echo >&2 "${me}: Sent notification email for ${status} on '${chart}.${name}'" - return 0 - else - echo >&2 "${me}: FAILED to send notification email for ${status} on '${chart}.${name}'" - return 1 - fi -} - -recipient="${1}" # the recepient of the email -hostname="${2}" # the hostname this event refers to -unique_id="${3}" # the unique id of this event -alarm_id="${4}" # the unique id of the alarm that generated this event -event_id="${5}" # the incremental id of the event, for this alarm -when="${6}" # the timestamp this event occured -name="${7}" # the name of the alarm, as given in netdata health.d entries -chart="${8}" # the name of the chart (type.id) -family="${9}" # the family of the chart -status="${10}" # the current status : UNITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL -old_status="${11}" # the previous status: UNITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL -value="${12}" # the current value -old_value="${13}" # the previous value -src="${14}" # the line number and file the alarm has been configured -duration="${15}" # the duration in seconds the previous state took -non_clear_duration="${16}" # the total duration in seconds this is non-clear -units="${17}" # the units of the value -info="${18}" # a short description of the alarm - -to="${recipients[${recipient}]}" -[ -z "${to}" ] && to="${default_recipient_for_all_roles}" -[ -z "${to}" ] && to="root" - -[ ! -z "${info}" ] && info="
${info}
" - -# get the system hostname -[ -z "${hostname}" ] && hostname="${NETDATA_HOSTNAME}" -[ -z "${hostname}" ] && hostname="${NETDATA_REGISTRY_HOSTNAME}" -[ -z "${hostname}" ] && hostname="$(hostname 2>/dev/null)" - -goto_url="${NETDATA_REGISTRY_URL}/goto-host-from-alarm.html?machine_guid=${NETDATA_REGISTRY_UNIQUE_ID}&chart=${chart}&family=${family}" - -date="$(date --date=@${when} 2>/dev/null)" -[ -z "${date}" ] && date="$(date 2>/dev/null)" - -# convert a duration in seconds, to a human readable duration -# using DAYS, MINUTES, SECONDS -duration4human() { - local s="${1}" d=0 h=0 m=0 ds="day" hs="hour" ms="minute" ss="second" - d=$(( s / 86400 )) - s=$(( s - (d * 86400) )) - h=$(( s / 3600 )) - s=$(( s - (h * 3600) )) - m=$(( s / 60 )) - s=$(( s - (m * 60) )) - - if [ ${d} -gt 0 ] - then - [ ${m} -ge 30 ] && h=$(( h + 1 )) - [ ${d} -gt 1 ] && ds="days" - [ ${h} -gt 1 ] && hs="hours" - if [ ${h} -gt 0 ] - then - echo "${d} ${ds} and ${h} ${hs}" - else - echo "${d} ${ds}" - fi - elif [ ${h} -gt 0 ] - then - [ ${s} -ge 30 ] && m=$(( m + 1 )) - [ ${h} -gt 1 ] && hs="hours" - [ ${m} -gt 1 ] && ms="minutes" - if [ ${m} -gt 0 ] - then - echo "${h} ${hs} and ${m} ${ms}" - else - echo "${h} ${hs}" - fi - elif [ ${m} -gt 0 ] - then - [ ${m} -gt 1 ] && ms="minutes" - [ ${s} -gt 1 ] && ss="seconds" - if [ ${s} -gt 0 ] - then - echo "${m} ${ms} and ${s} ${ss}" - else - echo "${m} ${ms}" - fi - else - [ ${s} -gt 1 ] && ss="seconds" - echo "${s} ${ss}" - fi -} - -severity="${status}" -raised_for="
(was ${old_status,,} for $(duration4human ${duration}))" -status_message="status unknown" -color="grey" -alarm="${name} = ${value} ${units}" - -# prepare the title based on status -case "${status}" in - CRITICAL) - status_message="is critical" - color="#ca414b" - ;; - - WARNING) - status_message="needs attention" - color="#caca4b" - ;; - - CLEAR) - status_message="recovered" - color="#77ca6d" - - # don't show the value when the status is CLEAR - # for certain alarms, this value might not have any meaning - alarm="${name}" - ;; -esac - -if [ "${status}" != "WARNING" -a "${status}" != "CRITICAL" -a "${status}" != "CLEAR" ] -then - # don't do anything if this is not WARNING, CRITICAL or CLEAR - echo >&2 "${me}: not sending notification email for ${status} on '${chart}.${name}'" - exit 0 -elif [ "${old_status}" != "WARNING" -a "${old_status}" != "CRITICAL" -a "${status}" = "CLEAR" ] -then - # don't do anything if this is CLEAR, but it was not WARNING or CRITICAL - echo >&2 "${me}: not sending notification email for ${status} on '${chart}.${name}' (last status was ${old_status})" - exit 0 -elif [ "${status}" = "CLEAR" ] -then - severity="Recovered from ${old_status}" - if [ $non_clear_duration -gt $duration ] - then - raised_for="
(had issues for $(duration4human ${non_clear_duration}))" - fi - -elif [ "${old_status}" = "WARNING" -a "${status}" = "CRITICAL" ] -then - severity="Escalated to ${status}" - if [ $non_clear_duration -gt $duration ] - then - raised_for="
(has issues for $(duration4human ${non_clear_duration}))" - fi - -elif [ "${old_status}" = "CRITICAL" -a "${status}" = "WARNING" ] -then - severity="Demoted to ${status}" - if [ $non_clear_duration -gt $duration ] - then - raised_for="
(has issues for $(duration4human ${non_clear_duration}))" - fi - -else - raised_for= -fi - -# send the email -cat < - - - - - - - - - -
-
- - - - - - - - - - - - -
-
netdata notification
-
-

${hostname} ${status_message}

-
-
- - - - - - - - - - - - - - - - - - - - - - - - - -
- ${chart} - Chart -
- ${alarm}${info} - Alarm -
- ${family} - Family -
- ${severity} - Severity -
${date} - ${raised_for} Time -
The source of this alarm is line ${src} -
Sent by - netdata, the real-time performance monitoring. -
-
-
-
-
- - -EOF +${0/alarm-email.sh/alarm-notify.sh} "${@}"