alarm-notify-basic.bash3.sh 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. #!/usr/bin/env bash
  2. # basic version of netdata notifier to work with bash3
  3. # only mail and syslog destinations are supported, one recipient each
  4. # - email: DEFAULT_RECIPIENT_EMAIL, "root" by default
  5. # - syslog: "netdata" with local6 facility; disabled by default
  6. # - also: setting recipient to "disabled" or "silent" stops notifications for this alert
  7. # in /etc/netdata/health_alarm_notify.conf set something like
  8. # EMAIL_SENDER="netdata@gesdev-vm.m0.maxidom.ru"
  9. # SEND_EMAIL="YES"
  10. # DEFAULT_RECIPIENT_EMAIL="root"
  11. # SEND_SYSLOG="YES"
  12. # SYSLOG_FACILITY="local6"
  13. # DEFAULT_RECIPIENT_SYSLOG="netdata"
  14. # netdata
  15. # real-time performance and health monitoring, done right!
  16. # (C) 2017 Costa Tsaousis <costa@tsaousis.gr>
  17. # GPL v3+
  18. #
  19. # Script to send alarm notifications for netdata
  20. #
  21. # Supported notification methods:
  22. # - emails by @ktsaou
  23. # - syslog messages by @Ferroin
  24. # - all the rest is pruned :)
  25. # -----------------------------------------------------------------------------
  26. # testing notifications
  27. if [ \( "${1}" = "test" -o "${2}" = "test" \) -a "${#}" -le 2 ]
  28. then
  29. if [ "${2}" = "test" ]
  30. then
  31. recipient="${1}"
  32. else
  33. recipient="${2}"
  34. fi
  35. [ -z "${recipient}" ] && recipient="sysadmin"
  36. id=1
  37. last="CLEAR"
  38. test_res=0
  39. for x in "WARNING" "CRITICAL" "CLEAR"
  40. do
  41. echo >&2
  42. echo >&2 "# SENDING TEST ${x} ALARM TO ROLE: ${recipient}"
  43. "${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"
  44. if [ $? -ne 0 ]
  45. then
  46. echo >&2 "# FAILED"
  47. test_res=1
  48. else
  49. echo >&2 "# OK"
  50. fi
  51. last="${x}"
  52. id=$((id + 1))
  53. done
  54. exit $test_res
  55. fi
  56. export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
  57. export LC_ALL=C
  58. # -----------------------------------------------------------------------------
  59. PROGRAM_NAME="$(basename "${0}")"
  60. logdate() {
  61. date "+%Y-%m-%d %H:%M:%S"
  62. }
  63. log() {
  64. local status="${1}"
  65. shift
  66. echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
  67. }
  68. warning() {
  69. log WARNING "${@}"
  70. }
  71. error() {
  72. log ERROR "${@}"
  73. }
  74. info() {
  75. log INFO "${@}"
  76. }
  77. fatal() {
  78. log FATAL "${@}"
  79. exit 1
  80. }
  81. debug=${NETDATA_ALARM_NOTIFY_DEBUG-0}
  82. debug() {
  83. [ "${debug}" = "1" ] && log DEBUG "${@}"
  84. }
  85. docurl() {
  86. if [ -z "${curl}" ]
  87. then
  88. error "\${curl} is unset."
  89. return 1
  90. fi
  91. if [ "${debug}" = "1" ]
  92. then
  93. echo >&2 "--- BEGIN curl command ---"
  94. printf >&2 "%q " ${curl} "${@}"
  95. echo >&2
  96. echo >&2 "--- END curl command ---"
  97. local out=$(mktemp /tmp/netdata-health-alarm-notify-XXXXXXXX)
  98. local code=$(${curl} ${curl_options} --write-out %{http_code} --output "${out}" --silent --show-error "${@}")
  99. local ret=$?
  100. echo >&2 "--- BEGIN received response ---"
  101. cat >&2 "${out}"
  102. echo >&2
  103. echo >&2 "--- END received response ---"
  104. echo >&2 "RECEIVED HTTP RESPONSE CODE: ${code}"
  105. rm "${out}"
  106. echo "${code}"
  107. return ${ret}
  108. fi
  109. ${curl} ${curl_options} --write-out %{http_code} --output /dev/null --silent --show-error "${@}"
  110. return $?
  111. }
  112. # -----------------------------------------------------------------------------
  113. # this is to be overwritten by the config file
  114. custom_sender() {
  115. info "not sending custom notification for ${status} of '${host}.${chart}.${name}'"
  116. }
  117. # -----------------------------------------------------------------------------
  118. # check for BASH v4+ (required for associative arrays)
  119. [ $(( ${BASH_VERSINFO[0]} )) -lt 3 ] && \
  120. fatal "BASH version 3 or later is required (this is ${BASH_VERSION})."
  121. # -----------------------------------------------------------------------------
  122. # defaults to allow running this script by hand
  123. [ -z "${NETDATA_CONFIG_DIR}" ] && NETDATA_CONFIG_DIR="$(dirname "${0}")/../../../../etc/netdata"
  124. [ -z "${NETDATA_CACHE_DIR}" ] && NETDATA_CACHE_DIR="$(dirname "${0}")/../../../../var/cache/netdata"
  125. [ -z "${NETDATA_REGISTRY_URL}" ] && NETDATA_REGISTRY_URL="https://registry.my-netdata.io"
  126. # -----------------------------------------------------------------------------
  127. # parse command line parameters
  128. roles="${1}" # the roles that should be notified for this event
  129. host="${2}" # the host generated this event
  130. unique_id="${3}" # the unique id of this event
  131. alarm_id="${4}" # the unique id of the alarm that generated this event
  132. event_id="${5}" # the incremental id of the event, for this alarm id
  133. when="${6}" # the timestamp this event occurred
  134. name="${7}" # the name of the alarm, as given in netdata health.d entries
  135. chart="${8}" # the name of the chart (type.id)
  136. family="${9}" # the family of the chart
  137. status="${10}" # the current status : REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
  138. old_status="${11}" # the previous status: REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
  139. value="${12}" # the current value of the alarm
  140. old_value="${13}" # the previous value of the alarm
  141. src="${14}" # the line number and file the alarm has been configured
  142. duration="${15}" # the duration in seconds of the previous alarm state
  143. non_clear_duration="${16}" # the total duration in seconds this is/was non-clear
  144. units="${17}" # the units of the value
  145. info="${18}" # a short description of the alarm
  146. value_string="${19}" # friendly value (with units)
  147. old_value_string="${20}" # friendly old value (with units)
  148. # -----------------------------------------------------------------------------
  149. # find a suitable hostname to use, if netdata did not supply a hostname
  150. this_host=$(hostname -s 2>/dev/null)
  151. [ -z "${host}" ] && host="${this_host}"
  152. # -----------------------------------------------------------------------------
  153. # screen statuses we don't need to send a notification
  154. # don't do anything if this is not WARNING, CRITICAL or CLEAR
  155. if [ "${status}" != "WARNING" -a "${status}" != "CRITICAL" -a "${status}" != "CLEAR" ]
  156. then
  157. info "not sending notification for ${status} of '${host}.${chart}.${name}'"
  158. exit 1
  159. fi
  160. # don't do anything if this is CLEAR, but it was not WARNING or CRITICAL
  161. if [ "${old_status}" != "WARNING" -a "${old_status}" != "CRITICAL" -a "${status}" = "CLEAR" ]
  162. then
  163. info "not sending notification for ${status} of '${host}.${chart}.${name}' (last status was ${old_status})"
  164. exit 1
  165. fi
  166. # -----------------------------------------------------------------------------
  167. # load configuration
  168. # By default fetch images from the global public registry.
  169. # This is required by default, since all notification methods need to download
  170. # images via the Internet, and private registries might not be reachable.
  171. # This can be overwritten at the configuration file.
  172. images_base_url="https://registry.my-netdata.io"
  173. # curl options to use
  174. curl_options=
  175. # needed commands
  176. # if empty they will be searched in the system path
  177. curl=
  178. sendmail=
  179. # enable / disable features
  180. SEND_EMAIL="YES"
  181. SEND_SYSLOG="YES"
  182. # syslog configs
  183. SYSLOG_FACILITY="local6"
  184. # email configs
  185. EMAIL_SENDER=
  186. DEFAULT_RECIPIENT_EMAIL="root"
  187. EMAIL_CHARSET=$(locale charmap 2>/dev/null)
  188. # load the user configuration
  189. # this will overwrite the variables above
  190. if [ -f "${NETDATA_CONFIG_DIR}/health_alarm_notify.conf" ]
  191. then
  192. source "${NETDATA_CONFIG_DIR}/health_alarm_notify.conf"
  193. else
  194. error "Cannot find file ${NETDATA_CONFIG_DIR}/health_alarm_notify.conf. Using internal defaults."
  195. fi
  196. # If we didn't autodetect the character set for e-mail and it wasn't
  197. # set by the user, we need to set it to a reasonable default. UTF-8
  198. # should be correct for almost all modern UNIX systems.
  199. if [ -z ${EMAIL_CHARSET} ]
  200. then
  201. EMAIL_CHARSET="UTF-8"
  202. fi
  203. # disable if role = silent or disabled
  204. if [[ "${role}" = "silent" || "${role}" = "disabled" ]]; then
  205. SEND_EMAIL="NO"
  206. SEND_SYSLOG="NO"
  207. fi
  208. if [[ "SEND_EMAIL" != "NO" ]]; then
  209. to_email=$DEFAULT_RECIPIENT_EMAIL
  210. else
  211. to_email=''
  212. fi
  213. if [[ "SEND_SYSLOG" != "NO" ]]; then
  214. to_syslog=$DEFAULT_RECIPIENT_SYSLOG
  215. else
  216. to_syslog=''
  217. fi
  218. # if we need sendmail, check for the sendmail command
  219. if [ "${SEND_EMAIL}" = "YES" -a -z "${sendmail}" ]
  220. then
  221. sendmail="$(which sendmail 2>/dev/null || command -v sendmail 2>/dev/null)"
  222. if [ -z "${sendmail}" ]
  223. then
  224. debug "Cannot find sendmail command in the system path. Disabling email notifications."
  225. SEND_EMAIL="NO"
  226. fi
  227. fi
  228. # if we need logger, check for the logger command
  229. if [ "${SEND_SYSLOG}" = "YES" -a -z "${logger}" ]
  230. then
  231. logger="$(which logger 2>/dev/null || command -v logger 2>/dev/null)"
  232. if [ -z "${logger}" ]
  233. then
  234. debug "Cannot find logger command in the system path. Disabling syslog notifications."
  235. SEND_SYSLOG="NO"
  236. fi
  237. fi
  238. # check that we have at least a method enabled
  239. if [ "${SEND_EMAIL}" != "YES" \
  240. -a "${SEND_SYSLOG}" != "YES" \
  241. ]
  242. then
  243. fatal "All notification methods are disabled. Not sending notification for host '${host}', chart '${chart}' to '${roles}' for '${name}' = '${value}' for status '${status}'."
  244. fi
  245. # -----------------------------------------------------------------------------
  246. # get the date the alarm happened
  247. date=$(date --date=@${when} "${DATE_FORMAT}" 2>/dev/null)
  248. [ -z "${date}" ] && date=$(date "${DATE_FORMAT}" 2>/dev/null)
  249. [ -z "${date}" ] && date=$(date --date=@${when} 2>/dev/null)
  250. [ -z "${date}" ] && date=$(date 2>/dev/null)
  251. # -----------------------------------------------------------------------------
  252. # function to URL encode a string
  253. urlencode() {
  254. local string="${1}" strlen encoded pos c o
  255. strlen=${#string}
  256. for (( pos=0 ; pos<strlen ; pos++ ))
  257. do
  258. c=${string:${pos}:1}
  259. case "${c}" in
  260. [-_.~a-zA-Z0-9])
  261. o="${c}"
  262. ;;
  263. *)
  264. printf -v o '%%%02x' "'${c}"
  265. ;;
  266. esac
  267. encoded+="${o}"
  268. done
  269. REPLY="${encoded}"
  270. echo "${REPLY}"
  271. }
  272. # -----------------------------------------------------------------------------
  273. # function to convert a duration in seconds, to a human readable duration
  274. # using DAYS, MINUTES, SECONDS
  275. duration4human() {
  276. local s="${1}" d=0 h=0 m=0 ds="day" hs="hour" ms="minute" ss="second" ret
  277. d=$(( s / 86400 ))
  278. s=$(( s - (d * 86400) ))
  279. h=$(( s / 3600 ))
  280. s=$(( s - (h * 3600) ))
  281. m=$(( s / 60 ))
  282. s=$(( s - (m * 60) ))
  283. if [ ${d} -gt 0 ]
  284. then
  285. [ ${m} -ge 30 ] && h=$(( h + 1 ))
  286. [ ${d} -gt 1 ] && ds="days"
  287. [ ${h} -gt 1 ] && hs="hours"
  288. if [ ${h} -gt 0 ]
  289. then
  290. ret="${d} ${ds} and ${h} ${hs}"
  291. else
  292. ret="${d} ${ds}"
  293. fi
  294. elif [ ${h} -gt 0 ]
  295. then
  296. [ ${s} -ge 30 ] && m=$(( m + 1 ))
  297. [ ${h} -gt 1 ] && hs="hours"
  298. [ ${m} -gt 1 ] && ms="minutes"
  299. if [ ${m} -gt 0 ]
  300. then
  301. ret="${h} ${hs} and ${m} ${ms}"
  302. else
  303. ret="${h} ${hs}"
  304. fi
  305. elif [ ${m} -gt 0 ]
  306. then
  307. [ ${m} -gt 1 ] && ms="minutes"
  308. [ ${s} -gt 1 ] && ss="seconds"
  309. if [ ${s} -gt 0 ]
  310. then
  311. ret="${m} ${ms} and ${s} ${ss}"
  312. else
  313. ret="${m} ${ms}"
  314. fi
  315. else
  316. [ ${s} -gt 1 ] && ss="seconds"
  317. ret="${s} ${ss}"
  318. fi
  319. REPLY="${ret}"
  320. echo "${REPLY}"
  321. }
  322. # -----------------------------------------------------------------------------
  323. # email sender
  324. send_email() {
  325. local ret= opts=
  326. if [[ "${SEND_EMAIL}" == "YES" ]]
  327. then
  328. if [[ ! -z "${EMAIL_SENDER}" ]]
  329. then
  330. if [[ "${EMAIL_SENDER}" =~ \".*\"\ \<.*\> ]]
  331. then
  332. # the name includes single quotes
  333. opts=" -f $(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1) -F $(echo "${EMAIL_SENDER}" | cut -d '<' -f 1)"
  334. elif [[ "${EMAIL_SENDER}" =~ \'.*\'\ \<.*\> ]]
  335. then
  336. # the name includes double quotes
  337. opts=" -f $(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1) -F $(echo "${EMAIL_SENDER}" | cut -d '<' -f 1)"
  338. elif [[ "${EMAIL_SENDER}" =~ .*\ \<.*\> ]]
  339. then
  340. # the name does not have any quotes
  341. opts=" -f $(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1) -F '$(echo "${EMAIL_SENDER}" | cut -d '<' -f 1)'"
  342. else
  343. # no name at all
  344. opts=" -f ${EMAIL_SENDER}"
  345. fi
  346. fi
  347. if [[ "${debug}" = "1" ]]
  348. then
  349. echo >&2 "--- BEGIN sendmail command ---"
  350. printf >&2 "%q " "${sendmail}" -t ${opts}
  351. echo >&2
  352. echo >&2 "--- END sendmail command ---"
  353. fi
  354. "${sendmail}" -t ${opts}
  355. ret=$?
  356. if [ ${ret} -eq 0 ]
  357. then
  358. info "sent email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}'"
  359. return 0
  360. else
  361. error "failed to send email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}' with error code ${ret}."
  362. return 1
  363. fi
  364. fi
  365. return 1
  366. }
  367. # -----------------------------------------------------------------------------
  368. # syslog sender
  369. send_syslog() {
  370. local facility=${SYSLOG_FACILITY:-"local6"} level='info' targets="${1}"
  371. local priority='' message='' host='' port='' prefix=''
  372. local temp1='' temp2=''
  373. [[ "${SEND_SYSLOG}" == "YES" ]] || return 1
  374. if [[ "${status}" == "CRITICAL" ]] ; then
  375. level='crit'
  376. elif [[ "${status}" == "WARNING" ]] ; then
  377. level='warning'
  378. fi
  379. for target in ${targets} ; do
  380. priority="${facility}.${level}"
  381. message=''
  382. host=''
  383. port=''
  384. prefix=''
  385. temp1=''
  386. temp2=''
  387. prefix=$(echo ${target} | cut -d '/' -f 2)
  388. temp1=$(echo ${target} | cut -d '/' -f 1)
  389. if [[ ${prefix} != ${temp1} ]] ; then
  390. if (echo ${temp1} | grep -q '@' ) ; then
  391. temp2=$(echo ${temp1} | cut -d '@' -f 1)
  392. host=$(echo ${temp1} | cut -d '@' -f 2)
  393. if [ ${temp2} != ${host} ] ; then
  394. priority=${temp2}
  395. fi
  396. port=$(echo ${host} | rev | cut -d ':' -f 1 | rev)
  397. if ( echo ${host} | grep -E -q '\[.*\]' ) ; then
  398. if ( echo ${port} | grep -q ']' ) ; then
  399. port=''
  400. else
  401. host=$(echo ${host} | rev | cut -d ':' -f 2- | rev)
  402. fi
  403. else
  404. if [ ${port} = ${host} ] ; then
  405. port=''
  406. else
  407. host=$(echo ${host} | cut -d ':' -f 1)
  408. fi
  409. fi
  410. else
  411. priority=${temp1}
  412. fi
  413. fi
  414. # message="${prefix} ${status} on ${host} at ${date}: ${chart} ${value_string}"
  415. message="${prefix} ${status}: ${chart} ${value_string}"
  416. if [ ${host} ] ; then
  417. logger_options="${logger_options} -n ${host}"
  418. if [ ${port} ] ; then
  419. logger_options="${logger_options} -P ${port}"
  420. fi
  421. fi
  422. ${logger} -p ${priority} ${logger_options} "${message}"
  423. done
  424. return $?
  425. }
  426. # -----------------------------------------------------------------------------
  427. # prepare the content of the notification
  428. # the url to send the user on click
  429. urlencode "${host}" >/dev/null; url_host="${REPLY}"
  430. urlencode "${chart}" >/dev/null; url_chart="${REPLY}"
  431. urlencode "${family}" >/dev/null; url_family="${REPLY}"
  432. urlencode "${name}" >/dev/null; url_name="${REPLY}"
  433. goto_url="${NETDATA_REGISTRY_URL}/goto-host-from-alarm.html?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}"
  434. # the severity of the alarm
  435. severity="${status}"
  436. # the time the alarm was raised
  437. duration4human ${duration} >/dev/null; duration_txt="${REPLY}"
  438. duration4human ${non_clear_duration} >/dev/null; non_clear_duration_txt="${REPLY}"
  439. raised_for="(was ${old_status} for ${duration_txt})"
  440. # the key status message
  441. status_message="status unknown"
  442. # the color of the alarm
  443. color="grey"
  444. # the alarm value
  445. alarm="${name//_/ } = ${value_string}"
  446. # the image of the alarm
  447. image="${images_base_url}/images/seo-performance-128.png"
  448. # prepare the title based on status
  449. case "${status}" in
  450. CRITICAL)
  451. image="${images_base_url}/images/alert-128-red.png"
  452. status_message="is critical"
  453. color="#ca414b"
  454. ;;
  455. WARNING)
  456. image="${images_base_url}/images/alert-128-orange.png"
  457. status_message="needs attention"
  458. color="#ffc107"
  459. ;;
  460. CLEAR)
  461. image="${images_base_url}/images/check-mark-2-128-green.png"
  462. status_message="recovered"
  463. color="#77ca6d"
  464. ;;
  465. esac
  466. if [ "${status}" = "CLEAR" ]
  467. then
  468. severity="Recovered from ${old_status}"
  469. if [ ${non_clear_duration} -gt ${duration} ]
  470. then
  471. raised_for="(alarm was raised for ${non_clear_duration_txt})"
  472. fi
  473. # don't show the value when the status is CLEAR
  474. # for certain alarms, this value might not have any meaning
  475. alarm="${name//_/ } ${raised_for}"
  476. elif [ "${old_status}" = "WARNING" -a "${status}" = "CRITICAL" ]
  477. then
  478. severity="Escalated to ${status}"
  479. if [ ${non_clear_duration} -gt ${duration} ]
  480. then
  481. raised_for="(alarm is raised for ${non_clear_duration_txt})"
  482. fi
  483. elif [ "${old_status}" = "CRITICAL" -a "${status}" = "WARNING" ]
  484. then
  485. severity="Demoted to ${status}"
  486. if [ ${non_clear_duration} -gt ${duration} ]
  487. then
  488. raised_for="(alarm is raised for ${non_clear_duration_txt})"
  489. fi
  490. else
  491. raised_for=
  492. fi
  493. # prepare HTML versions of elements
  494. info_html=
  495. [ ! -z "${info}" ] && info_html=" <small><br/>${info}</small>"
  496. raised_for_html=
  497. [ ! -z "${raised_for}" ] && raised_for_html="<br/><small>${raised_for}</small>"
  498. # -----------------------------------------------------------------------------
  499. # send the syslog message
  500. send_syslog ${to_syslog}
  501. SENT_SYSLOG=$?
  502. # -----------------------------------------------------------------------------
  503. # send the email
  504. send_email <<EOF
  505. To: ${to_email}
  506. Subject: ${host} ${status_message} - ${name//_/ } - ${chart}
  507. MIME-Version: 1.0
  508. Content-Type: multipart/alternative; boundary="multipart-boundary"
  509. This is a MIME-encoded multipart message
  510. --multipart-boundary
  511. Content-Type: text/plain; encoding=${EMAIL_CHARSET}
  512. Content-Disposition: inline
  513. Content-Transfer-Encoding: 8bit
  514. ${host} ${status_message}
  515. ${alarm} ${info}
  516. ${raised_for}
  517. Chart : ${chart}
  518. Family : ${family}
  519. Severity: ${severity}
  520. URL : ${goto_url}
  521. Source : ${src}
  522. Date : ${date}
  523. Value : ${value_string}
  524. Notification generated on ${this_host}
  525. --multipart-boundary
  526. Content-Type: text/html; encoding=${EMAIL_CHARSET}
  527. Content-Disposition: inline
  528. Content-Transfer-Encoding: 8bit
  529. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  530. <html xmlns="http://www.w3.org/1999/xhtml" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 14px; margin: 0; padding: 0;">
  531. <body style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; width: 100% !important; min-height: 100%; line-height: 1.6; background: #f6f6f6; margin:0; padding: 0;">
  532. <table>
  533. <tbody>
  534. <tr>
  535. <td style="vertical-align: top;" valign="top"></td>
  536. <td width="700" style="vertical-align: top; display: block !important; max-width: 700px !important; clear: both !important; margin: 0 auto; padding: 0;" valign="top">
  537. <div style="max-width: 700px; display: block; margin: 0 auto; padding: 20px;">
  538. <table width="100%" cellpadding="0" cellspacing="0" style="background: #fff; border: 1px solid #e9e9e9;">
  539. <tbody>
  540. <tr>
  541. <td bgcolor="#eee" style="padding: 5px 20px 5px 20px; background-color: #eee;">
  542. <div style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 20px; color: #777; font-weight: bold;">netdata notification</div>
  543. </td>
  544. </tr>
  545. <tr>
  546. <td bgcolor="${color}" style="font-size: 16px; vertical-align: top; font-weight: 400; text-align: center; margin: 0; padding: 10px; color: #ffffff; background: ${color} !important; border: 1px solid ${color}; border-top-color: ${color};" align="center" valign="top">
  547. <h1 style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-weight: 400; margin: 0;">${host} ${status_message}</h1>
  548. </td>
  549. </tr>
  550. <tr>
  551. <td style="vertical-align: top;" valign="top">
  552. <div style="margin: 0; padding: 20px; max-width: 700px;">
  553. <table width="100%" cellpadding="0" cellspacing="0" style="max-width:700px">
  554. <tbody>
  555. <tr>
  556. <td style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding:0 0 20px;" align="left" valign="top">
  557. <span>${chart}</span>
  558. <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Chart</span>
  559. </td>
  560. </tr>
  561. <tr>
  562. <td style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;" align="left" valign="top">
  563. <span>${value_string}</span>
  564. <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Value</span>
  565. </td>
  566. </tr>
  567. <tr style="margin: 0; padding: 0;">
  568. <td style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;" align="left" valign="top">
  569. <span><b>${alarm}</b>${info_html}</span>
  570. <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Alarm</span>
  571. </td>
  572. </tr>
  573. <tr>
  574. <td style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;" align="left" valign="top">
  575. <span>${family}</span>
  576. <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Family</span>
  577. </td>
  578. </tr>
  579. <tr style="margin: 0; padding: 0;">
  580. <td style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;" align="left" valign="top">
  581. <span>${severity}</span>
  582. <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Severity</span>
  583. </td>
  584. </tr>
  585. <tr style="margin: 0; padding: 0;">
  586. <td style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;" align="left" valign="top"><span>${date}</span>
  587. <span>${raised_for_html}</span> <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Time</span>
  588. </td>
  589. </tr>
  590. <tr style="margin: 0; padding: 0;">
  591. <td style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;">
  592. <a href="${goto_url}" style="font-size: 14px; color: #ffffff; text-decoration: none; line-height: 1.5; font-weight: bold; text-align: center; display: inline-block; text-transform: capitalize; background: #35568d; border-width: 1px; border-style: solid; border-color: #2b4c86; margin: 0; padding: 10px 15px;" target="_blank">View Netdata</a>
  593. </td>
  594. </tr>
  595. <tr style="text-align: center; margin: 0; padding: 0;">
  596. <td style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 11px; vertical-align: top; margin: 0; padding: 10px 0 0 0; color: #666666;" align="center" valign="bottom">The source of this alarm is line <code>${src}</code><br/>(alarms are configurable, edit this file to adapt the alarm to your needs)
  597. </td>
  598. </tr>
  599. <tr style="text-align: center; margin: 0; padding: 0;">
  600. <td style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; vertical-align: top; margin:0; padding: 20px 0 0 0; color: #666666; border-top: 1px solid #f0f0f0;" align="center" valign="bottom">Sent by
  601. <a href="https://mynetdata.io/" target="_blank">netdata</a>, the real-time performance and health monitoring, on <code>${this_host}</code>.
  602. </td>
  603. </tr>
  604. </tbody>
  605. </table>
  606. </div>
  607. </td>
  608. </tr>
  609. </tbody>
  610. </table>
  611. </div>
  612. </td>
  613. </tr>
  614. </tbody>
  615. </table>
  616. </body>
  617. </html>
  618. --multipart-boundary--
  619. EOF
  620. SENT_EMAIL=$?
  621. # -----------------------------------------------------------------------------
  622. # let netdata know
  623. if [ ${SENT_EMAIL} -eq 0 \
  624. -o ${SENT_SYSLOG} -eq 0 \
  625. ]
  626. then
  627. # we did send something
  628. exit 0
  629. fi
  630. # we did not send anything
  631. exit 1