@cryptotaxi247 / netdata-1 / commits / 0e914f744

SMSEagle integration (#19520)

Co-authored-by: Ilya Mashchenko <ilya@netdata.cloud>

marcin-smseagle committed Jan 31, 2025 at 09:51 UTC 0e914f7447623e8b7e3d02318d4e9d80c3f8740c
3 files changed +239
src/health/notifications/alarm-notify.sh.in
+88
@@ -21,6 +21,7 @@
21 # - kafka notifications by @ktsaou #1342
22 # - pagerduty.com notifications by Jim Cooley @jimcooley #1373
23 # - messagebird.com notifications by @tech_no_logical #1453
24 +# - smseagle notificaitons by @smseagle
25 # - hipchat notifications by @ktsaou #1561
26 # - fleep notifications by @Ferroin
27 # - prowlapp.com notifications by @Ferroin
@@ -270,6 +271,7 @@ sms
271 syslog
272 telegram
273 twilio
274 +smseagle
275 "
276
277 # -----------------------------------------------------------------------------
@@ -438,6 +440,13 @@ HIPCHAT_AUTH_TOKEN=
440 MESSAGEBIRD_ACCESS_KEY=
441 MESSAGEBIRD_NUMBER=
442
443 +#smseagle configs
444 +SMSEAGLE_API_URL=
445 +SMSEAGLE_API_ACCESSTOKEN=
446 +SMSEAGLE_MSG_TYPE="sms"
447 +SMSEAGLE_CALL_DURATION="10"
448 +SMSEAGLE_VOICE_ID="1"
449 +
450 # kavenegar configs
451 KAVENEGAR_API_KEY=
452 KAVENEGAR_SENDER=
@@ -718,6 +727,9 @@ fi
727 # check messagebird
728 { [ -z "${MESSAGEBIRD_ACCESS_KEY}" ] || [ -z "${MESSAGEBIRD_NUMBER}" ]; } && SEND_MESSAGEBIRD="NO"
729
730 +# check smseagle
731 +{ [ -z "${SMSEAGLE_API_URL}" ] || [ -z "${SMSEAGLE_API_ACCESSTOKEN}" ] || [ -z "${SMSEAGLE_MSG_TYPE}" ]; } && SEND_SMSEAGLE="NO"
732 +
733 # check kavenegar
734 { [ -z "${KAVENEGAR_API_KEY}" ] || [ -z "${KAVENEGAR_SENDER}" ]; } && SEND_KAVENEGAR="NO"
735
@@ -785,6 +797,7 @@ check_supported_targets() {
797 [ "${SEND_HIPCHAT}" = "YES" ] ||
798 [ "${SEND_TWILIO}" = "YES" ] ||
799 [ "${SEND_MESSAGEBIRD}" = "YES" ] ||
800 + [ "${SEND_SMSEAGLE}" = "YES" ] ||
801 [ "${SEND_KAVENEGAR}" = "YES" ] ||
802 [ "${SEND_TELEGRAM}" = "YES" ] ||
803 [ "${SEND_PUSHBULLET}" = "YES" ] ||
@@ -818,6 +831,7 @@ check_supported_targets() {
831 SEND_TWILIO="NO"
832 SEND_HIPCHAT="NO"
833 SEND_MESSAGEBIRD="NO"
834 + SEND_SMSEAGLE="NO"
835 SEND_KAVENEGAR="NO"
836 SEND_KAFKA="NO"
837 SEND_FLEEP="NO"
@@ -968,6 +982,7 @@ for method in "${SEND_EMAIL}" \
982 "${SEND_TWILIO}" \
983 "${SEND_HIPCHAT}" \
984 "${SEND_MESSAGEBIRD}" \
985 + "${SEND_SMSEAGLE}" \
986 "${SEND_KAVENEGAR}" \
987 "${SEND_PUSHBULLET}" \
988 "${SEND_KAFKA}" \
@@ -1474,6 +1489,68 @@ send_messagebird() {
1489 return 1
1490 }
1491
1492 +# -----------------------------------------------------------------------------
1493 +# smseagle sender
1494 +
1495 +send_smseagle() {
1496 + local address="${1}" access_token="${2}" msg_type="${3}" recipients="${4}" duration="${5}" voice_id="${6}" msg="${host} ${status_message}: ${chart}, ${alarm}" httpcode sent=0 user
1497 + if [ "${SEND_SMSEAGLE}" = "YES" ] && [ -n "${address}" ] && [ -n "${access_token}" ] && [ -n "${msg_type}" ] && [ -n "${recipients}" ] && [ -n "${msg}" ]; then
1498 +
1499 + if [ -z "${duration}" ] && { [ "${msg_type}" = "ring" ] || [ "${msg_type}" = "tts" ] || [ "${msg_type}" = "tts_advanced" ]; }; then
1500 + duration=10
1501 + fi
1502 +
1503 + if [ -z "${voice_id}" ] && [ "${msg_type}" = "tts_advanced" ]; then
1504 + voice_id=1
1505 + fi
1506 +
1507 + IFS=' ' read -r -a recipientsArray <<< "${recipients}"
1508 + for ((i=0; i<${#recipientsArray[@]}; i++)); do
1509 + if [ $i -gt 0 ]; then
1510 + to+=","
1511 + fi
1512 + to+="\"${recipientsArray[$i]}\""
1513 + done
1514 +
1515 + payload=$(cat <<EOF
1516 + {
1517 + "to": [${to}],
1518 + "text": "${msg}",
1519 + "duration": ${duration},
1520 + "voice_id": ${voice_id}
1521 + }
1522 +EOF
1523 +)
1524 + msg_type_endpoint="messages/sms"
1525 +
1526 + case ${msg_type} in
1527 + "sms") msg_type_endpoint="messages/sms" ;;
1528 + "mms") msg_type_endpoint="messages/mms" ;;
1529 + "ring") msg_type_endpoint="calls/ring" ;;
1530 + "tts") msg_type_endpoint="calls/tts" ;;
1531 + "tts_advanced") msg_type_endpoint="calls/tts_advanced" ;;
1532 + *)
1533 + esac
1534 +
1535 + httpcode=$(docurl -X POST \
1536 + --data "${payload}" \
1537 + -H "access-token: ${access_token}" \
1538 + -H "Accept: application/json" \
1539 + -H "Content-Type: application/json" \
1540 + "${address}/api/v2/${msg_type_endpoint}"
1541 + )
1542 +
1543 + if [ "${httpcode}" = "200" ]; then
1544 + info "Sending successful for ${notification_description}"
1545 + return 0
1546 + fi
1547 +
1548 + error "Sending failed for ${notification_description}, with response code ${httpcode}."
1549 + return 1
1550 + fi
1551 + return 1
1552 +}
1553 +
1554 # -----------------------------------------------------------------------------
1555 # kavenegar sender
1556
@@ -2708,6 +2785,16 @@ ${info}"
2785
2786 SENT_MESSAGEBIRD=$?
2787
2788 +# -----------------------------------------------------------------------------
2789 +# send the SMSEAGLE SMS
2790 +
2791 +send_smseagle "${SMSEAGLE_API_URL}" "${SMSEAGLE_API_ACCESSTOKEN}" "${SMSEAGLE_MSG_TYPE}" "${to_smseagle}" "${SMSEAGLE_CALL_DURATION}" "${SMSEAGLE_VOICE_ID}" "${host} ${status_message} - ${name//_/ } - ${chart}" "${alarm}
2792 +Severity: ${severity}
2793 +Chart: ${chart}
2794 +${info}"
2795 +
2796 +SENT_SMSEAGLE=$?
2797 +
2798 # -----------------------------------------------------------------------------
2799 # send the kavenegar SMS
2800
@@ -3667,6 +3754,7 @@ for state in "${SENT_EMAIL}" \
3754 "${SENT_TWILIO}" \
3755 "${SENT_HIPCHAT}" \
3756 "${SENT_MESSAGEBIRD}" \
3757 + "${SENT_SMSEAGLE}" \
3758 "${SENT_KAVENEGAR}" \
3759 "${SENT_PUSHBULLET}" \
3760 "${SENT_KAFKA}" \
src/health/notifications/health_alarm_notify.conf
+44
@@ -14,6 +14,7 @@
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 +# - sms messages to your cell phone or any sms enabled device (SMSEagle)
18 # - notifications to users on pagerduty.com
19 # - push notifications to iOS devices (via prowlapp.com)
20 # - notifications to Amazon SNS topics (aws.amazon.com)
@@ -823,6 +824,37 @@ MATRIX_ACCESSTOKEN=
824 # The format is !roomid:homeservername
825 DEFAULT_RECIPIENT_MATRIX=""
826
827 +#------------------------------------------------------------------------------
828 +# SMSEagle global notification options
829 +# enable/disable sending SMSEagle SMS notifications
830 +SEND_SMSEAGLE="YES"
831 +
832 +# if a role's recipients are not configured, a notification will be sent to
833 +# this SMS recipient (empty = do not send a notification for unconfigured
834 +# roles). Multiple recipients can be given like this: "PHONE1,PHONE2 ..."
835 +DEFAULT_RECIPIENT_SMSEAGLE="999888777"
836 +
837 +# SMSEagle HTTP API configuration
838 +#
839 +# The URL of the SMSEagle device accessible from NetData
840 +# e.g https://192.168.0.101
841 +SMSEAGLE_API_URL=""
842 +
843 +# An access token for the user created at SMSEagle device
844 +# See more for authentication: https://www.smseagle.eu/docs/apiv2/
845 +SMSEAGLE_API_ACCESSTOKEN=""
846 +
847 +# Choose a type of message/call
848 +# Available types: sms, mms, ring, tts, tts_advanced
849 +# Be aware that some types require additional parameters to be set (found below)
850 +SMSEAGLE_MSG_TYPE="sms"
851 +
852 +# Call duration, parameter required for Ring, TTS and TTS Advanced. Default value is 10.
853 +SMSEAGLE_CALL_DURATION="10"
854 +
855 +# ID of the voice model, required for TTS Advanced. Default value is 1.
856 +SMSEAGLE_VOICE_ID="1"
857 +
858 #------------------------------------------------------------------------------
859 # ntfy.sh global notification options
860
@@ -963,6 +995,8 @@ custom_sender() {
995
996 # role_recipients_messagebird[sysadmin]="${DEFAULT_RECIPIENT_MESSAGEBIRD}"
997
998 +# role_recipients_smseagle[sysadmin]="${DEFAULT_RECIPIENT_SMSEAGLE}"
999 +
1000 # role_recipients_kavenegar[sysadmin]="${DEFAULT_RECIPIENT_KAVENEGAR}"
1001
1002 # role_recipients_pd[sysadmin]="${DEFAULT_RECIPIENT_PD}"
@@ -1020,6 +1054,8 @@ custom_sender() {
1054
1055 # role_recipients_messagebird[domainadmin]="${DEFAULT_RECIPIENT_MESSAGEBIRD}"
1056
1057 +# role_recipients_smseagle[domainadmin]="${DEFAULT_RECIPIENT_SMSEAGLE}"
1058 +
1059 # role_recipients_kavenegar[domainadmin]="${DEFAULT_RECIPIENT_KAVENEGAR}"
1060
1061 # role_recipients_pd[domainadmin]="${DEFAULT_RECIPIENT_PD}"
@@ -1080,6 +1116,8 @@ custom_sender() {
1116
1117 # role_recipients_messagebird[dba]="${DEFAULT_RECIPIENT_MESSAGEBIRD}"
1118
1119 +# role_recipients_smseagle[dba]="${DEFAULT_RECIPIENT_SMSEAGLE}"
1120 +
1121 # role_recipients_kavenegar[dba]="${DEFAULT_RECIPIENT_KAVENEGAR}"
1122
1123 # role_recipients_pd[dba]="${DEFAULT_RECIPIENT_PD}"
@@ -1140,6 +1178,8 @@ custom_sender() {
1178
1179 # role_recipients_messagebird[webmaster]="${DEFAULT_RECIPIENT_MESSAGEBIRD}"
1180
1181 +# role_recipients_smseagle[webmaster]="${DEFAULT_RECIPIENT_SMSEAGLE}"
1182 +
1183 # role_recipients_kavenegar[webmaster]="${DEFAULT_RECIPIENT_KAVENEGAR}"
1184
1185 # role_recipients_pd[webmaster]="${DEFAULT_RECIPIENT_PD}"
@@ -1200,6 +1240,8 @@ custom_sender() {
1240
1241 # role_recipients_messagebird[proxyadmin]="${DEFAULT_RECIPIENT_MESSAGEBIRD}"
1242
1243 +# role_recipients_smseagle[proxyadmin]="${DEFAULT_RECIPIENT_SMSEAGLE}"
1244 +
1245 # role_recipients_kavenegar[proxyadmin]="${DEFAULT_RECIPIENT_KAVENEGAR}"
1246
1247 # role_recipients_pd[proxyadmin]="${DEFAULT_RECIPIENT_PD}"
@@ -1260,6 +1302,8 @@ custom_sender() {
1302
1303 # role_recipients_messagebird[sitemgr]="${DEFAULT_RECIPIENT_MESSAGEBIRD}"
1304
1305 +# role_recipients_smseagle[sitemgr]="${DEFAULT_RECIPIENT_SMSEAGLE}"
1306 +
1307 # role_recipients_kavenegar[sitemgr]="${DEFAULT_RECIPIENT_KAVENEGAR}"
1308
1309 # role_recipients_pd[sitemgr]="${DEFAULT_RECIPIENT_PD}"
src/health/notifications/smseagle/metadata.yaml new
+107
@@ -0,0 +1,107 @@
1 +# yamllint disable rule:line-length
2 +---
3 +- id: 'notify-smseagle'
4 + meta:
5 + name: 'SMSEagle'
6 + link: 'https://www.smseagle.eu/'
7 + categories:
8 + - notify.agent
9 + icon_filename: 'smseagle.svg'
10 + keywords:
11 + - smseagle
12 + overview:
13 + notification_description: |
14 + Forward notifications to SMSEagle device to send SMS, MMS, wake-up, or text-to-speech calls.
15 + notification_limitations: ''
16 + setup:
17 + prerequisites:
18 + list:
19 + - title: ''
20 + description: |
21 + Before using the API, you'll need to enable API access on your SMSEagle device by following these steps:
22 +
23 + 1. Navigate to the Web-GUI and select the "Users" menu.
24 + 2. Create a new user account with "User" access level.
25 + 3. Locate the "Access to API" option next to your newly created user.
26 + 4. Select APIv2 and click the "Generate new token" button to create your API access token.
27 + 5. Set up the appropriate permissions in the APIv2 Permission section.
28 +
29 + Optional: Enable the "Access to resources of all users" checkbox if you want this API key to access data across all users. By default, the API key can only access data created under its credentials.
30 + configuration:
31 + file:
32 + name: 'health_alarm_notify.conf'
33 + options:
34 + description: 'The following options can be defined for this notification'
35 + folding:
36 + title: 'Config Options'
37 + enabled: true
38 + list:
39 + - name: 'DEFAULT_RECIPIENT_SMSEAGLE'
40 + default_value: ''
41 + description: "If a role's recipients are not configured, a notification will be sent to this SMS recipient (empty = do not send a notification for unconfigured roles). Multiple recipients can be given like this: \"PHONE1,PHONE2...\""
42 + required: true
43 + detailed_description: |
44 + All roles will default to this variable if left unconfigured.
45 +
46 + You can then have different recipients per role, by editing `DEFAULT_RECIPIENT_SMSEAGLE` with the number you want, in the following entries at the bottom of the same file:
47 + ```
48 + role_recipients_smseagle[sysadmin]="+11222333444"
49 + role_recipients_smseagle[domainadmin]="+11222333445"
50 + role_recipients_smseagle[dba]="+11222333446"
51 + role_recipients_smseagle[webmaster]="+11222333447"
52 + role_recipients_smseagle[proxyadmin]="+11222333448"
53 + role_recipients_smseagle[sitemgr]="+11222333449"
54 + ```
55 + - name: 'SMSEAGLE_API_URL'
56 + default_value: ''
57 + description: ""
58 + required: true
59 + detailed_description: |
60 + The url of the SMSEagle device accessible from NetData, e.g https://192.168.0.101
61 + - name: 'SMSEAGLE_API_ACCESSTOKEN'
62 + default_value: ''
63 + description: ""
64 + required: true
65 + detailed_description: |
66 + An access token for the user created at SMSEagle device
67 + - name: 'SMSEAGLE_MSG_TYPE'
68 + default_value: 'sms'
69 + description: ""
70 + required: true
71 + detailed_description: |
72 + Choose a type of message/call. Available types: sms, mms, ring (wake-up call), tts (text-to-speech call), tts_advanced (multilanguage text-to-speech call). Be aware that some types require additional parameters to be set.
73 + - name: 'SMSEAGLE_CALL_DURATION'
74 + default_value: '10'
75 + description: ""
76 + required: true
77 + detailed_description: |
78 + Call duration, parameter required for Ring, TTS and TTS Advanced.
79 + - name: 'SMSEAGLE_VOICE_ID'
80 + default_value: '10'
81 + description: ""
82 + required: true
83 + detailed_description: |
84 + ID of the voice model, required for TTS Advanced.
85 + examples:
86 + folding:
87 + enabled: true
88 + title: ''
89 + list:
90 + - name: 'Basic Configuration'
91 + folding:
92 + enabled: false
93 + description: ''
94 + config: |
95 + #------------------------------------------------------------------------------
96 + # SMSEagle options
97 +
98 + SEND_SMSEAGLE="YES"
99 + SMSEAGLE_API_URL="XXXXXXXX"
100 + SMSEAGLE_API_ACCESSTOKEN="XXXXXXX"
101 + SMSEAGLE_MSG_TYPE="sms"
102 + SMSEAGLE_CALL_DURATION="10"
103 + SMSEAGLE_VOICE_ID="1"
104 + DEFAULT_RECIPIENT_SMSEAGLE="+11222333444"
105 + troubleshooting:
106 + problems:
107 + list: []