summaryrefslogtreecommitdiffstats
path: root/src/health/notifications/alarm-notify.sh.in
diff options
context:
space:
mode:
Diffstat (limited to 'src/health/notifications/alarm-notify.sh.in')
-rwxr-xr-xsrc/health/notifications/alarm-notify.sh.in62
1 files changed, 59 insertions, 3 deletions
diff --git a/src/health/notifications/alarm-notify.sh.in b/src/health/notifications/alarm-notify.sh.in
index c7c44cb11..d7baa7345 100755
--- a/src/health/notifications/alarm-notify.sh.in
+++ b/src/health/notifications/alarm-notify.sh.in
@@ -769,6 +769,9 @@ fi
# check custom
[ -z "${DEFAULT_RECIPIENT_CUSTOM}" ] && SEND_CUSTOM="NO"
+# check ilert
+[ -z "${ILERT_ALERT_SOURCE_URL}" ] && SEND_ILERT="NO"
+
# -----------------------------------------------------------------------------
# check the availability of targets
@@ -798,7 +801,8 @@ check_supported_targets() {
[ "${SEND_DYNATRACE}" = "YES" ] ||
[ "${SEND_OPSGENIE}" = "YES" ] ||
[ "${SEND_GOTIFY}" = "YES" ] ||
- [ "${SEND_NTFY}" = "YES" ]; then
+ [ "${SEND_NTFY}" = "YES" ] ||
+ [ "${SEND_ILERT}" = "YES" ]; then
# if we need curl, check for the curl command
if [ -z "${curl}" ]; then
curl="$(command -v curl 2>/dev/null)"
@@ -828,6 +832,7 @@ check_supported_targets() {
SEND_OPSGENIE="NO"
SEND_GOTIFY="NO"
SEND_NTFY="NO"
+ SEND_ILERT="NO"
fi
fi
@@ -983,7 +988,8 @@ for method in "${SEND_EMAIL}" \
"${SEND_DYNATRACE}" \
"${SEND_OPSGENIE}" \
"${SEND_GOTIFY}" \
- "${SEND_NTFY}" ; do
+ "${SEND_NTFY}" \
+ "${SEND_ILERT}" ; do
if [ "${method}" == "YES" ]; then
proceed=1
@@ -2432,6 +2438,50 @@ send_ntfy() {
}
# -----------------------------------------------------------------------------
+# ilert sender
+
+send_ilert() {
+ local payload httpcode
+ [ "${SEND_ILERT}" != "YES" ] && return 1
+
+ if [ -z "${ILERT_ALERT_SOURCE_URL}" ] ; then
+ info "Can't send ilert notification, because ILERT_ALERT_SOURCE_URL is not defined"
+ return 1
+ fi
+
+ payload=$(cat <<EOF
+ {
+ "alert" : "${name}",
+ "alert_url" : "${goto_url}",
+ "alarm_id" : ${alarm_id},
+ "chart" : "${chart}",
+ "date" : "${when}",
+ "duration" : "${duration_txt}",
+ "host" : "${host}",
+ "info" : "${info}",
+ "message" : "${status_message}",
+ "severity": ${status},
+ "total_critical" : "${total_critical}",
+ "total_warnings" : "${total_warnings}",
+ "value" : "${value_string}",
+ "image_url": "${image}",
+ "src" : "${src}"
+ }
+EOF
+)
+
+ httpcode=$(docurl -X POST -H "Content-Type: application/json" -d "${payload}" "${ILERT_ALERT_SOURCE_URL}")
+ if [ "${httpcode}" = "200" ] || [ "${httpcode}" = "202" ]; then
+ info "sent ilert event for ${notification_description}"
+ else
+ error "failed to send ilert event for ${notification_description}, with HTTP response status code ${httpcode}."
+ return 1
+ fi
+
+ return 0
+}
+
+# -----------------------------------------------------------------------------
# prepare the content of the notification
# the url to send the user on click
@@ -3604,6 +3654,11 @@ send_ntfy "${DEFAULT_RECIPIENT_NTFY}"
SENT_NTFY=$?
# -----------------------------------------------------------------------------
+# send messages to ilert
+send_ilert
+SENT_ILERT=$?
+
+# -----------------------------------------------------------------------------
# let netdata know
for state in "${SENT_EMAIL}" \
"${SENT_PUSHOVER}" \
@@ -3632,7 +3687,8 @@ for state in "${SENT_EMAIL}" \
"${SENT_DYNATRACE}" \
"${SENT_OPSGENIE}" \
"${SENT_GOTIFY}" \
- "${SENT_NTFY}"; do
+ "${SENT_NTFY}" \
+ "${SENT_ILERT}"; do
if [ "${state}" -eq 0 ]; then
# we sent something
exit 0