alarm-notify.sh.in 134 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574
  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. # - irc notifications by @manosf
  32. # - custom notifications by @ktsaou
  33. # - syslog messages by @Ferroin
  34. # - Microsoft Team notification by @tioumen
  35. # - RocketChat notifications by @Hermsi1337 #3777
  36. # - Google Hangouts Chat notifications by @EnzoAkira and @hendrikhofstadt
  37. # - Dynatrace Event by @illumine
  38. # - Stackpulse Event by @thiagoftsm
  39. # - Opsgenie by @thiaoftsm #9858
  40. # - Gotify by @coffeegrind123
  41. # -----------------------------------------------------------------------------
  42. # testing notifications
  43. if { [ "${1}" = "test" ] || [ "${2}" = "test" ]; } && [ "${#}" -le 2 ]; then
  44. if [ "${2}" = "test" ]; then
  45. recipient="${1}"
  46. else
  47. recipient="${2}"
  48. fi
  49. [ -z "${recipient}" ] && recipient="sysadmin"
  50. id=1
  51. last="CLEAR"
  52. test_res=0
  53. for x in "WARNING" "CRITICAL" "CLEAR"; do
  54. echo >&2
  55. echo >&2 "# SENDING TEST ${x} ALARM TO ROLE: ${recipient}"
  56. "${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
  57. #shellcheck disable=SC2181
  58. if [ $? -ne 0 ]; then
  59. echo >&2 "# FAILED"
  60. test_res=1
  61. else
  62. echo >&2 "# OK"
  63. fi
  64. last="${x}"
  65. id=$((id + 1))
  66. done
  67. exit $test_res
  68. fi
  69. export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
  70. export LC_ALL=C
  71. # -----------------------------------------------------------------------------
  72. PROGRAM_NAME="$(basename "${0}")"
  73. logdate() {
  74. date "+%Y-%m-%d %H:%M:%S"
  75. }
  76. log() {
  77. local status="${1}"
  78. shift
  79. echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
  80. }
  81. warning() {
  82. log WARNING "${@}"
  83. }
  84. error() {
  85. log ERROR "${@}"
  86. }
  87. info() {
  88. log INFO "${@}"
  89. }
  90. fatal() {
  91. log FATAL "${@}"
  92. exit 1
  93. }
  94. debug=${NETDATA_ALARM_NOTIFY_DEBUG-0}
  95. debug() {
  96. [ "${debug}" = "1" ] && log DEBUG "${@}"
  97. }
  98. docurl() {
  99. if [ -z "${curl}" ]; then
  100. error "${curl} is unset."
  101. return 1
  102. fi
  103. if [ "${debug}" = "1" ]; then
  104. echo >&2 "--- BEGIN curl command ---"
  105. printf >&2 "%q " ${curl} "${@}"
  106. echo >&2
  107. echo >&2 "--- END curl command ---"
  108. local out code ret
  109. out=$(mktemp /tmp/netdata-health-alarm-notify-XXXXXXXX)
  110. code=$(${curl} ${curl_options} --write-out "%{http_code}" --output "${out}" --silent --show-error "${@}")
  111. ret=$?
  112. echo >&2 "--- BEGIN received response ---"
  113. cat >&2 "${out}"
  114. echo >&2
  115. echo >&2 "--- END received response ---"
  116. echo >&2 "RECEIVED HTTP RESPONSE CODE: ${code}"
  117. rm "${out}"
  118. echo "${code}"
  119. return ${ret}
  120. fi
  121. ${curl} ${curl_options} --write-out "%{http_code}" --output /dev/null --silent --show-error "${@}"
  122. return $?
  123. }
  124. # -----------------------------------------------------------------------------
  125. # List of all the notification mechanisms we support.
  126. # Used in a couple of places to write more compact code.
  127. method_names="
  128. email
  129. pushover
  130. pushbullet
  131. telegram
  132. slack
  133. alerta
  134. flock
  135. discord
  136. hipchat
  137. twilio
  138. messagebird
  139. pd
  140. fleep
  141. syslog
  142. custom
  143. msteams
  144. kavenegar
  145. prowl
  146. irc
  147. awssns
  148. rocketchat
  149. sms
  150. hangouts
  151. dynatrace
  152. matrix
  153. "
  154. # -----------------------------------------------------------------------------
  155. # this is to be overwritten by the config file
  156. custom_sender() {
  157. info "not sending custom notification for ${status} of '${host}.${chart}.${name}'"
  158. }
  159. # -----------------------------------------------------------------------------
  160. # check for BASH v4+ (required for associative arrays)
  161. if [ ${BASH_VERSINFO[0]} -lt 4 ]; then
  162. fatal "BASH version 4 or later is required (this is ${BASH_VERSION})."
  163. fi
  164. # -----------------------------------------------------------------------------
  165. # defaults to allow running this script by hand
  166. [ -z "${NETDATA_USER_CONFIG_DIR}" ] && NETDATA_USER_CONFIG_DIR="@configdir_POST@"
  167. [ -z "${NETDATA_STOCK_CONFIG_DIR}" ] && NETDATA_STOCK_CONFIG_DIR="@libconfigdir_POST@"
  168. [ -z "${NETDATA_CACHE_DIR}" ] && NETDATA_CACHE_DIR="@cachedir_POST@"
  169. [ -z "${NETDATA_REGISTRY_URL}" ] && NETDATA_REGISTRY_URL="https://registry.my-netdata.io"
  170. [ -z "${NETDATA_REGISTRY_CLOUD_BASE_URL}" ] && NETDATA_REGISTRY_CLOUD_BASE_URL="https://app.netdata.cloud"
  171. # -----------------------------------------------------------------------------
  172. # parse command line parameters
  173. if [[ ${1} = "unittest" ]]; then
  174. unittest=1 # enable unit testing mode
  175. roles="${2}" # the role that should be used for unit testing
  176. cfgfile="${3}" # the location of the config file to use for unit testing
  177. status="${4}" # the current status : REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
  178. old_status="${5}" # the previous status: REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
  179. elif [[ ${1} = "dump_methods" ]]; then
  180. dump_methods=1
  181. status="WARNING"
  182. else
  183. roles="${1}" # the roles that should be notified for this event
  184. args_host="${2}" # the host generated this event
  185. unique_id="${3}" # the unique id of this event
  186. alarm_id="${4}" # the unique id of the alarm that generated this event
  187. event_id="${5}" # the incremental id of the event, for this alarm id
  188. when="${6}" # the timestamp this event occurred
  189. name="${7}" # the name of the alarm, as given in netdata health.d entries
  190. chart="${8}" # the name of the chart (type.id)
  191. family="${9}" # the family of the chart
  192. status="${10}" # the current status : REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
  193. old_status="${11}" # the previous status: REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
  194. value="${12}" # the current value of the alarm
  195. old_value="${13}" # the previous value of the alarm
  196. src="${14}" # the line number and file the alarm has been configured
  197. duration="${15}" # the duration in seconds of the previous alarm state
  198. non_clear_duration="${16}" # the total duration in seconds this is/was non-clear
  199. units="${17}" # the units of the value
  200. info="${18}" # a short description of the alarm
  201. value_string="${19}" # friendly value (with units)
  202. # shellcheck disable=SC2034
  203. # variable is unused, but https://github.com/netdata/netdata/pull/5164#discussion_r255572947
  204. old_value_string="${20}" # friendly old value (with units), previously named "old_value_string"
  205. calc_expression="${21}" # contains the expression that was evaluated to trigger the alarm
  206. calc_param_values="${22}" # the values of the parameters in the expression, at the time of the evaluation
  207. total_warnings="${23}" # Total number of alarms in WARNING state
  208. total_critical="${24}" # Total number of alarms in CRITICAL state
  209. total_warn_alarms="${25}" # List of alarms in warning state
  210. total_crit_alarms="${26}" # List of alarms in critical state
  211. classification="${27}" # The class field from .conf files
  212. edit_command_line="${28}" # The command to edit the alarm, with the line number
  213. child_machine_guid="${29}" # If populated, the notification is sent for a child
  214. fi
  215. # -----------------------------------------------------------------------------
  216. # find a suitable hostname to use, if netdata did not supply a hostname
  217. if [ -z ${args_host} ]; then
  218. this_host=$(hostname -s 2>/dev/null)
  219. host="${this_host}"
  220. args_host="${this_host}"
  221. else
  222. host="${args_host}"
  223. fi
  224. # -----------------------------------------------------------------------------
  225. # screen statuses we don't need to send a notification
  226. # don't do anything if this is not WARNING, CRITICAL or CLEAR
  227. if [ "${status}" != "WARNING" ] && [ "${status}" != "CRITICAL" ] && [ "${status}" != "CLEAR" ]; then
  228. info "not sending notification for ${status} of '${host}.${chart}.${name}'"
  229. exit 1
  230. fi
  231. # don't do anything if this is CLEAR, but it was not WARNING or CRITICAL
  232. if [ "${clear_alarm_always}" != "YES" ] && [ "${old_status}" != "WARNING" ] && [ "${old_status}" != "CRITICAL" ] && [ "${status}" = "CLEAR" ]; then
  233. info "not sending notification for ${status} of '${host}.${chart}.${name}' (last status was ${old_status})"
  234. exit 1
  235. fi
  236. # -----------------------------------------------------------------------------
  237. # load configuration
  238. # By default fetch images from the global public registry.
  239. # This is required by default, since all notification methods need to download
  240. # images via the Internet, and private registries might not be reachable.
  241. # This can be overwritten at the configuration file.
  242. images_base_url="https://registry.my-netdata.io"
  243. # curl options to use
  244. curl_options=""
  245. # hostname handling
  246. use_fqdn="NO"
  247. # needed commands
  248. # if empty they will be searched in the system path
  249. curl=
  250. sendmail=
  251. # enable / disable features
  252. for method_name in ${method_names^^}; do
  253. declare SEND_${method_name}="YES"
  254. declare DEFAULT_RECIPIENT_${method_name}
  255. done
  256. for method_name in ${method_names}; do
  257. declare -A role_recipients_${method_name}
  258. done
  259. # slack configs
  260. SLACK_WEBHOOK_URL=
  261. # Microsoft Teams configs
  262. MSTEAMS_WEBHOOK_URL=
  263. # Legacy Microsoft Teams configs for backwards compatibility:
  264. declare -A role_recipients_msteam
  265. # rocketchat configs
  266. ROCKETCHAT_WEBHOOK_URL=
  267. # alerta configs
  268. ALERTA_WEBHOOK_URL=
  269. ALERTA_API_KEY=
  270. # flock configs
  271. FLOCK_WEBHOOK_URL=
  272. # discord configs
  273. DISCORD_WEBHOOK_URL=
  274. # pushover configs
  275. PUSHOVER_APP_TOKEN=
  276. # pushbullet configs
  277. PUSHBULLET_ACCESS_TOKEN=
  278. PUSHBULLET_SOURCE_DEVICE=
  279. # twilio configs
  280. TWILIO_ACCOUNT_SID=
  281. TWILIO_ACCOUNT_TOKEN=
  282. TWILIO_NUMBER=
  283. # hipchat configs
  284. HIPCHAT_SERVER=
  285. HIPCHAT_AUTH_TOKEN=
  286. # messagebird configs
  287. MESSAGEBIRD_ACCESS_KEY=
  288. MESSAGEBIRD_NUMBER=
  289. # kavenegar configs
  290. KAVENEGAR_API_KEY=
  291. KAVENEGAR_SENDER=
  292. # telegram configs
  293. TELEGRAM_BOT_TOKEN=
  294. # kafka configs
  295. SEND_KAFKA="YES"
  296. KAFKA_URL=
  297. KAFKA_SENDER_IP=
  298. # pagerduty.com configs
  299. PD_SERVICE_KEY=
  300. USE_PD_VERSION=
  301. # fleep.io configs
  302. FLEEP_SENDER="${host}"
  303. # Amazon SNS configs
  304. AWSSNS_MESSAGE_FORMAT=
  305. # Matrix configs
  306. MATRIX_HOMESERVER=
  307. MATRIX_ACCESSTOKEN=
  308. # syslog configs
  309. SYSLOG_FACILITY=
  310. # email configs
  311. EMAIL_SENDER=
  312. EMAIL_CHARSET=$(locale charmap 2>/dev/null)
  313. EMAIL_THREADING=
  314. EMAIL_PLAINTEXT_ONLY=
  315. # irc configs
  316. IRC_NICKNAME=
  317. IRC_REALNAME=
  318. IRC_NETWORK=
  319. IRC_PORT=6667
  320. # hangouts configs
  321. declare -A HANGOUTS_WEBHOOK_URI
  322. declare -A HANGOUTS_WEBHOOK_THREAD
  323. # dynatrace configs
  324. DYNATRACE_SPACE=
  325. DYNATRACE_SERVER=
  326. DYNATRACE_TOKEN=
  327. DYNATRACE_TAG_VALUE=
  328. DYNATRACE_ANNOTATION_TYPE=
  329. DYNATRACE_EVENT=
  330. SEND_DYNATRACE=
  331. # stackpulse configs
  332. STACKPULSE_WEBHOOK=
  333. # gotify configs
  334. GOTIFY_APP_URL=
  335. GOTIFY_APP_TOKEN=
  336. # opsgenie configs
  337. OPSGENIE_API_KEY=
  338. # load the stock and user configuration files
  339. # these will overwrite the variables above
  340. if [ ${unittest} ]; then
  341. if source "${cfgfile}"; then
  342. error "Failed to load requested config file."
  343. exit 1
  344. fi
  345. else
  346. for CONFIG in "${NETDATA_STOCK_CONFIG_DIR}/health_alarm_notify.conf" "${NETDATA_USER_CONFIG_DIR}/health_alarm_notify.conf"; do
  347. if [ -f "${CONFIG}" ]; then
  348. debug "Loading config file '${CONFIG}'..."
  349. source "${CONFIG}" || error "Failed to load config file '${CONFIG}'."
  350. else
  351. warning "Cannot find file '${CONFIG}'."
  352. fi
  353. done
  354. fi
  355. OPSGENIE_API_URL=${OPSGENIE_API_URL:-"https://api.opsgenie.com"}
  356. # If we didn't autodetect the character set for e-mail and it wasn't
  357. # set by the user, we need to set it to a reasonable default. UTF-8
  358. # should be correct for almost all modern UNIX systems.
  359. if [ -z ${EMAIL_CHARSET} ]; then
  360. EMAIL_CHARSET="UTF-8"
  361. fi
  362. # If we've been asked to use FQDN's for the URL's in the alarm, do so,
  363. # unless we're sending an alarm for a child system which we can't get the
  364. # FQDN of easily.
  365. if [ "${use_fqdn}" = "YES" ] && [ "${host}" = "$(hostname -s 2>/dev/null)" ]; then
  366. host="$(hostname -f 2>/dev/null)"
  367. fi
  368. # -----------------------------------------------------------------------------
  369. # migrate old Microsoft Teams configuration keys after loading configuration
  370. msteams_migration() {
  371. SEND_MSTEAMS=${SEND_MSTEAM:-$SEND_MSTEAMS}
  372. unset -v SEND_MSTEAM
  373. DEFAULT_RECIPIENT_MSTEAMS=${DEFAULT_RECIPIENT_MSTEAM:-$DEFAULT_RECIPIENT_MSTEAMS}
  374. MSTEAMS_WEBHOOK_URL=${MSTEAM_WEBHOOK_URL:-$MSTEAMS_WEBHOOK_URL}
  375. MSTEAMS_ICON_DEFAULT=${MSTEAM_ICON_DEFAULT:-$MSTEAMS_ICON_DEFAULT}
  376. MSTEAMS_ICON_CLEAR=${MSTEAM_ICON_CLEAR:-$MSTEAMS_ICON_CLEAR}
  377. MSTEAMS_ICON_WARNING=${MSTEAM_ICON_WARNING:-$MSTEAMS_ICON_WARNING}
  378. MSTEAMS_ICON_CRITICAL=${MSTEAM_ICON_CRITICAL:-$MSTEAMS_ICON_CRITICAL}
  379. MSTEAMS_COLOR_DEFAULT=${MSTEAM_COLOR_DEFAULT:-$MSTEAMS_COLOR_DEFAULT}
  380. MSTEAMS_COLOR_CLEAR=${MSTEAM_COLOR_CLEAR:-$MSTEAMS_COLOR_CLEAR}
  381. MSTEAMS_COLOR_WARNING=${MSTEAM_COLOR_WARNING:-$MSTEAMS_COLOR_WARNING}
  382. MSTEAMS_COLOR_CRITICAL=${MSTEAM_COLOR_CRITICAL:-$MSTEAMS_COLOR_CRITICAL}
  383. # migrate role specific recipients:
  384. for key in "${!role_recipients_msteam[@]}"; do
  385. # Disable check, if role_recipients_msteams is ever used:
  386. # The role_recipients_$method are created and used programmatically
  387. # by iterating over $methods. shellcheck therefore doesn't realize
  388. # that role_recipients_msteams is actually used in the block
  389. # "find the recipients' addresses per method".
  390. # shellcheck disable=SC2034
  391. role_recipients_msteams["$key"]="${role_recipients_msteam["$key"]}"
  392. done
  393. }
  394. msteams_migration
  395. # -----------------------------------------------------------------------------
  396. # filter a recipient based on alarm event severity
  397. filter_recipient_by_criticality() {
  398. local method="${1}" x="${2}" r s
  399. shift
  400. r="${x/|*/}" # the recipient
  401. s="${x/*|/}" # the severity required for notifying this recipient
  402. # no severity filtering for this person
  403. [ "${r}" = "${s}" ] && return 0
  404. # the severity is invalid
  405. s="${s^^}"
  406. if [ "${s}" != "CRITICAL" ]; then
  407. error "SEVERITY FILTERING for ${x} VIA ${method}: invalid severity '${s,,}', only 'critical' is supported."
  408. return 0
  409. fi
  410. # create the status tracking directory for this user
  411. [ ! -d "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}" ] &&
  412. mkdir -p "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}"
  413. case "${status}" in
  414. CRITICAL)
  415. # make sure he will get future notifications for this alarm too
  416. touch "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}"
  417. debug "SEVERITY FILTERING for ${x} VIA ${method}: ALLOW: the alarm is CRITICAL (will now receive next status change)"
  418. return 0
  419. ;;
  420. WARNING)
  421. if [ -f "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}" ]; then
  422. # we do not remove the file, so that he will get future notifications of this alarm
  423. debug "SEVERITY FILTERING for ${x} VIA ${method}: ALLOW: recipient has been notified for this alarm in the past (will still receive next status change)"
  424. return 0
  425. fi
  426. ;;
  427. *)
  428. if [ -f "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}" ]; then
  429. # remove the file, so that he will only receive notifications for CRITICAL states for this alarm
  430. rm "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}"
  431. debug "SEVERITY FILTERING for ${x} VIA ${method}: ALLOW: recipient has been notified for this alarm (will only receive CRITICAL notifications from now on)"
  432. return 0
  433. fi
  434. ;;
  435. esac
  436. debug "SEVERITY FILTERING for ${x} VIA ${method}: BLOCK: recipient should not receive this notification"
  437. return 1
  438. }
  439. # -----------------------------------------------------------------------------
  440. # verify the delivery methods supported
  441. # check slack
  442. [ -z "${SLACK_WEBHOOK_URL}" ] && SEND_SLACK="NO"
  443. # check rocketchat
  444. [ -z "${ROCKETCHAT_WEBHOOK_URL}" ] && SEND_ROCKETCHAT="NO"
  445. # check alerta
  446. [ -z "${ALERTA_WEBHOOK_URL}" ] && SEND_ALERTA="NO"
  447. # check flock
  448. [ -z "${FLOCK_WEBHOOK_URL}" ] && SEND_FLOCK="NO"
  449. # check discord
  450. [ -z "${DISCORD_WEBHOOK_URL}" ] && SEND_DISCORD="NO"
  451. # check pushover
  452. [ -z "${PUSHOVER_APP_TOKEN}" ] && SEND_PUSHOVER="NO"
  453. # check pushbullet
  454. [ -z "${PUSHBULLET_ACCESS_TOKEN}" ] && SEND_PUSHBULLET="NO"
  455. # check twilio
  456. { [ -z "${TWILIO_ACCOUNT_TOKEN}" ] || [ -z "${TWILIO_ACCOUNT_SID}" ] || [ -z "${TWILIO_NUMBER}" ]; } && SEND_TWILIO="NO"
  457. # check hipchat
  458. [ -z "${HIPCHAT_AUTH_TOKEN}" ] && SEND_HIPCHAT="NO"
  459. # check messagebird
  460. { [ -z "${MESSAGEBIRD_ACCESS_KEY}" ] || [ -z "${MESSAGEBIRD_NUMBER}" ]; } && SEND_MESSAGEBIRD="NO"
  461. # check kavenegar
  462. { [ -z "${KAVENEGAR_API_KEY}" ] || [ -z "${KAVENEGAR_SENDER}" ]; } && SEND_KAVENEGAR="NO"
  463. # check telegram
  464. [ -z "${TELEGRAM_BOT_TOKEN}" ] && SEND_TELEGRAM="NO"
  465. # check kafka
  466. { [ -z "${KAFKA_URL}" ] || [ -z "${KAFKA_SENDER_IP}" ]; } && SEND_KAFKA="NO"
  467. # check irc
  468. [ -z "${IRC_NETWORK}" ] && SEND_IRC="NO"
  469. # check hangouts
  470. [ ${#HANGOUTS_WEBHOOK_URI[@]} -eq 0 ] && SEND_HANGOUTS="NO"
  471. # check fleep
  472. #shellcheck disable=SC2153
  473. { [ -z "${FLEEP_SERVER}" ] || [ -z "${FLEEP_SENDER}" ]; } && SEND_FLEEP="NO"
  474. # check dynatrace
  475. { [ -z "${DYNATRACE_SPACE}" ] ||
  476. [ -z "${DYNATRACE_SERVER}" ] ||
  477. [ -z "${DYNATRACE_TOKEN}" ] ||
  478. [ -z "${DYNATRACE_TAG_VALUE}" ] ||
  479. [ -z "${DYNATRACE_EVENT}" ]; } && SEND_DYNATRACE="NO"
  480. # check opsgenie
  481. [ -z "${OPSGENIE_API_KEY}" ] && SEND_OPSGENIE="NO"
  482. # check matrix
  483. { [ -z "${MATRIX_HOMESERVER}" ] || [ -z "${MATRIX_ACCESSTOKEN}" ]; } && SEND_MATRIX="NO"
  484. # check gotify
  485. { [ -z "${GOTIFY_APP_TOKEN}" ] || [ -z "${GOTIFY_APP_URL}" ]; } && SEND_GOTIFY="NO"
  486. # check stackpulse
  487. [ -z "${STACKPULSE_WEBHOOK}" ] && SEND_STACKPULSE="NO"
  488. # check msteams
  489. [ -z "${MSTEAMS_WEBHOOK_URL}" ] && SEND_MSTEAMS="NO"
  490. # check pd
  491. [ -z "${DEFAULT_RECIPIENT_PD}" ] && SEND_PD="NO"
  492. # check prowl
  493. [ -z "${DEFAULT_RECIPIENT_PROWL}" ] && SEND_PROWL="NO"
  494. # check custom
  495. [ -z "${DEFAULT_RECIPIENT_CUSTOM}" ] && SEND_CUSTOM="NO"
  496. if [ "${SEND_PUSHOVER}" = "YES" ] ||
  497. [ "${SEND_SLACK}" = "YES" ] ||
  498. [ "${SEND_ROCKETCHAT}" = "YES" ] ||
  499. [ "${SEND_ALERTA}" = "YES" ] ||
  500. [ "${SEND_PD}" = "YES" ] ||
  501. [ "${SEND_FLOCK}" = "YES" ] ||
  502. [ "${SEND_DISCORD}" = "YES" ] ||
  503. [ "${SEND_HIPCHAT}" = "YES" ] ||
  504. [ "${SEND_TWILIO}" = "YES" ] ||
  505. [ "${SEND_MESSAGEBIRD}" = "YES" ] ||
  506. [ "${SEND_KAVENEGAR}" = "YES" ] ||
  507. [ "${SEND_TELEGRAM}" = "YES" ] ||
  508. [ "${SEND_PUSHBULLET}" = "YES" ] ||
  509. [ "${SEND_KAFKA}" = "YES" ] ||
  510. [ "${SEND_FLEEP}" = "YES" ] ||
  511. [ "${SEND_PROWL}" = "YES" ] ||
  512. [ "${SEND_HANGOUTS}" = "YES" ] ||
  513. [ "${SEND_MATRIX}" = "YES" ] ||
  514. [ "${SEND_CUSTOM}" = "YES" ] ||
  515. [ "${SEND_MSTEAMS}" = "YES" ] ||
  516. [ "${SEND_DYNATRACE}" = "YES" ] ||
  517. [ "${SEND_STACKPULSE}" = "YES" ] ||
  518. [ "${SEND_OPSGENIE}" = "YES" ] ||
  519. [ "${SEND_GOTIFY}" = "YES" ]; then
  520. # if we need curl, check for the curl command
  521. if [ -z "${curl}" ]; then
  522. curl="$(command -v curl 2>/dev/null)"
  523. fi
  524. if [ -z "${curl}" ]; then
  525. error "Cannot find curl command in the system path. Disabling all curl based notifications."
  526. SEND_PUSHOVER="NO"
  527. SEND_PUSHBULLET="NO"
  528. SEND_TELEGRAM="NO"
  529. SEND_SLACK="NO"
  530. SEND_MSTEAMS="NO"
  531. SEND_ROCKETCHAT="NO"
  532. SEND_ALERTA="NO"
  533. SEND_PD="NO"
  534. SEND_FLOCK="NO"
  535. SEND_DISCORD="NO"
  536. SEND_TWILIO="NO"
  537. SEND_HIPCHAT="NO"
  538. SEND_MESSAGEBIRD="NO"
  539. SEND_KAVENEGAR="NO"
  540. SEND_KAFKA="NO"
  541. SEND_FLEEP="NO"
  542. SEND_PROWL="NO"
  543. SEND_HANGOUTS="NO"
  544. SEND_MATRIX="NO"
  545. SEND_CUSTOM="NO"
  546. SEND_DYNATRACE="NO"
  547. SEND_STACKPULSE="NO"
  548. SEND_OPSGENIE="NO"
  549. SEND_GOTIFY="NO"
  550. fi
  551. fi
  552. if [ "${SEND_SMS}" = "YES" ]; then
  553. if [ -z "${sendsms}" ]; then
  554. sendsms="$(command -v sendsms 2>/dev/null)"
  555. fi
  556. if [ -z "${sendsms}" ]; then
  557. SEND_SMS="NO"
  558. fi
  559. fi
  560. # if we need sendmail, check for the sendmail command
  561. if [ "${SEND_EMAIL}" = "YES" ] && [ -z "${sendmail}" ]; then
  562. sendmail="$(command -v sendmail 2>/dev/null)"
  563. if [ -z "${sendmail}" ]; then
  564. debug "Cannot find sendmail command in the system path. Disabling email notifications."
  565. SEND_EMAIL="NO"
  566. fi
  567. fi
  568. # if we need logger, check for the logger command
  569. if [ "${SEND_SYSLOG}" = "YES" ] && [ -z "${logger}" ]; then
  570. logger="$(command -v logger 2>/dev/null)"
  571. if [ -z "${logger}" ]; then
  572. debug "Cannot find logger command in the system path. Disabling syslog notifications."
  573. SEND_SYSLOG="NO"
  574. fi
  575. fi
  576. # if we need aws, check for the aws command
  577. if [ "${SEND_AWSSNS}" = "YES" ] && [ -z "${aws}" ]; then
  578. aws="$(command -v aws 2>/dev/null)"
  579. if [ -z "${aws}" ]; then
  580. debug "Cannot find aws command in the system path. Disabling Amazon SNS notifications."
  581. SEND_AWSSNS="NO"
  582. fi
  583. fi
  584. if [ ${dump_methods} ]; then
  585. for name in "${!SEND_@}"; do
  586. if [ "${!name}" = "YES" ]; then
  587. echo "$name"
  588. fi
  589. done
  590. exit
  591. fi
  592. # -----------------------------------------------------------------------------
  593. # find the recipients' addresses per method
  594. # netdata may call us with multiple roles, and roles may have multiple but
  595. # overlapping recipients - so, here we find the unique recipients.
  596. for method_name in ${method_names}; do
  597. send_var="SEND_${method_name^^}"
  598. if [ "${!send_var}" = "NO" ]; then
  599. continue
  600. fi
  601. declare -A arr_var=()
  602. for x in ${roles//,/ }; do
  603. # the roles 'silent' and 'disabled' mean:
  604. # don't send a notification for this role
  605. if [ "${x}" = "silent" ] || [ "${x}" = "disabled" ]; then
  606. continue
  607. fi
  608. role_recipients="role_recipients_${method_name}[$x]"
  609. default_recipient_var="DEFAULT_RECIPIENT_${method_name^^}"
  610. a="${!role_recipients}"
  611. [ -z "${a}" ] && a="${!default_recipient_var}"
  612. for r in ${a//,/ }; do
  613. [ "${r}" != "disabled" ] && filter_recipient_by_criticality ${method_name} "${r}" && arr_var[${r/|*/}]="1"
  614. done
  615. done
  616. # build the list of recipients
  617. to_var="to_${method_name}"
  618. declare to_${method_name}="${!arr_var[*]}"
  619. [ -z "${!to_var}" ] && declare ${send_var}="NO"
  620. done
  621. # -----------------------------------------------------------------------------
  622. # handle fixup of the email recipient list.
  623. fix_to_email() {
  624. to_email=
  625. while [ -n "${1}" ]; do
  626. [ -n "${to_email}" ] && to_email="${to_email}, "
  627. to_email="${to_email}${1}"
  628. shift 1
  629. done
  630. }
  631. # ${to_email} without quotes here
  632. fix_to_email ${to_email}
  633. # -----------------------------------------------------------------------------
  634. # handle output if we're running in unit test mode
  635. if [ ${unittest} ]; then
  636. for method_name in ${method_names}; do
  637. to_var="to_${method_name}"
  638. echo "results: ${method_name}: ${!to_var}"
  639. done
  640. exit 0
  641. fi
  642. # -----------------------------------------------------------------------------
  643. # check that we have at least a method enabled
  644. proceed=0
  645. for method in "${SEND_EMAIL}" \
  646. "${SEND_PUSHOVER}" \
  647. "${SEND_TELEGRAM}" \
  648. "${SEND_SLACK}" \
  649. "${SEND_ROCKETCHAT}" \
  650. "${SEND_ALERTA}" \
  651. "${SEND_FLOCK}" \
  652. "${SEND_DISCORD}" \
  653. "${SEND_TWILIO}" \
  654. "${SEND_HIPCHAT}" \
  655. "${SEND_MESSAGEBIRD}" \
  656. "${SEND_KAVENEGAR}" \
  657. "${SEND_PUSHBULLET}" \
  658. "${SEND_KAFKA}" \
  659. "${SEND_PD}" \
  660. "${SEND_FLEEP}" \
  661. "${SEND_PROWL}" \
  662. "${SEND_MATRIX}" \
  663. "${SEND_CUSTOM}" \
  664. "${SEND_IRC}" \
  665. "${SEND_HANGOUTS}" \
  666. "${SEND_AWSSNS}" \
  667. "${SEND_SYSLOG}" \
  668. "${SEND_SMS}" \
  669. "${SEND_MSTEAMS}" \
  670. "${SEND_DYNATRACE}" \
  671. "${SEND_STACKPULSE}" \
  672. "${SEND_OPSGENIE}" \
  673. "${SEND_GOTIFY}" ; do
  674. if [ "${method}" == "YES" ]; then
  675. proceed=1
  676. break
  677. fi
  678. done
  679. if [ "$proceed" -eq 0 ]; then
  680. fatal "All notification methods are disabled. Not sending notification for host '${host}', chart '${chart}' to '${roles}' for '${name}' = '${value}' for status '${status}'."
  681. fi
  682. # -----------------------------------------------------------------------------
  683. # get the date the alarm happened
  684. date=$(date --date=@${when} "${date_format}" 2>/dev/null)
  685. [ -z "${date}" ] && date=$(date "${date_format}" 2>/dev/null)
  686. [ -z "${date}" ] && date=$(date --date=@${when} 2>/dev/null)
  687. [ -z "${date}" ] && date=$(date 2>/dev/null)
  688. # -----------------------------------------------------------------------------
  689. # get the date in utc the alarm happened
  690. date_utc=$(date --date=@${when} "${date_format}" -u 2>/dev/null)
  691. [ -z "${date_utc}" ] && date_utc=$(date -u "${date_format}" 2>/dev/null)
  692. [ -z "${date_utc}" ] && date_utc=$(date -u --date=@${when} 2>/dev/null)
  693. [ -z "${date_utc}" ] && date_utc=$(date -u 2>/dev/null)
  694. # ----------------------------------------------------------------------------
  695. # prepare some extra headers if we've been asked to thread e-mails
  696. if [ "${SEND_EMAIL}" == "YES" ] && [ "${EMAIL_THREADING}" != "NO" ]; then
  697. email_thread_headers="In-Reply-To: <${chart}-${name}@${host}>\\r\\nReferences: <${chart}-${name}@${host}>"
  698. else
  699. email_thread_headers=
  700. fi
  701. # -----------------------------------------------------------------------------
  702. # function to URL encode a string
  703. urlencode() {
  704. local string="${1}" strlen encoded pos c o
  705. strlen=${#string}
  706. for ((pos = 0; pos < strlen; pos++)); do
  707. c=${string:pos:1}
  708. case "${c}" in
  709. [-_.~a-zA-Z0-9])
  710. o="${c}"
  711. ;;
  712. *)
  713. printf -v o '%%%02x' "'${c}"
  714. ;;
  715. esac
  716. encoded+="${o}"
  717. done
  718. REPLY="${encoded}"
  719. echo "${REPLY}"
  720. }
  721. # -----------------------------------------------------------------------------
  722. # function to convert a duration in seconds, to a human readable duration
  723. # using DAYS, MINUTES, SECONDS
  724. duration4human() {
  725. local s="${1}" d=0 h=0 m=0 ds="day" hs="hour" ms="minute" ss="second" ret
  726. d=$((s / 86400))
  727. s=$((s - (d * 86400)))
  728. h=$((s / 3600))
  729. s=$((s - (h * 3600)))
  730. m=$((s / 60))
  731. s=$((s - (m * 60)))
  732. if [ ${d} -gt 0 ]; then
  733. [ ${m} -ge 30 ] && h=$((h + 1))
  734. [ ${d} -gt 1 ] && ds="days"
  735. [ ${h} -gt 1 ] && hs="hours"
  736. if [ ${h} -gt 0 ]; then
  737. ret="${d} ${ds} and ${h} ${hs}"
  738. else
  739. ret="${d} ${ds}"
  740. fi
  741. elif [ ${h} -gt 0 ]; then
  742. [ ${s} -ge 30 ] && m=$((m + 1))
  743. [ ${h} -gt 1 ] && hs="hours"
  744. [ ${m} -gt 1 ] && ms="minutes"
  745. if [ ${m} -gt 0 ]; then
  746. ret="${h} ${hs} and ${m} ${ms}"
  747. else
  748. ret="${h} ${hs}"
  749. fi
  750. elif [ ${m} -gt 0 ]; then
  751. [ ${m} -gt 1 ] && ms="minutes"
  752. [ ${s} -gt 1 ] && ss="seconds"
  753. if [ ${s} -gt 0 ]; then
  754. ret="${m} ${ms} and ${s} ${ss}"
  755. else
  756. ret="${m} ${ms}"
  757. fi
  758. else
  759. [ ${s} -gt 1 ] && ss="seconds"
  760. ret="${s} ${ss}"
  761. fi
  762. REPLY="${ret}"
  763. echo "${REPLY}"
  764. }
  765. # -----------------------------------------------------------------------------
  766. # email sender
  767. send_email() {
  768. local ret opts=() sender_email="${EMAIL_SENDER}" sender_name=
  769. if [ "${SEND_EMAIL}" = "YES" ]; then
  770. if [ -n "${EMAIL_SENDER}" ]; then
  771. if [[ ${EMAIL_SENDER} =~ ^\".*\"\ \<.*\>$ ]]; then
  772. # the name includes double quotes
  773. sender_email="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)"
  774. sender_name="$(echo "${EMAIL_SENDER}" | cut -d '"' -f 2)"
  775. elif [[ ${EMAIL_SENDER} =~ ^\'.*\'\ \<.*\>$ ]]; then
  776. # the name includes single quotes
  777. sender_email="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)"
  778. sender_name="$(echo "${EMAIL_SENDER}" | cut -d "'" -f 2)"
  779. elif [[ ${EMAIL_SENDER} =~ ^.*\ \<.*\>$ ]]; then
  780. # the name does not have any quotes
  781. sender_email="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)"
  782. sender_name="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 1)"
  783. fi
  784. fi
  785. [ -n "${sender_email}" ] && opts+=(-f "${sender_email}")
  786. [ -n "${sender_name}" ] && ${sendmail} -F 2>&1 | head -1 | grep -qv "sendmail: unrecognized option: F" && opts+=(-F "${sender_name}")
  787. if [ "${debug}" = "1" ]; then
  788. echo >&2 "--- BEGIN sendmail command ---"
  789. printf >&2 "%q " "${sendmail}" -t "${opts[@]}"
  790. echo >&2
  791. echo >&2 "--- END sendmail command ---"
  792. fi
  793. local cmd_output
  794. cmd_output=$("${sendmail}" -t "${opts[@]}" 2>&1)
  795. ret=$?
  796. if [ ${ret} -eq 0 ]; then
  797. info "sent email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}'"
  798. return 0
  799. else
  800. error "failed to send email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}' with error code ${ret} (${cmd_output})."
  801. return 1
  802. fi
  803. fi
  804. return 1
  805. }
  806. # -----------------------------------------------------------------------------
  807. # pushover sender
  808. send_pushover() {
  809. local apptoken="${1}" usertokens="${2}" when="${3}" url="${4}" status="${5}" title="${6}" message="${7}" httpcode sent=0 user priority
  810. if [ "${SEND_PUSHOVER}" = "YES" ] && [ -n "${apptoken}" ] && [ -n "${usertokens}" ] && [ -n "${title}" ] && [ -n "${message}" ]; then
  811. # https://pushover.net/api
  812. priority=-2
  813. case "${status}" in
  814. CLEAR) priority=-1 ;; # low priority: no sound or vibration
  815. WARNING) priority=0 ;; # normal priority: respect quiet hours
  816. CRITICAL) priority=1 ;; # high priority: bypass quiet hours
  817. *) priority=-2 ;; # lowest priority: no notification at all
  818. esac
  819. for user in ${usertokens}; do
  820. httpcode=$(docurl \
  821. --form-string "token=${apptoken}" \
  822. --form-string "user=${user}" \
  823. --form-string "html=1" \
  824. --form-string "title=${title}" \
  825. --form-string "message=${message}" \
  826. --form-string "timestamp=${when}" \
  827. --form-string "url=${url}" \
  828. --form-string "url_title=Open netdata dashboard to view the alarm" \
  829. --form-string "priority=${priority}" \
  830. https://api.pushover.net/1/messages.json)
  831. if [ "${httpcode}" = "200" ]; then
  832. info "sent pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
  833. sent=$((sent + 1))
  834. else
  835. error "failed to send pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP response status code ${httpcode}."
  836. fi
  837. done
  838. [ ${sent} -gt 0 ] && return 0
  839. fi
  840. return 1
  841. }
  842. # -----------------------------------------------------------------------------
  843. # pushbullet sender
  844. send_pushbullet() {
  845. local userapikey="${1}" source_device="${2}" recipients="${3}" url="${4}" title="${5}" message="${6}" httpcode sent=0 userOrChannelTag
  846. if [ "${SEND_PUSHBULLET}" = "YES" ] && [ -n "${userapikey}" ] && [ -n "${recipients}" ] && [ -n "${message}" ] && [ -n "${title}" ]; then
  847. # https://docs.pushbullet.com/#create-push
  848. # Accept specification of user(s) (PushBullet account email address) and/or channel tag(s), separated by spaces.
  849. # If recipient begins with a "#" then send to channel tag, otherwise send to email recipient.
  850. for userOrChannelTag in ${recipients}; do
  851. if [ "${userOrChannelTag::1}" = "#" ]; then
  852. userOrChannelTag_type="channel_tag"
  853. userOrChannelTag="${userOrChannelTag:1}" # Remove hash from start of channel tag (required by pushbullet API)
  854. else
  855. userOrChannelTag_type="email"
  856. fi
  857. httpcode=$(docurl \
  858. --header 'Access-Token: '${userapikey}'' \
  859. --header 'Content-Type: application/json' \
  860. --data-binary @<(
  861. cat <<EOF
  862. {"title": "${title}",
  863. "type": "link",
  864. "${userOrChannelTag_type}": "${userOrChannelTag}",
  865. "body": "$(echo -n ${message})",
  866. "url": "${url}",
  867. "source_device_iden": "${source_device}"}
  868. EOF
  869. ) "https://api.pushbullet.com/v2/pushes" -X POST)
  870. if [ "${httpcode}" = "200" ]; then
  871. info "sent pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${userOrChannelTag}'"
  872. sent=$((sent + 1))
  873. else
  874. error "failed to send pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${userOrChannelTag}' with HTTP response status code ${httpcode}."
  875. fi
  876. done
  877. [ ${sent} -gt 0 ] && return 0
  878. fi
  879. return 1
  880. }
  881. # -----------------------------------------------------------------------------
  882. # kafka sender
  883. send_kafka() {
  884. local httpcode sent=0
  885. if [ "${SEND_KAFKA}" = "YES" ]; then
  886. httpcode=$(docurl -X POST \
  887. --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}\"}" \
  888. "${KAFKA_URL}")
  889. if [ "${httpcode}" = "204" ]; then
  890. info "sent kafka data for: ${host} ${chart}.${name} is ${status} and ip '${KAFKA_SENDER_IP}'"
  891. sent=$((sent + 1))
  892. else
  893. error "failed to send kafka data for: ${host} ${chart}.${name} is ${status} and ip '${KAFKA_SENDER_IP}' with HTTP response status code ${httpcode}."
  894. fi
  895. [ ${sent} -gt 0 ] && return 0
  896. fi
  897. return 1
  898. }
  899. # -----------------------------------------------------------------------------
  900. # pagerduty.com sender
  901. send_pd() {
  902. local recipients="${1}" sent=0 severity current_time payload url response_code
  903. unset t
  904. case ${status} in
  905. CLEAR) t='resolve' ; severity='info' ;;
  906. WARNING) t='trigger' ; severity='warning' ;;
  907. CRITICAL) t='trigger' ; severity='critical' ;;
  908. esac
  909. if [ ${SEND_PD} = "YES" ] && [ -n "${t}" ]; then
  910. if [ "$(uname)" == "Linux" ]; then
  911. current_time=$(date -d @${when} +'%Y-%m-%dT%H:%M:%S.000')
  912. else
  913. current_time=$(date -r ${when} +'%Y-%m-%dT%H:%M:%S.000')
  914. fi
  915. for PD_SERVICE_KEY in ${recipients}; do
  916. d="${status} ${name} = ${value_string} - ${host}, ${family}"
  917. if [ ${USE_PD_VERSION} = "2" ]; then
  918. payload="$(
  919. cat <<EOF
  920. {
  921. "payload" : {
  922. "summary": "${info:0:1024}",
  923. "source" : "${args_host}",
  924. "severity" : "${severity}",
  925. "timestamp" : "${current_time}",
  926. "group" : "${family}",
  927. "class" : "${chart}",
  928. "custom_details": {
  929. "value_w_units": "${value_string}",
  930. "when": "${when}",
  931. "duration" : "${duration}",
  932. "roles": "${roles}",
  933. "alarm_id" : "${alarm_id}",
  934. "name" : "${name}",
  935. "chart" : "${chart}",
  936. "family" : "${family}",
  937. "status" : "${status}",
  938. "old_status" : "${old_status}",
  939. "value" : "${value}",
  940. "old_value" : "${old_value}",
  941. "src" : "${src}",
  942. "non_clear_duration" : "${non_clear_duration}",
  943. "units" : "${units}",
  944. "info" : "${info}"
  945. }
  946. },
  947. "routing_key": "${PD_SERVICE_KEY}",
  948. "event_action": "${t}",
  949. "dedup_key": "${unique_id}"
  950. }
  951. EOF
  952. )"
  953. url="https://events.pagerduty.com/v2/enqueue"
  954. response_code="202"
  955. else
  956. payload="$(
  957. cat <<EOF
  958. {
  959. "service_key": "${PD_SERVICE_KEY}",
  960. "event_type": "${t}",
  961. "incident_key" : "${alarm_id}",
  962. "description": "${d}",
  963. "details": {
  964. "value_w_units": "${value_string}",
  965. "when": "${when}",
  966. "duration" : "${duration}",
  967. "roles": "${roles}",
  968. "alarm_id" : "${alarm_id}",
  969. "name" : "${name}",
  970. "chart" : "${chart}",
  971. "family" : "${family}",
  972. "status" : "${status}",
  973. "old_status" : "${old_status}",
  974. "value" : "${value}",
  975. "old_value" : "${old_value}",
  976. "src" : "${src}",
  977. "non_clear_duration" : "${non_clear_duration}",
  978. "units" : "${units}",
  979. "info" : "${info}"
  980. }
  981. }
  982. EOF
  983. )"
  984. url="https://events.pagerduty.com/generic/2010-04-15/create_event.json"
  985. response_code="200"
  986. fi
  987. httpcode=$(docurl -X POST --data "${payload}" ${url})
  988. if [ "${httpcode}" = "${response_code}" ]; then
  989. info "sent pagerduty notification for: ${host} ${chart}.${name} is ${status}'"
  990. sent=$((sent + 1))
  991. else
  992. error "failed to send pagerduty notification for: ${host} ${chart}.${name} is ${status}, with HTTP response status code ${httpcode}."
  993. fi
  994. done
  995. [ ${sent} -gt 0 ] && return 0
  996. fi
  997. return 1
  998. }
  999. # -----------------------------------------------------------------------------
  1000. # twilio sender
  1001. send_twilio() {
  1002. local accountsid="${1}" accounttoken="${2}" twilionumber="${3}" recipients="${4}" title="${5}" message="${6}" httpcode sent=0 user
  1003. if [ "${SEND_TWILIO}" = "YES" ] && [ -n "${accountsid}" ] && [ -n "${accounttoken}" ] && [ -n "${twilionumber}" ] && [ -n "${recipients}" ] && [ -n "${message}" ] && [ -n "${title}" ]; then
  1004. #https://www.twilio.com/packages/labs/code/bash/twilio-sms
  1005. for user in ${recipients}; do
  1006. httpcode=$(docurl -X POST \
  1007. --data-urlencode "From=${twilionumber}" \
  1008. --data-urlencode "To=${user}" \
  1009. --data-urlencode "Body=${title} ${message}" \
  1010. -u "${accountsid}:${accounttoken}" \
  1011. "https://api.twilio.com/2010-04-01/Accounts/${accountsid}/Messages.json")
  1012. if [ "${httpcode}" = "201" ]; then
  1013. info "sent Twilio SMS for: ${host} ${chart}.${name} is ${status} to '${user}'"
  1014. sent=$((sent + 1))
  1015. else
  1016. error "failed to send Twilio SMS for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP response status code ${httpcode}."
  1017. fi
  1018. done
  1019. [ ${sent} -gt 0 ] && return 0
  1020. fi
  1021. return 1
  1022. }
  1023. # -----------------------------------------------------------------------------
  1024. # hipchat sender
  1025. send_hipchat() {
  1026. local authtoken="${1}" recipients="${2}" message="${3}" httpcode sent=0 room color msg_format notify
  1027. # remove <small></small> from the message
  1028. message="${message//<small>/}"
  1029. message="${message//<\/small>/}"
  1030. if [ "${SEND_HIPCHAT}" = "YES" ] && [ -n "${HIPCHAT_SERVER}" ] && [ -n "${authtoken}" ] && [ -n "${recipients}" ] && [ -n "${message}" ]; then
  1031. # Valid values: html, text.
  1032. # Defaults to 'html'.
  1033. msg_format="html"
  1034. # Background color for message. Valid values: yellow, green, red, purple, gray, random. Defaults to 'yellow'.
  1035. case "${status}" in
  1036. WARNING) color="yellow" ;;
  1037. CRITICAL) color="red" ;;
  1038. CLEAR) color="green" ;;
  1039. *) color="gray" ;;
  1040. esac
  1041. # Whether this message should trigger a user notification (change the tab color, play a sound, notify mobile phones, etc).
  1042. # Each recipient's notification preferences are taken into account.
  1043. # Defaults to false.
  1044. notify="true"
  1045. for room in ${recipients}; do
  1046. httpcode=$(docurl -X POST \
  1047. -H "Content-type: application/json" \
  1048. -H "Authorization: Bearer ${authtoken}" \
  1049. -d "{\"color\": \"${color}\", \"from\": \"${host}\", \"message_format\": \"${msg_format}\", \"message\": \"${message}\", \"notify\": \"${notify}\"}" \
  1050. "https://${HIPCHAT_SERVER}/v2/room/${room}/notification")
  1051. if [ "${httpcode}" = "204" ]; then
  1052. info "sent HipChat notification for: ${host} ${chart}.${name} is ${status} to '${room}'"
  1053. sent=$((sent + 1))
  1054. else
  1055. error "failed to send HipChat notification for: ${host} ${chart}.${name} is ${status} to '${room}' with HTTP response status code ${httpcode}."
  1056. fi
  1057. done
  1058. [ ${sent} -gt 0 ] && return 0
  1059. fi
  1060. return 1
  1061. }
  1062. # -----------------------------------------------------------------------------
  1063. # messagebird sender
  1064. send_messagebird() {
  1065. local accesskey="${1}" messagebirdnumber="${2}" recipients="${3}" title="${4}" message="${5}" httpcode sent=0 user
  1066. if [ "${SEND_MESSAGEBIRD}" = "YES" ] && [ -n "${accesskey}" ] && [ -n "${messagebirdnumber}" ] && [ -n "${recipients}" ] && [ -n "${message}" ] && [ -n "${title}" ]; then
  1067. #https://developers.messagebird.com/docs/messaging
  1068. for user in ${recipients}; do
  1069. httpcode=$(docurl -X POST \
  1070. --data-urlencode "originator=${messagebirdnumber}" \
  1071. --data-urlencode "recipients=${user}" \
  1072. --data-urlencode "body=${title} ${message}" \
  1073. --data-urlencode "datacoding=auto" \
  1074. -H "Authorization: AccessKey ${accesskey}" \
  1075. "https://rest.messagebird.com/messages")
  1076. if [ "${httpcode}" = "201" ]; then
  1077. info "sent Messagebird SMS for: ${host} ${chart}.${name} is ${status} to '${user}'"
  1078. sent=$((sent + 1))
  1079. else
  1080. error "failed to send Messagebird SMS for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP response status code ${httpcode}."
  1081. fi
  1082. done
  1083. [ ${sent} -gt 0 ] && return 0
  1084. fi
  1085. return 1
  1086. }
  1087. # -----------------------------------------------------------------------------
  1088. # kavenegar sender
  1089. send_kavenegar() {
  1090. local API_KEY="${1}" kavenegarsender="${2}" recipients="${3}" title="${4}" message="${5}" httpcode sent=0 user
  1091. if [ "${SEND_KAVENEGAR}" = "YES" ] && [ -n "${API_KEY}" ] && [ -n "${kavenegarsender}" ] && [ -n "${recipients}" ] && [ -n "${message}" ] && [ -n "${title}" ]; then
  1092. # http://api.kavenegar.com/v1/{API-KEY}/sms/send.json
  1093. for user in ${recipients}; do
  1094. httpcode=$(docurl -X POST http://api.kavenegar.com/v1/${API_KEY}/sms/send.json \
  1095. --data-urlencode "sender=${kavenegarsender}" \
  1096. --data-urlencode "receptor=${user}" \
  1097. --data-urlencode "message=${title} ${message}")
  1098. if [ "${httpcode}" = "200" ]; 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 response status code ${httpcode}."
  1103. fi
  1104. done
  1105. [ ${sent} -gt 0 ] && return 0
  1106. fi
  1107. return 1
  1108. }
  1109. # -----------------------------------------------------------------------------
  1110. # telegram sender
  1111. send_telegram() {
  1112. local bottoken="${1}" chatids="${2}" message="${3}" httpcode sent=0 chatid emoji disableNotification=""
  1113. if [ "${status}" = "CLEAR" ]; then disableNotification="--data-urlencode disable_notification=true"; fi
  1114. case "${status}" in
  1115. WARNING) emoji="⚠️" ;;
  1116. CRITICAL) emoji="🔴" ;;
  1117. CLEAR) emoji="✅" ;;
  1118. *) emoji="⚪️" ;;
  1119. esac
  1120. if [ "${SEND_TELEGRAM}" = "YES" ] && [ -n "${bottoken}" ] && [ -n "${chatids}" ] && [ -n "${message}" ]; then
  1121. for chatid in ${chatids}; do
  1122. # https://core.telegram.org/bots/api#sendmessage
  1123. httpcode=$(docurl ${disableNotification} \
  1124. --data-urlencode "parse_mode=HTML" \
  1125. --data-urlencode "disable_web_page_preview=true" \
  1126. --data-urlencode "text=${emoji} ${message}" \
  1127. "https://api.telegram.org/bot${bottoken}/sendMessage?chat_id=${chatid}")
  1128. if [ "${httpcode}" = "200" ]; then
  1129. info "sent telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}'"
  1130. sent=$((sent + 1))
  1131. elif [ "${httpcode}" = "401" ]; then
  1132. error "failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}': Wrong bot token."
  1133. else
  1134. error "failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}' with HTTP response status code ${httpcode}."
  1135. fi
  1136. done
  1137. [ ${sent} -gt 0 ] && return 0
  1138. fi
  1139. return 1
  1140. }
  1141. # -----------------------------------------------------------------------------
  1142. # Microsoft Team sender
  1143. send_msteams() {
  1144. local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
  1145. [ "${SEND_MSTEAMS}" != "YES" ] && return 1
  1146. case "${status}" in
  1147. WARNING) icon="${MSTEAMS_ICON_WARNING}" && color="${MSTEAMS_COLOR_WARNING}" ;;
  1148. CRITICAL) icon="${MSTEAMS_ICON_CRITICAL}" && color="${MSTEAMS_COLOR_CRITICAL}" ;;
  1149. CLEAR) icon="${MSTEAMS_ICON_CLEAR}" && color="${MSTEAMS_COLOR_CLEAR}" ;;
  1150. *) icon="${MSTEAMS_ICON_DEFAULT}" && color="${MSTEAMS_COLOR_DEFAULT}" ;;
  1151. esac
  1152. for channel in ${channels}; do
  1153. ## More details are available here regarding the payload syntax options : https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference
  1154. ## Online designer : https://adaptivecards.io/designer/
  1155. payload="$(
  1156. cat <<EOF
  1157. {
  1158. "@context": "http://schema.org/extensions",
  1159. "@type": "MessageCard",
  1160. "themeColor": "${color}",
  1161. "title": "$icon Alert ${status} from netdata for ${host}",
  1162. "text": "${host} ${status_message}, ${chart} (_${family}_), *${alarm}*",
  1163. "potentialAction": [
  1164. {
  1165. "@type": "OpenUri",
  1166. "name": "Netdata",
  1167. "targets": [
  1168. { "os": "default", "uri": "${goto_url}" }
  1169. ]
  1170. }
  1171. ]
  1172. }
  1173. EOF
  1174. )"
  1175. # Replacing in the webhook CHANNEL string by the MS Teams channel name from conf file.
  1176. cur_webhook="${webhook//CHANNEL/${channel}}"
  1177. httpcode=$(docurl -H "Content-Type: application/json" -d "${payload}" "${cur_webhook}")
  1178. if [ "${httpcode}" = "200" ]; then
  1179. info "sent Microsoft team notification for: ${host} ${chart}.${name} is ${status} to '${cur_webhook}'"
  1180. sent=$((sent + 1))
  1181. else
  1182. error "failed to send Microsoft team notification for: ${host} ${chart}.${name} is ${status} to '${cur_webhook}', with HTTP response status code ${httpcode}."
  1183. fi
  1184. done
  1185. [ ${sent} -gt 0 ] && return 0
  1186. return 1
  1187. }
  1188. # slack sender
  1189. send_slack() {
  1190. local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
  1191. [ "${SEND_SLACK}" != "YES" ] && return 1
  1192. case "${status}" in
  1193. WARNING) color="warning" ;;
  1194. CRITICAL) color="danger" ;;
  1195. CLEAR) color="good" ;;
  1196. *) color="#777777" ;;
  1197. esac
  1198. for channel in ${channels}; do
  1199. # Default entry in the recipient is without a hash in front (backwards-compatible). Accept specification of channel or user.
  1200. if [ "${channel::1}" != "#" ] && [ "${channel::1}" != "@" ]; then channel="#$channel"; fi
  1201. # If channel is equal to "#" then do not send the channel attribute at all. Slack also defines channels and users in webhooks.
  1202. if [ "${channel}" = "#" ]; then
  1203. ch=""
  1204. chstr="without specifying a channel"
  1205. else
  1206. ch="\"channel\": \"${channel}\","
  1207. chstr="to '${channel}'"
  1208. fi
  1209. payload="$(
  1210. cat <<EOF
  1211. {
  1212. $ch
  1213. "username": "netdata on ${host}",
  1214. "icon_url": "${images_base_url}/images/banner-icon-144x144.png",
  1215. "text": "${host} ${status_message}, \`${chart}\` (_${family}_), *${alarm}*",
  1216. "attachments": [
  1217. {
  1218. "fallback": "${alarm} - ${chart} (${family}) - ${info}",
  1219. "color": "${color}",
  1220. "title": "${alarm}",
  1221. "title_link": "${goto_url}",
  1222. "text": "${info}",
  1223. "fields": [
  1224. {
  1225. "title": "${chart}",
  1226. "short": true
  1227. },
  1228. {
  1229. "title": "${family}",
  1230. "short": true
  1231. }
  1232. ],
  1233. "thumb_url": "${image}",
  1234. "footer": "by ${host}",
  1235. "ts": ${when}
  1236. }
  1237. ]
  1238. }
  1239. EOF
  1240. )"
  1241. httpcode=$(docurl -X POST --data-urlencode "payload=${payload}" "${webhook}")
  1242. if [ "${httpcode}" = "200" ]; then
  1243. info "sent slack notification for: ${host} ${chart}.${name} is ${status} ${chstr}"
  1244. sent=$((sent + 1))
  1245. else
  1246. error "failed to send slack notification for: ${host} ${chart}.${name} is ${status} ${chstr}, with HTTP response status code ${httpcode}."
  1247. fi
  1248. done
  1249. [ ${sent} -gt 0 ] && return 0
  1250. return 1
  1251. }
  1252. # -----------------------------------------------------------------------------
  1253. # rocketchat sender
  1254. send_rocketchat() {
  1255. local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
  1256. [ "${SEND_ROCKETCHAT}" != "YES" ] && return 1
  1257. case "${status}" in
  1258. WARNING) color="warning" ;;
  1259. CRITICAL) color="danger" ;;
  1260. CLEAR) color="good" ;;
  1261. *) color="#777777" ;;
  1262. esac
  1263. for channel in ${channels}; do
  1264. payload="$(
  1265. cat <<EOF
  1266. {
  1267. "channel": "#${channel}",
  1268. "alias": "netdata on ${host}",
  1269. "avatar": "${images_base_url}/images/banner-icon-144x144.png",
  1270. "text": "${host} ${status_message}, \`${chart}\` (_${family}_), *${alarm}*",
  1271. "attachments": [
  1272. {
  1273. "color": "${color}",
  1274. "title": "${alarm}",
  1275. "title_link": "${goto_url}",
  1276. "text": "${info}",
  1277. "fields": [
  1278. {
  1279. "title": "${chart}",
  1280. "short": true,
  1281. "value": "chart"
  1282. },
  1283. {
  1284. "title": "${family}",
  1285. "short": true,
  1286. "value": "family"
  1287. }
  1288. ],
  1289. "thumb_url": "${image}",
  1290. "ts": "${when}"
  1291. }
  1292. ]
  1293. }
  1294. EOF
  1295. )"
  1296. httpcode=$(docurl -X POST --data-urlencode "payload=${payload}" "${webhook}")
  1297. if [ "${httpcode}" = "200" ]; then
  1298. info "sent rocketchat notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
  1299. sent=$((sent + 1))
  1300. else
  1301. error "failed to send rocketchat notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP response status code ${httpcode}."
  1302. fi
  1303. done
  1304. [ ${sent} -gt 0 ] && return 0
  1305. return 1
  1306. }
  1307. # -----------------------------------------------------------------------------
  1308. # alerta sender
  1309. send_alerta() {
  1310. local webhook="${1}" channels="${2}" httpcode sent=0 channel severity resource event payload auth
  1311. [ "${SEND_ALERTA}" != "YES" ] && return 1
  1312. case "${status}" in
  1313. CRITICAL) severity="critical" ;;
  1314. WARNING) severity="warning" ;;
  1315. CLEAR) severity="cleared" ;;
  1316. *) severity="indeterminate" ;;
  1317. esac
  1318. if [[ ${chart} == httpcheck* ]]; then
  1319. resource=$chart
  1320. event=$name
  1321. else
  1322. resource="${host}:${family}"
  1323. event="${chart}.${name}"
  1324. fi
  1325. for channel in ${channels}; do
  1326. payload="$(
  1327. cat <<EOF
  1328. {
  1329. "resource": "${resource}",
  1330. "event": "${event}",
  1331. "environment": "${channel}",
  1332. "severity": "${severity}",
  1333. "service": ["Netdata"],
  1334. "group": "Performance",
  1335. "value": "${value_string}",
  1336. "text": "${info}",
  1337. "tags": ["alarm_id:${alarm_id}"],
  1338. "attributes": {
  1339. "roles": "${roles}",
  1340. "name": "${name}",
  1341. "chart": "${chart}",
  1342. "family": "${family}",
  1343. "source": "${src}",
  1344. "moreInfo": "<a href=\"${goto_url}\">View Netdata</a>"
  1345. },
  1346. "origin": "netdata/${host}",
  1347. "type": "netdataAlarm",
  1348. "rawData": "${BASH_ARGV[@]}"
  1349. }
  1350. EOF
  1351. )"
  1352. if [ -n "${ALERTA_API_KEY}" ]; then
  1353. auth="Key ${ALERTA_API_KEY}"
  1354. fi
  1355. httpcode=$(docurl -X POST "${webhook}/alert" -H "Content-Type: application/json" -H "Authorization: $auth" --data "${payload}")
  1356. if [ "${httpcode}" = "200" ] || [ "${httpcode}" = "201" ]; then
  1357. info "sent alerta notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
  1358. sent=$((sent + 1))
  1359. elif [ "${httpcode}" = "202" ]; then
  1360. info "suppressed alerta notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
  1361. else
  1362. error "failed to send alerta notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP response status code ${httpcode}."
  1363. fi
  1364. done
  1365. [ ${sent} -gt 0 ] && return 0
  1366. return 1
  1367. }
  1368. # -----------------------------------------------------------------------------
  1369. # flock sender
  1370. send_flock() {
  1371. local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
  1372. [ "${SEND_FLOCK}" != "YES" ] && return 1
  1373. case "${status}" in
  1374. WARNING) color="warning" ;;
  1375. CRITICAL) color="danger" ;;
  1376. CLEAR) color="good" ;;
  1377. *) color="#777777" ;;
  1378. esac
  1379. for channel in ${channels}; do
  1380. httpcode=$(docurl -X POST "${webhook}" -H "Content-Type: application/json" -d "{
  1381. \"sendAs\": {
  1382. \"name\" : \"netdata on ${host}\",
  1383. \"profileImage\" : \"${images_base_url}/images/banner-icon-144x144.png\"
  1384. },
  1385. \"text\": \"${host} *${status_message}*\",
  1386. \"timestamp\": \"${when}\",
  1387. \"attachments\": [
  1388. {
  1389. \"description\": \"${chart} (${family}) - ${info}\",
  1390. \"color\": \"${color}\",
  1391. \"title\": \"${alarm}\",
  1392. \"url\": \"${goto_url}\",
  1393. \"text\": \"${info}\",
  1394. \"views\": {
  1395. \"image\": {
  1396. \"original\": { \"src\": \"${image}\", \"width\": 400, \"height\": 400 },
  1397. \"thumbnail\": { \"src\": \"${image}\", \"width\": 50, \"height\": 50 },
  1398. \"filename\": \"${image}\"
  1399. }
  1400. }
  1401. }
  1402. ]
  1403. }")
  1404. if [ "${httpcode}" = "200" ]; then
  1405. info "sent flock notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
  1406. sent=$((sent + 1))
  1407. else
  1408. error "failed to send flock notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP response status code ${httpcode}."
  1409. fi
  1410. done
  1411. [ ${sent} -gt 0 ] && return 0
  1412. return 1
  1413. }
  1414. # -----------------------------------------------------------------------------
  1415. # discord sender
  1416. send_discord() {
  1417. local webhook="${1}/slack" channels="${2}" httpcode sent=0 channel color payload username
  1418. [ "${SEND_DISCORD}" != "YES" ] && return 1
  1419. case "${status}" in
  1420. WARNING) color="warning" ;;
  1421. CRITICAL) color="danger" ;;
  1422. CLEAR) color="good" ;;
  1423. *) color="#777777" ;;
  1424. esac
  1425. for channel in ${channels}; do
  1426. username="netdata on ${host}"
  1427. [ ${#username} -gt 32 ] && username="${username:0:29}..."
  1428. payload="$(
  1429. cat <<EOF
  1430. {
  1431. "channel": "#${channel}",
  1432. "username": "${username}",
  1433. "text": "${host} ${status_message}, \`${chart}\` (_${family}_), *${alarm}*",
  1434. "icon_url": "${images_base_url}/images/banner-icon-144x144.png",
  1435. "attachments": [
  1436. {
  1437. "color": "${color}",
  1438. "title": "${alarm}",
  1439. "title_link": "${goto_url}",
  1440. "text": "${info}",
  1441. "fields": [
  1442. {
  1443. "title": "${chart}",
  1444. "value": "${family}"
  1445. }
  1446. ],
  1447. "thumb_url": "${image}",
  1448. "footer_icon": "${images_base_url}/images/banner-icon-144x144.png",
  1449. "footer": "${host}",
  1450. "ts": ${when}
  1451. }
  1452. ]
  1453. }
  1454. EOF
  1455. )"
  1456. httpcode=$(docurl -X POST --data-urlencode "payload=${payload}" "${webhook}")
  1457. if [ "${httpcode}" = "200" ]; then
  1458. info "sent discord notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
  1459. sent=$((sent + 1))
  1460. else
  1461. error "failed to send discord notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP response status code ${httpcode}."
  1462. fi
  1463. done
  1464. [ ${sent} -gt 0 ] && return 0
  1465. return 1
  1466. }
  1467. # -----------------------------------------------------------------------------
  1468. # fleep sender
  1469. send_fleep() {
  1470. local httpcode sent=0 webhooks="${1}" data message
  1471. if [ "${SEND_FLEEP}" = "YES" ]; then
  1472. message="${host} ${status_message}, \`${chart}\` (${family}), *${alarm}*\\n${info}"
  1473. for hook in ${webhooks}; do
  1474. data="{ "
  1475. data="${data} 'message': '${message}', "
  1476. data="${data} 'user': '${FLEEP_SENDER}' "
  1477. data="${data} }"
  1478. httpcode=$(docurl -X POST --data "${data}" "https://fleep.io/hook/${hook}")
  1479. if [ "${httpcode}" = "200" ]; then
  1480. info "sent fleep data for: ${host} ${chart}.${name} is ${status} and user '${FLEEP_SENDER}'"
  1481. sent=$((sent + 1))
  1482. else
  1483. error "failed to send fleep data for: ${host} ${chart}.${name} is ${status} and user '${FLEEP_SENDER}' with HTTP response status code ${httpcode}."
  1484. fi
  1485. done
  1486. [ ${sent} -gt 0 ] && return 0
  1487. fi
  1488. return 1
  1489. }
  1490. # -----------------------------------------------------------------------------
  1491. # Prowl sender
  1492. send_prowl() {
  1493. local httpcode sent=0 data message keys prio=0 alarm_url event
  1494. if [ "${SEND_PROWL}" = "YES" ]; then
  1495. message="$(urlencode "${host} ${status_message}, \`${chart}\` (${family}), *${alarm}*\\n${info}")"
  1496. message="description=${message}"
  1497. keys="$(urlencode "$(echo "${1}" | tr ' ' ,)")"
  1498. keys="apikey=${keys}"
  1499. app="application=Netdata"
  1500. case "${status}" in
  1501. CRITICAL)
  1502. prio=2
  1503. ;;
  1504. WARNING)
  1505. prio=1
  1506. ;;
  1507. esac
  1508. prio="priority=${prio}"
  1509. alarm_url="$(urlencode ${goto_url})"
  1510. alarm_url="url=${alarm_url}"
  1511. event="$(urlencode "${host} ${status_message}")"
  1512. event="event=${event}"
  1513. data="${keys}&${prio}&${alarm_url}&${app}&${event}&${message}"
  1514. httpcode=$(docurl -X POST --data "${data}" "https://api.prowlapp.com/publicapi/add")
  1515. if [ "${httpcode}" = "200" ]; then
  1516. info "sent prowl data for: ${host} ${chart}.${name} is ${status}"
  1517. sent=1
  1518. else
  1519. error "failed to send prowl data for: ${host} ${chart}.${name} is ${status} with with error code ${httpcode}."
  1520. fi
  1521. [ ${sent} -gt 0 ] && return 0
  1522. fi
  1523. return 1
  1524. }
  1525. # -----------------------------------------------------------------------------
  1526. # irc sender
  1527. send_irc() {
  1528. local NICKNAME="${1}" REALNAME="${2}" CHANNELS="${3}" NETWORK="${4}" PORT="${5}" SERVERNAME="${6}" MESSAGE="${7}" sent=0 channel color send_alarm reply_codes error
  1529. if [ "${SEND_IRC}" = "YES" ] && [ -n "${NICKNAME}" ] && [ -n "${REALNAME}" ] && [ -n "${CHANNELS}" ] && [ -n "${NETWORK}" ] && [ -n "${SERVERNAME}" ] && [ -n "${PORT}" ]; then
  1530. case "${status}" in
  1531. WARNING) color="warning" ;;
  1532. CRITICAL) color="danger" ;;
  1533. CLEAR) color="good" ;;
  1534. *) color="#777777" ;;
  1535. esac
  1536. SNDMESSAGE="${MESSAGE//$'\n'/", "}"
  1537. for CHANNEL in ${CHANNELS}; do
  1538. error=0
  1539. send_alarm=$(echo -e "USER ${NICKNAME} guest ${REALNAME} ${SERVERNAME}\\nNICK ${NICKNAME}\\nJOIN ${CHANNEL}\\nPRIVMSG ${CHANNEL} :${SNDMESSAGE}\\nQUIT\\n" \ | nc "${NETWORK}" "${PORT}")
  1540. reply_codes=$(echo "${send_alarm}" | cut -d ' ' -f 2 | grep -o '[0-9]*')
  1541. for code in ${reply_codes}; do
  1542. if [ "${code}" -ge 400 ] && [ "${code}" -le 599 ]; then
  1543. error=1
  1544. break
  1545. fi
  1546. done
  1547. if [ "${error}" -eq 0 ]; then
  1548. info "sent irc notification for: ${host} ${chart}.${name} is ${status} to '${CHANNEL}'"
  1549. sent=$((sent + 1))
  1550. else
  1551. error "failed to send irc notification for: ${host} ${chart}.${name} is ${status} to '${CHANNEL}', with error code ${code}."
  1552. fi
  1553. done
  1554. fi
  1555. [ ${sent} -gt 0 ] && return 0
  1556. return 1
  1557. }
  1558. # -----------------------------------------------------------------------------
  1559. # Amazon SNS sender
  1560. send_awssns() {
  1561. local targets="${1}" message='' sent=0 region=''
  1562. local default_format="${status} on ${host} at ${date}: ${chart} ${value_string}"
  1563. [ "${SEND_AWSSNS}" = "YES" ] || return 1
  1564. message=${AWSSNS_MESSAGE_FORMAT:-${default_format}}
  1565. for target in ${targets}; do
  1566. # Extract the region from the target ARN. We need to explicitly specify the region so that it matches up correctly.
  1567. region="$(echo ${target} | cut -f 4 -d ':')"
  1568. if ${aws} sns publish --region "${region}" --subject "${host} ${status_message} - ${name//_/ } - ${chart}" --message "${message}" --target-arn ${target} &>/dev/null; then
  1569. info "sent Amazon SNS notification for: ${host} ${chart}.${name} is ${status} to '${target}'"
  1570. sent=$((sent + 1))
  1571. else
  1572. error "failed to send Amazon SNS notification for: ${host} ${chart}.${name} is ${status} to '${target}'"
  1573. fi
  1574. done
  1575. [ ${sent} -gt 0 ] && return 0
  1576. return 1
  1577. }
  1578. # -----------------------------------------------------------------------------
  1579. # Matrix sender
  1580. send_matrix() {
  1581. local homeserver="${1}" webhook accesstoken rooms="${2}" httpcode sent=0 payload
  1582. [ "${SEND_MATRIX}" != "YES" ] && return 1
  1583. [ -z "${MATRIX_ACCESSTOKEN}" ] && return 1
  1584. accesstoken="${MATRIX_ACCESSTOKEN}"
  1585. case "${status}" in
  1586. WARNING) emoji="⚠️" ;;
  1587. CRITICAL) emoji="🔴" ;;
  1588. CLEAR) emoji="✅" ;;
  1589. *) emoji="⚪️" ;;
  1590. esac
  1591. for room in ${rooms}; do
  1592. webhook="$homeserver/_matrix/client/r0/rooms/$(urlencode $room)/send/m.room.message?access_token=$accesstoken"
  1593. payload="$(
  1594. cat <<EOF
  1595. {
  1596. "msgtype": "m.notice",
  1597. "format": "org.matrix.custom.html",
  1598. "formatted_body": "${emoji} ${host} ${status_message} - <b>${name//_/ }</b><br>${chart} (${family})<br><a href=\"${goto_url}\">${alarm}</a><br><i>${info}</i>",
  1599. "body": "${emoji} ${host} ${status_message} - ${name//_/ } ${chart} (${family}) ${goto_url} ${alarm} ${info}"
  1600. }
  1601. EOF
  1602. )"
  1603. httpcode=$(docurl -X POST --data "${payload}" "${webhook}")
  1604. if [ "${httpcode}" == "200" ]; then
  1605. info "sent Matrix notification for: ${host} ${chart}.${name} is ${status} to '${room}'"
  1606. sent=$((sent + 1))
  1607. else
  1608. error "failed to send Matrix notification for: ${host} ${chart}.${name} is ${status} to '${room}', with HTTP response status code ${httpcode}."
  1609. fi
  1610. done
  1611. [ ${sent} -gt 0 ] && return 0
  1612. return 1
  1613. }
  1614. # -----------------------------------------------------------------------------
  1615. # syslog sender
  1616. send_syslog() {
  1617. local facility=${SYSLOG_FACILITY:-"local6"} level='info' targets="${1}"
  1618. local priority='' message='' server='' port='' prefix=''
  1619. local temp1='' temp2=''
  1620. [ "${SEND_SYSLOG}" = "YES" ] || return 1
  1621. if [ "${status}" = "CRITICAL" ]; then
  1622. level='crit'
  1623. elif [ "${status}" = "WARNING" ]; then
  1624. level='warning'
  1625. fi
  1626. for target in ${targets}; do
  1627. priority="${facility}.${level}"
  1628. message=''
  1629. server=''
  1630. port=''
  1631. prefix=''
  1632. temp1=''
  1633. temp2=''
  1634. prefix=$(echo ${target} | cut -d '/' -f 2)
  1635. temp1=$(echo ${target} | cut -d '/' -f 1)
  1636. if [ ${prefix} != ${temp1} ]; then
  1637. if (echo ${temp1} | grep -q '@'); then
  1638. temp2=$(echo ${temp1} | cut -d '@' -f 1)
  1639. server=$(echo ${temp1} | cut -d '@' -f 2)
  1640. if [ ${temp2} != ${server} ]; then
  1641. priority=${temp2}
  1642. fi
  1643. port=$(echo ${server} | rev | cut -d ':' -f 1 | rev)
  1644. if (echo ${server} | grep -E -q '\[.*\]'); then
  1645. if (echo ${port} | grep -q ']'); then
  1646. port=''
  1647. else
  1648. server=$(echo ${server} | rev | cut -d ':' -f 2- | rev)
  1649. fi
  1650. else
  1651. if [ ${port} = ${server} ]; then
  1652. port=''
  1653. else
  1654. server=$(echo ${server} | cut -d ':' -f 1)
  1655. fi
  1656. fi
  1657. else
  1658. priority=${temp1}
  1659. fi
  1660. fi
  1661. message="${prefix} ${status} on ${host} at ${date}: ${chart} ${value_string}"
  1662. if [ ${server} ]; then
  1663. logger_options="${logger_options} -n ${server}"
  1664. if [ ${port} ]; then
  1665. logger_options="${logger_options} -P ${port}"
  1666. fi
  1667. fi
  1668. ${logger} -p ${priority} ${logger_options} "${message}"
  1669. done
  1670. return $?
  1671. }
  1672. # -----------------------------------------------------------------------------
  1673. # SMS sender
  1674. send_sms() {
  1675. local recipients="${1}" errcode errmessage sent=0
  1676. # Human readable SMS
  1677. local msg="${host} ${status_message}: ${chart} (${family}), ${alarm}"
  1678. # limit it to 160 characters
  1679. msg="${msg:0:160}"
  1680. if [ "${SEND_SMS}" = "YES" ] && [ -n "${sendsms}" ] && [ -n "${recipients}" ] && [ -n "${msg}" ]; then
  1681. # http://api.kavenegar.com/v1/{API-KEY}/sms/send.json
  1682. for phone in ${recipients}; do
  1683. errmessage=$($sendsms $phone "$msg" 2>&1)
  1684. errcode=$?
  1685. if [ ${errcode} -eq 0 ]; then
  1686. info "sent smstools3 SMS for: ${host} ${chart}.${name} is ${status} to '${user}'"
  1687. sent=$((sent + 1))
  1688. else
  1689. error "failed to send smstools3 SMS for: ${host} ${chart}.${name} is ${status} to '${user}' with error code ${errcode}: ${errmessage}."
  1690. fi
  1691. done
  1692. [ ${sent} -gt 0 ] && return 0
  1693. fi
  1694. return 1
  1695. }
  1696. # -----------------------------------------------------------------------------
  1697. # hangouts sender
  1698. send_hangouts() {
  1699. local rooms="${1}" httpcode sent=0 room color payload webhook thread
  1700. [ "${SEND_HANGOUTS}" != "YES" ] && return 1
  1701. case "${status}" in
  1702. WARNING) color="#ffa700" ;;
  1703. CRITICAL) color="#d62d20" ;;
  1704. CLEAR) color="#008744" ;;
  1705. *) color="#777777" ;;
  1706. esac
  1707. for room in ${rooms}; do
  1708. if [ -z "${HANGOUTS_WEBHOOK_URI[$room]}" ] ; then
  1709. info "Can't send Hangouts notification for: ${host} ${chart}.${name} to room ${room}. HANGOUTS_WEBHOOK_URI[$room] not defined"
  1710. else
  1711. if [ -n "${HANGOUTS_WEBHOOK_THREAD[$room]}" ]; then
  1712. thread="\"name\" : \"${HANGOUTS_WEBHOOK_THREAD[$room]}\""
  1713. fi
  1714. webhook="${HANGOUTS_WEBHOOK_URI[$room]}"
  1715. payload="$(
  1716. cat <<EOF
  1717. {
  1718. "cards": [
  1719. {
  1720. "header": {
  1721. "title": "Netdata on ${host}",
  1722. "imageUrl": "${images_base_url}/images/banner-icon-144x144.png",
  1723. "imageStyle": "IMAGE"
  1724. },
  1725. "sections": [
  1726. {
  1727. "header": "<b>${host}</b>",
  1728. "widgets": [
  1729. {
  1730. "keyValue": {
  1731. "topLabel": "Status Message",
  1732. "content": "<b>${status_message}</b>",
  1733. "contentMultiline": "true",
  1734. "iconUrl": "${image}",
  1735. "onClick": {
  1736. "openLink": {
  1737. "url": "${goto_url}"
  1738. }
  1739. }
  1740. }
  1741. },
  1742. {
  1743. "keyValue": {
  1744. "topLabel": "${chart} | ${family}",
  1745. "content": "<font color=${color}>${alarm}</font>",
  1746. "contentMultiline": "true"
  1747. }
  1748. }
  1749. ]
  1750. },
  1751. {
  1752. "widgets": [
  1753. {
  1754. "textParagraph": {
  1755. "text": "<font color=\"#0057e7\">@ ${date}\n<b>${info}</b></font>"
  1756. }
  1757. }
  1758. ]
  1759. },
  1760. {
  1761. "widgets": [
  1762. {
  1763. "buttons": [
  1764. {
  1765. "textButton": {
  1766. "text": "Go to ${host}",
  1767. "onClick": {
  1768. "openLink": {
  1769. "url": "${goto_url}"
  1770. }
  1771. }
  1772. }
  1773. }
  1774. ]
  1775. }
  1776. ]
  1777. }
  1778. ]
  1779. }
  1780. ],
  1781. "thread": {
  1782. $thread
  1783. }
  1784. }
  1785. EOF
  1786. )"
  1787. httpcode=$(docurl -H "Content-Type: application/json" -X POST -d "${payload}" "${webhook}")
  1788. if [ "${httpcode}" = "200" ]; then
  1789. info "sent hangouts notification for: ${host} ${chart}.${name} is ${status} to '${room}'"
  1790. sent=$((sent + 1))
  1791. else
  1792. error "failed to send hangouts notification for: ${host} ${chart}.${name} is ${status} to '${room}', with HTTP response status code ${httpcode}."
  1793. fi
  1794. fi
  1795. done
  1796. [ ${sent} -gt 0 ] && return 0
  1797. return 1
  1798. }
  1799. # -----------------------------------------------------------------------------
  1800. # Dynatrace sender
  1801. send_dynatrace() {
  1802. [ "${SEND_DYNATRACE}" != "YES" ] && return 1
  1803. local dynatrace_url="${DYNATRACE_SERVER}/e/${DYNATRACE_SPACE}/api/v1/events"
  1804. local description="Netdata Notification for: ${host} ${chart}.${name} is ${status}"
  1805. local payload=""
  1806. payload=$(cat <<EOF
  1807. {
  1808. "title": "Netdata Alarm from ${host}",
  1809. "source" : "${DYNATRACE_ANNOTATION_TYPE}",
  1810. "description" : "${description}",
  1811. "eventType": "${DYNATRACE_EVENT}",
  1812. "attachRules":{
  1813. "tagRule":[{
  1814. "meTypes":["HOST"],
  1815. "tags":["${DYNATRACE_TAG_VALUE}"]
  1816. }]
  1817. },
  1818. "customProperties":{
  1819. "description": "${description}"
  1820. }
  1821. }
  1822. EOF
  1823. )
  1824. # echo ${payload}
  1825. httpcode=$(docurl -X POST -H "Authorization: Api-token ${DYNATRACE_TOKEN}" -H "Content-Type: application/json" -d "${payload}" ${dynatrace_url})
  1826. ret=$?
  1827. if [ ${ret} -eq 0 ]; then
  1828. if [ "${httpcode}" = "200" ]; then
  1829. info "sent ${DYNATRACE_EVENT} to ${DYNATRACE_SERVER}"
  1830. return 0
  1831. else
  1832. warning "Dynatrace ${DYNATRACE_SERVER} responded ${httpcode} notification for: ${host} ${chart}.${name} is ${status} was not sent!"
  1833. return 1
  1834. fi
  1835. else
  1836. error "failed to sent ${DYNATRACE_EVENT} notification for: ${host} ${chart}.${name} is ${status} to ${DYNATRACE_SERVER} with error code ${ret}."
  1837. return 1
  1838. fi
  1839. }
  1840. # -----------------------------------------------------------------------------
  1841. # Stackpulse sender
  1842. send_stackpulse() {
  1843. local payload httpcode oldv currv
  1844. [ "${SEND_STACKPULSE}" != "YES" ] && return 1
  1845. # We are sending null when values are nan to avoid errors while JSON message is parsed
  1846. [ "${old_value}" != "nan" ] && oldv="${old_value}" || oldv="null"
  1847. [ "${value}" != "nan" ] && currv="${value}" || currv="null"
  1848. payload=$(cat <<EOF
  1849. {
  1850. "Node" : "${host}",
  1851. "Chart" : "${chart}",
  1852. "OldValue" : ${oldv},
  1853. "Value" : ${currv},
  1854. "Units" : "${units}",
  1855. "OldStatus" : "${old_status}",
  1856. "Status" : "${status}",
  1857. "Alarm" : "${name}",
  1858. "Date": ${when},
  1859. "Duration": ${duration},
  1860. "NonClearDuration": ${non_clear_duration},
  1861. "Description" : "${status_message}, ${info}",
  1862. "CalcExpression" : "${calc_expression}",
  1863. "CalcParamValues" : "${calc_param_values}",
  1864. "TotalWarnings" : "${total_warnings}",
  1865. "TotalCritical" : "${total_critical}",
  1866. "ID" : ${alarm_id}
  1867. }
  1868. EOF
  1869. )
  1870. httpcode=$(docurl -X POST -H "Content-Type: application/json" -d "${payload}" ${STACKPULSE_WEBHOOK})
  1871. if [ "${httpcode}" = "200" ]; then
  1872. info "sent stackpulse notification for: ${host} ${chart}.${name} is ${status}"
  1873. else
  1874. error "failed to send stackpulse notification for: ${host} ${chart}.${name} is ${status}, with HTTP response status code ${httpcode}."
  1875. return 1
  1876. fi
  1877. return 0
  1878. }
  1879. # -----------------------------------------------------------------------------
  1880. # Opsgenie sender
  1881. send_opsgenie() {
  1882. local payload httpcode oldv currv
  1883. [ "${SEND_OPSGENIE}" != "YES" ] && return 1
  1884. if [ -z "${OPSGENIE_API_KEY}" ] ; then
  1885. info "Can't send Opsgenie notification, because OPSGENIE_API_KEY is not defined"
  1886. return 1
  1887. fi
  1888. # We are sending null when values are nan to avoid errors while JSON message is parsed
  1889. [ "${old_value}" != "nan" ] && oldv="${old_value}" || oldv="null"
  1890. [ "${value}" != "nan" ] && currv="${value}" || currv="null"
  1891. payload=$(cat <<EOF
  1892. {
  1893. "host" : "${host}",
  1894. "unique_id" : "${unique_id}",
  1895. "alarmId" : ${alarm_id},
  1896. "eventId" : ${event_id},
  1897. "chart" : "${chart}",
  1898. "when": ${when},
  1899. "name" : "${name}",
  1900. "family" : "${family}",
  1901. "status" : "${status}",
  1902. "old_status" : "${old_status}",
  1903. "value" : ${currv},
  1904. "old_value" : ${oldv},
  1905. "duration": ${duration},
  1906. "non_clear_duration": ${non_clear_duration},
  1907. "units" : "${units}",
  1908. "info" : "${status_message}, ${info}",
  1909. "calc_expression" : "${calc_expression}",
  1910. "total_warnings" : "${total_warnings}",
  1911. "total_critical" : "${total_critical}",
  1912. "src" : "${src}"
  1913. }
  1914. EOF
  1915. )
  1916. httpcode=$(docurl -X POST -H "Content-Type: application/json" -d "${payload}" "${OPSGENIE_API_URL}/v1/json/integrations/webhooks/netdata?apiKey=${OPSGENIE_API_KEY}")
  1917. # https://docs.opsgenie.com/docs/alert-api#create-alert
  1918. if [ "${httpcode}" = "200" ]; then
  1919. info "sent opsgenie notification for: ${host} ${chart}.${name} is ${status}"
  1920. else
  1921. error "failed to send opsgenie notification for: ${host} ${chart}.${name} is ${status}, with HTTP error code ${httpcode}."
  1922. return 1
  1923. fi
  1924. return 0
  1925. }
  1926. # -----------------------------------------------------------------------------
  1927. # Gotify sender
  1928. send_gotify() {
  1929. local payload httpcode priority
  1930. [ "${SEND_GOTIFY}" != "YES" ] && return 1
  1931. if [ -z "${GOTIFY_APP_TOKEN}" ] ; then
  1932. info "Can't send Gotify notification, because GOTIFY_APP_TOKEN is not defined"
  1933. return 1
  1934. fi
  1935. # priority for Gotify Android app
  1936. case "${status}" in
  1937. CRITICAL) priority=10 ;; # sound + vibration
  1938. WARNING) priority=4 ;; # sound
  1939. *) priority=1 ;; # notification only
  1940. esac
  1941. payload=$(cat <<EOF
  1942. {
  1943. "title" : "${status}, ${name} = ${value_string}, on ${host}",
  1944. "message" : "${date}: ${chart} ${value_string}",
  1945. "priority" : ${priority}
  1946. }
  1947. EOF
  1948. )
  1949. httpcode=$(docurl -X POST -H "Content-Type: application/json" -d "${payload}" "${GOTIFY_APP_URL}/message?token=${GOTIFY_APP_TOKEN}")
  1950. if [ "${httpcode}" = "200" ]; then
  1951. info "sent gotify notification for: ${host} ${chart}.${name} is ${status}"
  1952. else
  1953. error "failed to send gotify notification for: ${host} ${chart}.${name} is ${status}, with HTTP error code ${httpcode}."
  1954. return 1
  1955. fi
  1956. return 0
  1957. }
  1958. # -----------------------------------------------------------------------------
  1959. # prepare the content of the notification
  1960. # the url to send the user on click
  1961. urlencode "${args_host}" >/dev/null
  1962. url_host="${REPLY}"
  1963. urlencode "${chart}" >/dev/null
  1964. url_chart="${REPLY}"
  1965. urlencode "${family}" >/dev/null
  1966. url_family="${REPLY}"
  1967. urlencode "${name}" >/dev/null
  1968. url_name="${REPLY}"
  1969. urlencode "${value_string}" >/dev/null
  1970. url_value_string="${REPLY}"
  1971. 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}&alarm_when=${when}&alarm_status=${status}&alarm_chart=${chart}&alarm_value=${url_value_string}"
  1972. GOTOCLOUD=0
  1973. if [ "${NETDATA_REGISTRY_URL}" == "https://registry.my-netdata.io" ]; then
  1974. if [ -z "${NETDATA_REGISTRY_UNIQUE_ID}" ]; then
  1975. if [ -f "@registrydir_POST@/netdata.public.unique.id" ]; then
  1976. NETDATA_REGISTRY_UNIQUE_ID="$(cat "@registrydir_POST@/netdata.public.unique.id")"
  1977. fi
  1978. fi
  1979. if [ -n "${NETDATA_REGISTRY_UNIQUE_ID}" ]; then
  1980. GOTOCLOUD=1
  1981. fi
  1982. fi
  1983. if [ ${GOTOCLOUD} -eq 0 ]; then
  1984. goto_url="${NETDATA_REGISTRY_URL}/goto-host-from-alarm.html?${redirect_params}"
  1985. else
  1986. # Temporarily disable alarm redirection, as the cloud endpoint no longer exists. This functionality will be restored after discussion on #9487. For now, just lead to netdata.cloud
  1987. # Re-allow alarm redirection, for alarms 2.0, new template
  1988. if [ -z "${child_machine_guid}" ]; then
  1989. goto_url="${NETDATA_REGISTRY_CLOUD_BASE_URL}/alarms/redirect?agentId=${NETDATA_REGISTRY_UNIQUE_ID}&${redirect_params}"
  1990. else
  1991. goto_url="${NETDATA_REGISTRY_CLOUD_BASE_URL}/alarms/redirect?agentId=${NETDATA_REGISTRY_UNIQUE_ID}&childId=${child_machine_guid}&${redirect_params}"
  1992. fi
  1993. fi
  1994. # the severity of the alarm
  1995. severity="${status}"
  1996. # the time the alarm was raised
  1997. duration4human ${duration} >/dev/null
  1998. duration_txt="${REPLY}"
  1999. duration4human ${non_clear_duration} >/dev/null
  2000. non_clear_duration_txt="${REPLY}"
  2001. raised_for="(was ${old_status,,} for ${duration_txt})"
  2002. # the key status message
  2003. status_message="status unknown"
  2004. # the color of the alarm
  2005. color="grey"
  2006. # the alarm value
  2007. alarm="${name//_/ } = ${value_string}"
  2008. # the image of the alarm
  2009. image="${images_base_url}/images/banner-icon-144x144.png"
  2010. # have a default email status, in case the following case does not catch it
  2011. status_email_subject="${status}"
  2012. # prepare the title based on status
  2013. case "${status}" in
  2014. CRITICAL)
  2015. image="${images_base_url}/images/alert-128-red.png"
  2016. alarm_badge="${NETDATA_REGISTRY_CLOUD_BASE_URL}/static/email/img/label_critical.png"
  2017. status_message="is critical"
  2018. status_email_subject="Critical"
  2019. color="#ca414b"
  2020. rich_status_raised_for="Raised to critical, for ${non_clear_duration_txt}"
  2021. background_color="#FFEBEF"
  2022. border_color="#FF4136"
  2023. text_color="#FF4136"
  2024. action_text_color="#FFFFFF"
  2025. ;;
  2026. WARNING)
  2027. image="${images_base_url}/images/alert-128-orange.png"
  2028. alarm_badge="${NETDATA_REGISTRY_CLOUD_BASE_URL}/static/email/img/label_warning.png"
  2029. status_message="needs attention"
  2030. status_email_subject="Warning"
  2031. color="#ffc107"
  2032. rich_status_raised_for="Raised to warning, for ${non_clear_duration_txt}"
  2033. background_color="#FFF8E1"
  2034. border_color="#FFC300"
  2035. text_color="#536775"
  2036. action_text_color="#35414A"
  2037. ;;
  2038. CLEAR)
  2039. image="${images_base_url}/images/check-mark-2-128-green.png"
  2040. alarm_badge="${NETDATA_REGISTRY_CLOUD_BASE_URL}/static/email/img/label_recovered.png"
  2041. status_message="recovered"
  2042. status_email_subject="Clear"
  2043. color="#77ca6d"
  2044. rich_status_raised_for=
  2045. background_color="#E5F5E8"
  2046. border_color="#68C47D"
  2047. text_color="#00AB44"
  2048. action_text_color="#FFFFFF"
  2049. ;;
  2050. esac
  2051. # the html email subject
  2052. html_email_subject="${status_email_subject}, ${name} = ${value_string}, on ${host}"
  2053. if [ "${status}" = "CLEAR" ]; then
  2054. severity="Recovered from ${old_status}"
  2055. if [ ${non_clear_duration} -gt ${duration} ]; then
  2056. raised_for="(alarm was raised for ${non_clear_duration_txt})"
  2057. fi
  2058. rich_status_raised_for="Recovered from ${old_status,,}, ${raised_for}"
  2059. # don't show the value when the status is CLEAR
  2060. # for certain alarms, this value might not have any meaning
  2061. alarm="${name//_/ } ${raised_for}"
  2062. html_email_subject="${status_email_subject}, ${name} ${raised_for}, on ${host}"
  2063. elif { [ "${old_status}" = "WARNING" ] && [ "${status}" = "CRITICAL" ]; }; then
  2064. severity="Escalated to ${status}"
  2065. if [ ${non_clear_duration} -gt ${duration} ]; then
  2066. raised_for="(alarm is raised for ${non_clear_duration_txt})"
  2067. fi
  2068. rich_status_raised_for="Escalated to critical, ${raised_for}"
  2069. elif { [ "${old_status}" = "CRITICAL" ] && [ "${status}" = "WARNING" ]; }; then
  2070. severity="Demoted to ${status}"
  2071. if [ ${non_clear_duration} -gt ${duration} ]; then
  2072. raised_for="(alarm is raised for ${non_clear_duration_txt})"
  2073. fi
  2074. rich_status_raised_for="Demoted to warning, ${raised_for}"
  2075. else
  2076. raised_for=
  2077. fi
  2078. # prepare HTML versions of elements
  2079. info_html=
  2080. [ -n "${info}" ] && info_html=" <small><br/>${info}</small>"
  2081. raised_for_html=
  2082. [ -n "${raised_for}" ] && raised_for_html="<br/><small>${raised_for}</small>"
  2083. # -----------------------------------------------------------------------------
  2084. # send the slack notification
  2085. # slack aggregates posts from the same username
  2086. # so we use "${host} ${status}" as the bot username, to make them diff
  2087. send_slack "${SLACK_WEBHOOK_URL}" "${to_slack}"
  2088. SENT_SLACK=$?
  2089. # -----------------------------------------------------------------------------
  2090. # send the hangouts notification
  2091. # hangouts aggregates posts from the same room
  2092. # so we use "${host} ${status}" as the room, to make them diff
  2093. send_hangouts "${to_hangouts}"
  2094. SENT_HANGOUTS=$?
  2095. # -----------------------------------------------------------------------------
  2096. # send the Microsoft Teams notification
  2097. # Microsoft teams aggregates posts from the same username
  2098. # so we use "${host} ${status}" as the bot username, to make them diff
  2099. send_msteams "${MSTEAMS_WEBHOOK_URL}" "${to_msteams}"
  2100. SENT_MSTEAMS=$?
  2101. # -----------------------------------------------------------------------------
  2102. # send the rocketchat notification
  2103. # rocketchat aggregates posts from the same username
  2104. # so we use "${host} ${status}" as the bot username, to make them diff
  2105. send_rocketchat "${ROCKETCHAT_WEBHOOK_URL}" "${to_rocketchat}"
  2106. SENT_ROCKETCHAT=$?
  2107. # -----------------------------------------------------------------------------
  2108. # send the alerta notification
  2109. # alerta aggregates posts from the same username
  2110. # so we use "${host} ${status}" as the bot username, to make them diff
  2111. send_alerta "${ALERTA_WEBHOOK_URL}" "${to_alerta}"
  2112. SENT_ALERTA=$?
  2113. # -----------------------------------------------------------------------------
  2114. # send the flock notification
  2115. # flock aggregates posts from the same username
  2116. # so we use "${host} ${status}" as the bot username, to make them diff
  2117. send_flock "${FLOCK_WEBHOOK_URL}" "${to_flock}"
  2118. SENT_FLOCK=$?
  2119. # -----------------------------------------------------------------------------
  2120. # send the discord notification
  2121. # discord aggregates posts from the same username
  2122. # so we use "${host} ${status}" as the bot username, to make them diff
  2123. send_discord "${DISCORD_WEBHOOK_URL}" "${to_discord}"
  2124. SENT_DISCORD=$?
  2125. # -----------------------------------------------------------------------------
  2126. # send the pushover notification
  2127. send_pushover "${PUSHOVER_APP_TOKEN}" "${to_pushover}" "${when}" "${goto_url}" "${status}" "${host} ${status_message} - ${name//_/ } - ${chart}" "
  2128. <font color=\"${color}\"><b>${alarm}</b></font>${info_html}<br/>&nbsp;
  2129. <small><b>${chart}</b><br/>Chart<br/>&nbsp;</small>
  2130. <small><b>${family}</b><br/>Family<br/>&nbsp;</small>
  2131. <small><b>${severity}</b><br/>Severity<br/>&nbsp;</small>
  2132. <small><b>${date}${raised_for_html}</b><br/>Time<br/>&nbsp;</small>
  2133. <a href=\"${goto_url}\">View Netdata</a><br/>&nbsp;
  2134. <small><small>The source of this alarm is line ${src}</small></small>
  2135. "
  2136. SENT_PUSHOVER=$?
  2137. # -----------------------------------------------------------------------------
  2138. # send the pushbullet notification
  2139. send_pushbullet "${PUSHBULLET_ACCESS_TOKEN}" "${PUSHBULLET_SOURCE_DEVICE}" "${to_pushbullet}" "${goto_url}" "${host} ${status_message} - ${name//_/ } - ${chart}" "${alarm}\\n
  2140. Severity: ${severity}\\n
  2141. Chart: ${chart}\\n
  2142. Family: ${family}\\n
  2143. ${date}\\n
  2144. The source of this alarm is line ${src}"
  2145. SENT_PUSHBULLET=$?
  2146. # -----------------------------------------------------------------------------
  2147. # send the twilio SMS
  2148. send_twilio "${TWILIO_ACCOUNT_SID}" "${TWILIO_ACCOUNT_TOKEN}" "${TWILIO_NUMBER}" "${to_twilio}" "${host} ${status_message} - ${name//_/ } - ${chart}" "${alarm}
  2149. Severity: ${severity}
  2150. Chart: ${chart}
  2151. Family: ${family}
  2152. ${info}"
  2153. SENT_TWILIO=$?
  2154. # -----------------------------------------------------------------------------
  2155. # send the messagebird SMS
  2156. send_messagebird "${MESSAGEBIRD_ACCESS_KEY}" "${MESSAGEBIRD_NUMBER}" "${to_messagebird}" "${host} ${status_message} - ${name//_/ } - ${chart}" "${alarm}
  2157. Severity: ${severity}
  2158. Chart: ${chart}
  2159. Family: ${family}
  2160. ${info}"
  2161. SENT_MESSAGEBIRD=$?
  2162. # -----------------------------------------------------------------------------
  2163. # send the kavenegar SMS
  2164. send_kavenegar "${KAVENEGAR_API_KEY}" "${KAVENEGAR_SENDER}" "${to_kavenegar}" "${host} ${status_message} - ${name//_/ } - ${chart}" "${alarm}
  2165. Severity: ${severity}
  2166. Chart: ${chart}
  2167. Family: ${family}
  2168. ${info}"
  2169. SENT_KAVENEGAR=$?
  2170. # -----------------------------------------------------------------------------
  2171. # send the telegram.org message
  2172. # https://core.telegram.org/bots/api#formatting-options
  2173. send_telegram "${TELEGRAM_BOT_TOKEN}" "${to_telegram}" "${host} ${status_message} - <b>${name//_/ }</b>
  2174. ${chart} (${family})
  2175. <a href=\"${goto_url}\">${alarm}</a>
  2176. <i>${info}</i>"
  2177. SENT_TELEGRAM=$?
  2178. # -----------------------------------------------------------------------------
  2179. # send the kafka message
  2180. send_kafka
  2181. SENT_KAFKA=$?
  2182. # -----------------------------------------------------------------------------
  2183. # send the pagerduty.com message
  2184. send_pd "${to_pd}"
  2185. SENT_PD=$?
  2186. # -----------------------------------------------------------------------------
  2187. # send the fleep message
  2188. send_fleep "${to_fleep}"
  2189. SENT_FLEEP=$?
  2190. # -----------------------------------------------------------------------------
  2191. # send the Prowl message
  2192. send_prowl "${to_prowl}"
  2193. SENT_PROWL=$?
  2194. # -----------------------------------------------------------------------------
  2195. # send the irc message
  2196. send_irc "${IRC_NICKNAME}" "${IRC_REALNAME}" "${to_irc}" "${IRC_NETWORK}" "${IRC_PORT}" "${host}" "${host} ${status_message} - ${name//_/ } - ${chart} ----- ${alarm}
  2197. Severity: ${severity}
  2198. Chart: ${chart}
  2199. Family: ${family}
  2200. ${info}"
  2201. SENT_IRC=$?
  2202. # -----------------------------------------------------------------------------
  2203. # send the SMS message with smstools3
  2204. send_sms "${to_sms}"
  2205. SENT_SMS=$?
  2206. # -----------------------------------------------------------------------------
  2207. # send the custom message
  2208. send_custom() {
  2209. # is it enabled?
  2210. [ "${SEND_CUSTOM}" != "YES" ] && return 1
  2211. # do we have any sender?
  2212. [ -z "${1}" ] && return 1
  2213. # call the custom_sender function
  2214. custom_sender "${@}"
  2215. }
  2216. send_custom "${to_custom}"
  2217. SENT_CUSTOM=$?
  2218. # -----------------------------------------------------------------------------
  2219. # send hipchat message
  2220. send_hipchat "${HIPCHAT_AUTH_TOKEN}" "${to_hipchat}" " \
  2221. ${host} ${status_message}<br/> \
  2222. <b>${alarm}</b> ${info_html}<br/> \
  2223. <b>${chart}</b> (family <b>${family}</b>)<br/> \
  2224. <b>${date}${raised_for_html}</b><br/> \
  2225. <a href=\\\"${goto_url}\\\">View netdata dashboard</a> \
  2226. (source of alarm ${src}) \
  2227. "
  2228. SENT_HIPCHAT=$?
  2229. # -----------------------------------------------------------------------------
  2230. # send the Amazon SNS message
  2231. send_awssns "${to_awssns}"
  2232. SENT_AWSSNS=$?
  2233. # -----------------------------------------------------------------------------
  2234. # send the Matrix message
  2235. send_matrix "${MATRIX_HOMESERVER}" "${to_matrix}"
  2236. SENT_MATRIX=$?
  2237. # -----------------------------------------------------------------------------
  2238. # send the syslog message
  2239. send_syslog "${to_syslog}"
  2240. SENT_SYSLOG=$?
  2241. # -----------------------------------------------------------------------------
  2242. # send the email
  2243. IFS='' read -r -d '' email_plaintext_part <<EOF
  2244. Content-Type: text/plain; encoding=${EMAIL_CHARSET}
  2245. Content-Disposition: inline
  2246. Content-Transfer-Encoding: 8bit
  2247. ${host} ${status_message}
  2248. ${alarm} ${info}
  2249. ${raised_for}
  2250. Chart : ${chart}
  2251. Family : ${family}
  2252. Severity: ${severity}
  2253. URL : ${goto_url}
  2254. Source : ${src}
  2255. Date : ${date}
  2256. Notification generated on ${host}
  2257. Evaluated Expression : ${calc_expression}
  2258. Expression Variables : ${calc_param_values}
  2259. The host has ${total_warnings} WARNING and ${total_critical} CRITICAL alarm(s) raised.
  2260. EOF
  2261. if [[ "${EMAIL_PLAINTEXT_ONLY}" == "YES" ]]; then
  2262. send_email <<EOF
  2263. To: ${to_email}
  2264. Subject: ${host} ${status_message} - ${name//_/ } - ${chart}
  2265. MIME-Version: 1.0
  2266. Content-Type: multipart/alternative; boundary="multipart-boundary"
  2267. ${email_thread_headers}
  2268. X-Netdata-Severity: ${status,,}
  2269. X-Netdata-Alert-Name: $name
  2270. X-Netdata-Chart: $chart
  2271. X-Netdata-Family: $family
  2272. X-Netdata-Classification: $classification
  2273. X-Netdata-Host: $host
  2274. X-Netdata-Role: $roles
  2275. This is a MIME-encoded multipart message
  2276. --multipart-boundary
  2277. ${email_plaintext_part}
  2278. --multipart-boundary--
  2279. EOF
  2280. else
  2281. now=$(date "+%s")
  2282. if [ -n "$total_warn_alarms" ]; then
  2283. while read -d, -r pair; do
  2284. IFS='=' read -r key val <<<"$pair"
  2285. date_w=$(date --date=@${val} "${date_format}" 2>/dev/null)
  2286. [ -z "${date_w}" ] && date_w=$(date "${date_format}" 2>/dev/null)
  2287. [ -z "${date_w}" ] && date_w=$(date --date=@${val} 2>/dev/null)
  2288. [ -z "${date_w}" ] && date_w=$(date 2>/dev/null)
  2289. elapsed=$((now - val))
  2290. duration4human ${elapsed} >/dev/null
  2291. elapsed_txt="${REPLY}"
  2292. WARN_ALARMS+="
  2293. <div class=\"set-font\" style=\"font-family: 'IBM Plex Sans', sans-serif; background: #FFFFFF; background-color: #FFFFFF; margin: 0px auto; max-width: 600px;\">
  2294. <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style=\"background:#FFFFFF;background-color:#FFFFFF;width:100%;\">
  2295. <tbody>
  2296. <tr>
  2297. <td style=\"border-top:8px solid #F7F8F8;direction:ltr;font-size:0px;padding:20px 0;text-align:center;\">
  2298. <!--[if mso | IE]><table role=\"presentation\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"\" style=\"vertical-align:top;width:300px;\" ><![endif]-->
  2299. <div class=\"mj-column-per-50 mj-outlook-group-fix\" style=\"font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:50%;\">
  2300. <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style=\"vertical-align:top;\" width=\"100%\">
  2301. <tbody>
  2302. <tr>
  2303. <td align=\"left\" style=\"font-size:0px;padding:10px 25px;word-break:break-word;\">
  2304. <div style=\"font-family:Open Sans, sans-serif;font-size:14px;font-weight:600;line-height:1;text-align:left;color:#35414A;\">${key}</div>
  2305. </td>
  2306. </tr>
  2307. <tr>
  2308. <td align=\"left\" style=\"font-size:0px;padding:10px 25px;padding-top:2px;word-break:break-word;\">
  2309. <div style=\"font-family:Open Sans, sans-serif;font-size:12px;line-height:1;text-align:left;color:#35414A;\">${date_w}</div>
  2310. </td>
  2311. </tr>
  2312. </tbody>
  2313. </table>
  2314. </div>
  2315. <!--[if mso | IE]></td><td class=\"\" style=\"vertical-align:top;width:300px;\" ><![endif]-->
  2316. <div class=\"mj-column-per-50 mj-outlook-group-fix\" style=\"font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:50%;\">
  2317. <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\">
  2318. <tbody>
  2319. <tr>
  2320. <td style=\"vertical-align:top;padding-top:13px;\">
  2321. <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style width=\"100%\">
  2322. <tbody>
  2323. <tr>
  2324. <td align=\"right\" style=\"font-size:0px;padding:10px 25px;word-break:break-word;\">
  2325. <div style=\"font-family:Open Sans, sans-serif;font-size:13px;line-height:1;text-align:right;color:#555555;\"><span style=\"background-color:#FFF8E1; border: 1px solid #FFC300; border-radius:36px; padding: 2px 12px; margin-top: 20px; white-space: nowrap\">
  2326. Warning for ${elapsed_txt}
  2327. </span></div>
  2328. </td>
  2329. </tr>
  2330. </tbody>
  2331. </table>
  2332. </td>
  2333. </tr>
  2334. </tbody>
  2335. </table>
  2336. </div>
  2337. <!--[if mso | IE]></td></tr></table><![endif]-->
  2338. </td>
  2339. </tr>
  2340. </tbody>
  2341. </table>
  2342. </div>
  2343. "
  2344. done <<<"$total_warn_alarms,"
  2345. fi
  2346. if [ -n "$total_crit_alarms" ]; then
  2347. while read -d, -r pair; do
  2348. IFS='=' read -r key val <<<"$pair"
  2349. date_c=$(date --date=@${val} "${date_format}" 2>/dev/null)
  2350. [ -z "${date_c}" ] && date_c=$(date "${date_format}" 2>/dev/null)
  2351. [ -z "${date_c}" ] && date_c=$(date --date=@${val} 2>/dev/null)
  2352. [ -z "${date_c}" ] && date_c=$(date 2>/dev/null)
  2353. elapsed=$((now - val))
  2354. duration4human ${elapsed} >/dev/null
  2355. elapsed_txt="${REPLY}"
  2356. CRIT_ALARMS+="
  2357. <div class=\"set-font\" style=\"font-family: 'IBM Plex Sans', sans-serif; background: #FFFFFF; background-color: #FFFFFF; margin: 0px auto; max-width: 600px;\">
  2358. <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style=\"background:#FFFFFF;background-color:#FFFFFF;width:100%;\">
  2359. <tbody>
  2360. <tr>
  2361. <td style=\"border-top:8px solid #F7F8F8;direction:ltr;font-size:0px;padding:20px 0;text-align:center;\">
  2362. <!--[if mso | IE]><table role=\"presentation\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"\" style=\"vertical-align:top;width:300px;\" ><![endif]-->
  2363. <div class=\"mj-column-per-50 mj-outlook-group-fix\" style=\"font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:50%;\">
  2364. <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style=\"vertical-align:top;\" width=\"100%\">
  2365. <tbody>
  2366. <tr>
  2367. <td align=\"left\" style=\"font-size:0px;padding:10px 25px;word-break:break-word;\">
  2368. <div style=\"font-family:Open Sans, sans-serif;font-size:14px;font-weight:600;line-height:1;text-align:left;color:#35414A;\">${key}</div>
  2369. </td>
  2370. </tr>
  2371. <tr>
  2372. <td align=\"left\" style=\"font-size:0px;padding:10px 25px;padding-top:2px;word-break:break-word;\">
  2373. <div style=\"font-family:Open Sans, sans-serif;font-size:12px;line-height:1;text-align:left;color:#35414A;\">${date_c}</div>
  2374. </td>
  2375. </tr>
  2376. </tbody>
  2377. </table>
  2378. </div>
  2379. <!--[if mso | IE]></td><td class=\"\" style=\"vertical-align:top;width:300px;\" ><![endif]-->
  2380. <div class=\"mj-column-per-50 mj-outlook-group-fix\" style=\"font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:50%;\">
  2381. <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\">
  2382. <tbody>
  2383. <tr>
  2384. <td style=\"vertical-align:top;padding-top:13px;\">
  2385. <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style width=\"100%\">
  2386. <tbody>
  2387. <tr>
  2388. <td align=\"right\" style=\"font-size:0px;padding:10px 25px;word-break:break-word;\">
  2389. <div style=\"font-family:Open Sans, sans-serif;font-size:13px;line-height:1;text-align:right;color:#35414A;\"><span style=\"background-color:#FFEBEF; border: 1px solid #FF4136; border-radius:36px; padding: 2px 12px; margin-top: 20px; white-space: nowrap\">
  2390. Critical for ${elapsed_txt}
  2391. </span></div>
  2392. </td>
  2393. </tr>
  2394. </tbody>
  2395. </table>
  2396. </td>
  2397. </tr>
  2398. </tbody>
  2399. </table>
  2400. </div>
  2401. <!--[if mso | IE]></td></tr></table><![endif]-->
  2402. </td>
  2403. </tr>
  2404. </tbody>
  2405. </table>
  2406. </div>
  2407. "
  2408. done <<<"$total_crit_alarms,"
  2409. fi
  2410. if (( total_warnings + total_critical > 15 )); then
  2411. EXTRA_ALARMS_LIST_TEXT="(Showing latest 15 alerts)"
  2412. fi
  2413. if [ -n "$edit_command_line" ]; then
  2414. IFS='=' read -r edit_command line s_host <<<"$edit_command_line"
  2415. fi
  2416. IFS='' read -r -d '' email_html_part <<EOF
  2417. Content-Type: text/html; encoding=${EMAIL_CHARSET}
  2418. Content-Disposition: inline
  2419. Content-Transfer-Encoding: 8bit
  2420. <!doctype html>
  2421. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
  2422. <head>
  2423. <title>
  2424. </title>
  2425. <!--[if !mso]><!-->
  2426. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  2427. <!--<![endif]-->
  2428. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  2429. <meta name="viewport" content="width=device-width, initial-scale=1">
  2430. <style type="text/css">
  2431. #outlook a { padding:0; }
  2432. body { margin:0;padding:0;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%; }
  2433. table, td { border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt; }
  2434. img { border:0;height:auto;line-height:100%; outline:none;text-decoration:none;-ms-interpolation-mode:bicubic; }
  2435. p { display:block;margin:13px 0; }
  2436. </style>
  2437. <!--[if mso]>
  2438. <xml>
  2439. <o:OfficeDocumentSettings>
  2440. <o:AllowPNG/>
  2441. <o:PixelsPerInch>96</o:PixelsPerInch>
  2442. </o:OfficeDocumentSettings>
  2443. </xml>
  2444. <![endif]-->
  2445. <!--[if lte mso 11]>
  2446. <style type="text/css">
  2447. .mj-outlook-group-fix { width:100% !important; }
  2448. </style>
  2449. <![endif]-->
  2450. <!--[if !mso]><!-->
  2451. <link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;500;600;700&display=swap" rel="stylesheet" type="text/css">
  2452. <link href="https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700" rel="stylesheet" type="text/css">
  2453. <style type="text/css">
  2454. @import url(https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;500;600;700&display=swap);
  2455. @import url(https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700);
  2456. </style>
  2457. <!--<![endif]-->
  2458. <style type="text/css">
  2459. @media only screen and (min-width:100px) {
  2460. .mj-column-px-130 { width:130px !important; max-width: 130px; }
  2461. .mj-column-per-50 { width:50% !important; max-width: 50%; }
  2462. .mj-column-per-70 { width:70% !important; max-width: 70%; }
  2463. .mj-column-per-30 { width:30% !important; max-width: 30%; }
  2464. .mj-column-per-100 { width:100% !important; max-width: 100%; }
  2465. .mj-column-px-66 { width:66px !important; max-width: 66px; }
  2466. .mj-column-px-400 { width:400px !important; max-width: 400px; }
  2467. }
  2468. </style>
  2469. <style type="text/css">
  2470. @media only screen and (max-width:100px) {
  2471. table.mj-full-width-mobile { width: 100% !important; }
  2472. td.mj-full-width-mobile { width: auto !important; }
  2473. }
  2474. </style>
  2475. </head>
  2476. <body style="word-spacing:normal;">
  2477. <div class="svgbg" style="background-image: url('https://staging.netdata.cloud/static/email/img/isotype_600.png'); background-repeat: no-repeat; background-position: top center; background-size: 600px 192px;">
  2478. <!--[if mso | IE]><table align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:600px;" width="600" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]-->
  2479. <div style="margin:0px auto;max-width:600px;">
  2480. <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
  2481. <tbody>
  2482. <tr>
  2483. <td style="direction:ltr;font-size:0px;padding:20px 0;padding-bottom:50px;padding-left:0;text-align:left;">
  2484. <!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:130px;" ><![endif]-->
  2485. <div class="mj-column-px-130 mj-outlook-group-fix" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:130px;">
  2486. <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;" width="100%">
  2487. <tbody>
  2488. <tr>
  2489. <td align="center" style="font-size:0px;padding:10px 25px;padding-right:0;padding-left:0;word-break:break-word;">
  2490. <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:collapse;border-spacing:0px;">
  2491. <tbody>
  2492. <tr>
  2493. <td style="width:130px;">
  2494. <img alt="Netdata Logo" height="auto" src="https://app.netdata.cloud/static/email/img/full_logo.png" style="border:0;display:block;outline:none;text-decoration:none;height:auto;width:100%;font-size:13px;" width="130">
  2495. </td>
  2496. </tr>
  2497. </tbody>
  2498. </table>
  2499. </td>
  2500. </tr>
  2501. </tbody>
  2502. </table>
  2503. </div>
  2504. <!--[if mso | IE]></td><td class="" style="vertical-align:top;width:300px;" ><![endif]-->
  2505. <div class="mj-column-per-50 mj-outlook-group-fix" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:50%;">
  2506. <table border="0" cellpadding="0" cellspacing="0" role="presentation" width="100%">
  2507. <tbody>
  2508. <tr>
  2509. <td style="vertical-align:top;padding-top:4px;">
  2510. <table border="0" cellpadding="0" cellspacing="0" role="presentation" style width="100%">
  2511. <tbody>
  2512. <tr>
  2513. <td align="left" style="font-size:0px;padding:10px 25px;padding-left:10px;word-break:break-word;">
  2514. <div style="font-family:Open Sans, sans-serif;font-size:16px;line-height:1;text-align:left;color:#35414A;">Notification</div>
  2515. </td>
  2516. </tr>
  2517. </tbody>
  2518. </table>
  2519. </td>
  2520. </tr>
  2521. </tbody>
  2522. </table>
  2523. </div>
  2524. <!--[if mso | IE]></td></tr></table><![endif]-->
  2525. </td>
  2526. </tr>
  2527. </tbody>
  2528. </table>
  2529. </div>
  2530. <!--[if mso | IE]></td></tr></table><table align="center" border="0" cellpadding="0" cellspacing="0" class="no-collapse-outlook" style="width:600px;" width="600" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]-->
  2531. <div class="no-collapse" style="border-collapse: initial; margin: 0px auto; border-radius: 4px; max-width: 600px;">
  2532. <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;border-radius:4px;">
  2533. <tbody>
  2534. <tr>
  2535. <td style="border:1px solid ${border_color};direction:ltr;font-size:0px;padding:20px 0;text-align:center;">
  2536. <!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="set-font-outlook" width="600px" ><table align="center" border="0" cellpadding="0" cellspacing="0" class="set-font-outlook" style="width:598px;" width="598" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]-->
  2537. <div class="set-font" style="font-family: 'IBM Plex Sans', sans-serif; margin: 0px auto; max-width: 598px;">
  2538. <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
  2539. <tbody>
  2540. <tr>
  2541. <td style="direction:ltr;font-size:0px;padding:20px 0;padding-bottom:0;padding-top:0;text-align:center;">
  2542. <!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:418.6px;" ><![endif]-->
  2543. <div class="mj-column-per-70 mj-outlook-group-fix" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:70%;">
  2544. <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;" width="100%">
  2545. <tbody>
  2546. <tr>
  2547. <td align="left" style="font-size:0px;padding:10px 25px;padding-top:15px;word-break:break-word;">
  2548. <div style="font-family:Open Sans, sans-serif;font-size:20px;font-weight:700;line-height:1;text-align:left;color:#35414A;">${name}</div>
  2549. </td>
  2550. </tr>
  2551. </tbody>
  2552. </table>
  2553. </div>
  2554. <!--[if mso | IE]></td><td class="" style="vertical-align:top;width:179.4px;" ><![endif]-->
  2555. <div class="mj-column-per-30 mj-outlook-group-fix" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:30%;">
  2556. <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;" width="100%">
  2557. <tbody>
  2558. <tr>
  2559. <td align="right" style="font-size:0px;padding:10px 25px;padding-right:25px;word-break:break-word;">
  2560. <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:collapse;border-spacing:0px;">
  2561. <tbody>
  2562. <tr>
  2563. <td style="width:100px;">
  2564. <img height="auto" src="${alarm_badge}" style="border:0;display:block;outline:none;text-decoration:none;height:auto;width:100%;font-size:13px;" width="100"/>
  2565. </td>
  2566. </tr>
  2567. </tbody>
  2568. </table>
  2569. </td>
  2570. </tr>
  2571. </tbody>
  2572. </table>
  2573. </div>
  2574. <!--[if mso | IE]></td></tr></table><![endif]-->
  2575. </td>
  2576. </tr>
  2577. </tbody>
  2578. </table>
  2579. </div>
  2580. <!--[if mso | IE]></td></tr></table></td></tr><tr><td class="set-font-outlook" width="600px" ><table align="center" border="0" cellpadding="0" cellspacing="0" class="set-font-outlook" style="width:598px;" width="598" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]-->
  2581. <div class="set-font" style="font-family: 'IBM Plex Sans', sans-serif; margin: 0px auto; max-width: 598px;">
  2582. <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
  2583. <tbody>
  2584. <tr>
  2585. <td style="direction:ltr;font-size:0px;padding:0;text-align:center;">
  2586. <!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:598px;" ><![endif]-->
  2587. <div class="mj-column-per-100 mj-outlook-group-fix" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
  2588. <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;" width="100%">
  2589. <tbody>
  2590. <tr>
  2591. <td align="left" style="font-size:0px;padding:10px 25px;padding-top:0;word-break:break-word;">
  2592. <div style="font-family:IBM Plex Sans, sans-serif;font-size:16px;line-height:1;text-align:left;color:#35414A;">on ${host}</div>
  2593. </td>
  2594. </tr>
  2595. </tbody>
  2596. </table>
  2597. </div>
  2598. <!--[if mso | IE]></td></tr></table><![endif]-->
  2599. </td>
  2600. </tr>
  2601. </tbody>
  2602. </table>
  2603. </div>
  2604. <!--[if mso | IE]></td></tr></table></td></tr><tr><td class="set-font-outlook" width="600px" ><table align="center" border="0" cellpadding="0" cellspacing="0" class="set-font-outlook" style="width:598px;" width="598" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]-->
  2605. <div class="set-font" style="font-family: 'IBM Plex Sans', sans-serif; margin: 0px auto; max-width: 598px;">
  2606. <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
  2607. <tbody>
  2608. <tr>
  2609. <td style="direction:ltr;font-size:0px;padding:20px 0;text-align:center;">
  2610. <!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:598px;" ><![endif]-->
  2611. <div class="mj-column-per-100 mj-outlook-group-fix" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
  2612. <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;" width="100%">
  2613. <tbody>
  2614. <tr>
  2615. <td align="left" style="font-size:0px;padding:10px 25px;padding-top:0;word-break:break-word;">
  2616. <div style="font-family:Open Sans, sans-serif;font-size:26px;font-weight:700;line-height:1;text-align:left;color:#35414A;"><span style="color: ${text_color}; font-size:26px; background: ${background_color}; padding:4px 24px; border-radius: 36px">${value_string}
  2617. </span></div>
  2618. </td>
  2619. </tr>
  2620. </tbody>
  2621. </table>
  2622. </div>
  2623. <!--[if mso | IE]></td></tr></table><![endif]-->
  2624. </td>
  2625. </tr>
  2626. </tbody>
  2627. </table>
  2628. </div>
  2629. <!--[if mso | IE]></td></tr></table></td></tr><tr><td class="set-font-outlook" width="600px" ><table align="center" border="0" cellpadding="0" cellspacing="0" class="set-font-outlook" style="width:598px;" width="598" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]-->
  2630. <div class="set-font" style="font-family: 'IBM Plex Sans', sans-serif; margin: 0px auto; max-width: 598px;">
  2631. <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
  2632. <tbody>
  2633. <tr>
  2634. <td style="direction:ltr;font-size:0px;padding:20px 0;padding-bottom:0;padding-top:0;text-align:center;">
  2635. <!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:598px;" ><![endif]-->
  2636. <div class="mj-column-per-100 mj-outlook-group-fix" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
  2637. <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;" width="100%">
  2638. <tbody>
  2639. <tr>
  2640. <td align="left" style="font-size:0px;padding:10px 25px;padding-top:0;word-break:break-word;">
  2641. <div style="font-family:Open Sans, sans-serif;font-size:16px;line-height:21px;text-align:left;color:#35414A;">Details: ${info}</div>
  2642. </td>
  2643. </tr>
  2644. </tbody>
  2645. </table>
  2646. </div>
  2647. <!--[if mso | IE]></td></tr></table><![endif]-->
  2648. </td>
  2649. </tr>
  2650. </tbody>
  2651. </table>
  2652. </div>
  2653. <!--[if mso | IE]></td></tr></table></td></tr><tr><td class="set-font-outlook" width="600px" ><table align="center" border="0" cellpadding="0" cellspacing="0" class="set-font-outlook" style="width:598px;" width="598" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]-->
  2654. <div class="set-font" style="font-family: 'IBM Plex Sans', sans-serif; margin: 0px auto; max-width: 598px;">
  2655. <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
  2656. <tbody>
  2657. <tr>
  2658. <td style="direction:ltr;font-size:0px;padding:20px 0;padding-bottom:0;padding-top:0;text-align:center;">
  2659. <!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:598px;" ><![endif]-->
  2660. <div class="mj-column-per-100 mj-outlook-group-fix" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
  2661. <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;" width="100%">
  2662. <tbody>
  2663. <tr>
  2664. <td align="center" vertical-align="middle" style="font-size:0px;padding:10px 25px;word-break:break-word;">
  2665. <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:separate;width:100%;line-height:100%;">
  2666. <tr>
  2667. <td
  2668. align="center" bgcolor="${border_color}" role="presentation" style="border:none;border-radius:3px;cursor:auto;height:44px;background:${border_color};" valign="middle">
  2669. <p style="display:block;background:${border_color};color:#ffffff;font-size:13px;font-weight:600;line-height:44px;margin:0;text-decoration:none;text-transform:none;mso-padding-alt:0px;border-radius:3px;">
  2670. <a href="${goto_url}" style="color: ${action_text_color}; text-decoration: none; width: 100%; display: inline-block">GO TO CHART</a>
  2671. </p>
  2672. </td>
  2673. </tr>
  2674. </table>
  2675. </td>
  2676. </tr>
  2677. </tbody>
  2678. </table>
  2679. </div>
  2680. <!--[if mso | IE]></td></tr></table><![endif]-->
  2681. </td>
  2682. </tr>
  2683. </tbody>
  2684. </table>
  2685. </div>
  2686. <!--[if mso | IE]></td></tr></table></td></tr></table><![endif]-->
  2687. </td>
  2688. </tr>
  2689. </tbody>
  2690. </table>
  2691. </div>
  2692. <!--[if mso | IE]></td></tr></table><![endif]-->
  2693. <div style="height:32px;line-height:32px;">&#8202;</div>
  2694. <!--[if mso | IE]><table align="center" border="0" cellpadding="0" cellspacing="0" class="set-font-outlook" style="width:600px;" width="600" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]-->
  2695. <div class="set-font" style="font-family: 'IBM Plex Sans', sans-serif; background: ${background_color}; background-color: ${background_color}; margin: 0px auto; border-radius: 4px; max-width: 600px;">
  2696. <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="background:${background_color};background-color:${background_color};width:100%;border-radius:4px;">
  2697. <tbody>
  2698. <tr>
  2699. <td style="direction:ltr;font-size:0px;padding:20px 0;text-align:center;">
  2700. <!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:600px;" ><![endif]-->
  2701. <div class="mj-column-per-100 mj-outlook-group-fix" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
  2702. <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;" width="100%">
  2703. <tbody>
  2704. <tr>
  2705. <td align="left" style="font-size:0px;padding:10px 25px;padding-bottom:6px;word-break:break-word;">
  2706. <div style="font-family:Open Sans, sans-serif;font-size:18px;line-height:1;text-align:left;color:#35414A;">Chart:
  2707. <span style="font-weight:700; font-size:20px">${chart}</span></div>
  2708. </td>
  2709. </tr>
  2710. <tr>
  2711. <td align="left" style="font-size:0px;padding:10px 25px;padding-top:0;word-break:break-word;">
  2712. <div style="font-family:Open Sans, sans-serif;font-size:18px;line-height:1;text-align:left;color:#35414A;">Family:
  2713. <span style="font-weight:700; font-size:20px">${family}</span></div>
  2714. </td>
  2715. </tr>
  2716. <tr>
  2717. <td align="left" style="font-size:0px;padding:10px 25px;padding-top:4px;word-break:break-word;">
  2718. <div style="font-family:Open Sans, sans-serif;font-size:14px;line-height:1;text-align:left;color:#35414A;">${rich_status_raised_for}</div>
  2719. </td>
  2720. </tr>
  2721. <tr>
  2722. <td align="center" style="font-size:0px;padding:10px 25px;word-break:break-word;">
  2723. <p style="border-top:solid 1px lightgrey;font-size:1px;margin:0px auto;width:100%;">
  2724. </p>
  2725. <!--[if mso | IE]><table align="center" border="0" cellpadding="0" cellspacing="0" style="border-top:solid 1px lightgrey;font-size:1px;margin:0px auto;width:550px;" role="presentation" width="550px" ><tr><td style="height:0;line-height:0;"> &nbsp;
  2726. </td></tr></table><![endif]-->
  2727. </td>
  2728. </tr>
  2729. <tr>
  2730. <td align="left" style="font-size:0px;padding:10px 25px;padding-bottom:6px;word-break:break-word;">
  2731. <div style="font-family:Open Sans, sans-serif;font-size:16px;line-height:1;text-align:left;color:#35414A;">On
  2732. <span style="font-weight:600">${date}</span></div>
  2733. </td>
  2734. </tr>
  2735. <tr>
  2736. <td align="left" style="font-size:0px;padding:10px 25px;padding-top:0;word-break:break-word;">
  2737. <div style="font-family:Open Sans, sans-serif;font-size:16px;line-height:1;text-align:left;color:#35414A;">By:
  2738. <span style="font-weight:600">${host}</span></div>
  2739. </td>
  2740. </tr>
  2741. <tr>
  2742. <td align="left" style="font-size:0px;padding:10px 25px;padding-top:4px;word-break:break-word;">
  2743. <div style="font-family:Open Sans, sans-serif;font-size:14px;line-height:1;text-align:left;color:#35414A;">Global time:
  2744. <span style="font-weight:600">${date_utc}</span></div>
  2745. </td>
  2746. </tr>
  2747. <tr>
  2748. <td align="center" style="font-size:0px;padding:10px 25px;word-break:break-word;">
  2749. <p style="border-top:solid 1px lightgrey;font-size:1px;margin:0px auto;width:100%;">
  2750. </p>
  2751. <!--[if mso | IE]><table align="center" border="0" cellpadding="0" cellspacing="0" style="border-top:solid 1px lightgrey;font-size:1px;margin:0px auto;width:550px;" role="presentation" width="550px" ><tr><td style="height:0;line-height:0;"> &nbsp;
  2752. </td></tr></table><![endif]-->
  2753. </td>
  2754. </tr>
  2755. <tr>
  2756. <td align="left" style="font-size:0px;padding:10px 25px;padding-bottom:6px;word-break:break-word;">
  2757. <div style="font-family:Open Sans, sans-serif;font-size:16px;line-height:1;text-align:left;color:#35414A;">Classification:
  2758. <span style="font-weight:600">${classification}</span></div>
  2759. </td>
  2760. </tr>
  2761. <tr>
  2762. <td align="left" style="font-size:0px;padding:10px 25px;padding-top:0;word-break:break-word;">
  2763. <div style="font-family:Open Sans, sans-serif;font-size:16px;line-height:1;text-align:left;color:#35414A;">Role:
  2764. <span style="font-weight:600">${roles}</span></div>
  2765. </td>
  2766. </tr>
  2767. </tbody>
  2768. </table>
  2769. </div>
  2770. <!--[if mso | IE]></td></tr></table><![endif]-->
  2771. </td>
  2772. </tr>
  2773. </tbody>
  2774. </table>
  2775. </div>
  2776. <!--[if mso | IE]></td></tr></table><table align="center" border="0" cellpadding="0" cellspacing="0" class="set-font-outlook" style="width:600px;" width="600" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]-->
  2777. <div class="set-font" style="font-family: 'IBM Plex Sans', sans-serif; margin: 0px auto; max-width: 600px;">
  2778. <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
  2779. <tbody>
  2780. <tr>
  2781. <td style="direction:ltr;font-size:0px;padding:20px 0;padding-left:25px;text-align:left;">
  2782. <!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:66px;" ><![endif]-->
  2783. <div class="mj-column-px-66 mj-outlook-group-fix" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:66px;">
  2784. <table border="0" cellpadding="0" cellspacing="0" role="presentation" width="100%">
  2785. <tbody>
  2786. <tr>
  2787. <td style="vertical-align:top;padding:0;">
  2788. <table border="0" cellpadding="0" cellspacing="0" role="presentation" style width="100%">
  2789. <tbody>
  2790. <tr>
  2791. <td align="left" style="font-size:0px;padding:10px 25px;padding-right:0;padding-left:0;word-break:break-word;">
  2792. <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:collapse;border-spacing:0px;">
  2793. <tbody>
  2794. <tr>
  2795. <td style="width:48px;">
  2796. <img height="auto" src="https://app.netdata.cloud/static/email/img/community_icon.png" style="border:0;display:block;outline:none;text-decoration:none;height:auto;width:100%;font-size:13px;" width="48">
  2797. </td>
  2798. </tr>
  2799. </tbody>
  2800. </table>
  2801. </td>
  2802. </tr>
  2803. </tbody>
  2804. </table>
  2805. </td>
  2806. </tr>
  2807. </tbody>
  2808. </table>
  2809. </div>
  2810. <!--[if mso | IE]></td><td align="left" class="" style="vertical-align:top;width:400px;" ><![endif]-->
  2811. <div class="mj-column-px-400 mj-outlook-group-fix" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:400px;">
  2812. <table border="0" cellpadding="0" cellspacing="0" role="presentation" width="100%">
  2813. <tbody>
  2814. <tr>
  2815. <td style="vertical-align:top;padding-left:0;">
  2816. <table border="0" cellpadding="0" cellspacing="0" role="presentation" style width="100%">
  2817. <tbody>
  2818. <tr>
  2819. <td align="left" style="font-size:0px;padding:10px 25px;padding-left:0;word-break:break-word;">
  2820. <div style="font-family:Open Sans, sans-serif;font-size:16px;font-weight:700;line-height:1;text-align:left;color:#35414A;">Want to know more about this alert?</div>
  2821. </td>
  2822. </tr>
  2823. <tr>
  2824. <td align="left" style="font-size:0px;padding:10px 25px;padding-left:0;word-break:break-word;">
  2825. <div style="font-family:Open Sans, sans-serif;font-size:14px;line-height:1.3;text-align:left;color:#35414A;">Join the troubleshooting discussion for this alert on our <a href="https://community.netdata.cloud/t/${name//[._]/-}" class="link" style="color: #00AB44; text-decoration: none;">community forums</a>.</div>
  2826. </td>
  2827. </tr>
  2828. </tbody>
  2829. </table>
  2830. </td>
  2831. </tr>
  2832. </tbody>
  2833. </table>
  2834. </div>
  2835. <!--[if mso | IE]></td></tr></table><![endif]-->
  2836. </td>
  2837. </tr>
  2838. </tbody>
  2839. </table>
  2840. </div>
  2841. <!--[if mso | IE]></td></tr></table><table align="center" border="0" cellpadding="0" cellspacing="0" class="set-font-outlook" style="width:600px;" width="600" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]-->
  2842. <div class="set-font" style="font-family: 'IBM Plex Sans', sans-serif; margin: 0px auto; max-width: 600px;">
  2843. <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
  2844. <tbody>
  2845. <tr>
  2846. <td style="direction:ltr;font-size:0px;padding:20px 0;padding-left:25px;text-align:left;">
  2847. <!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:66px;" ><![endif]-->
  2848. <div class="mj-column-px-66 mj-outlook-group-fix" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:66px;">
  2849. <table border="0" cellpadding="0" cellspacing="0" role="presentation" width="100%">
  2850. <tbody>
  2851. <tr>
  2852. <td style="vertical-align:top;padding:0;">
  2853. <table border="0" cellpadding="0" cellspacing="0" role="presentation" style width="100%">
  2854. <tbody>
  2855. <tr>
  2856. <td align="left" style="font-size:0px;padding:10px 25px;padding-right:0;padding-left:0;word-break:break-word;">
  2857. <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:collapse;border-spacing:0px;">
  2858. <tbody>
  2859. <tr>
  2860. <td style="width:48px;">
  2861. <img height="auto" src="https://app.netdata.cloud/static/email/img/configure_icon.png" style="border:0;display:block;outline:none;text-decoration:none;height:auto;width:100%;font-size:13px;" width="48">
  2862. </td>
  2863. </tr>
  2864. </tbody>
  2865. </table>
  2866. </td>
  2867. </tr>
  2868. </tbody>
  2869. </table>
  2870. </td>
  2871. </tr>
  2872. </tbody>
  2873. </table>
  2874. </div>
  2875. <!--[if mso | IE]></td><td align="left" class="" style="vertical-align:top;width:400px;" ><![endif]-->
  2876. <div class="mj-column-px-400 mj-outlook-group-fix" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:400px;">
  2877. <table border="0" cellpadding="0" cellspacing="0" role="presentation" width="100%">
  2878. <tbody>
  2879. <tr>
  2880. <td style="vertical-align:top;padding-left:0;">
  2881. <table border="0" cellpadding="0" cellspacing="0" role="presentation" style width="100%">
  2882. <tbody>
  2883. <tr>
  2884. <td align="left" style="font-size:0px;padding:10px 25px;padding-left:0;word-break:break-word;">
  2885. <div style="font-family:Open Sans, sans-serif;font-size:16px;font-weight:700;line-height:1;text-align:left;color:#35414A;">Need to configure this alert?</div>
  2886. </td>
  2887. </tr>
  2888. <tr>
  2889. <td align="left" style="font-size:0px;padding:10px 25px;padding-left:0;word-break:break-word;">
  2890. <div style="font-family:Open Sans, sans-serif;font-size:14px;line-height:1.3;text-align:left;color:#35414A;"><span style="color: #00AB44"><a href="https://learn.netdata.cloud/docs/agent/health/notifications#:~:text=To%20edit%20it%20on%20your,have%20one%20or%20more%20destinations" class="link" style="color: #00AB44; text-decoration: none;">Edit</a></span> this alert's configuration file by logging into $s_host and running the following command:</div>
  2891. </td>
  2892. </tr>
  2893. <tr>
  2894. <td align="left" style="font-size:0px;padding:10px 25px;padding-top:8px;padding-left:0;word-break:break-word;">
  2895. <div style="font-family:Open Sans, sans-serif;font-size:12px;line-height:1.3;text-align:left;color:#35414A;">${edit_command} <br>
  2896. <br>The alarm to edit is at line ${line}</div>
  2897. </td>
  2898. </tr>
  2899. </tbody>
  2900. </table>
  2901. </td>
  2902. </tr>
  2903. </tbody>
  2904. </table>
  2905. </div>
  2906. <!--[if mso | IE]></td></tr></table><![endif]-->
  2907. </td>
  2908. </tr>
  2909. </tbody>
  2910. </table>
  2911. </div>
  2912. <!--[if mso | IE]></td></tr></table><table align="center" border="0" cellpadding="0" cellspacing="0" class="history-wrapper-outlook" style="width:600px;" width="600" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]-->
  2913. <div class="history-wrapper" style="background: #F7F8F8; background-color: #F7F8F8; margin: 0px auto; max-width: 100%;">
  2914. <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="background:#F7F8F8;background-color:#F7F8F8;width:100%;">
  2915. <tbody>
  2916. <tr>
  2917. <td style="direction:ltr;font-size:0px;padding:0;padding-bottom:24px;text-align:center;">
  2918. <!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="set-font-outlook" width="600px" ><table align="center" border="0" cellpadding="0" cellspacing="0" class="set-font-outlook" style="width:600px;" width="600" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]-->
  2919. <div class="set-font" style="font-family: 'IBM Plex Sans', sans-serif; margin: 0px auto; max-width: 600px;">
  2920. <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
  2921. <tbody>
  2922. <tr>
  2923. <td style="direction:ltr;font-size:0px;padding:20px 0;padding-bottom:12px;text-align:center;">
  2924. <!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:600px;" ><![endif]-->
  2925. <div class="mj-column-per-100 mj-outlook-group-fix" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
  2926. <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;" width="100%">
  2927. <tbody>
  2928. <tr>
  2929. <td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
  2930. <div style="font-family:Open Sans, sans-serif;font-size:16px;line-height:1;text-align:center;color:#35414A;">The node has
  2931. <span style="font-weight:600">${total_warnings} warning</span>
  2932. and
  2933. <span style="font-weight:600">${total_critical} critical</span>
  2934. additional active alert(s)</div>
  2935. </td>
  2936. </tr>
  2937. <td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
  2938. <div style="font-family:Open Sans, sans-serif;font-size:12px;line-height:1;text-align:center;color:#35414A;">${EXTRA_ALARMS_LIST_TEXT}</div>
  2939. </td>
  2940. </tr>
  2941. </tbody>
  2942. </table>
  2943. </div>
  2944. <!--[if mso | IE]></td></tr></table><![endif]-->
  2945. </td>
  2946. </tr>
  2947. </tbody>
  2948. </table>
  2949. </div>
  2950. ${CRIT_ALARMS}
  2951. ${WARN_ALARMS}
  2952. <!--[if mso | IE]></td></tr></table></td></tr></table><![endif]-->
  2953. </td>
  2954. </tr>
  2955. </tbody>
  2956. </table>
  2957. </div>
  2958. <!--[if mso | IE]></td></tr></table><table align="center" border="0" cellpadding="0" cellspacing="0" class="set-font-outlook" style="width:600px;" width="600" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]-->
  2959. <div class="set-font" style="font-family: 'IBM Plex Sans', sans-serif; margin: 0px auto; max-width: 600px;">
  2960. <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
  2961. <tbody>
  2962. <tr>
  2963. <td style="direction:ltr;font-size:0px;padding:20px 0;text-align:center;">
  2964. <!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:600px;" ><![endif]-->
  2965. <div class="mj-column-per-100 mj-outlook-group-fix" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
  2966. <table border="0" cellpadding="0" cellspacing="0" role="presentation" width="100%">
  2967. <tbody>
  2968. <tr>
  2969. <td style="vertical-align:top;padding-top:44px;padding-bottom:12px;">
  2970. <table border="0" cellpadding="0" cellspacing="0" role="presentation" style width="100%">
  2971. <tbody>
  2972. <tr>
  2973. <td align="left" style="font-size:0px;padding:10px 25px;padding-top:0;padding-bottom:0;word-break:break-word;">
  2974. <div style="font-family:Open Sans, sans-serif;font-size:13px;line-height:1;text-align:center;color:#35414A;">© Netdata 2021 - The real-time performance and health monitoring</div>
  2975. </td>
  2976. </tr>
  2977. </tbody>
  2978. </table>
  2979. </td>
  2980. </tr>
  2981. </tbody>
  2982. </table>
  2983. </div>
  2984. <!--[if mso | IE]></td></tr></table><![endif]-->
  2985. </td>
  2986. </tr>
  2987. </tbody>
  2988. </table>
  2989. </div>
  2990. <!--[if mso | IE]></td></tr></table><![endif]-->
  2991. </div>
  2992. </body>
  2993. </html>
  2994. EOF
  2995. send_email <<EOF
  2996. To: ${to_email}
  2997. Subject: ${html_email_subject}
  2998. MIME-Version: 1.0
  2999. Content-Type: multipart/alternative; boundary="multipart-boundary"
  3000. ${email_thread_headers}
  3001. X-Netdata-Severity: ${status,,}
  3002. X-Netdata-Alert-Name: $name
  3003. X-Netdata-Chart: $chart
  3004. X-Netdata-Family: $family
  3005. X-Netdata-Classification: $classification
  3006. X-Netdata-Host: $host
  3007. X-Netdata-Role: $roles
  3008. This is a MIME-encoded multipart message
  3009. --multipart-boundary
  3010. ${email_plaintext_part}
  3011. --multipart-boundary
  3012. ${email_html_part}
  3013. --multipart-boundary--
  3014. EOF
  3015. fi
  3016. SENT_EMAIL=$?
  3017. # -----------------------------------------------------------------------------
  3018. # send the EVENT to Dynatrace
  3019. send_dynatrace "${host}" "${chart}" "${name}" "${status}"
  3020. SENT_DYNATRACE=$?
  3021. # -----------------------------------------------------------------------------
  3022. # send the EVENT to Stackpulse
  3023. send_stackpulse
  3024. SENT_STACKPULSE=$?
  3025. # -----------------------------------------------------------------------------
  3026. # send messages to Opsgenie
  3027. send_opsgenie
  3028. SENT_OPSGENIE=$?
  3029. # -----------------------------------------------------------------------------
  3030. # send messages to Gotify
  3031. send_gotify
  3032. SENT_GOTIFY=$?
  3033. # -----------------------------------------------------------------------------
  3034. # let netdata know
  3035. for state in "${SENT_EMAIL}" \
  3036. "${SENT_PUSHOVER}" \
  3037. "${SENT_TELEGRAM}" \
  3038. "${SENT_SLACK}" \
  3039. "${SENT_HANGOUTS}" \
  3040. "${SENT_ROCKETCHAT}" \
  3041. "${SENT_ALERTA}" \
  3042. "${SENT_FLOCK}" \
  3043. "${SENT_DISCORD}" \
  3044. "${SENT_TWILIO}" \
  3045. "${SENT_HIPCHAT}" \
  3046. "${SENT_MESSAGEBIRD}" \
  3047. "${SENT_KAVENEGAR}" \
  3048. "${SENT_PUSHBULLET}" \
  3049. "${SENT_KAFKA}" \
  3050. "${SENT_PD}" \
  3051. "${SENT_FLEEP}" \
  3052. "${SENT_PROWL}" \
  3053. "${SENT_CUSTOM}" \
  3054. "${SENT_IRC}" \
  3055. "${SENT_AWSSNS}" \
  3056. "${SENT_MATRIX}" \
  3057. "${SENT_SYSLOG}" \
  3058. "${SENT_SMS}" \
  3059. "${SENT_MSTEAMS}" \
  3060. "${SENT_DYNATRACE}" \
  3061. "${SENT_STACKPULSE}" \
  3062. "${SENT_OPSGENIE}" \
  3063. "${SENT_GOTIFY}"; do
  3064. if [ "${state}" -eq 0 ]; then
  3065. # we sent something
  3066. exit 0
  3067. fi
  3068. done
  3069. # we did not send anything
  3070. exit 1