@cryptotaxi247 / netdata-1 / commits / 9c807630e

Add SMS Server Tools 3 SMS notifications (#5662)

* Add SMS Server Tools 3 SMS notifications * Minor reordering to present changes better * Fix typo in README link * Fix Codacy Missing code-language flag * Fix missing "to" in readme

Chris Akritidis committed Mar 25, 2019 at 10:52 UTC 9c807630ea5e10144892a5bfc5379b36c2a63e8d
6 files changed +122 -1
README.md
+1 -1
@@ -246,7 +246,7 @@ This is what you should expect from Netdata:
246
247 ### Health Monitoring & Alarms
248 - **Sophisticated alerting** - comes with hundreds of alarms, **out of the box**! Supports dynamic thresholds, hysteresis, alarm templates, multiple role-based notification methods.
249 -- **Notifications**: [alerta.io](health/notifications/alerta/), [amazon sns](health/notifications/awssns/), [discordapp.com](health/notifications/discord/), [email](health/notifications/email/), [flock.com](health/notifications/flock/), [irs](health/notifications/irc/), [kavenegar.com](health/notifications/kavenegar/), [messagebird.com](health/notifications/messagebird/), [pagerduty.com](health/notifications/pagerduty/), [pushbullet.com](health/notifications/pushbullet/), [pushover.net](health/notifications/pushover/), [rocket.chat](health/notifications/rocketchat/), [slack.com](health/notifications/slack/), [syslog](health/notifications/syslog/), [telegram.org](health/notifications/telegram/), [twilio.com](health/notifications/twilio/), [web](health/notifications/web/).
249 +- **Notifications**: [alerta.io](health/notifications/alerta/), [amazon sns](health/notifications/awssns/), [discordapp.com](health/notifications/discord/), [email](health/notifications/email/), [flock.com](health/notifications/flock/), [irc](health/notifications/irc/), [kavenegar.com](health/notifications/kavenegar/), [messagebird.com](health/notifications/messagebird/), [pagerduty.com](health/notifications/pagerduty/), [prowl](health/notifications/prowl/), [pushbullet.com](health/notifications/pushbullet/), [pushover.net](health/notifications/pushover/), [rocket.chat](health/notifications/rocketchat/), [slack.com](health/notifications/slack/), [smstools3](health/notifications/smstools3/), [syslog](health/notifications/syslog/), [telegram.org](health/notifications/telegram/), [twilio.com](health/notifications/twilio/), [web](health/notifications/web/).
250
251 ### Integrations
252 - **time-series dbs** - can archive its metrics to `graphite`, `opentsdb`, `prometheus`, json document DBs, in the same or lower resolution (lower: to prevent it from congesting these servers due to the amount of data collected).
health/notifications/Makefile.am
+1
@@ -39,6 +39,7 @@ include pushbullet/Makefile.inc
39 include pushover/Makefile.inc
40 include rocketchat/Makefile.inc
41 include slack/Makefile.inc
42 +include smstools3/Makefile.inc
43 include syslog/Makefile.inc
44 include telegram/Makefile.inc
45 include twilio/Makefile.inc
health/notifications/alarm-notify.sh.in
+48
@@ -165,6 +165,7 @@ kavenegar
165 prowl
166 awssns
167 rocketchat
168 +sms
169 "
170
171 # -----------------------------------------------------------------------------
@@ -537,6 +538,14 @@ if [ "${SEND_PUSHOVER}" = "YES" ] ||
538 fi
539 fi
540
541 +if [ "${SEND_SMS}" = "YES" ]; then
542 + if [ -z "${sendsms}" ]; then
543 + sendsms="$(command -v sendsms 2>/dev/null)"
544 + fi
545 + if [ -z "${sendsms}" ]; then
546 + SEND_SMS="NO"
547 + fi
548 +fi
549 # if we need sendmail, check for the sendmail command
550 if [ "${SEND_EMAIL}" = "YES" ] && [ -z "${sendmail}" ]; then
551 sendmail="$(command -v sendmail 2>/dev/null)"
@@ -649,6 +658,7 @@ for method in "${SEND_EMAIL}" \
658 "${SEND_IRC}" \
659 "${SEND_AWSSNS}" \
660 "${SEND_SYSLOG}" \
661 + "${SEND_SMS}" \
662 "${SEND_MSTEAM}"; do
663 if [ "${method}" == "YES" ]; then
664 proceed=1
@@ -1726,6 +1736,36 @@ send_syslog() {
1736 return $?
1737 }
1738
1739 +# -----------------------------------------------------------------------------
1740 +# SMS sender
1741 +
1742 +send_sms() {
1743 + local recipients="${1}" exitcode sent=0
1744 +
1745 + # Human readable SMS
1746 + local msg="${host} ${status_message}: ${chart} (${family}), ${alarm}"
1747 +
1748 + # limit it to 160 characters
1749 + msg="${msg:0:160}"
1750 +
1751 + if [ "${SEND_SMS}" = "YES" ] && [ -n "${sendsms}" ] && [ -n "${recipients}" ] && [ -n "${msg}" ]; then
1752 + # http://api.kavenegar.com/v1/{API-KEY}/sms/send.json
1753 + for phone in ${recipients}; do
1754 + exitcode=$($sendsms $phone "$msg")
1755 + if [ ${exitcode} -eq 0 ]; then
1756 + info "sent smstools3 SMS for: ${host} ${chart}.${name} is ${status} to '${user}'"
1757 + sent=$((sent + 1))
1758 + else
1759 + error "failed to send smstools3 SMS for: ${host} ${chart}.${name} is ${status} to '${user}' with error code ${exitcode}."
1760 + fi
1761 + done
1762 +
1763 + [ ${sent} -gt 0 ] && return 0
1764 + fi
1765 +
1766 + return 1
1767 +}
1768 +
1769 # -----------------------------------------------------------------------------
1770 # prepare the content of the notification
1771
@@ -1995,6 +2035,13 @@ ${info}"
2035
2036 SENT_IRC=$?
2037
2038 +# -----------------------------------------------------------------------------
2039 +# send the SMS message with smstools3
2040 +
2041 +send_sms "${to_sms}"
2042 +
2043 +SENT_SMS=$?
2044 +
2045 # -----------------------------------------------------------------------------
2046 # send the custom message
2047
@@ -2209,6 +2256,7 @@ for state in "${SENT_EMAIL}" \
2256 "${SENT_IRC}" \
2257 "${SENT_AWSSNS}" \
2258 "${SENT_SYSLOG}" \
2259 + "${SENT_SMS}" \
2260 "${SENT_MSTEAM}"; do
2261 if [ "${state}" -eq 0 ]; then
2262 # we sent something
health/notifications/health_alarm_notify.conf
+28
@@ -13,6 +13,7 @@
13 # - messages to your telegram chat / group chat (telegram.org)
14 # - sms messages to your cell phone or any sms enabled device (twilio.com)
15 # - sms messages to your cell phone or any sms enabled device (messagebird.com)
16 +# - sms messages to your cell phone or any sms enabled device (smstools3)
17 # - notifications to users on pagerduty.com
18 # - push notifications to iOS devices (via prowlapp.com)
19 # - notifications to Amazon SNS topics (aws.amazon.com)
@@ -110,6 +111,11 @@ logger=""
111 # If not found, Amazon SNS notifications will be silently disabled.
112 aws=""
113
114 +# The full path of the sendsms command (smstools3).
115 +# If empty, the system $PATH will be searched for it.
116 +# If not found, SMS notifications will be silently disabled.
117 +sendsms=""
118 +
119 #------------------------------------------------------------------------------
120 # extra options for external commands
121 #
@@ -692,6 +698,18 @@ AWSSNS_MESSAGE_FORMAT="${status} on ${host} at ${date}: ${chart} ${value_string}
698 #
699 DEFAULT_RECIPIENT_AWSSNS=""
700
701 +#------------------------------------------------------------------------------
702 +# SMS Server Tools 3 (smstools3) global notification options
703 +
704 +# enable/disable sending SMS Server Tools 3 SMS notifications
705 +SEND_SMS="YES"
706 +
707 +# if a role's recipients are not configured, a notification will be sent to
708 +# this SMS channel (empty = do not send a notification for unconfigured
709 +# roles). Multiple recipients can be given like this: "PHONE1 PHONE2 ..."
710 +
711 +DEFAULT_RECIPIENT_SMS=""
712 +
713 #------------------------------------------------------------------------------
714 # custom notifications
715 #
@@ -844,6 +862,8 @@ role_recipients_custom[domainadmin]="${DEFAULT_RECIPIENT_CUSTOM}"
862
863 role_recipients_msteam[domainadmin]="${DEFAULT_RECIPIENT_MSTEAM}"
864
865 +role_recipients_sms[domainadmin]="${DEFAULT_RECIPIENT_SMS}"
866 +
867 # -----------------------------------------------------------------------------
868 # database servers alarms
869 # mysql, redis, memcached, postgres, etc
@@ -888,6 +908,8 @@ role_recipients_custom[dba]="${DEFAULT_RECIPIENT_CUSTOM}"
908
909 role_recipients_msteam[dba]="${DEFAULT_RECIPIENT_MSTEAM}"
910
911 +role_recipients_sms[dba]="${DEFAULT_RECIPIENT_SMS}"
912 +
913 # -----------------------------------------------------------------------------
914 # web servers alarms
915 # apache, nginx, lighttpd, etc
@@ -932,6 +954,8 @@ role_recipients_custom[webmaster]="${DEFAULT_RECIPIENT_CUSTOM}"
954
955 role_recipients_msteam[webmaster]="${DEFAULT_RECIPIENT_MSTEAM}"
956
957 +role_recipients_sms[webmaster]="${DEFAULT_RECIPIENT_SMS}"
958 +
959 # -----------------------------------------------------------------------------
960 # proxy servers alarms
961 # squid, etc
@@ -976,6 +1000,8 @@ role_recipients_custom[proxyadmin]="${DEFAULT_RECIPIENT_CUSTOM}"
1000
1001 role_recipients_msteam[proxyadmin]="${DEFAULT_RECIPIENT_MSTEAM}"
1002
1003 +role_recipients_sms[proxyadmin]="${DEFAULT_RECIPIENT_SMS}"
1004 +
1005 # -----------------------------------------------------------------------------
1006 # peripheral devices
1007 # UPS, photovoltaics, etc
@@ -1017,3 +1043,5 @@ role_recipients_awssns[sitemgr]="${DEFAULT_RECIPIENT_AWSSNS}"
1043 role_recipients_custom[sitemgr]="${DEFAULT_RECIPIENT_CUSTOM}"
1044
1045 role_recipients_msteam[sitemgr]="${DEFAULT_RECIPIENT_MSTEAM}"
1046 +
1047 +role_recipients_sms[sitemgr]="${DEFAULT_RECIPIENT_SMS}"
health/notifications/smstools3/Makefile.inc new
+12
@@ -0,0 +1,12 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +# THIS IS NOT A COMPLETE Makefile
4 +# IT IS INCLUDED BY ITS PARENT'S Makefile.am
5 +# IT IS REQUIRED TO REFERENCE ALL FILES RELATIVE TO THE PARENT
6 +
7 +# install these files
8 +dist_noinst_DATA += \
9 + smstools3/README.md \
10 + smstools3/Makefile.inc \
11 + $(NULL)
12 +
health/notifications/smstools3/README.md new
+32
@@ -0,0 +1,32 @@
1 +# SMS Server Tools 3
2 +
3 +The [SMS Server Tools 3](http://smstools3.kekekasvi.com/) is a SMS Gateway software which can send and receive short messages through GSM modems and mobile phones.
4 +
5 +To have netdata send notifications via SMS Server Tools 3, you'll first need to [install](http://smstools3.kekekasvi.com/index.php?p=compiling) and [configure](http://smstools3.kekekasvi.com/index.php?p=configure) smsd.
6 +
7 +You then just need to configure the recipient phone numbers in `health_alarm_notify.conf`:
8 +
9 +```sh
10 +#------------------------------------------------------------------------------
11 +# SMS Server Tools 3 (smstools3) global notification options
12 +
13 +# enable/disable sending SMS Server Tools 3 SMS notifications
14 +SEND_SMS="YES"
15 +
16 +# if a role's recipients are not configured, a notification will be sent to
17 +# this SMS channel (empty = do not send a notification for unconfigured
18 +# roles). Multiple recipients can be given like this: "PHONE1 PHONE2 ..."
19 +
20 +DEFAULT_RECIPIENT_SMS=""
21 +```
22 +
23 +Netdata uses the script `sendsms` that is installed by `smstools3` and just passes a phone number and a message to it. If `sendsms` is not in `$PATH`, you can pass its location in `health_alarm_notify.conf`:
24 +
25 +```sh
26 +# The full path of the sendsms command (smstools3).
27 +# If empty, the system $PATH will be searched for it.
28 +# If not found, SMS notifications will be silently disabled.
29 +sendsms=""
30 +```
31 +
32 +[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Fhealth%2Fnotifications%2Fsmstools3%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)]()