alarm-notify.sh.in 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268
  1. #!/usr/bin/env bash
  2. #shellcheck source=/dev/null disable=SC2086,SC2154
  3. # netdata
  4. # real-time performance and health monitoring, done right!
  5. # (C) 2017 Costa Tsaousis <costa@tsaousis.gr>
  6. # SPDX-License-Identifier: GPL-3.0-or-later
  7. #
  8. # Script to send alarm notifications for netdata
  9. #
  10. # Features:
  11. # - multiple notification methods
  12. # - multiple roles per alarm
  13. # - multiple recipients per role
  14. # - severity filtering per recipient
  15. #
  16. # Supported notification methods:
  17. # - emails by @ktsaou
  18. # - slack.com notifications by @ktsaou
  19. # - alerta.io notifications by @kattunga
  20. # - discordapp.com notifications by @lowfive
  21. # - pushover.net notifications by @ktsaou
  22. # - pushbullet.com push notifications by Tiago Peralta @tperalta82 #1070
  23. # - telegram.org notifications by @hashworks #1002
  24. # - twilio.com notifications by Levi Blaney @shadycuz #1211
  25. # - kafka notifications by @ktsaou #1342
  26. # - pagerduty.com notifications by Jim Cooley @jimcooley #1373
  27. # - messagebird.com notifications by @tech_no_logical #1453
  28. # - hipchat notifications by @ktsaou #1561
  29. # - fleep notifications by @Ferroin
  30. # - prowlapp.com notifications by @Ferroin
  31. # - custom notifications by @ktsaou
  32. # - syslog messages by @Ferroin
  33. # - Microsoft Team notification by @tioumen
  34. # - RocketChat notifications by @Hermsi1337 #3777
  35. # -----------------------------------------------------------------------------
  36. # testing notifications
  37. if { [ "${1}" = "test" ] || [ "${2}" = "test" ]; } && [ "${#}" -le 2 ]; then
  38. if [ "${2}" = "test" ]; then
  39. recipient="${1}"
  40. else
  41. recipient="${2}"
  42. fi
  43. [ -z "${recipient}" ] && recipient="sysadmin"
  44. id=1
  45. last="CLEAR"
  46. test_res=0
  47. for x in "WARNING" "CRITICAL" "CLEAR"; do
  48. echo >&2
  49. echo >&2 "# SENDING TEST ${x} ALARM TO ROLE: ${recipient}"
  50. "${0}" "${recipient}" "$(hostname)" 1 1 "${id}" "$(date +%s)" "test_alarm" "test.chart" "test.family" "${x}" "${last}" 100 90 "${0}" 1 $((0 + id)) "units" "this is a test alarm to verify notifications work" "new value" "old value" "evaluated expression" "expression variable values" 0 0
  51. #shellcheck disable=SC2181
  52. if [ $? -ne 0 ]; then
  53. echo >&2 "# FAILED"
  54. test_res=1
  55. else
  56. echo >&2 "# OK"
  57. fi
  58. last="${x}"
  59. id=$((id + 1))
  60. done
  61. exit $test_res
  62. fi
  63. export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
  64. export LC_ALL=C
  65. # -----------------------------------------------------------------------------
  66. PROGRAM_NAME="$(basename "${0}")"
  67. logdate() {
  68. date "+%Y-%m-%d %H:%M:%S"
  69. }
  70. log() {
  71. local status="${1}"
  72. shift
  73. echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
  74. }
  75. warning() {
  76. log WARNING "${@}"
  77. }
  78. error() {
  79. log ERROR "${@}"
  80. }
  81. info() {
  82. log INFO "${@}"
  83. }
  84. fatal() {
  85. log FATAL "${@}"
  86. exit 1
  87. }
  88. debug=${NETDATA_ALARM_NOTIFY_DEBUG-0}
  89. debug() {
  90. [ "${debug}" = "1" ] && log DEBUG "${@}"
  91. }
  92. docurl() {
  93. if [ -z "${curl}" ]; then
  94. error "${curl} is unset."
  95. return 1
  96. fi
  97. if [ "${debug}" = "1" ]; then
  98. echo >&2 "--- BEGIN curl command ---"
  99. printf >&2 "%q " ${curl} "${@}"
  100. echo >&2
  101. echo >&2 "--- END curl command ---"
  102. local out code ret
  103. out=$(mktemp /tmp/netdata-health-alarm-notify-XXXXXXXX)
  104. code=$(${curl} ${curl_options} --write-out "%{http_code}" --output "${out}" --silent --show-error "${@}")
  105. ret=$?
  106. echo >&2 "--- BEGIN received response ---"
  107. cat >&2 "${out}"
  108. echo >&2
  109. echo >&2 "--- END received response ---"
  110. echo >&2 "RECEIVED HTTP RESPONSE CODE: ${code}"
  111. rm "${out}"
  112. echo "${code}"
  113. return ${ret}
  114. fi
  115. ${curl} ${curl_options} --write-out "%{http_code}" --output /dev/null --silent --show-error "${@}"
  116. return $?
  117. }
  118. # -----------------------------------------------------------------------------
  119. # List of all the notification mechanisms we support.
  120. # Used in a couple of places to write more compact code.
  121. method_names="
  122. email
  123. pushover
  124. pushbullet
  125. telegram
  126. slack
  127. alerta
  128. flock
  129. discord
  130. hipchat
  131. twilio
  132. messagebird
  133. pd
  134. fleep
  135. syslog
  136. custom
  137. msteam
  138. kavenegar
  139. prowl
  140. awssns
  141. rocketchat
  142. sms
  143. "
  144. # -----------------------------------------------------------------------------
  145. # this is to be overwritten by the config file
  146. custom_sender() {
  147. info "not sending custom notification for ${status} of '${host}.${chart}.${name}'"
  148. }
  149. # -----------------------------------------------------------------------------
  150. # check for BASH v4+ (required for associative arrays)
  151. if [ ${BASH_VERSINFO[0]} -lt 4 ]; then
  152. fatal "BASH version 4 or later is required (this is ${BASH_VERSION})."
  153. fi
  154. # -----------------------------------------------------------------------------
  155. # defaults to allow running this script by hand
  156. [ -z "${NETDATA_USER_CONFIG_DIR}" ] && NETDATA_USER_CONFIG_DIR="@configdir_POST@"
  157. [ -z "${NETDATA_STOCK_CONFIG_DIR}" ] && NETDATA_STOCK_CONFIG_DIR="@libconfigdir_POST@"
  158. [ -z "${NETDATA_CACHE_DIR}" ] && NETDATA_CACHE_DIR="@cachedir_POST@"
  159. [ -z "${NETDATA_REGISTRY_URL}" ] && NETDATA_REGISTRY_URL="https://registry.my-netdata.io"
  160. # -----------------------------------------------------------------------------
  161. # parse command line parameters
  162. if [ ${1} = "unittest" ]; then
  163. unittest=1 # enable unit testing mode
  164. roles="${2}" # the role that should be used for unit testing
  165. cfgfile="${3}" # the location of the config file to use for unit testing
  166. status="${4}" # the current status : REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
  167. old_status="${5}" # the previous status: REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
  168. else
  169. roles="${1}" # the roles that should be notified for this event
  170. args_host="${2}" # the host generated this event
  171. unique_id="${3}" # the unique id of this event
  172. alarm_id="${4}" # the unique id of the alarm that generated this event
  173. event_id="${5}" # the incremental id of the event, for this alarm id
  174. when="${6}" # the timestamp this event occurred
  175. name="${7}" # the name of the alarm, as given in netdata health.d entries
  176. chart="${8}" # the name of the chart (type.id)
  177. family="${9}" # the family of the chart
  178. status="${10}" # the current status : REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
  179. old_status="${11}" # the previous status: REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
  180. value="${12}" # the current value of the alarm
  181. old_value="${13}" # the previous value of the alarm
  182. src="${14}" # the line number and file the alarm has been configured
  183. duration="${15}" # the duration in seconds of the previous alarm state
  184. non_clear_duration="${16}" # the total duration in seconds this is/was non-clear
  185. units="${17}" # the units of the value
  186. info="${18}" # a short description of the alarm
  187. value_string="${19}" # friendly value (with units)
  188. # shellcheck disable=SC2034
  189. # variable is unused, but https://github.com/netdata/netdata/pull/5164#discussion_r255572947
  190. old_value_string="${20}" # friendly old value (with units), previously named "old_value_string"
  191. calc_expression="${21}" # contains the expression that was evaluated to trigger the alarm
  192. calc_param_values="${22}" # the values of the parameters in the expression, at the time of the evaluation
  193. total_warnings="${23}" # Total number of alarms in WARNING state
  194. total_critical="${24}" # Total number of alarms in CRITICAL state
  195. fi
  196. # -----------------------------------------------------------------------------
  197. # find a suitable hostname to use, if netdata did not supply a hostname
  198. if [ -z ${args_host} ]; then
  199. this_host=$(hostname -s 2>/dev/null)
  200. host="${this_host}"
  201. args_host="${this_host}"
  202. else
  203. host="${args_host}"
  204. fi
  205. # -----------------------------------------------------------------------------
  206. # screen statuses we don't need to send a notification
  207. # don't do anything if this is not WARNING, CRITICAL or CLEAR
  208. if [ "${status}" != "WARNING" ] && [ "${status}" != "CRITICAL" ] && [ "${status}" != "CLEAR" ]; then
  209. info "not sending notification for ${status} of '${host}.${chart}.${name}'"
  210. exit 1
  211. fi
  212. # don't do anything if this is CLEAR, but it was not WARNING or CRITICAL
  213. if [ "${clear_alarm_always}" != "YES" ] && [ "${old_status}" != "WARNING" ] && [ "${old_status}" != "CRITICAL" ] && [ "${status}" = "CLEAR" ]; then
  214. info "not sending notification for ${status} of '${host}.${chart}.${name}' (last status was ${old_status})"
  215. exit 1
  216. fi
  217. # -----------------------------------------------------------------------------
  218. # load configuration
  219. # By default fetch images from the global public registry.
  220. # This is required by default, since all notification methods need to download
  221. # images via the Internet, and private registries might not be reachable.
  222. # This can be overwritten at the configuration file.
  223. images_base_url="https://registry.my-netdata.io"
  224. # curl options to use
  225. curl_options=""
  226. # hostname handling
  227. use_fqdn="NO"
  228. # needed commands
  229. # if empty they will be searched in the system path
  230. curl=
  231. sendmail=
  232. # enable / disable features
  233. for method_name in ${method_names^^}; do
  234. declare SEND_${method_name}="YES"
  235. declare DEFAULT_RECIPIENT_${method_name}
  236. done
  237. for method_name in ${method_names}; do
  238. declare -A role_recipients_${method_name}
  239. done
  240. # slack configs
  241. SLACK_WEBHOOK_URL=
  242. # Microsoft Team configs
  243. MSTEAM_WEBHOOK_URL=
  244. # rocketchat configs
  245. ROCKETCHAT_WEBHOOK_URL=
  246. # alerta configs
  247. ALERTA_WEBHOOK_URL=
  248. ALERTA_API_KEY=
  249. # flock configs
  250. FLOCK_WEBHOOK_URL=
  251. # discord configs
  252. DISCORD_WEBHOOK_URL=
  253. # pushover configs
  254. PUSHOVER_APP_TOKEN=
  255. # pushbullet configs
  256. PUSHBULLET_ACCESS_TOKEN=
  257. PUSHBULLET_SOURCE_DEVICE=
  258. # twilio configs
  259. TWILIO_ACCOUNT_SID=
  260. TWILIO_ACCOUNT_TOKEN=
  261. TWILIO_NUMBER=
  262. # hipchat configs
  263. HIPCHAT_SERVER=
  264. HIPCHAT_AUTH_TOKEN=
  265. # messagebird configs
  266. MESSAGEBIRD_ACCESS_KEY=
  267. MESSAGEBIRD_NUMBER=
  268. # kavenegar configs
  269. KAVENEGAR_API_KEY=
  270. KAVENEGAR_SENDER=
  271. # telegram configs
  272. TELEGRAM_BOT_TOKEN=
  273. # kafka configs
  274. SEND_KAFKA="YES"
  275. KAFKA_URL=
  276. KAFKA_SENDER_IP=
  277. # pagerduty.com configs
  278. PD_SERVICE_KEY=
  279. # fleep.io configs
  280. FLEEP_SENDER="${host}"
  281. # Amazon SNS configs
  282. AWSSNS_MESSAGE_FORMAT=
  283. # syslog configs
  284. SYSLOG_FACILITY=
  285. # email configs
  286. EMAIL_SENDER=
  287. EMAIL_CHARSET=$(locale charmap 2>/dev/null)
  288. EMAIL_THREADING=
  289. # irc configs
  290. IRC_NICKNAME=
  291. IRC_REALNAME=
  292. IRC_NETWORK=
  293. # load the stock and user configuration files
  294. # these will overwrite the variables above
  295. if [ ${unittest} ]; then
  296. if source "${cfgfile}"; then
  297. error "Failed to load requested config file."
  298. exit 1
  299. fi
  300. else
  301. for CONFIG in "${NETDATA_STOCK_CONFIG_DIR}/health_alarm_notify.conf" "${NETDATA_USER_CONFIG_DIR}/health_alarm_notify.conf"; do
  302. if [ -f "${CONFIG}" ]; then
  303. debug "Loading config file '${CONFIG}'..."
  304. source "${CONFIG}" || error "Failed to load config file '${CONFIG}'."
  305. else
  306. warning "Cannot find file '${CONFIG}'."
  307. fi
  308. done
  309. fi
  310. # If we didn't autodetect the character set for e-mail and it wasn't
  311. # set by the user, we need to set it to a reasonable default. UTF-8
  312. # should be correct for almost all modern UNIX systems.
  313. if [ -z ${EMAIL_CHARSET} ]; then
  314. EMAIL_CHARSET="UTF-8"
  315. fi
  316. # If we've been asked to use FQDN's for the URL's in the alarm, do so,
  317. # unless we're sending an alarm for a slave system which we can't get the
  318. # FQDN of easily.
  319. if [ "${use_fqdn}" = "YES" ] && [ "${host}" = "$(hostname -s 2>/dev/null)" ]; then
  320. host="$(hostname -f 2>/dev/null)"
  321. fi
  322. # -----------------------------------------------------------------------------
  323. # filter a recipient based on alarm event severity
  324. filter_recipient_by_criticality() {
  325. local method="${1}" x="${2}" r s
  326. shift
  327. r="${x/|*/}" # the recipient
  328. s="${x/*|/}" # the severity required for notifying this recipient
  329. # no severity filtering for this person
  330. [ "${r}" = "${s}" ] && return 0
  331. # the severity is invalid
  332. s="${s^^}"
  333. if [ "${s}" != "CRITICAL" ]; then
  334. error "SEVERITY FILTERING for ${x} VIA ${method}: invalid severity '${s,,}', only 'critical' is supported."
  335. return 0
  336. fi
  337. # create the status tracking directory for this user
  338. [ ! -d "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}" ] &&
  339. mkdir -p "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}"
  340. case "${status}" in
  341. CRITICAL)
  342. # make sure he will get future notifications for this alarm too
  343. touch "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}"
  344. debug "SEVERITY FILTERING for ${x} VIA ${method}: ALLOW: the alarm is CRITICAL (will now receive next status change)"
  345. return 0
  346. ;;
  347. WARNING)
  348. if [ -f "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}" ]; then
  349. # we do not remove the file, so that he will get future notifications of this alarm
  350. debug "SEVERITY FILTERING for ${x} VIA ${method}: ALLOW: recipient has been notified for this alarm in the past (will still receive next status change)"
  351. return 0
  352. fi
  353. ;;
  354. *)
  355. if [ -f "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}" ]; then
  356. # remove the file, so that he will only receive notifications for CRITICAL states for this alarm
  357. rm "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}"
  358. debug "SEVERITY FILTERING for ${x} VIA ${method}: ALLOW: recipient has been notified for this alarm (will only receive CRITICAL notifications from now on)"
  359. return 0
  360. fi
  361. ;;
  362. esac
  363. debug "SEVERITY FILTERING for ${x} VIA ${method}: BLOCK: recipient should not receive this notification"
  364. return 1
  365. }
  366. # -----------------------------------------------------------------------------
  367. # verify the delivery methods supported
  368. # check slack
  369. [ -z "${SLACK_WEBHOOK_URL}" ] && SEND_SLACK="NO"
  370. # check rocketchat
  371. [ -z "${ROCKETCHAT_WEBHOOK_URL}" ] && SEND_ROCKETCHAT="NO"
  372. # check alerta
  373. [ -z "${ALERTA_WEBHOOK_URL}" ] && SEND_ALERTA="NO"
  374. # check flock
  375. [ -z "${FLOCK_WEBHOOK_URL}" ] && SEND_FLOCK="NO"
  376. # check discord
  377. [ -z "${DISCORD_WEBHOOK_URL}" ] && SEND_DISCORD="NO"
  378. # check pushover
  379. [ -z "${PUSHOVER_APP_TOKEN}" ] && SEND_PUSHOVER="NO"
  380. # check pushbullet
  381. [ -z "${PUSHBULLET_ACCESS_TOKEN}" ] && SEND_PUSHBULLET="NO"
  382. # check twilio
  383. { [ -z "${TWILIO_ACCOUNT_TOKEN}" ] || [ -z "${TWILIO_ACCOUNT_SID}" ] || [ -z "${TWILIO_NUMBER}" ]; } && SEND_TWILIO="NO"
  384. # check hipchat
  385. [ -z "${HIPCHAT_AUTH_TOKEN}" ] && SEND_HIPCHAT="NO"
  386. # check messagebird
  387. { [ -z "${MESSAGEBIRD_ACCESS_KEY}" ] || [ -z "${MESSAGEBIRD_NUMBER}" ]; } && SEND_MESSAGEBIRD="NO"
  388. # check kavenegar
  389. { [ -z "${KAVENEGAR_API_KEY}" ] || [ -z "${KAVENEGAR_SENDER}" ]; } && SEND_KAVENEGAR="NO"
  390. # check telegram
  391. [ -z "${TELEGRAM_BOT_TOKEN}" ] && SEND_TELEGRAM="NO"
  392. # check kafka
  393. { [ -z "${KAFKA_URL}" ] || [ -z "${KAFKA_SENDER_IP}" ]; } && SEND_KAFKA="NO"
  394. # check irc
  395. [ -z "${IRC_NETWORK}" ] && SEND_IRC="NO"
  396. # check fleep
  397. #shellcheck disable=SC2153
  398. { [ -z "${FLEEP_SERVER}" ] || [ -z "${FLEEP_SENDER}" ]; } && SEND_FLEEP="NO"
  399. if [ "${SEND_PUSHOVER}" = "YES" ] ||
  400. [ "${SEND_SLACK}" = "YES" ] ||
  401. [ "${SEND_ROCKETCHAT}" = "YES" ] ||
  402. [ "${SEND_ALERTA}" = "YES" ] ||
  403. [ "${SEND_PD}" = "YES" ] ||
  404. [ "${SEND_FLOCK}" = "YES" ] ||
  405. [ "${SEND_DISCORD}" = "YES" ] ||
  406. [ "${SEND_HIPCHAT}" = "YES" ] ||
  407. [ "${SEND_TWILIO}" = "YES" ] ||
  408. [ "${SEND_MESSAGEBIRD}" = "YES" ] ||
  409. [ "${SEND_KAVENEGAR}" = "YES" ] ||
  410. [ "${SEND_TELEGRAM}" = "YES" ] ||
  411. [ "${SEND_PUSHBULLET}" = "YES" ] ||
  412. [ "${SEND_KAFKA}" = "YES" ] ||
  413. [ "${SEND_FLEEP}" = "YES" ] ||
  414. [ "${SEND_PROWL}" = "YES" ] ||
  415. [ "${SEND_CUSTOM}" = "YES" ] ||
  416. [ "${SEND_MSTEAM}" = "YES" ]; then
  417. # if we need curl, check for the curl command
  418. if [ -z "${curl}" ]; then
  419. curl="$(command -v curl 2>/dev/null)"
  420. fi
  421. if [ -z "${curl}" ]; then
  422. error "Cannot find curl command in the system path. Disabling all curl based notifications."
  423. SEND_PUSHOVER="NO"
  424. SEND_PUSHBULLET="NO"
  425. SEND_TELEGRAM="NO"
  426. SEND_SLACK="NO"
  427. SEND_MSTEAM="NO"
  428. SEND_ROCKETCHAT="NO"
  429. SEND_ALERTA="NO"
  430. SEND_PD="NO"
  431. SEND_FLOCK="NO"
  432. SEND_DISCORD="NO"
  433. SEND_TWILIO="NO"
  434. SEND_HIPCHAT="NO"
  435. SEND_MESSAGEBIRD="NO"
  436. SEND_KAVENEGAR="NO"
  437. SEND_KAFKA="NO"
  438. SEND_FLEEP="NO"
  439. SEND_PROWL="NO"
  440. SEND_CUSTOM="NO"
  441. fi
  442. fi
  443. if [ "${SEND_SMS}" = "YES" ]; then
  444. if [ -z "${sendsms}" ]; then
  445. sendsms="$(command -v sendsms 2>/dev/null)"
  446. fi
  447. if [ -z "${sendsms}" ]; then
  448. SEND_SMS="NO"
  449. fi
  450. fi
  451. # if we need sendmail, check for the sendmail command
  452. if [ "${SEND_EMAIL}" = "YES" ] && [ -z "${sendmail}" ]; then
  453. sendmail="$(command -v sendmail 2>/dev/null)"
  454. if [ -z "${sendmail}" ]; then
  455. debug "Cannot find sendmail command in the system path. Disabling email notifications."
  456. SEND_EMAIL="NO"
  457. fi
  458. fi
  459. # if we need logger, check for the logger command
  460. if [ "${SEND_SYSLOG}" = "YES" ] && [ -z "${logger}" ]; then
  461. logger="$(command -v logger 2>/dev/null)"
  462. if [ -z "${logger}" ]; then
  463. debug "Cannot find logger command in the system path. Disabling syslog notifications."
  464. SEND_SYSLOG="NO"
  465. fi
  466. fi
  467. # if we need aws, check for the aws command
  468. if [ "${SEND_AWSSNS}" = "YES" ] && [ -z "${aws}" ]; then
  469. aws="$(command -v aws 2>/dev/null)"
  470. if [ -z "${aws}" ]; then
  471. debug "Cannot find aws command in the system path. Disabling Amazon SNS notifications."
  472. SEND_AWSSNS="NO"
  473. fi
  474. fi
  475. # -----------------------------------------------------------------------------
  476. # find the recipients' addresses per method
  477. # netdata may call us with multiple roles, and roles may have multiple but
  478. # overlapping recipients - so, here we find the unique recipients.
  479. for method_name in ${method_names}; do
  480. send_var="SEND_${method_name^^}"
  481. if [ "${!send_var}" = "NO" ]; then
  482. continue
  483. fi
  484. declare -A arr_var=()
  485. for x in ${roles//,/ }; do
  486. # the roles 'silent' and 'disabled' mean:
  487. # don't send a notification for this role
  488. if [ "${x}" = "silent" ] || [ "${x}" = "disabled" ]; then
  489. continue
  490. fi
  491. role_recipients="role_recipients_${method_name}[$x]"
  492. default_recipient_var="DEFAULT_RECIPIENT_${method_name^^}"
  493. a="${!role_recipients}"
  494. [ -z "${a}" ] && a="${!default_recipient_var}"
  495. for r in ${a//,/ }; do
  496. [ "${r}" != "disabled" ] && filter_recipient_by_criticality ${method_name} "${r}" && arr_var[${r/|*/}]="1"
  497. done
  498. done
  499. # build the list of recipients
  500. to_var="to_${method_name}"
  501. declare to_${method_name}="${!arr_var[*]}"
  502. [ -z "${!to_var}" ] && declare ${send_var}="NO"
  503. done
  504. # -----------------------------------------------------------------------------
  505. # handle fixup of the email recipient list.
  506. fix_to_email() {
  507. to_email=
  508. while [ -n "${1}" ]; do
  509. [ -n "${to_email}" ] && to_email="${to_email}, "
  510. to_email="${to_email}${1}"
  511. shift 1
  512. done
  513. }
  514. # ${to_email} without quotes here
  515. fix_to_email ${to_email}
  516. # -----------------------------------------------------------------------------
  517. # handle output if we're running in unit test mode
  518. if [ ${unittest} ]; then
  519. for method_name in ${method_names}; do
  520. to_var="to_${method_name}"
  521. echo "results: ${method_name}: ${!to_var}"
  522. done
  523. exit 0
  524. fi
  525. # -----------------------------------------------------------------------------
  526. # check that we have at least a method enabled
  527. proceed=0
  528. for method in "${SEND_EMAIL}" \
  529. "${SEND_PUSHOVER}" \
  530. "${SEND_TELEGRAM}" \
  531. "${SEND_SLACK}" \
  532. "${SEND_ROCKETCHAT}" \
  533. "${SEND_ALERTA}" \
  534. "${SEND_FLOCK}" \
  535. "${SEND_DISCORD}" \
  536. "${SEND_TWILIO}" \
  537. "${SEND_HIPCHAT}" \
  538. "${SEND_MESSAGEBIRD}" \
  539. "${SEND_KAVENEGAR}" \
  540. "${SEND_PUSHBULLET}" \
  541. "${SEND_KAFKA}" \
  542. "${SEND_PD}" \
  543. "${SEND_FLEEP}" \
  544. "${SEND_CUSTOM}" \
  545. "${SEND_IRC}" \
  546. "${SEND_AWSSNS}" \
  547. "${SEND_SYSLOG}" \
  548. "${SEND_SMS}" \
  549. "${SEND_MSTEAM}"; do
  550. if [ "${method}" == "YES" ]; then
  551. proceed=1
  552. break
  553. fi
  554. done
  555. if [ "$proceed" -eq 0 ]; then
  556. fatal "All notification methods are disabled. Not sending notification for host '${host}', chart '${chart}' to '${roles}' for '${name}' = '${value}' for status '${status}'."
  557. fi
  558. # -----------------------------------------------------------------------------
  559. # get the date the alarm happened
  560. date=$(date --date=@${when} "${date_format}" 2>/dev/null)
  561. [ -z "${date}" ] && date=$(date "${date_format}" 2>/dev/null)
  562. [ -z "${date}" ] && date=$(date --date=@${when} 2>/dev/null)
  563. [ -z "${date}" ] && date=$(date 2>/dev/null)
  564. # ----------------------------------------------------------------------------
  565. # prepare some extra headers if we've been asked to thread e-mails
  566. if [ "${SEND_EMAIL}" == "YES" ] && [ "${EMAIL_THREADING}" != "NO" ]; then
  567. email_thread_headers="In-Reply-To: <${chart}-${name}@${host}>\\nReferences: <${chart}-${name}@${host}>"
  568. else
  569. email_thread_headers=
  570. fi
  571. # -----------------------------------------------------------------------------
  572. # function to URL encode a string
  573. urlencode() {
  574. local string="${1}" strlen encoded pos c o
  575. strlen=${#string}
  576. for ((pos = 0; pos < strlen; pos++)); do
  577. c=${string:pos:1}
  578. case "${c}" in
  579. [-_.~a-zA-Z0-9])
  580. o="${c}"
  581. ;;
  582. *)
  583. printf -v o '%%%02x' "'${c}"
  584. ;;
  585. esac
  586. encoded+="${o}"
  587. done
  588. REPLY="${encoded}"
  589. echo "${REPLY}"
  590. }
  591. # -----------------------------------------------------------------------------
  592. # function to convert a duration in seconds, to a human readable duration
  593. # using DAYS, MINUTES, SECONDS
  594. duration4human() {
  595. local s="${1}" d=0 h=0 m=0 ds="day" hs="hour" ms="minute" ss="second" ret
  596. d=$((s / 86400))
  597. s=$((s - (d * 86400)))
  598. h=$((s / 3600))
  599. s=$((s - (h * 3600)))
  600. m=$((s / 60))
  601. s=$((s - (m * 60)))
  602. if [ ${d} -gt 0 ]; then
  603. [ ${m} -ge 30 ] && h=$((h + 1))
  604. [ ${d} -gt 1 ] && ds="days"
  605. [ ${h} -gt 1 ] && hs="hours"
  606. if [ ${h} -gt 0 ]; then
  607. ret="${d} ${ds} and ${h} ${hs}"
  608. else
  609. ret="${d} ${ds}"
  610. fi
  611. elif [ ${h} -gt 0 ]; then
  612. [ ${s} -ge 30 ] && m=$((m + 1))
  613. [ ${h} -gt 1 ] && hs="hours"
  614. [ ${m} -gt 1 ] && ms="minutes"
  615. if [ ${m} -gt 0 ]; then
  616. ret="${h} ${hs} and ${m} ${ms}"
  617. else
  618. ret="${h} ${hs}"
  619. fi
  620. elif [ ${m} -gt 0 ]; then
  621. [ ${m} -gt 1 ] && ms="minutes"
  622. [ ${s} -gt 1 ] && ss="seconds"
  623. if [ ${s} -gt 0 ]; then
  624. ret="${m} ${ms} and ${s} ${ss}"
  625. else
  626. ret="${m} ${ms}"
  627. fi
  628. else
  629. [ ${s} -gt 1 ] && ss="seconds"
  630. ret="${s} ${ss}"
  631. fi
  632. REPLY="${ret}"
  633. echo "${REPLY}"
  634. }
  635. # -----------------------------------------------------------------------------
  636. # email sender
  637. send_email() {
  638. local ret opts=() sender_email="${EMAIL_SENDER}" sender_name=
  639. if [ "${SEND_EMAIL}" = "YES" ]; then
  640. if [ -n "${EMAIL_SENDER}" ]; then
  641. if [[ ${EMAIL_SENDER} =~ ^\".*\"\ \<.*\>$ ]]; then
  642. # the name includes double quotes
  643. sender_email="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)"
  644. sender_name="$(echo "${EMAIL_SENDER}" | cut -d '"' -f 2)"
  645. elif [[ ${EMAIL_SENDER} =~ ^\'.*\'\ \<.*\>$ ]]; then
  646. # the name includes single quotes
  647. sender_email="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)"
  648. sender_name="$(echo "${EMAIL_SENDER}" | cut -d "'" -f 2)"
  649. elif [[ ${EMAIL_SENDER} =~ ^.*\ \<.*\>$ ]]; then
  650. # the name does not have any quotes
  651. sender_email="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)"
  652. sender_name="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 1)"
  653. fi
  654. fi
  655. [ -n "${sender_email}" ] && opts+=(-f "${sender_email}")
  656. [ -n "${sender_name}" ] && opts+=(-F "${sender_name}")
  657. if [ "${debug}" = "1" ]; then
  658. echo >&2 "--- BEGIN sendmail command ---"
  659. printf >&2 "%q " "${sendmail}" -t "${opts[@]}"
  660. echo >&2
  661. echo >&2 "--- END sendmail command ---"
  662. fi
  663. "${sendmail}" -t "${opts[@]}"
  664. ret=$?
  665. if [ ${ret} -eq 0 ]; then
  666. info "sent email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}'"
  667. return 0
  668. else
  669. error "failed to send email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}' with error code ${ret}."
  670. return 1
  671. fi
  672. fi
  673. return 1
  674. }
  675. # -----------------------------------------------------------------------------
  676. # pushover sender
  677. send_pushover() {
  678. local apptoken="${1}" usertokens="${2}" when="${3}" url="${4}" status="${5}" title="${6}" message="${7}" httpcode sent=0 user priority
  679. if [ "${SEND_PUSHOVER}" = "YES" ] && [ -n "${apptoken}" ] && [ -n "${usertokens}" ] && [ -n "${title}" ] && [ -n "${message}" ]; then
  680. # https://pushover.net/api
  681. priority=-2
  682. case "${status}" in
  683. CLEAR) priority=-1 ;; # low priority: no sound or vibration
  684. WARNING) priority=0 ;; # normal priority: respect quiet hours
  685. CRITICAL) priority=1 ;; # high priority: bypass quiet hours
  686. *) priority=-2 ;; # lowest priority: no notification at all
  687. esac
  688. for user in ${usertokens}; do
  689. httpcode=$(docurl \
  690. --form-string "token=${apptoken}" \
  691. --form-string "user=${user}" \
  692. --form-string "html=1" \
  693. --form-string "title=${title}" \
  694. --form-string "message=${message}" \
  695. --form-string "timestamp=${when}" \
  696. --form-string "url=${url}" \
  697. --form-string "url_title=Open netdata dashboard to view the alarm" \
  698. --form-string "priority=${priority}" \
  699. https://api.pushover.net/1/messages.json)
  700. if [ "${httpcode}" = "200" ]; then
  701. info "sent pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
  702. sent=$((sent + 1))
  703. else
  704. error "failed to send pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
  705. fi
  706. done
  707. [ ${sent} -gt 0 ] && return 0
  708. fi
  709. return 1
  710. }
  711. # -----------------------------------------------------------------------------
  712. # pushbullet sender
  713. send_pushbullet() {
  714. local userapikey="${1}" source_device="${2}" recipients="${3}" url="${4}" title="${5}" message="${6}" httpcode sent=0 user
  715. if [ "${SEND_PUSHBULLET}" = "YES" ] && [ -n "${userapikey}" ] && [ -n "${recipients}" ] && [ -n "${message}" ] && [ -n "${title}" ]; then
  716. #https://docs.pushbullet.com/#create-push
  717. for user in ${recipients}; do
  718. httpcode=$(docurl \
  719. --header 'Access-Token: '${userapikey}'' \
  720. --header 'Content-Type: application/json' \
  721. --data-binary @<(
  722. cat <<EOF
  723. {"title": "${title}",
  724. "type": "link",
  725. "email": "${user}",
  726. "body": "$(echo -n ${message})",
  727. "url": "${url}",
  728. "source_device_iden": "${source_device}"}
  729. EOF
  730. ) "https://api.pushbullet.com/v2/pushes" -X POST)
  731. if [ "${httpcode}" = "200" ]; then
  732. info "sent pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
  733. sent=$((sent + 1))
  734. else
  735. error "failed to send pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
  736. fi
  737. done
  738. [ ${sent} -gt 0 ] && return 0
  739. fi
  740. return 1
  741. }
  742. # -----------------------------------------------------------------------------
  743. # kafka sender
  744. send_kafka() {
  745. local httpcode sent=0
  746. if [ "${SEND_KAFKA}" = "YES" ]; then
  747. httpcode=$(docurl -X POST \
  748. --data "{host_ip:\"${KAFKA_SENDER_IP}\",when:${when},name:\"${name}\",chart:\"${chart}\",family:\"${family}\",status:\"${status}\",old_status:\"${old_status}\",value:${value},old_value:${old_value},duration:${duration},non_clear_duration:${non_clear_duration},units:\"${units}\",info:\"${info}\"}" \
  749. "${KAFKA_URL}")
  750. if [ "${httpcode}" = "204" ]; then
  751. info "sent kafka data for: ${host} ${chart}.${name} is ${status} and ip '${KAFKA_SENDER_IP}'"
  752. sent=$((sent + 1))
  753. else
  754. error "failed to send kafka data for: ${host} ${chart}.${name} is ${status} and ip '${KAFKA_SENDER_IP}' with HTTP error code ${httpcode}."
  755. fi
  756. [ ${sent} -gt 0 ] && return 0
  757. fi
  758. return 1
  759. }
  760. # -----------------------------------------------------------------------------
  761. # pagerduty.com sender
  762. send_pd() {
  763. local recipients="${1}" sent=0
  764. unset t
  765. case ${status} in
  766. CLEAR) t='resolve' ;;
  767. WARNING) t='trigger' ;;
  768. CRITICAL) t='trigger' ;;
  769. esac
  770. if [ ${SEND_PD} = "YES" ] && [ -n "${t}" ]; then
  771. for PD_SERVICE_KEY in ${recipients}; do
  772. d="${status} ${name} = ${value_string} - ${host}, ${family}"
  773. payload="$(
  774. cat <<EOF
  775. {
  776. "service_key": "${PD_SERVICE_KEY}",
  777. "event_type": "${t}",
  778. "incident_key" : "${alarm_id}",
  779. "description": "${d}",
  780. "details": {
  781. "value_w_units": "${value_string}",
  782. "when": "${when}",
  783. "duration" : "${duration}",
  784. "roles": "${roles}",
  785. "alarm_id" : "${alarm_id}",
  786. "name" : "${name}",
  787. "chart" : "${chart}",
  788. "family" : "${family}",
  789. "status" : "${status}",
  790. "old_status" : "${old_status}",
  791. "value" : "${value}",
  792. "old_value" : "${old_value}",
  793. "src" : "${src}",
  794. "non_clear_duration" : "${non_clear_duration}",
  795. "units" : "${units}",
  796. "info" : "${info}"
  797. }
  798. }
  799. EOF
  800. )"
  801. httpcode=$(docurl -X POST --data "${payload}" "https://events.pagerduty.com/generic/2010-04-15/create_event.json")
  802. if [ "${httpcode}" = "200" ]; then
  803. info "sent pagerduty notification for: ${host} ${chart}.${name} is ${status}'"
  804. sent=$((sent + 1))
  805. else
  806. error "failed to send pagerduty notification for: ${host} ${chart}.${name} is ${status}, with HTTP error code ${httpcode}."
  807. fi
  808. done
  809. [ ${sent} -gt 0 ] && return 0
  810. fi
  811. return 1
  812. }
  813. # -----------------------------------------------------------------------------
  814. # twilio sender
  815. send_twilio() {
  816. local accountsid="${1}" accounttoken="${2}" twilionumber="${3}" recipients="${4}" title="${5}" message="${6}" httpcode sent=0 user
  817. if [ "${SEND_TWILIO}" = "YES" ] && [ -n "${accountsid}" ] && [ -n "${accounttoken}" ] && [ -n "${twilionumber}" ] && [ -n "${recipients}" ] && [ -n "${message}" ] && [ -n "${title}" ]; then
  818. #https://www.twilio.com/packages/labs/code/bash/twilio-sms
  819. for user in ${recipients}; do
  820. httpcode=$(docurl -X POST \
  821. --data-urlencode "From=${twilionumber}" \
  822. --data-urlencode "To=${user}" \
  823. --data-urlencode "Body=${title} ${message}" \
  824. -u "${accountsid}:${accounttoken}" \
  825. "https://api.twilio.com/2010-04-01/Accounts/${accountsid}/Messages.json")
  826. if [ "${httpcode}" = "201" ]; then
  827. info "sent Twilio SMS for: ${host} ${chart}.${name} is ${status} to '${user}'"
  828. sent=$((sent + 1))
  829. else
  830. error "failed to send Twilio SMS for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
  831. fi
  832. done
  833. [ ${sent} -gt 0 ] && return 0
  834. fi
  835. return 1
  836. }
  837. # -----------------------------------------------------------------------------
  838. # hipchat sender
  839. send_hipchat() {
  840. local authtoken="${1}" recipients="${2}" message="${3}" httpcode sent=0 room color msg_format notify
  841. # remove <small></small> from the message
  842. message="${message//<small>/}"
  843. message="${message//<\/small>/}"
  844. if [ "${SEND_HIPCHAT}" = "YES" ] && [ -n "${HIPCHAT_SERVER}" ] && [ -n "${authtoken}" ] && [ -n "${recipients}" ] && [ -n "${message}" ]; then
  845. # Valid values: html, text.
  846. # Defaults to 'html'.
  847. msg_format="html"
  848. # Background color for message. Valid values: yellow, green, red, purple, gray, random. Defaults to 'yellow'.
  849. case "${status}" in
  850. WARNING) color="yellow" ;;
  851. CRITICAL) color="red" ;;
  852. CLEAR) color="green" ;;
  853. *) color="gray" ;;
  854. esac
  855. # Whether this message should trigger a user notification (change the tab color, play a sound, notify mobile phones, etc).
  856. # Each recipient's notification preferences are taken into account.
  857. # Defaults to false.
  858. notify="true"
  859. for room in ${recipients}; do
  860. httpcode=$(docurl -X POST \
  861. -H "Content-type: application/json" \
  862. -H "Authorization: Bearer ${authtoken}" \
  863. -d "{\"color\": \"${color}\", \"from\": \"${host}\", \"message_format\": \"${msg_format}\", \"message\": \"${message}\", \"notify\": \"${notify}\"}" \
  864. "https://${HIPCHAT_SERVER}/v2/room/${room}/notification")
  865. if [ "${httpcode}" = "204" ]; then
  866. info "sent HipChat notification for: ${host} ${chart}.${name} is ${status} to '${room}'"
  867. sent=$((sent + 1))
  868. else
  869. error "failed to send HipChat notification for: ${host} ${chart}.${name} is ${status} to '${room}' with HTTP error code ${httpcode}."
  870. fi
  871. done
  872. [ ${sent} -gt 0 ] && return 0
  873. fi
  874. return 1
  875. }
  876. # -----------------------------------------------------------------------------
  877. # messagebird sender
  878. send_messagebird() {
  879. local accesskey="${1}" messagebirdnumber="${2}" recipients="${3}" title="${4}" message="${5}" httpcode sent=0 user
  880. if [ "${SEND_MESSAGEBIRD}" = "YES" ] && [ -n "${accesskey}" ] && [ -n "${messagebirdnumber}" ] && [ -n "${recipients}" ] && [ -n "${message}" ] && [ -n "${title}" ]; then
  881. #https://developers.messagebird.com/docs/messaging
  882. for user in ${recipients}; do
  883. httpcode=$(docurl -X POST \
  884. --data-urlencode "originator=${messagebirdnumber}" \
  885. --data-urlencode "recipients=${user}" \
  886. --data-urlencode "body=${title} ${message}" \
  887. --data-urlencode "datacoding=auto" \
  888. -H "Authorization: AccessKey ${accesskey}" \
  889. "https://rest.messagebird.com/messages")
  890. if [ "${httpcode}" = "201" ]; then
  891. info "sent Messagebird SMS for: ${host} ${chart}.${name} is ${status} to '${user}'"
  892. sent=$((sent + 1))
  893. else
  894. error "failed to send Messagebird SMS for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
  895. fi
  896. done
  897. [ ${sent} -gt 0 ] && return 0
  898. fi
  899. return 1
  900. }
  901. # -----------------------------------------------------------------------------
  902. # kavenegar sender
  903. send_kavenegar() {
  904. local API_KEY="${1}" kavenegarsender="${2}" recipients="${3}" title="${4}" message="${5}" httpcode sent=0 user
  905. if [ "${SEND_KAVENEGAR}" = "YES" ] && [ -n "${API_KEY}" ] && [ -n "${kavenegarsender}" ] && [ -n "${recipients}" ] && [ -n "${message}" ] && [ -n "${title}" ]; then
  906. # http://api.kavenegar.com/v1/{API-KEY}/sms/send.json
  907. for user in ${recipients}; do
  908. httpcode=$(docurl -X POST http://api.kavenegar.com/v1/${API_KEY}/sms/send.json \
  909. --data-urlencode "sender=${kavenegarsender}" \
  910. --data-urlencode "receptor=${user}" \
  911. --data-urlencode "message=${title} ${message}")
  912. if [ "${httpcode}" = "200" ]; then
  913. info "sent Kavenegar SMS for: ${host} ${chart}.${name} is ${status} to '${user}'"
  914. sent=$((sent + 1))
  915. else
  916. error "failed to send Kavenegar SMS for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
  917. fi
  918. done
  919. [ ${sent} -gt 0 ] && return 0
  920. fi
  921. return 1
  922. }
  923. # -----------------------------------------------------------------------------
  924. # telegram sender
  925. send_telegram() {
  926. local bottoken="${1}" chatids="${2}" message="${3}" httpcode sent=0 chatid emoji disableNotification=""
  927. if [ "${status}" = "CLEAR" ]; then disableNotification="--data-urlencode disable_notification=true"; fi
  928. case "${status}" in
  929. WARNING) emoji="⚠️" ;;
  930. CRITICAL) emoji="🔴" ;;
  931. CLEAR) emoji="✅" ;;
  932. *) emoji="⚪️" ;;
  933. esac
  934. if [ "${SEND_TELEGRAM}" = "YES" ] && [ -n "${bottoken}" ] && [ -n "${chatids}" ] && [ -n "${message}" ]; then
  935. for chatid in ${chatids}; do
  936. # https://core.telegram.org/bots/api#sendmessage
  937. httpcode=$(docurl ${disableNotification} \
  938. --data-urlencode "parse_mode=HTML" \
  939. --data-urlencode "disable_web_page_preview=true" \
  940. --data-urlencode "text=${emoji} ${message}" \
  941. "https://api.telegram.org/bot${bottoken}/sendMessage?chat_id=${chatid}")
  942. if [ "${httpcode}" = "200" ]; then
  943. info "sent telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}'"
  944. sent=$((sent + 1))
  945. elif [ "${httpcode}" = "401" ]; then
  946. error "failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}': Wrong bot token."
  947. else
  948. error "failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}' with HTTP error code ${httpcode}."
  949. fi
  950. done
  951. [ ${sent} -gt 0 ] && return 0
  952. fi
  953. return 1
  954. }
  955. # -----------------------------------------------------------------------------
  956. # Microsoft Team sender
  957. send_msteam() {
  958. local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
  959. [ "${SEND_MSTEAM}" != "YES" ] && return 1
  960. case "${status}" in
  961. WARNING) icon="${MSTEAM_ICON_WARNING}" && color="${MSTEAM_COLOR_WARNING}" ;;
  962. CRITICAL) icon="${MSTEAM_ICON_CRITICAL}" && color="${MSTEAM_COLOR_CRITICAL}" ;;
  963. CLEAR) icon="${MSTEAM_ICON_CLEAR}" && color="${MSTEAM_COLOR_CLEAR}" ;;
  964. *) icon="${MSTEAM_ICON_DEFAULT}" && color="${MSTEAM_COLOR_DEFAULT}" ;;
  965. esac
  966. for channel in ${channels}; do
  967. ## More details are available here regarding the payload syntax options : https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference
  968. ## Online designer : https://acdesignerbeta.azurewebsites.net/
  969. payload="$(
  970. cat <<EOF
  971. {
  972. "@context": "http://schema.org/extensions",
  973. "@type": "MessageCard",
  974. "themeColor": "${color}",
  975. "title": "$icon Alert ${status} from netdata for ${host}",
  976. "text": "${host} ${status_message}, ${chart} (_${family}_), *${alarm}*",
  977. "potentialAction": [
  978. {
  979. "@type": "OpenUri",
  980. "name": "Netdata",
  981. "targets": [
  982. { "os": "default", "uri": "${goto_url}" }
  983. ]
  984. }
  985. ]
  986. }
  987. EOF
  988. )"
  989. # Replacing in the webhook CHANNEL string by the MS Teams channel name from conf file.
  990. webhook="${webhook//CHANNEL/${channel}}"
  991. httpcode=$(docurl -H "Content-Type: application/json" -d "${payload}" "${webhook}")
  992. if [ "${httpcode}" = "200" ]; then
  993. info "sent Microsoft team notification for: ${host} ${chart}.${name} is ${status} to '${webhook}'"
  994. sent=$((sent + 1))
  995. else
  996. error "failed to send Microsoft team notification for: ${host} ${chart}.${name} is ${status} to '${webhook}', with HTTP error code ${httpcode}."
  997. fi
  998. done
  999. [ ${sent} -gt 0 ] && return 0
  1000. return 1
  1001. }
  1002. # slack sender
  1003. send_slack() {
  1004. local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
  1005. [ "${SEND_SLACK}" != "YES" ] && return 1
  1006. case "${status}" in
  1007. WARNING) color="warning" ;;
  1008. CRITICAL) color="danger" ;;
  1009. CLEAR) color="good" ;;
  1010. *) color="#777777" ;;
  1011. esac
  1012. for channel in ${channels}; do
  1013. # Default entry in the recipient is without a hash in front (backwards-compatible). Accept specification of channel or user.
  1014. if [ "${channel::1}" != "#" ] && [ "${channel::1}" != "@" ]; then channel="#$channel"; fi
  1015. # If channel is equal to "#" then do not send the channel attribute at all. Slack also defines channels and users in webhooks.
  1016. if [ "${channel}" = "#" ]; then
  1017. ch=""
  1018. chstr="without specifying a channel"
  1019. else
  1020. ch="\"channel\": \"${channel}\","
  1021. chstr="to '${channel}'"
  1022. fi
  1023. payload="$(
  1024. cat <<EOF
  1025. {
  1026. $ch
  1027. "username": "netdata on ${host}",
  1028. "icon_url": "${images_base_url}/images/banner-icon-144x144.png",
  1029. "text": "${host} ${status_message}, \`${chart}\` (_${family}_), *${alarm}*",
  1030. "attachments": [
  1031. {
  1032. "fallback": "${alarm} - ${chart} (${family}) - ${info}",
  1033. "color": "${color}",
  1034. "title": "${alarm}",
  1035. "title_link": "${goto_url}",
  1036. "text": "${info}",
  1037. "fields": [
  1038. {
  1039. "title": "${chart}",
  1040. "short": true
  1041. },
  1042. {
  1043. "title": "${family}",
  1044. "short": true
  1045. }
  1046. ],
  1047. "thumb_url": "${image}",
  1048. "footer": "by ${host}",
  1049. "ts": ${when}
  1050. }
  1051. ]
  1052. }
  1053. EOF
  1054. )"
  1055. httpcode=$(docurl -X POST --data-urlencode "payload=${payload}" "${webhook}")
  1056. if [ "${httpcode}" = "200" ]; then
  1057. info "sent slack notification for: ${host} ${chart}.${name} is ${status} ${chstr}"
  1058. sent=$((sent + 1))
  1059. else
  1060. error "failed to send slack notification for: ${host} ${chart}.${name} is ${status} ${chstr}, with HTTP error code ${httpcode}."
  1061. fi
  1062. done
  1063. [ ${sent} -gt 0 ] && return 0
  1064. return 1
  1065. }
  1066. # -----------------------------------------------------------------------------
  1067. # rocketchat sender
  1068. send_rocketchat() {
  1069. local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
  1070. [ "${SEND_ROCKETCHAT}" != "YES" ] && return 1
  1071. case "${status}" in
  1072. WARNING) color="warning" ;;
  1073. CRITICAL) color="danger" ;;
  1074. CLEAR) color="good" ;;
  1075. *) color="#777777" ;;
  1076. esac
  1077. for channel in ${channels}; do
  1078. payload="$(
  1079. cat <<EOF
  1080. {
  1081. "channel": "#${channel}",
  1082. "alias": "netdata on ${host}",
  1083. "avatar": "${images_base_url}/images/banner-icon-144x144.png",
  1084. "text": "${host} ${status_message}, \`${chart}\` (_${family}_), *${alarm}*",
  1085. "attachments": [
  1086. {
  1087. "color": "${color}",
  1088. "title": "${alarm}",
  1089. "title_link": "${goto_url}",
  1090. "text": "${info}",
  1091. "fields": [
  1092. {
  1093. "title": "${chart}",
  1094. "short": true,
  1095. "value": "chart"
  1096. },
  1097. {
  1098. "title": "${family}",
  1099. "short": true,
  1100. "value": "family"
  1101. }
  1102. ],
  1103. "thumb_url": "${image}",
  1104. "ts": "${when}"
  1105. }
  1106. ]
  1107. }
  1108. EOF
  1109. )"
  1110. httpcode=$(docurl -X POST --data-urlencode "payload=${payload}" "${webhook}")
  1111. if [ "${httpcode}" = "200" ]; then
  1112. info "sent rocketchat notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
  1113. sent=$((sent + 1))
  1114. else
  1115. error "failed to send rocketchat notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP error code ${httpcode}."
  1116. fi
  1117. done
  1118. [ ${sent} -gt 0 ] && return 0
  1119. return 1
  1120. }
  1121. # -----------------------------------------------------------------------------
  1122. # alerta sender
  1123. send_alerta() {
  1124. local webhook="${1}" channels="${2}" httpcode sent=0 channel severity resource event payload auth
  1125. [ "${SEND_ALERTA}" != "YES" ] && return 1
  1126. case "${status}" in
  1127. CRITICAL) severity="critical" ;;
  1128. WARNING) severity="warning" ;;
  1129. CLEAR) severity="cleared" ;;
  1130. *) severity="indeterminate" ;;
  1131. esac
  1132. if [[ ${chart} == httpcheck* ]]; then
  1133. resource=$chart
  1134. event=$name
  1135. else
  1136. resource="${host}:${family}"
  1137. event="${chart}.${name}"
  1138. fi
  1139. for channel in ${channels}; do
  1140. payload="$(
  1141. cat <<EOF
  1142. {
  1143. "resource": "${resource}",
  1144. "event": "${event}",
  1145. "environment": "${channel}",
  1146. "severity": "${severity}",
  1147. "service": ["Netdata"],
  1148. "group": "Performance",
  1149. "value": "${value_string}",
  1150. "text": "${info}",
  1151. "tags": ["alarm_id:${alarm_id}"],
  1152. "attributes": {
  1153. "roles": "${roles}",
  1154. "name": "${name}",
  1155. "chart": "${chart}",
  1156. "family": "${family}",
  1157. "source": "${src}",
  1158. "moreInfo": "<a href=\"${goto_url}\">View Netdata</a>"
  1159. },
  1160. "origin": "netdata/${host}",
  1161. "type": "netdataAlarm",
  1162. "rawData": "${BASH_ARGV[@]}"
  1163. }
  1164. EOF
  1165. )"
  1166. if [ -n "${ALERTA_API_KEY}" ]; then
  1167. auth="Key ${ALERTA_API_KEY}"
  1168. fi
  1169. httpcode=$(docurl -X POST "${webhook}/alert" -H "Content-Type: application/json" -H "Authorization: $auth" --data "${payload}")
  1170. if [ "${httpcode}" = "200" ] || [ "${httpcode}" = "201" ]; then
  1171. info "sent alerta notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
  1172. sent=$((sent + 1))
  1173. elif [ "${httpcode}" = "202" ]; then
  1174. info "suppressed alerta notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
  1175. else
  1176. error "failed to send alerta notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP error code ${httpcode}."
  1177. fi
  1178. done
  1179. [ ${sent} -gt 0 ] && return 0
  1180. return 1
  1181. }
  1182. # -----------------------------------------------------------------------------
  1183. # flock sender
  1184. send_flock() {
  1185. local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
  1186. [ "${SEND_FLOCK}" != "YES" ] && return 1
  1187. case "${status}" in
  1188. WARNING) color="warning" ;;
  1189. CRITICAL) color="danger" ;;
  1190. CLEAR) color="good" ;;
  1191. *) color="#777777" ;;
  1192. esac
  1193. for channel in ${channels}; do
  1194. httpcode=$(docurl -X POST "${webhook}" -H "Content-Type: application/json" -d "{
  1195. \"sendAs\": {
  1196. \"name\" : \"netdata on ${host}\",
  1197. \"profileImage\" : \"${images_base_url}/images/banner-icon-144x144.png\"
  1198. },
  1199. \"text\": \"${host} *${status_message}*\",
  1200. \"timestamp\": \"${when}\",
  1201. \"attachments\": [
  1202. {
  1203. \"description\": \"${chart} (${family}) - ${info}\",
  1204. \"color\": \"${color}\",
  1205. \"title\": \"${alarm}\",
  1206. \"url\": \"${goto_url}\",
  1207. \"text\": \"${info}\",
  1208. \"views\": {
  1209. \"image\": {
  1210. \"original\": { \"src\": \"${image}\", \"width\": 400, \"height\": 400 },
  1211. \"thumbnail\": { \"src\": \"${image}\", \"width\": 50, \"height\": 50 },
  1212. \"filename\": \"${image}\"
  1213. }
  1214. }
  1215. }
  1216. ]
  1217. }")
  1218. if [ "${httpcode}" = "200" ]; then
  1219. info "sent flock notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
  1220. sent=$((sent + 1))
  1221. else
  1222. error "failed to send flock notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP error code ${httpcode}."
  1223. fi
  1224. done
  1225. [ ${sent} -gt 0 ] && return 0
  1226. return 1
  1227. }
  1228. # -----------------------------------------------------------------------------
  1229. # discord sender
  1230. send_discord() {
  1231. local webhook="${1}/slack" channels="${2}" httpcode sent=0 channel color payload username
  1232. [ "${SEND_DISCORD}" != "YES" ] && return 1
  1233. case "${status}" in
  1234. WARNING) color="warning" ;;
  1235. CRITICAL) color="danger" ;;
  1236. CLEAR) color="good" ;;
  1237. *) color="#777777" ;;
  1238. esac
  1239. for channel in ${channels}; do
  1240. username="netdata on ${host}"
  1241. [ ${#username} -gt 32 ] && username="${username:0:29}..."
  1242. payload="$(
  1243. cat <<EOF
  1244. {
  1245. "channel": "#${channel}",
  1246. "username": "${username}",
  1247. "text": "${host} ${status_message}, \`${chart}\` (_${family}_), *${alarm}*",
  1248. "icon_url": "${images_base_url}/images/banner-icon-144x144.png",
  1249. "attachments": [
  1250. {
  1251. "color": "${color}",
  1252. "title": "${alarm}",
  1253. "title_link": "${goto_url}",
  1254. "text": "${info}",
  1255. "fields": [
  1256. {
  1257. "title": "${chart}",
  1258. "value": "${family}"
  1259. }
  1260. ],
  1261. "thumb_url": "${image}",
  1262. "footer_icon": "${images_base_url}/images/banner-icon-144x144.png",
  1263. "footer": "${host}",
  1264. "ts": ${when}
  1265. }
  1266. ]
  1267. }
  1268. EOF
  1269. )"
  1270. httpcode=$(docurl -X POST --data-urlencode "payload=${payload}" "${webhook}")
  1271. if [ "${httpcode}" = "200" ]; then
  1272. info "sent discord notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
  1273. sent=$((sent + 1))
  1274. else
  1275. error "failed to send discord notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP error code ${httpcode}."
  1276. fi
  1277. done
  1278. [ ${sent} -gt 0 ] && return 0
  1279. return 1
  1280. }
  1281. # -----------------------------------------------------------------------------
  1282. # fleep sender
  1283. send_fleep() {
  1284. local httpcode sent=0 webhooks="${1}" data message
  1285. if [ "${SEND_FLEEP}" = "YES" ]; then
  1286. message="${host} ${status_message}, \`${chart}\` (${family}), *${alarm}*\\n${info}"
  1287. for hook in ${webhooks}; do
  1288. data="{ "
  1289. data="${data} 'message': '${message}', "
  1290. data="${data} 'user': '${FLEEP_SENDER}' "
  1291. data="${data} }"
  1292. httpcode=$(docurl -X POST --data "${data}" "https://fleep.io/hook/${hook}")
  1293. if [ "${httpcode}" = "200" ]; then
  1294. info "sent fleep data for: ${host} ${chart}.${name} is ${status} and user '${FLEEP_SENDER}'"
  1295. sent=$((sent + 1))
  1296. else
  1297. error "failed to send fleep data for: ${host} ${chart}.${name} is ${status} and user '${FLEEP_SENDER}' with HTTP error code ${httpcode}."
  1298. fi
  1299. done
  1300. [ ${sent} -gt 0 ] && return 0
  1301. fi
  1302. return 1
  1303. }
  1304. # -----------------------------------------------------------------------------
  1305. # Prowl sender
  1306. send_prowl() {
  1307. local httpcode sent=0 data message keys prio=0 alarm_url event
  1308. if [ "${SEND_PROWL}" = "YES" ]; then
  1309. message="$(urlencode "${host} ${status_message}, \`${chart}\` (${family}), *${alarm}*\\n${info}")"
  1310. message="description=${message}"
  1311. keys="$(urlencode "$(echo "${1}" | tr ' ' ,)")"
  1312. keys="apikey=${keys}"
  1313. app="application=Netdata"
  1314. case "${status}" in
  1315. CRITICAL)
  1316. prio=2
  1317. ;;
  1318. WARNING)
  1319. prio=1
  1320. ;;
  1321. esac
  1322. prio="priority=${prio}"
  1323. alarm_url="$(urlencode ${goto_url})"
  1324. alarm_url="url=${alarm_url}"
  1325. event="$(urlencode "${host} ${status_message}")"
  1326. event="event=${event}"
  1327. data="${keys}&${prio}&${alarm_url}&${app}&${event}&${message}"
  1328. httpcode=$(docurl -X POST --data "${data}" "https://api.prowlapp.com/publicapi/add")
  1329. if [ "${httpcode}" = "200" ]; then
  1330. info "sent prowl data for: ${host} ${chart}.${name} is ${status}"
  1331. sent=1
  1332. else
  1333. error "failed to send prowl data for: ${host} ${chart}.${name} is ${status} with with error code ${httpcode}."
  1334. fi
  1335. [ ${sent} -gt 0 ] && return 0
  1336. fi
  1337. return 1
  1338. }
  1339. # -----------------------------------------------------------------------------
  1340. # irc sender
  1341. send_irc() {
  1342. local NICKNAME="${1}" REALNAME="${2}" CHANNELS="${3}" NETWORK="${4}" SERVERNAME="${5}" MESSAGE="${6}" sent=0 channel color send_alarm reply_codes error
  1343. if [ "${SEND_IRC}" = "YES" ] && [ -n "${NICKNAME}" ] && [ -n "${REALNAME}" ] && [ -n "${CHANNELS}" ] && [ -n "${NETWORK}" ] && [ -n "${SERVERNAME}" ]; then
  1344. case "${status}" in
  1345. WARNING) color="warning" ;;
  1346. CRITICAL) color="danger" ;;
  1347. CLEAR) color="good" ;;
  1348. *) color="#777777" ;;
  1349. esac
  1350. for CHANNEL in ${CHANNELS}; do
  1351. error=0
  1352. send_alarm=$(echo -e "USER ${NICKNAME} guest ${REALNAME} ${SERVERNAME}\\nNICK ${NICKNAME}\\nJOIN ${CHANNEL}\\nPRIVMSG ${CHANNEL} :${MESSAGE}\\nQUIT\\n" \ | nc "${NETWORK}" 6667)
  1353. reply_codes=$(echo "${send_alarm}" | cut -d ' ' -f 2 | grep -o '[0-9]*')
  1354. for code in ${reply_codes}; do
  1355. if [ "${code}" -ge 400 ] && [ "${code}" -le 599 ]; then
  1356. error=1
  1357. break
  1358. fi
  1359. done
  1360. if [ "${error}" -eq 0 ]; then
  1361. info "sent irc notification for: ${host} ${chart}.${name} is ${status} to '${CHANNEL}'"
  1362. sent=$((sent + 1))
  1363. else
  1364. error "failed to send irc notification for: ${host} ${chart}.${name} is ${status} to '${CHANNEL}', with error code ${code}."
  1365. fi
  1366. done
  1367. fi
  1368. [ ${sent} -gt 0 ] && return 0
  1369. return 1
  1370. }
  1371. # -----------------------------------------------------------------------------
  1372. # Amazon SNS sender
  1373. send_awssns() {
  1374. local targets="${1}" message='' sent=0 region=''
  1375. local default_format="${status} on ${host} at ${date}: ${chart} ${value_string}"
  1376. [ "${SEND_AWSSNS}" = "YES" ] || return 1
  1377. message=${AWSSNS_MESSAGE_FORMAT:-${default_format}}
  1378. for target in ${targets}; do
  1379. # Extract the region from the target ARN. We need to explicitly specify the region so that it matches up correctly.
  1380. region="$(echo ${target} | cut -f 4 -d ':')"
  1381. if ${aws} sns publish --region "${region}" --subject "${host} ${status_message} - ${name//_/ } - ${chart}" --message "${message}" --target-arn ${target} &>/dev/null; then
  1382. info "sent Amazon SNS notification for: ${host} ${chart}.${name} is ${status} to '${target}'"
  1383. sent=$((sent + 1))
  1384. else
  1385. error "failed to send Amazon SNS notification for: ${host} ${chart}.${name} is ${status} to '${target}'"
  1386. fi
  1387. done
  1388. [ ${sent} -gt 0 ] && return 0
  1389. return 1
  1390. }
  1391. # -----------------------------------------------------------------------------
  1392. # syslog sender
  1393. send_syslog() {
  1394. local facility=${SYSLOG_FACILITY:-"local6"} level='info' targets="${1}"
  1395. local priority='' message='' host='' port='' prefix=''
  1396. local temp1='' temp2=''
  1397. [ "${SEND_SYSLOG}" = "YES" ] || return 1
  1398. if [ "${status}" = "CRITICAL" ]; then
  1399. level='crit'
  1400. elif [ "${status}" = "WARNING" ]; then
  1401. level='warning'
  1402. fi
  1403. for target in ${targets}; do
  1404. priority="${facility}.${level}"
  1405. message=''
  1406. host=''
  1407. port=''
  1408. prefix=''
  1409. temp1=''
  1410. temp2=''
  1411. prefix=$(echo ${target} | cut -d '/' -f 2)
  1412. temp1=$(echo ${target} | cut -d '/' -f 1)
  1413. if [ ${prefix} != ${temp1} ]; then
  1414. if (echo ${temp1} | grep -q '@'); then
  1415. temp2=$(echo ${temp1} | cut -d '@' -f 1)
  1416. host=$(echo ${temp1} | cut -d '@' -f 2)
  1417. if [ ${temp2} != ${host} ]; then
  1418. priority=${temp2}
  1419. fi
  1420. port=$(echo ${host} | rev | cut -d ':' -f 1 | rev)
  1421. if (echo ${host} | grep -E -q '\[.*\]'); then
  1422. if (echo ${port} | grep -q ']'); then
  1423. port=''
  1424. else
  1425. host=$(echo ${host} | rev | cut -d ':' -f 2- | rev)
  1426. fi
  1427. else
  1428. if [ ${port} = ${host} ]; then
  1429. port=''
  1430. else
  1431. host=$(echo ${host} | cut -d ':' -f 1)
  1432. fi
  1433. fi
  1434. else
  1435. priority=${temp1}
  1436. fi
  1437. fi
  1438. message="${prefix} ${status} on ${host} at ${date}: ${chart} ${value_string}"
  1439. if [ ${host} ]; then
  1440. logger_options="${logger_options} -n ${host}"
  1441. if [ ${port} ]; then
  1442. logger_options="${logger_options} -P ${port}"
  1443. fi
  1444. fi
  1445. ${logger} -p ${priority} ${logger_options} "${message}"
  1446. done
  1447. return $?
  1448. }
  1449. # -----------------------------------------------------------------------------
  1450. # SMS sender
  1451. send_sms() {
  1452. local recipients="${1}" errcode errmessage sent=0
  1453. # Human readable SMS
  1454. local msg="${host} ${status_message}: ${chart} (${family}), ${alarm}"
  1455. # limit it to 160 characters
  1456. msg="${msg:0:160}"
  1457. if [ "${SEND_SMS}" = "YES" ] && [ -n "${sendsms}" ] && [ -n "${recipients}" ] && [ -n "${msg}" ]; then
  1458. # http://api.kavenegar.com/v1/{API-KEY}/sms/send.json
  1459. for phone in ${recipients}; do
  1460. errmessage=$($sendsms $phone "$msg" 2>&1)
  1461. errcode=$?
  1462. if [ ${errcode} -eq 0 ]; then
  1463. info "sent smstools3 SMS for: ${host} ${chart}.${name} is ${status} to '${user}'"
  1464. sent=$((sent + 1))
  1465. else
  1466. error "failed to send smstools3 SMS for: ${host} ${chart}.${name} is ${status} to '${user}' with error code ${errcode}: ${errmessage}."
  1467. fi
  1468. done
  1469. [ ${sent} -gt 0 ] && return 0
  1470. fi
  1471. return 1
  1472. }
  1473. # -----------------------------------------------------------------------------
  1474. # prepare the content of the notification
  1475. # the url to send the user on click
  1476. urlencode "${args_host}" >/dev/null
  1477. url_host="${REPLY}"
  1478. urlencode "${chart}" >/dev/null
  1479. url_chart="${REPLY}"
  1480. urlencode "${family}" >/dev/null
  1481. url_family="${REPLY}"
  1482. urlencode "${name}" >/dev/null
  1483. url_name="${REPLY}"
  1484. redirect_params="host=${url_host}&chart=${url_chart}&family=${url_family}&alarm=${url_name}&alarm_unique_id=${unique_id}&alarm_id=${alarm_id}&alarm_event_id=${event_id}"
  1485. GOTOCLOUD=0
  1486. if [ "${NETDATA_REGISTRY_URL}" == "https://registry.my-netdata.io" ]; then
  1487. if [ -z "${NETDATA_REGISTRY_UNIQUE_ID}" ]; then
  1488. if [ -f "@registrydir_POST@/netdata.public.unique.id" ]; then
  1489. NETDATA_REGISTRY_UNIQUE_ID="$(cat "@registrydir_POST@/netdata.public.unique.id")"
  1490. fi
  1491. fi
  1492. if [ ! -z "${NETDATA_REGISTRY_UNIQUE_ID}" ]; then
  1493. GOTOCLOUD=1
  1494. fi
  1495. fi
  1496. if [ ${GOTOCLOUD} -eq 0 ]; then
  1497. goto_url="${NETDATA_REGISTRY_URL}/goto-host-from-alarm.html?${redirect_params}"
  1498. else
  1499. goto_url="https://netdata.cloud/alarms/redirect?agentID=${NETDATA_REGISTRY_UNIQUE_ID}&${redirect_params}"
  1500. fi
  1501. # the severity of the alarm
  1502. severity="${status}"
  1503. # the time the alarm was raised
  1504. duration4human ${duration} >/dev/null
  1505. duration_txt="${REPLY}"
  1506. duration4human ${non_clear_duration} >/dev/null
  1507. non_clear_duration_txt="${REPLY}"
  1508. raised_for="(was ${old_status,,} for ${duration_txt})"
  1509. # the key status message
  1510. status_message="status unknown"
  1511. # the color of the alarm
  1512. color="grey"
  1513. # the alarm value
  1514. alarm="${name//_/ } = ${value_string}"
  1515. # the image of the alarm
  1516. image="${images_base_url}/images/banner-icon-144x144.png"
  1517. # prepare the title based on status
  1518. case "${status}" in
  1519. CRITICAL)
  1520. image="${images_base_url}/images/alert-128-red.png"
  1521. status_message="is critical"
  1522. color="#ca414b"
  1523. ;;
  1524. WARNING)
  1525. image="${images_base_url}/images/alert-128-orange.png"
  1526. status_message="needs attention"
  1527. color="#ffc107"
  1528. ;;
  1529. CLEAR)
  1530. image="${images_base_url}/images/check-mark-2-128-green.png"
  1531. status_message="recovered"
  1532. color="#77ca6d"
  1533. ;;
  1534. esac
  1535. if [ "${status}" = "CLEAR" ]; then
  1536. severity="Recovered from ${old_status}"
  1537. if [ ${non_clear_duration} -gt ${duration} ]; then
  1538. raised_for="(alarm was raised for ${non_clear_duration_txt})"
  1539. fi
  1540. # don't show the value when the status is CLEAR
  1541. # for certain alarms, this value might not have any meaning
  1542. alarm="${name//_/ } ${raised_for}"
  1543. elif { [ "${old_status}" = "WARNING" ] && [ "${status}" = "CRITICAL" ]; }; then
  1544. severity="Escalated to ${status}"
  1545. if [ ${non_clear_duration} -gt ${duration} ]; then
  1546. raised_for="(alarm is raised for ${non_clear_duration_txt})"
  1547. fi
  1548. elif { [ "${old_status}" = "CRITICAL" ] && [ "${status}" = "WARNING" ]; }; then
  1549. severity="Demoted to ${status}"
  1550. if [ ${non_clear_duration} -gt ${duration} ]; then
  1551. raised_for="(alarm is raised for ${non_clear_duration_txt})"
  1552. fi
  1553. else
  1554. raised_for=
  1555. fi
  1556. # prepare HTML versions of elements
  1557. info_html=
  1558. [ -n "${info}" ] && info_html=" <small><br/>${info}</small>"
  1559. raised_for_html=
  1560. [ -n "${raised_for}" ] && raised_for_html="<br/><small>${raised_for}</small>"
  1561. # -----------------------------------------------------------------------------
  1562. # send the slack notification
  1563. # slack aggregates posts from the same username
  1564. # so we use "${host} ${status}" as the bot username, to make them diff
  1565. send_slack "${SLACK_WEBHOOK_URL}" "${to_slack}"
  1566. SENT_SLACK=$?
  1567. # -----------------------------------------------------------------------------
  1568. # send the Microsoft notification
  1569. # Microsoft team aggregates posts from the same username
  1570. # so we use "${host} ${status}" as the bot username, to make them diff
  1571. send_msteam "${MSTEAM_WEBHOOK_URL}" "${to_msteam}"
  1572. SENT_MSTEAM=$?
  1573. # -----------------------------------------------------------------------------
  1574. # send the rocketchat notification
  1575. # rocketchat aggregates posts from the same username
  1576. # so we use "${host} ${status}" as the bot username, to make them diff
  1577. send_rocketchat "${ROCKETCHAT_WEBHOOK_URL}" "${to_rocketchat}"
  1578. SENT_ROCKETCHAT=$?
  1579. # -----------------------------------------------------------------------------
  1580. # send the alerta notification
  1581. # alerta aggregates posts from the same username
  1582. # so we use "${host} ${status}" as the bot username, to make them diff
  1583. send_alerta "${ALERTA_WEBHOOK_URL}" "${to_alerta}"
  1584. SENT_ALERTA=$?
  1585. # -----------------------------------------------------------------------------
  1586. # send the flock notification
  1587. # flock aggregates posts from the same username
  1588. # so we use "${host} ${status}" as the bot username, to make them diff
  1589. send_flock "${FLOCK_WEBHOOK_URL}" "${to_flock}"
  1590. SENT_FLOCK=$?
  1591. # -----------------------------------------------------------------------------
  1592. # send the discord notification
  1593. # discord aggregates posts from the same username
  1594. # so we use "${host} ${status}" as the bot username, to make them diff
  1595. send_discord "${DISCORD_WEBHOOK_URL}" "${to_discord}"
  1596. SENT_DISCORD=$?
  1597. # -----------------------------------------------------------------------------
  1598. # send the pushover notification
  1599. send_pushover "${PUSHOVER_APP_TOKEN}" "${to_pushover}" "${when}" "${goto_url}" "${status}" "${host} ${status_message} - ${name//_/ } - ${chart}" "
  1600. <font color=\"${color}\"><b>${alarm}</b></font>${info_html}<br/>&nbsp;
  1601. <small><b>${chart}</b><br/>Chart<br/>&nbsp;</small>
  1602. <small><b>${family}</b><br/>Family<br/>&nbsp;</small>
  1603. <small><b>${severity}</b><br/>Severity<br/>&nbsp;</small>
  1604. <small><b>${date}${raised_for_html}</b><br/>Time<br/>&nbsp;</small>
  1605. <a href=\"${goto_url}\">View Netdata</a><br/>&nbsp;
  1606. <small><small>The source of this alarm is line ${src}</small></small>
  1607. "
  1608. SENT_PUSHOVER=$?
  1609. # -----------------------------------------------------------------------------
  1610. # send the pushbullet notification
  1611. send_pushbullet "${PUSHBULLET_ACCESS_TOKEN}" "${PUSHBULLET_SOURCE_DEVICE}" "${to_pushbullet}" "${goto_url}" "${host} ${status_message} - ${name//_/ } - ${chart}" "${alarm}\\n
  1612. Severity: ${severity}\\n
  1613. Chart: ${chart}\\n
  1614. Family: ${family}\\n
  1615. $(date -d @${when})\\n
  1616. The source of this alarm is line ${src}"
  1617. SENT_PUSHBULLET=$?
  1618. # -----------------------------------------------------------------------------
  1619. # send the twilio SMS
  1620. send_twilio "${TWILIO_ACCOUNT_SID}" "${TWILIO_ACCOUNT_TOKEN}" "${TWILIO_NUMBER}" "${to_twilio}" "${host} ${status_message} - ${name//_/ } - ${chart}" "${alarm}
  1621. Severity: ${severity}
  1622. Chart: ${chart}
  1623. Family: ${family}
  1624. ${info}"
  1625. SENT_TWILIO=$?
  1626. # -----------------------------------------------------------------------------
  1627. # send the messagebird SMS
  1628. send_messagebird "${MESSAGEBIRD_ACCESS_KEY}" "${MESSAGEBIRD_NUMBER}" "${to_messagebird}" "${host} ${status_message} - ${name//_/ } - ${chart}" "${alarm}
  1629. Severity: ${severity}
  1630. Chart: ${chart}
  1631. Family: ${family}
  1632. ${info}"
  1633. SENT_MESSAGEBIRD=$?
  1634. # -----------------------------------------------------------------------------
  1635. # send the kavenegar SMS
  1636. send_kavenegar "${KAVENEGAR_API_KEY}" "${KAVENEGAR_SENDER}" "${to_kavenegar}" "${host} ${status_message} - ${name//_/ } - ${chart}" "${alarm}
  1637. Severity: ${severity}
  1638. Chart: ${chart}
  1639. Family: ${family}
  1640. ${info}"
  1641. SENT_KAVENEGAR=$?
  1642. # -----------------------------------------------------------------------------
  1643. # send the telegram.org message
  1644. # https://core.telegram.org/bots/api#formatting-options
  1645. send_telegram "${TELEGRAM_BOT_TOKEN}" "${to_telegram}" "${host} ${status_message} - <b>${name//_/ }</b>
  1646. ${chart} (${family})
  1647. <a href=\"${goto_url}\">${alarm}</a>
  1648. <i>${info}</i>"
  1649. SENT_TELEGRAM=$?
  1650. # -----------------------------------------------------------------------------
  1651. # send the kafka message
  1652. send_kafka
  1653. SENT_KAFKA=$?
  1654. # -----------------------------------------------------------------------------
  1655. # send the pagerduty.com message
  1656. send_pd "${to_pd}"
  1657. SENT_PD=$?
  1658. # -----------------------------------------------------------------------------
  1659. # send the fleep message
  1660. send_fleep "${to_fleep}"
  1661. SENT_FLEEP=$?
  1662. # -----------------------------------------------------------------------------
  1663. # send the Prowl message
  1664. send_prowl "${to_prowl}"
  1665. SENT_PROWL=$?
  1666. # -----------------------------------------------------------------------------
  1667. # send the irc message
  1668. send_irc "${IRC_NICKNAME}" "${IRC_REALNAME}" "${to_irc}" "${IRC_NETWORK}" "${host}" "${host} ${status_message} - ${name//_/ } - ${chart} ----- ${alarm}
  1669. Severity: ${severity}
  1670. Chart: ${chart}
  1671. Family: ${family}
  1672. ${info}"
  1673. SENT_IRC=$?
  1674. # -----------------------------------------------------------------------------
  1675. # send the SMS message with smstools3
  1676. send_sms "${to_sms}"
  1677. SENT_SMS=$?
  1678. # -----------------------------------------------------------------------------
  1679. # send the custom message
  1680. send_custom() {
  1681. # is it enabled?
  1682. [ "${SEND_CUSTOM}" != "YES" ] && return 1
  1683. # do we have any sender?
  1684. [ -z "${1}" ] && return 1
  1685. # call the custom_sender function
  1686. custom_sender "${@}"
  1687. }
  1688. send_custom "${to_custom}"
  1689. SENT_CUSTOM=$?
  1690. # -----------------------------------------------------------------------------
  1691. # send hipchat message
  1692. send_hipchat "${HIPCHAT_AUTH_TOKEN}" "${to_hipchat}" " \
  1693. ${host} ${status_message}<br/> \
  1694. <b>${alarm}</b> ${info_html}<br/> \
  1695. <b>${chart}</b> (family <b>${family}</b>)<br/> \
  1696. <b>${date}${raised_for_html}</b><br/> \
  1697. <a href=\\\"${goto_url}\\\">View netdata dashboard</a> \
  1698. (source of alarm ${src}) \
  1699. "
  1700. SENT_HIPCHAT=$?
  1701. # -----------------------------------------------------------------------------
  1702. # send the Amazon SNS message
  1703. send_awssns "${to_awssns}"
  1704. SENT_AWSSNS=$?
  1705. # -----------------------------------------------------------------------------
  1706. # send the syslog message
  1707. send_syslog "${to_syslog}"
  1708. SENT_SYSLOG=$?
  1709. # -----------------------------------------------------------------------------
  1710. # send the email
  1711. send_email <<EOF
  1712. To: ${to_email}
  1713. Subject: ${host} ${status_message} - ${name//_/ } - ${chart}
  1714. MIME-Version: 1.0
  1715. Content-Type: multipart/alternative; boundary="multipart-boundary"
  1716. ${email_thread_headers}
  1717. This is a MIME-encoded multipart message
  1718. --multipart-boundary
  1719. Content-Type: text/plain; encoding=${EMAIL_CHARSET}
  1720. Content-Disposition: inline
  1721. Content-Transfer-Encoding: 8bit
  1722. ${host} ${status_message}
  1723. ${alarm} ${info}
  1724. ${raised_for}
  1725. Chart : ${chart}
  1726. Family : ${family}
  1727. Severity: ${severity}
  1728. URL : ${goto_url}
  1729. Source : ${src}
  1730. Date : ${date}
  1731. Notification generated on ${host}
  1732. Evaluated Expression : ${calc_expression}
  1733. Expression Variables : ${calc_param_values}
  1734. The host has ${total_warnings} WARNING and ${total_critical} CRITICAL alarm(s) raised.
  1735. --multipart-boundary
  1736. Content-Type: text/html; encoding=${EMAIL_CHARSET}
  1737. Content-Disposition: inline
  1738. Content-Transfer-Encoding: 8bit
  1739. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  1740. <html xmlns="http://www.w3.org/1999/xhtml" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 14px; margin: 0; padding: 0;">
  1741. <body style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; width: 100% !important; min-height: 100%; line-height: 1.6; background: #f6f6f6; margin:0; padding: 0;">
  1742. <table>
  1743. <tbody>
  1744. <tr>
  1745. <td style="vertical-align: top;" valign="top"></td>
  1746. <td width="700" style="vertical-align: top; display: block !important; max-width: 700px !important; clear: both !important; margin: 0 auto; padding: 0;" valign="top">
  1747. <div style="max-width: 700px; display: block; margin: 0 auto; padding: 20px;">
  1748. <table width="100%" cellpadding="0" cellspacing="0" style="background: #fff; border: 1px solid #e9e9e9;">
  1749. <tbody>
  1750. <tr>
  1751. <td bgcolor="#eee" style="padding: 5px 20px 5px 20px; background-color: #eee;">
  1752. <div style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 20px; color: #777; font-weight: bold;">netdata notification</div>
  1753. </td>
  1754. </tr>
  1755. <tr>
  1756. <td bgcolor="${color}" style="font-size: 16px; vertical-align: top; font-weight: 400; text-align: center; margin: 0; padding: 10px; color: #ffffff; background: ${color} !important; border: 1px solid ${color}; border-top-color: ${color};" align="center" valign="top">
  1757. <h1 style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-weight: 400; margin: 0;">${host} ${status_message}</h1>
  1758. </td>
  1759. </tr>
  1760. <tr>
  1761. <td style="vertical-align: top;" valign="top">
  1762. <div style="margin: 0; padding: 20px; max-width: 700px;">
  1763. <table width="100%" cellpadding="0" cellspacing="0" style="max-width:700px">
  1764. <tbody>
  1765. <tr>
  1766. <td style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding:0 0 20px;" align="left" valign="top">
  1767. <span>${chart}</span>
  1768. <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Chart</span>
  1769. </td>
  1770. </tr>
  1771. <tr style="margin: 0; padding: 0;">
  1772. <td style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;" align="left" valign="top">
  1773. <span><b>${alarm}</b>${info_html}</span>
  1774. <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Alarm</span>
  1775. </td>
  1776. </tr>
  1777. <tr>
  1778. <td style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;" align="left" valign="top">
  1779. <span>${family}</span>
  1780. <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Family</span>
  1781. </td>
  1782. </tr>
  1783. <tr style="margin: 0; padding: 0;">
  1784. <td style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;" align="left" valign="top">
  1785. <span>${severity}</span>
  1786. <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Severity</span>
  1787. </td>
  1788. </tr>
  1789. <tr style="margin: 0; padding: 0;">
  1790. <td style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;" align="left" valign="top"><span>${date}</span>
  1791. <span>${raised_for_html}</span> <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Time</span>
  1792. </td>
  1793. </tr>
  1794. <tr style="margin: 0; padding: 0;">
  1795. <td style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;" align="left" valign="top">
  1796. <span>${calc_expression}</span>
  1797. <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Evaluated Expression</span>
  1798. </td>
  1799. </tr>
  1800. <tr style="margin: 0; padding: 0;">
  1801. <td style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;" align="left" valign="top">
  1802. <span>${calc_param_values}</span>
  1803. <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Expression Variables</span>
  1804. </td>
  1805. </tr>
  1806. <tr style="margin: 0; padding: 0;">
  1807. <td style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;" align="left" valign="top">
  1808. The host has ${total_warnings} WARNING and ${total_critical} CRITICAL alarm(s) raised.
  1809. </td>
  1810. </tr>
  1811. <tr style="margin: 0; padding: 0;">
  1812. <td style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;">
  1813. <a href="${goto_url}" style="font-size: 14px; color: #ffffff; text-decoration: none; line-height: 1.5; font-weight: bold; text-align: center; display: inline-block; text-transform: capitalize; background: #35568d; border-width: 1px; border-style: solid; border-color: #2b4c86; margin: 0; padding: 10px 15px;" target="_blank">View Netdata</a>
  1814. </td>
  1815. </tr>
  1816. <tr style="text-align: center; margin: 0; padding: 0;">
  1817. <td style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 11px; vertical-align: top; margin: 0; padding: 10px 0 0 0; color: #666666;" align="center" valign="bottom">The source of this alarm is line <code>${src}</code><br/>(alarms are configurable, edit this file to adapt the alarm to your needs)
  1818. </td>
  1819. </tr>
  1820. <tr style="text-align: center; margin: 0; padding: 0;">
  1821. <td style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; vertical-align: top; margin:0; padding: 20px 0 0 0; color: #666666; border-top: 1px solid #f0f0f0;" align="center" valign="bottom">Sent by
  1822. <a href="https://mynetdata.io/" target="_blank">netdata</a>, the real-time performance and health monitoring, on <code>${host}</code>.
  1823. </td>
  1824. </tr>
  1825. </tbody>
  1826. </table>
  1827. </div>
  1828. </td>
  1829. </tr>
  1830. </tbody>
  1831. </table>
  1832. </div>
  1833. </td>
  1834. </tr>
  1835. </tbody>
  1836. </table>
  1837. </body>
  1838. </html>
  1839. --multipart-boundary--
  1840. EOF
  1841. SENT_EMAIL=$?
  1842. # -----------------------------------------------------------------------------
  1843. # let netdata know
  1844. for state in "${SENT_EMAIL}" \
  1845. "${SENT_PUSHOVER}" \
  1846. "${SENT_TELEGRAM}" \
  1847. "${SENT_SLACK}" \
  1848. "${SENT_ROCKETCHAT}" \
  1849. "${SENT_ALERTA}" \
  1850. "${SENT_FLOCK}" \
  1851. "${SENT_DISCORD}" \
  1852. "${SENT_TWILIO}" \
  1853. "${SENT_HIPCHAT}" \
  1854. "${SENT_MESSAGEBIRD}" \
  1855. "${SENT_KAVENEGAR}" \
  1856. "${SENT_PUSHBULLET}" \
  1857. "${SENT_KAFKA}" \
  1858. "${SENT_PD}" \
  1859. "${SENT_FLEEP}" \
  1860. "${SENT_PROWL}" \
  1861. "${SENT_CUSTOM}" \
  1862. "${SENT_IRC}" \
  1863. "${SENT_AWSSNS}" \
  1864. "${SENT_SYSLOG}" \
  1865. "${SENT_SMS}" \
  1866. "${SENT_MSTEAM}"; do
  1867. if [ "${state}" -eq 0 ]; then
  1868. # we sent something
  1869. exit 0
  1870. fi
  1871. done
  1872. # we did not send anything
  1873. exit 1