@cryptotaxi247 / netdata-1 / commits / e4cb54f97

Add Kavenegar.com, Iranian API based sms service

vahit committed Sep 26, 2017 at 11:54 UTC e4cb54f97d2b27a75cc2f2fbb90a3083c8e60cbb
3 files changed +103 -1
README.md
+1 -1
@@ -64,7 +64,7 @@ Netdata is featured at <b><a href="https://octoverse.github.com/" target="_blank
64 hundreds of alarms, **out of the box**!<br/>
65 supports dynamic thresholds, hysteresis, alarm templates,
66 multiple role-based notification methods (such as email, slack.com,
67 - pushover.net, pushbullet.com, telegram.org, twilio.com, messagebird.com)
67 + pushover.net, pushbullet.com, telegram.org, twilio.com, messagebird.com, kavenegar.com)
68
69 - **Extensible**<br/>
70 you can monitor anything you can get a metric for,
conf.d/health_alarm_notify.conf
+33
@@ -80,6 +80,7 @@ curl=""
80 # discord : "alarms disasters|critical"
81 # twilio : "+15555555555 +17777777777|critical"
82 # messagebird: "+15555555555 +17777777777|critical"
83 +# kavenegar : "09155555555 09177777777|critical"
84 # pd : "<pd_service_key_1> <pd_service_key_2>|critical"
85 #
86 # If a recipient is set to empty string, the default recipient of the given
@@ -204,6 +205,28 @@ MESSAGEBIRD_NUMBER=""
205 DEFAULT_RECIPIENT_MESSAGEBIRD=""
206
207
208 +#------------------------------------------------------------------------------
209 +# Kavenegar (Kavenegar.com) SMS options
210 +
211 +# multiple recipients can be given like this:
212 +# "09155555555 09177777777"
213 +
214 +# enable/disable sending messagebird SMS
215 +SEND_KAVENEGAR="YES"
216 +
217 +# to get an access key, after selecting and purchasing your desired service
218 +# at http://kavenegar.com/pricing.html
219 +# login to your account, go to your dashboard and my account are
220 +# https://panel.kavenegar.com/Client/setting/account from API Key
221 +# copy your api key. You can generate new API Key too.
222 +# You can find and select kevenegar sender number from this place.
223 +
224 +# Without an API key, netdata cannot send KAVENEGAR text messages.
225 +KAVENEGAR_API_KEY=""
226 +KAVENEGAR_SENDER=""
227 +DEFAULT_RECIPIENT_KAVENEGAR=""
228 +
229 +
230 #------------------------------------------------------------------------------
231 # telegram (telegram.org) global notification options
232
@@ -406,6 +429,8 @@ role_recipients_twilio[sysadmin]="${DEFAULT_RECIPIENT_TWILIO}"
429
430 role_recipients_messagebird[sysadmin]="${DEFAULT_RECIPIENT_MESSAGEBIRD}"
431
432 +role_recipients_kavenegar[sysadmin]="${DEFAULT_RECIPIENT_KAVENEGAR}"
433 +
434 role_recipients_pd[sysadmin]="${DEFAULT_RECIPIENT_PD}"
435
436 role_recipients_custom[sysadmin]="${DEFAULT_RECIPIENT_CUSTOM}"
@@ -431,6 +456,8 @@ role_recipients_twilio[domainadmin]="${DEFAULT_RECIPIENT_TWILIO}"
456
457 role_recipients_messagebird[domainadmin]="${DEFAULT_RECIPIENT_MESSAGEBIRD}"
458
459 +role_recipients_kavenegar[domainadmin]="${DEFAULT_RECIPIENT_KAVENEGAR}"
460 +
461 role_recipients_pd[domainadmin]="${DEFAULT_RECIPIENT_PD}"
462
463 role_recipients_custom[domainadmin]="${DEFAULT_RECIPIENT_CUSTOM}"
@@ -457,6 +484,8 @@ role_recipients_twilio[dba]="${DEFAULT_RECIPIENT_TWILIO}"
484
485 role_recipients_messagebird[dba]="${DEFAULT_RECIPIENT_MESSAGEBIRD}"
486
487 +role_recipients_kavenegar[dba]="${DEFAULT_RECIPIENT_KAVENEGAR}"
488 +
489 role_recipients_pd[dba]="${DEFAULT_RECIPIENT_PD}"
490
491 role_recipients_custom[dba]="${DEFAULT_RECIPIENT_CUSTOM}"
@@ -483,6 +512,8 @@ role_recipients_twilio[webmaster]="${DEFAULT_RECIPIENT_TWILIO}"
512
513 role_recipients_messagebird[webmaster]="${DEFAULT_RECIPIENT_MESSAGEBIRD}"
514
515 +role_recipients_kavenegar[webmaster]="${DEFAULT_RECIPIENT_KAVENEGAR}"
516 +
517 role_recipients_pd[webmaster]="${DEFAULT_RECIPIENT_PD}"
518
519 role_recipients_custom[webmaster]="${DEFAULT_RECIPIENT_CUSTOM}"
@@ -509,6 +540,8 @@ role_recipients_twilio[proxyadmin]="${DEFAULT_RECIPIENT_TWILIO}"
540
541 role_recipients_messagebird[proxyadmin]="${DEFAULT_RECIPIENT_MESSAGEBIRD}"
542
543 +role_recipients_kavenegar[proxyadmin]="${DEFAULT_RECIPIENT_KAVENEGAR}"
544 +
545 role_recipients_pd[proxyadmin]="${DEFAULT_RECIPIENT_PD}"
546
547 role_recipients_custom[proxyadmin]="${DEFAULT_RECIPIENT_CUSTOM}"
plugins.d/alarm-notify.sh
+69
@@ -224,6 +224,7 @@ SEND_PUSHOVER="YES"
224 SEND_TWILIO="YES"
225 SEND_HIPCHAT="YES"
226 SEND_MESSAGEBIRD="YES"
227 +SEND_KAVENEGAR="YES"
228 SEND_TELEGRAM="YES"
229 SEND_EMAIL="YES"
230 SEND_PUSHBULLET="YES"
@@ -270,6 +271,12 @@ MESSAGEBIRD_NUMBER=
271 DEFAULT_RECIPIENT_MESSAGEBIRD=
272 declare -A role_recipients_messagebird=()
273
274 +# kavenegar configs
275 +KAVENEGAR_API_KEY=""
276 +KAVENEGAR_SENDER=""
277 +DEFAULT_RECIPIENT_KAVENEGAR=""
278 +declare -A role_recipients_kavenegar=""
279 +
280 # telegram configs
281 TELEGRAM_BOT_TOKEN=
282 DEFAULT_RECIPIENT_TELEGRAM=
@@ -382,6 +389,7 @@ declare -A arr_pd=()
389 declare -A arr_email=()
390 declare -A arr_custom=()
391 declare -A arr_messagebird=()
392 +declare -A arr_kavenegar=()
393
394 # netdata may call us with multiple roles, and roles may have multiple but
395 # overlapping recipients - so, here we find the unique recipients.
@@ -439,6 +447,14 @@ do
447 [ "${r}" != "disabled" ] && filter_recipient_by_criticality messagebird "${r}" && arr_messagebird[${r/|*/}]="1"
448 done
449
450 + # kavenegar
451 + a="${role_recipients_kavenegar[${x}]}"
452 + [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_KAVENEGAR}"
453 + for r in ${a//,/ }
454 + do
455 + [ "${r}" != "disabled" ] && filter_recipient_by_criticality kavenegar "${r}" && arr_kavenegar[${r/|*/}]="1"
456 + done
457 +
458 # telegram
459 a="${role_recipients_telegram[${x}]}"
460 [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_TELEGRAM}"
@@ -509,6 +525,10 @@ to_hipchat="${!arr_hipchat[*]}"
525 to_messagebird="${!arr_messagebird[*]}"
526 [ -z "${to_messagebird}" ] && SEND_MESSAGEBIRD="NO"
527
528 +# build the list of kavenegar recipients (phone numbers)
529 +to_kavenegar="${!arr_kavenegar[*]}"
530 +[ -z "${to_kavenegar}" ] && SEND_KAVENEGAR="NO"
531 +
532 # check array of telegram recipients (chat ids)
533 to_telegram="${!arr_telegram[*]}"
534 [ -z "${to_telegram}" ] && SEND_TELEGRAM="NO"
@@ -555,6 +575,9 @@ done
575 # check messagebird
576 [ -z "${MESSAGEBIRD_ACCESS_KEY}" -o -z "${MESSAGEBIRD_NUMBER}" ] && SEND_MESSAGEBIRD="NO"
577
578 +# check kavenegar
579 +[ -z "${KAVENEGAR_API_KEY}" -o -z "${KAVENEGAR_SENDER}" ] && SEND_KAVENEGAR="NO"
580 +
581 # check telegram
582 [ -z "${TELEGRAM_BOT_TOKEN}" ] && SEND_TELEGRAM="NO"
583
@@ -582,6 +605,7 @@ if [ \( \
605 -o "${SEND_HIPCHAT}" = "YES" \
606 -o "${SEND_TWILIO}" = "YES" \
607 -o "${SEND_MESSAGEBIRD}" = "YES" \
608 + -o "${SEND_KAVENEGAR}" = "YES" \
609 -o "${SEND_TELEGRAM}" = "YES" \
610 -o "${SEND_PUSHBULLET}" = "YES" \
611 -o "${SEND_KAFKA}" = "YES" \
@@ -599,6 +623,7 @@ if [ \( \
623 SEND_TWILIO="NO"
624 SEND_HIPCHAT="NO"
625 SEND_MESSAGEBIRD="NO"
626 + SEND_KAVENEGAR="NO"
627 SEND_KAFKA="NO"
628 fi
629 fi
@@ -623,6 +648,7 @@ if [ "${SEND_EMAIL}" != "YES" \
648 -a "${SEND_TWILIO}" != "YES" \
649 -a "${SEND_HIPCHAT}" != "YES" \
650 -a "${SEND_MESSAGEBIRD}" != "YES" \
651 + -a "${SEND_KAVENEGAR}" != "YES" \
652 -a "${SEND_PUSHBULLET}" != "YES" \
653 -a "${SEND_KAFKA}" != "YES" \
654 -a "${SEND_PD}" != "YES" \
@@ -1053,6 +1079,36 @@ send_messagebird() {
1079 return 1
1080 }
1081
1082 +# -----------------------------------------------------------------------------
1083 +# kavenegar sender
1084 +
1085 +send_kavenegar() {
1086 + local API_KEY="${1}" kavenegarsender="${2}" recipients="${3}" title="${4}" message="${5}" httpcode sent=0 user
1087 + if [ "${SEND_KAVENEGAR}" = "YES" -a ! -z "${API_KEY}" -a ! -z "${kavenegarsender}" -a ! -z "${recipients}" -a ! -z "${message}" -a ! -z "${title}" ]
1088 + then
1089 + # http://api.kavenegar.com/v1/{API-KEY}/sms/send.json
1090 + for user in ${recipients}
1091 + do
1092 + httpcode=$(docurl -X POST http://api.kavenegar.com/v1/${API_KEY}/sms/send.json \
1093 + --data-urlencode "sender=${kavenegarsender}" \
1094 + --data-urlencode "receptor=${user}" \
1095 + --data-urlencode "message=${title} ${message}")
1096 +
1097 + if [ "${httpcode}" == "201" ]
1098 + then
1099 + info "sent Kavenegar SMS for: ${host} ${chart}.${name} is ${status} to '${user}'"
1100 + sent=$((sent + 1))
1101 + else
1102 + error "failed to send Kavenegar SMS for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
1103 + fi
1104 + done
1105 +
1106 + [ ${sent} -gt 0 ] && return 0
1107 + fi
1108 +
1109 + return 1
1110 +}
1111 +
1112 # -----------------------------------------------------------------------------
1113 # telegram sender
1114
@@ -1383,6 +1439,18 @@ ${info}"
1439 SENT_MESSAGEBIRD=$?
1440
1441
1442 +# -----------------------------------------------------------------------------
1443 +# send the kavenegar SMS
1444 +
1445 +send_kavenegar "${KAVENEGAR_API_KEY}" "${KAVENEGAR_SENDER}" "${to_kavenegar}" "${host} ${status_message} - ${name//_/ } - ${chart}" "${alarm}
1446 +Severity: ${severity}
1447 +Chart: ${chart}
1448 +Family: ${family}
1449 +${info}"
1450 +
1451 +SENT_KAVENEGAR=$?
1452 +
1453 +
1454 # -----------------------------------------------------------------------------
1455 # send the telegram.org message
1456
@@ -1574,6 +1642,7 @@ if [ ${SENT_EMAIL} -eq 0 \
1642 -o ${SENT_TWILIO} -eq 0 \
1643 -o ${SENT_HIPCHAT} -eq 0 \
1644 -o ${SENT_MESSAGEBIRD} -eq 0 \
1645 + -o ${SENT_KAVENEGAR} -eq 0 \
1646 -o ${SENT_PUSHBULLET} -eq 0 \
1647 -o ${SENT_KAFKA} -eq 0 \
1648 -o ${SENT_PD} -eq 0 \