summaryrefslogtreecommitdiffstats
path: root/plugins.d
diff options
context:
space:
mode:
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2016-10-23 23:07:58 +0300
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2016-10-23 23:07:58 +0300
commit072e244f93439abf6e0d0ef109e606bec42350c0 (patch)
treecfe7423780748632cd03e769568fbf6b0b2ccec3 /plugins.d
parent9110abcb944099fe8fd94037e66baedd976be873 (diff)
alarm-test script rewritten - fixes #943; pushbullet notifications follow the format of the others; minor other improvements
Diffstat (limited to 'plugins.d')
-rwxr-xr-xplugins.d/alarm-notify.sh48
-rwxr-xr-x[-rw-r--r--]plugins.d/alarm-test.sh13
2 files changed, 46 insertions, 15 deletions
diff --git a/plugins.d/alarm-notify.sh b/plugins.d/alarm-notify.sh
index a41c55bc70..28f550f306 100755
--- a/plugins.d/alarm-notify.sh
+++ b/plugins.d/alarm-notify.sh
@@ -15,12 +15,36 @@
#
# Supported notification methods:
# - emails
-# - pushover.net notifications
-# - pushbullet.com push notifications
# - slack.com notifications
-# - telegram.org notifications
+# - pushover.net notifications
+# - pushbullet.com push notifications by Tiago Peralta @tperalta82 PR #1070
+# - telegram.org notifications by @hashworks PR #1002
#
+# -----------------------------------------------------------------------------
+# testing notifications
+
+if [ \( "${1}" = "test" -o "${2}" = "test" \) -a "${#}" -le 2 ]
+then
+ if [ "${2}" = "test" ]
+ then
+ recipient="${1}"
+ else
+ recipient="${2}"
+ fi
+
+ [ -z "${recipient}" ] && recipient="sysadmin"
+
+ echo >&2 ">> SENDING TEST ALARM TO ROLE: ${recipient} <<"
+
+ "${0}" "${recipient}" 'test' '1' '1' '1' '1' 'test_alarm' 'test_alarm' 'test' 'CRITICAL' 'CLEAR' '1' '1' "${0}" '1' '1' 'number' 'test alarm to verify notifications work'
+ ret=$?
+
+ [ ${ret} -ne 0 ] && echo >&2 ">> FAILED <<" && exit ${ret}
+ echo >&2 ">> OK <<"
+ exit $?
+fi
+
export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
export LC_ALL=C
@@ -499,7 +523,7 @@ send_pushover() {
# pushbullet sender
send_pushbullet() {
- local userapikey="${1}" recipients="${2}" message="${3}" title="${4}" httpcode sent=0 user
+ local userapikey="${1}" recipients="${2}" title="${3}" message="${4}" httpcode sent=0 user
if [ "${SEND_PUSHBULLET}" = "YES" -a ! -z "${userapikey}" -a ! -z "${recipients}" -a ! -z "${message}" -a ! -z "${title}" ]
then
#https://docs.pushbullet.com/#create-push
@@ -518,10 +542,10 @@ EOF
if [ "${httpcode}" == "200" ]
then
- echo >&2 "${me}: Sent pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
+ info "sent pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
sent=$((sent + 1))
else
- echo >&2 "${me}: Failed to send pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
+ error "failed to send pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
fi
done
@@ -750,14 +774,12 @@ SENT_PUSHOVER=$?
# -----------------------------------------------------------------------------
# send the pushbullet notification
-pushbullet_message="${alarm} \n
-Severity: ${severity} \n
-Chart: ${chart} \n
-Family: ${family} \n
-To View Netdata go to: ${goto_url} \n
+send_pushbullet "${PUSHBULLET_ACCESS_TOKEN}" "${to_pushbullet}" "${host} ${status_message} - ${name//_/ } - ${chart}" "${alarm}\n
+Severity: ${severity}\n
+Chart: ${chart}\n
+Family: ${family}\n
+To View Netdata go to: ${goto_url}\n
The source of this alarm is line ${src}"
-pushbullet_title="${status} at ${host} ${status_message} - ${name//_/ } - ${chart}}"
-send_pushbullet "${PUSHBULLET_ACCESS_TOKEN}" "${to_pushbullet}" "$pushbullet_message" "$pushbullet_title"
SENT_PUSHBULLET=$?
diff --git a/plugins.d/alarm-test.sh b/plugins.d/alarm-test.sh
index b97155d8ee..1963111a53 100644..100755
--- a/plugins.d/alarm-test.sh
+++ b/plugins.d/alarm-test.sh
@@ -1,3 +1,12 @@
#!/usr/bin/env bash
-DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-$($DIR/alarm-notify.sh 'sysadmin' 'DummyAlarm' '1475604061' '1475604028' '3' '1475604369' '10min_cpu_usage' 'system.cpu' 'cpu' 'WARNING' 'CLEAR' '83' '80' '2@/etc/netdata/health.d/cpu.conf' '360' '0' '%' 'average cpu utilization for the last 45 minutes'})
+
+# netdata
+# real-time performance and health monitoring, done right!
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
+# GPL v3+
+#
+# Script to test alarm notifications for netdata
+
+dir="$(dirname "${0}")"
+${dir}/alarm-notify.sh test "${1}"
+exit $?