@cryptotaxi247 / netdata-1 / commits / 7cbb47be0

RPM spec and patches for sles 11 (#3708)

* RPM spec and patches for sles 11 * some fixes to alarm-notify.bash3 to make codacity happy * replace ugly bash3 alarm notifier with trimmed rewrite * notification format fixes * update README for sles11 contrib

Alexey Vekshin committed Nov 30, 2018 at 12:02 UTC 7cbb47be0c26b5bd91e95ac010129668e4b49eb0
6 files changed +880
contrib/sles11/README.md new
+9
@@ -0,0 +1,9 @@
1 +# spec to build netdata RPM for sles 11
2 +
3 +Based on [opensuse rpm spec](https://build.opensuse.org/package/show/network/netdata) with some
4 +changes and additions for sles 11 backport, namely:
5 +- init.d script
6 +- run-time dependency on python ordereddict backport
7 +- patch for netdata python.d plugin to work with older python
8 +- crude hack of notification script to work with bash 3 (email and syslog only, one destination,
9 + see comments at the top)
contrib/sles11/alarm-notify-basic.bash3.sh new
+755
@@ -0,0 +1,755 @@
1 +#!/usr/bin/env bash
2 +
3 +# basic version of netdata notifier to work with bash3
4 +# only mail and syslog destinations are supported, one recipient each
5 +# - email: DEFAULT_RECIPIENT_EMAIL, "root" by default
6 +# - syslog: "netdata" with local6 facility; disabled by default
7 +# - also: setting recipient to "disabled" or "silent" stops notifications for this alert
8 +
9 +# in /etc/netdata/health_alarm_notify.conf set something like
10 +# EMAIL_SENDER="netdata@gesdev-vm.m0.maxidom.ru"
11 +# SEND_EMAIL="YES"
12 +# DEFAULT_RECIPIENT_EMAIL="root"
13 +# SEND_SYSLOG="YES"
14 +# SYSLOG_FACILITY="local6"
15 +# DEFAULT_RECIPIENT_SYSLOG="netdata"
16 +
17 +# netdata
18 +# real-time performance and health monitoring, done right!
19 +# (C) 2017 Costa Tsaousis <costa@tsaousis.gr>
20 +# GPL v3+
21 +#
22 +# Script to send alarm notifications for netdata
23 +#
24 +# Supported notification methods:
25 +# - emails by @ktsaou
26 +# - syslog messages by @Ferroin
27 +# - all the rest is pruned :)
28 +
29 +# -----------------------------------------------------------------------------
30 +# testing notifications
31 +
32 +if [ \( "${1}" = "test" -o "${2}" = "test" \) -a "${#}" -le 2 ]
33 +then
34 + if [ "${2}" = "test" ]
35 + then
36 + recipient="${1}"
37 + else
38 + recipient="${2}"
39 + fi
40 +
41 + [ -z "${recipient}" ] && recipient="sysadmin"
42 +
43 + id=1
44 + last="CLEAR"
45 + test_res=0
46 + for x in "WARNING" "CRITICAL" "CLEAR"
47 + do
48 + echo >&2
49 + echo >&2 "# SENDING TEST ${x} ALARM TO ROLE: ${recipient}"
50 +
51 + "${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"
52 + if [ $? -ne 0 ]
53 + then
54 + echo >&2 "# FAILED"
55 + test_res=1
56 + else
57 + echo >&2 "# OK"
58 + fi
59 +
60 + last="${x}"
61 + id=$((id + 1))
62 + done
63 +
64 + exit $test_res
65 +fi
66 +
67 +export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
68 +export LC_ALL=C
69 +
70 +# -----------------------------------------------------------------------------
71 +
72 +PROGRAM_NAME="$(basename "${0}")"
73 +
74 +logdate() {
75 + date "+%Y-%m-%d %H:%M:%S"
76 +}
77 +
78 +log() {
79 + local status="${1}"
80 + shift
81 +
82 + echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
83 +
84 +}
85 +
86 +warning() {
87 + log WARNING "${@}"
88 +}
89 +
90 +error() {
91 + log ERROR "${@}"
92 +}
93 +
94 +info() {
95 + log INFO "${@}"
96 +}
97 +
98 +fatal() {
99 + log FATAL "${@}"
100 + exit 1
101 +}
102 +
103 +debug=${NETDATA_ALARM_NOTIFY_DEBUG-0}
104 +debug() {
105 + [ "${debug}" = "1" ] && log DEBUG "${@}"
106 +}
107 +
108 +docurl() {
109 + if [ -z "${curl}" ]
110 + then
111 + error "\${curl} is unset."
112 + return 1
113 + fi
114 +
115 + if [ "${debug}" = "1" ]
116 + then
117 + echo >&2 "--- BEGIN curl command ---"
118 + printf >&2 "%q " ${curl} "${@}"
119 + echo >&2
120 + echo >&2 "--- END curl command ---"
121 +
122 + local out=$(mktemp /tmp/netdata-health-alarm-notify-XXXXXXXX)
123 + local code=$(${curl} ${curl_options} --write-out %{http_code} --output "${out}" --silent --show-error "${@}")
124 + local ret=$?
125 + echo >&2 "--- BEGIN received response ---"
126 + cat >&2 "${out}"
127 + echo >&2
128 + echo >&2 "--- END received response ---"
129 + echo >&2 "RECEIVED HTTP RESPONSE CODE: ${code}"
130 + rm "${out}"
131 + echo "${code}"
132 + return ${ret}
133 + fi
134 +
135 + ${curl} ${curl_options} --write-out %{http_code} --output /dev/null --silent --show-error "${@}"
136 + return $?
137 +}
138 +
139 +# -----------------------------------------------------------------------------
140 +# this is to be overwritten by the config file
141 +
142 +custom_sender() {
143 + info "not sending custom notification for ${status} of '${host}.${chart}.${name}'"
144 +}
145 +
146 +
147 +# -----------------------------------------------------------------------------
148 +
149 +# check for BASH v4+ (required for associative arrays)
150 +[ $(( ${BASH_VERSINFO[0]} )) -lt 3 ] && \
151 + fatal "BASH version 3 or later is required (this is ${BASH_VERSION})."
152 +
153 +# -----------------------------------------------------------------------------
154 +# defaults to allow running this script by hand
155 +
156 +[ -z "${NETDATA_CONFIG_DIR}" ] && NETDATA_CONFIG_DIR="$(dirname "${0}")/../../../../etc/netdata"
157 +[ -z "${NETDATA_CACHE_DIR}" ] && NETDATA_CACHE_DIR="$(dirname "${0}")/../../../../var/cache/netdata"
158 +[ -z "${NETDATA_REGISTRY_URL}" ] && NETDATA_REGISTRY_URL="https://registry.my-netdata.io"
159 +
160 +# -----------------------------------------------------------------------------
161 +# parse command line parameters
162 +
163 +roles="${1}" # the roles that should be notified for this event
164 +host="${2}" # the host generated this event
165 +unique_id="${3}" # the unique id of this event
166 +alarm_id="${4}" # the unique id of the alarm that generated this event
167 +event_id="${5}" # the incremental id of the event, for this alarm id
168 +when="${6}" # the timestamp this event occurred
169 +name="${7}" # the name of the alarm, as given in netdata health.d entries
170 +chart="${8}" # the name of the chart (type.id)
171 +family="${9}" # the family of the chart
172 +status="${10}" # the current status : REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
173 +old_status="${11}" # the previous status: REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
174 +value="${12}" # the current value of the alarm
175 +old_value="${13}" # the previous value of the alarm
176 +src="${14}" # the line number and file the alarm has been configured
177 +duration="${15}" # the duration in seconds of the previous alarm state
178 +non_clear_duration="${16}" # the total duration in seconds this is/was non-clear
179 +units="${17}" # the units of the value
180 +info="${18}" # a short description of the alarm
181 +value_string="${19}" # friendly value (with units)
182 +old_value_string="${20}" # friendly old value (with units)
183 +
184 +# -----------------------------------------------------------------------------
185 +# find a suitable hostname to use, if netdata did not supply a hostname
186 +
187 +this_host=$(hostname -s 2>/dev/null)
188 +[ -z "${host}" ] && host="${this_host}"
189 +
190 +# -----------------------------------------------------------------------------
191 +# screen statuses we don't need to send a notification
192 +
193 +# don't do anything if this is not WARNING, CRITICAL or CLEAR
194 +if [ "${status}" != "WARNING" -a "${status}" != "CRITICAL" -a "${status}" != "CLEAR" ]
195 +then
196 + info "not sending notification for ${status} of '${host}.${chart}.${name}'"
197 + exit 1
198 +fi
199 +
200 +# don't do anything if this is CLEAR, but it was not WARNING or CRITICAL
201 +if [ "${old_status}" != "WARNING" -a "${old_status}" != "CRITICAL" -a "${status}" = "CLEAR" ]
202 +then
203 + info "not sending notification for ${status} of '${host}.${chart}.${name}' (last status was ${old_status})"
204 + exit 1
205 +fi
206 +
207 +# -----------------------------------------------------------------------------
208 +# load configuration
209 +
210 +# By default fetch images from the global public registry.
211 +# This is required by default, since all notification methods need to download
212 +# images via the Internet, and private registries might not be reachable.
213 +# This can be overwritten at the configuration file.
214 +images_base_url="https://registry.my-netdata.io"
215 +
216 +# curl options to use
217 +curl_options=
218 +
219 +# needed commands
220 +# if empty they will be searched in the system path
221 +curl=
222 +sendmail=
223 +
224 +# enable / disable features
225 +SEND_EMAIL="YES"
226 +SEND_SYSLOG="YES"
227 +
228 +# syslog configs
229 +SYSLOG_FACILITY="local6"
230 +
231 +# email configs
232 +EMAIL_SENDER=
233 +DEFAULT_RECIPIENT_EMAIL="root"
234 +EMAIL_CHARSET=$(locale charmap 2>/dev/null)
235 +
236 +# load the user configuration
237 +# this will overwrite the variables above
238 +if [ -f "${NETDATA_CONFIG_DIR}/health_alarm_notify.conf" ]
239 + then
240 + source "${NETDATA_CONFIG_DIR}/health_alarm_notify.conf"
241 +else
242 + error "Cannot find file ${NETDATA_CONFIG_DIR}/health_alarm_notify.conf. Using internal defaults."
243 +fi
244 +
245 +# If we didn't autodetect the character set for e-mail and it wasn't
246 +# set by the user, we need to set it to a reasonable default. UTF-8
247 +# should be correct for almost all modern UNIX systems.
248 +if [ -z ${EMAIL_CHARSET} ]
249 + then
250 + EMAIL_CHARSET="UTF-8"
251 +fi
252 +
253 +# disable if role = silent or disabled
254 +if [[ "${role}" = "silent" || "${role}" = "disabled" ]]; then
255 + SEND_EMAIL="NO"
256 + SEND_SYSLOG="NO"
257 +fi
258 +
259 +if [[ "SEND_EMAIL" != "NO" ]]; then
260 + to_email=$DEFAULT_RECIPIENT_EMAIL
261 +else
262 + to_email=''
263 +fi
264 +
265 +if [[ "SEND_SYSLOG" != "NO" ]]; then
266 + to_syslog=$DEFAULT_RECIPIENT_SYSLOG
267 +else
268 + to_syslog=''
269 +fi
270 +
271 +# if we need sendmail, check for the sendmail command
272 +if [ "${SEND_EMAIL}" = "YES" -a -z "${sendmail}" ]
273 + then
274 + sendmail="$(which sendmail 2>/dev/null || command -v sendmail 2>/dev/null)"
275 + if [ -z "${sendmail}" ]
276 + then
277 + debug "Cannot find sendmail command in the system path. Disabling email notifications."
278 + SEND_EMAIL="NO"
279 + fi
280 +fi
281 +
282 +# if we need logger, check for the logger command
283 +if [ "${SEND_SYSLOG}" = "YES" -a -z "${logger}" ]
284 + then
285 + logger="$(which logger 2>/dev/null || command -v logger 2>/dev/null)"
286 + if [ -z "${logger}" ]
287 + then
288 + debug "Cannot find logger command in the system path. Disabling syslog notifications."
289 + SEND_SYSLOG="NO"
290 + fi
291 +fi
292 +
293 +# check that we have at least a method enabled
294 +if [ "${SEND_EMAIL}" != "YES" \
295 + -a "${SEND_SYSLOG}" != "YES" \
296 + ]
297 + then
298 + fatal "All notification methods are disabled. Not sending notification for host '${host}', chart '${chart}' to '${roles}' for '${name}' = '${value}' for status '${status}'."
299 +fi
300 +
301 +# -----------------------------------------------------------------------------
302 +# get the date the alarm happened
303 +
304 +date=$(date --date=@${when} "${DATE_FORMAT}" 2>/dev/null)
305 +[ -z "${date}" ] && date=$(date "${DATE_FORMAT}" 2>/dev/null)
306 +[ -z "${date}" ] && date=$(date --date=@${when} 2>/dev/null)
307 +[ -z "${date}" ] && date=$(date 2>/dev/null)
308 +
309 +# -----------------------------------------------------------------------------
310 +# function to URL encode a string
311 +
312 +urlencode() {
313 + local string="${1}" strlen encoded pos c o
314 +
315 + strlen=${#string}
316 + for (( pos=0 ; pos<strlen ; pos++ ))
317 + do
318 + c=${string:${pos}:1}
319 + case "${c}" in
320 + [-_.~a-zA-Z0-9])
321 + o="${c}"
322 + ;;
323 +
324 + *)
325 + printf -v o '%%%02x' "'${c}"
326 + ;;
327 + esac
328 + encoded+="${o}"
329 + done
330 +
331 + REPLY="${encoded}"
332 + echo "${REPLY}"
333 +}
334 +
335 +# -----------------------------------------------------------------------------
336 +# function to convert a duration in seconds, to a human readable duration
337 +# using DAYS, MINUTES, SECONDS
338 +
339 +duration4human() {
340 + local s="${1}" d=0 h=0 m=0 ds="day" hs="hour" ms="minute" ss="second" ret
341 + d=$(( s / 86400 ))
342 + s=$(( s - (d * 86400) ))
343 + h=$(( s / 3600 ))
344 + s=$(( s - (h * 3600) ))
345 + m=$(( s / 60 ))
346 + s=$(( s - (m * 60) ))
347 +
348 + if [ ${d} -gt 0 ]
349 + then
350 + [ ${m} -ge 30 ] && h=$(( h + 1 ))
351 + [ ${d} -gt 1 ] && ds="days"
352 + [ ${h} -gt 1 ] && hs="hours"
353 + if [ ${h} -gt 0 ]
354 + then
355 + ret="${d} ${ds} and ${h} ${hs}"
356 + else
357 + ret="${d} ${ds}"
358 + fi
359 + elif [ ${h} -gt 0 ]
360 + then
361 + [ ${s} -ge 30 ] && m=$(( m + 1 ))
362 + [ ${h} -gt 1 ] && hs="hours"
363 + [ ${m} -gt 1 ] && ms="minutes"
364 + if [ ${m} -gt 0 ]
365 + then
366 + ret="${h} ${hs} and ${m} ${ms}"
367 + else
368 + ret="${h} ${hs}"
369 + fi
370 + elif [ ${m} -gt 0 ]
371 + then
372 + [ ${m} -gt 1 ] && ms="minutes"
373 + [ ${s} -gt 1 ] && ss="seconds"
374 + if [ ${s} -gt 0 ]
375 + then
376 + ret="${m} ${ms} and ${s} ${ss}"
377 + else
378 + ret="${m} ${ms}"
379 + fi
380 + else
381 + [ ${s} -gt 1 ] && ss="seconds"
382 + ret="${s} ${ss}"
383 + fi
384 +
385 + REPLY="${ret}"
386 + echo "${REPLY}"
387 +}
388 +
389 +# -----------------------------------------------------------------------------
390 +# email sender
391 +
392 +send_email() {
393 + local ret= opts=
394 + if [[ "${SEND_EMAIL}" == "YES" ]]
395 + then
396 +
397 + if [[ ! -z "${EMAIL_SENDER}" ]]
398 + then
399 + if [[ "${EMAIL_SENDER}" =~ \".*\"\ \<.*\> ]]
400 + then
401 + # the name includes single quotes
402 + opts=" -f $(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1) -F $(echo "${EMAIL_SENDER}" | cut -d '<' -f 1)"
403 + elif [[ "${EMAIL_SENDER}" =~ \'.*\'\ \<.*\> ]]
404 + then
405 + # the name includes double quotes
406 + opts=" -f $(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1) -F $(echo "${EMAIL_SENDER}" | cut -d '<' -f 1)"
407 + elif [[ "${EMAIL_SENDER}" =~ .*\ \<.*\> ]]
408 + then
409 + # the name does not have any quotes
410 + opts=" -f $(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1) -F '$(echo "${EMAIL_SENDER}" | cut -d '<' -f 1)'"
411 + else
412 + # no name at all
413 + opts=" -f ${EMAIL_SENDER}"
414 + fi
415 + fi
416 +
417 + if [[ "${debug}" = "1" ]]
418 + then
419 + echo >&2 "--- BEGIN sendmail command ---"
420 + printf >&2 "%q " "${sendmail}" -t ${opts}
421 + echo >&2
422 + echo >&2 "--- END sendmail command ---"
423 + fi
424 +
425 + "${sendmail}" -t ${opts}
426 + ret=$?
427 +
428 + if [ ${ret} -eq 0 ]
429 + then
430 + info "sent email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}'"
431 + return 0
432 + else
433 + error "failed to send email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}' with error code ${ret}."
434 + return 1
435 + fi
436 + fi
437 +
438 + return 1
439 +}
440 +
441 +# -----------------------------------------------------------------------------
442 +# syslog sender
443 +
444 +send_syslog() {
445 + local facility=${SYSLOG_FACILITY:-"local6"} level='info' targets="${1}"
446 + local priority='' message='' host='' port='' prefix=''
447 + local temp1='' temp2=''
448 +
449 + [[ "${SEND_SYSLOG}" == "YES" ]] || return 1
450 +
451 + if [[ "${status}" == "CRITICAL" ]] ; then
452 + level='crit'
453 + elif [[ "${status}" == "WARNING" ]] ; then
454 + level='warning'
455 + fi
456 +
457 + for target in ${targets} ; do
458 + priority="${facility}.${level}"
459 + message=''
460 + host=''
461 + port=''
462 + prefix=''
463 + temp1=''
464 + temp2=''
465 +
466 + prefix=$(echo ${target} | cut -d '/' -f 2)
467 + temp1=$(echo ${target} | cut -d '/' -f 1)
468 +
469 + if [[ ${prefix} != ${temp1} ]] ; then
470 + if (echo ${temp1} | grep -q '@' ) ; then
471 + temp2=$(echo ${temp1} | cut -d '@' -f 1)
472 + host=$(echo ${temp1} | cut -d '@' -f 2)
473 +
474 + if [ ${temp2} != ${host} ] ; then
475 + priority=${temp2}
476 + fi
477 +
478 + port=$(echo ${host} | rev | cut -d ':' -f 1 | rev)
479 +
480 + if ( echo ${host} | grep -E -q '\[.*\]' ) ; then
481 + if ( echo ${port} | grep -q ']' ) ; then
482 + port=''
483 + else
484 + host=$(echo ${host} | rev | cut -d ':' -f 2- | rev)
485 + fi
486 + else
487 + if [ ${port} = ${host} ] ; then
488 + port=''
489 + else
490 + host=$(echo ${host} | cut -d ':' -f 1)
491 + fi
492 + fi
493 + else
494 + priority=${temp1}
495 + fi
496 + fi
497 +
498 + # message="${prefix} ${status} on ${host} at ${date}: ${chart} ${value_string}"
499 +
500 + message="${prefix} ${status}: ${chart} ${value_string}"
501 +
502 + if [ ${host} ] ; then
503 + logger_options="${logger_options} -n ${host}"
504 + if [ ${port} ] ; then
505 + logger_options="${logger_options} -P ${port}"
506 + fi
507 + fi
508 +
509 + ${logger} -p ${priority} ${logger_options} "${message}"
510 + done
511 +
512 + return $?
513 +}
514 +
515 +
516 +# -----------------------------------------------------------------------------
517 +# prepare the content of the notification
518 +
519 +# the url to send the user on click
520 +urlencode "${host}" >/dev/null; url_host="${REPLY}"
521 +urlencode "${chart}" >/dev/null; url_chart="${REPLY}"
522 +urlencode "${family}" >/dev/null; url_family="${REPLY}"
523 +urlencode "${name}" >/dev/null; url_name="${REPLY}"
524 +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}"
525 +
526 +# the severity of the alarm
527 +severity="${status}"
528 +
529 +# the time the alarm was raised
530 +duration4human ${duration} >/dev/null; duration_txt="${REPLY}"
531 +duration4human ${non_clear_duration} >/dev/null; non_clear_duration_txt="${REPLY}"
532 +raised_for="(was ${old_status} for ${duration_txt})"
533 +
534 +# the key status message
535 +status_message="status unknown"
536 +
537 +# the color of the alarm
538 +color="grey"
539 +
540 +# the alarm value
541 +alarm="${name//_/ } = ${value_string}"
542 +
543 +# the image of the alarm
544 +image="${images_base_url}/images/seo-performance-128.png"
545 +
546 +# prepare the title based on status
547 +case "${status}" in
548 + CRITICAL)
549 + image="${images_base_url}/images/alert-128-red.png"
550 + status_message="is critical"
551 + color="#ca414b"
552 + ;;
553 +
554 + WARNING)
555 + image="${images_base_url}/images/alert-128-orange.png"
556 + status_message="needs attention"
557 + color="#ffc107"
558 + ;;
559 +
560 + CLEAR)
561 + image="${images_base_url}/images/check-mark-2-128-green.png"
562 + status_message="recovered"
563 + color="#77ca6d"
564 + ;;
565 +esac
566 +
567 +if [ "${status}" = "CLEAR" ]
568 +then
569 + severity="Recovered from ${old_status}"
570 + if [ ${non_clear_duration} -gt ${duration} ]
571 + then
572 + raised_for="(alarm was raised for ${non_clear_duration_txt})"
573 + fi
574 +
575 + # don't show the value when the status is CLEAR
576 + # for certain alarms, this value might not have any meaning
577 + alarm="${name//_/ } ${raised_for}"
578 +
579 +elif [ "${old_status}" = "WARNING" -a "${status}" = "CRITICAL" ]
580 +then
581 + severity="Escalated to ${status}"
582 + if [ ${non_clear_duration} -gt ${duration} ]
583 + then
584 + raised_for="(alarm is raised for ${non_clear_duration_txt})"
585 + fi
586 +
587 +elif [ "${old_status}" = "CRITICAL" -a "${status}" = "WARNING" ]
588 +then
589 + severity="Demoted to ${status}"
590 + if [ ${non_clear_duration} -gt ${duration} ]
591 + then
592 + raised_for="(alarm is raised for ${non_clear_duration_txt})"
593 + fi
594 +
595 +else
596 + raised_for=
597 +fi
598 +
599 +# prepare HTML versions of elements
600 +info_html=
601 +[ ! -z "${info}" ] && info_html=" <small><br/>${info}</small>"
602 +
603 +raised_for_html=
604 +[ ! -z "${raised_for}" ] && raised_for_html="<br/><small>${raised_for}</small>"
605 +
606 +
607 +# -----------------------------------------------------------------------------
608 +# send the syslog message
609 +
610 +send_syslog ${to_syslog}
611 +
612 +SENT_SYSLOG=$?
613 +
614 +# -----------------------------------------------------------------------------
615 +# send the email
616 +
617 +send_email <<EOF
618 +To: ${to_email}
619 +Subject: ${host} ${status_message} - ${name//_/ } - ${chart}
620 +MIME-Version: 1.0
621 +Content-Type: multipart/alternative; boundary="multipart-boundary"
622 +
623 +This is a MIME-encoded multipart message
624 +
625 +--multipart-boundary
626 +Content-Type: text/plain; encoding=${EMAIL_CHARSET}
627 +Content-Disposition: inline
628 +Content-Transfer-Encoding: 8bit
629 +
630 +${host} ${status_message}
631 +
632 +${alarm} ${info}
633 +${raised_for}
634 +
635 +Chart : ${chart}
636 +Family : ${family}
637 +Severity: ${severity}
638 +URL : ${goto_url}
639 +Source : ${src}
640 +Date : ${date}
641 +Value : ${value_string}
642 +Notification generated on ${this_host}
643 +
644 +--multipart-boundary
645 +Content-Type: text/html; encoding=${EMAIL_CHARSET}
646 +Content-Disposition: inline
647 +Content-Transfer-Encoding: 8bit
648 +
649 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
650 +<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;">
651 +<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;">
652 +<table>
653 + <tbody>
654 + <tr>
655 + <td style="vertical-align: top;" valign="top"></td>
656 + <td width="700" style="vertical-align: top; display: block !important; max-width: 700px !important; clear: both !important; margin: 0 auto; padding: 0;" valign="top">
657 + <div style="max-width: 700px; display: block; margin: 0 auto; padding: 20px;">
658 + <table width="100%" cellpadding="0" cellspacing="0" style="background: #fff; border: 1px solid #e9e9e9;">
659 + <tbody>
660 + <tr>
661 + <td bgcolor="#eee" style="padding: 5px 20px 5px 20px; background-color: #eee;">
662 + <div style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 20px; color: #777; font-weight: bold;">netdata notification</div>
663 + </td>
664 + </tr>
665 + <tr>
666 + <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">
667 + <h1 style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-weight: 400; margin: 0;">${host} ${status_message}</h1>
668 + </td>
669 + </tr>
670 + <tr>
671 + <td style="vertical-align: top;" valign="top">
672 + <div style="margin: 0; padding: 20px; max-width: 700px;">
673 + <table width="100%" cellpadding="0" cellspacing="0" style="max-width:700px">
674 + <tbody>
675 + <tr>
676 + <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">
677 + <span>${chart}</span>
678 + <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Chart</span>
679 + </td>
680 + </tr>
681 + <tr>
682 + <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">
683 + <span>${value_string}</span>
684 + <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Value</span>
685 + </td>
686 + </tr>
687 + <tr style="margin: 0; padding: 0;">
688 + <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">
689 + <span><b>${alarm}</b>${info_html}</span>
690 + <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Alarm</span>
691 + </td>
692 + </tr>
693 + <tr>
694 + <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">
695 + <span>${family}</span>
696 + <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Family</span>
697 + </td>
698 + </tr>
699 + <tr style="margin: 0; padding: 0;">
700 + <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">
701 + <span>${severity}</span>
702 + <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Severity</span>
703 + </td>
704 + </tr>
705 + <tr style="margin: 0; padding: 0;">
706 + <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>
707 + <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>
708 + </td>
709 + </tr>
710 + <tr style="margin: 0; padding: 0;">
711 + <td style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;">
712 + <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>
713 + </td>
714 + </tr>
715 + <tr style="text-align: center; margin: 0; padding: 0;">
716 + <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)
717 + </td>
718 + </tr>
719 + <tr style="text-align: center; margin: 0; padding: 0;">
720 + <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
721 + <a href="https://mynetdata.io/" target="_blank">netdata</a>, the real-time performance and health monitoring, on <code>${this_host}</code>.
722 + </td>
723 + </tr>
724 + </tbody>
725 + </table>
726 + </div>
727 + </td>
728 + </tr>
729 + </tbody>
730 + </table>
731 + </div>
732 + </td>
733 + </tr>
734 + </tbody>
735 +</table>
736 +</body>
737 +</html>
738 +--multipart-boundary--
739 +EOF
740 +
741 +SENT_EMAIL=$?
742 +
743 +# -----------------------------------------------------------------------------
744 +# let netdata know
745 +
746 +if [ ${SENT_EMAIL} -eq 0 \
747 + -o ${SENT_SYSLOG} -eq 0 \
748 + ]
749 + then
750 + # we did send something
751 + exit 0
752 +fi
753 +
754 +# we did not send anything
755 +exit 1
contrib/sles11/netdata-alarms-bash3.patch new
+10
@@ -0,0 +1,10 @@
1 +--- system/netdata.conf.orig 2018-05-10 19:44:49.000000000 +0300
2 ++++ system/netdata.conf 2018-05-10 19:45:14.000000000 +0300
3 +@@ -22,3 +22,7 @@
4 + [web]
5 + web files owner = root
6 + web files group = netdata
7 ++
8 ++[health]
9 ++ # script for sles 11, mail notifications only
10 ++ script to execute on alarm = /usr/lib64/netdata/plugins.d/alarm-notify.bash3.sh
contrib/sles11/netdata-automake-no-dist-xz.patch new
+13
@@ -0,0 +1,13 @@
1 +diff -u netdata-1.6.0.orig/Makefile.am netdata-1.6.0/Makefile.am
2 +--- netdata-1.6.0.orig/Makefile.am 2017-03-20 19:32:47.000000000 +0100
3 ++++ netdata-1.6.0/Makefile.am 2017-06-25 23:46:14.403426661 +0200
4 +@@ -1,7 +1,7 @@
5 + #
6 + # Copyright (C) 2015 Alon Bar-Lev <alon.barlev@gmail.com>
7 + #
8 +-AUTOMAKE_OPTIONS=foreign dist-bzip2 dist-xz 1.10
9 ++AUTOMAKE_OPTIONS=foreign dist-bzip2 1.10
10 + ACLOCAL_AMFLAGS = -I m4
11 +
12 + MAINTAINERCLEANFILES= \
13 +
contrib/sles11/netdata-python-plugin-sles11.patch new
+28
@@ -0,0 +1,28 @@
1 +diff -u netdata-1.10.0.orig/plugins.d/python.d.plugin netdata-1.10.0/plugins.d/python.d.plugin
2 +--- netdata-1.10.0.orig/plugins.d/python.d.plugin 2018-05-08 20:01:40.000000000 +0300
3 ++++ netdata-1.10.0/plugins.d/python.d.plugin 2018-05-08 20:06:57.000000000 +0300
4 +@@ -15,10 +15,8 @@
5 + from sys import version_info, argv
6 + from time import sleep
7 +
8 +-try:
9 +- from time import monotonic as time
10 +-except ImportError:
11 +- from time import time
12 ++# from time import monotonic as time
13 ++from time import time
14 +
15 + PY_VERSION = version_info[:2]
16 + PLUGIN_CONFIG_DIR = os.getenv('NETDATA_CONFIG_DIR', os.path.dirname(__file__) + '/../../../../etc/netdata') + '/'
17 +@@ -32,10 +30,7 @@
18 + from bases.loggers import PythonDLogger
19 + from bases.collection import setdefault_values, run_and_exit
20 +
21 +-try:
22 +- from collections import OrderedDict
23 +-except ImportError:
24 +- from third_party.ordereddict import OrderedDict
25 ++from ordereddict import OrderedDict
26 +
27 + BASE_CONFIG = {'update_every': os.getenv('NETDATA_UPDATE_EVERY', 1),
28 + 'retries': 60,
contrib/sles11/netdata.init new
+65
@@ -0,0 +1,65 @@
1 +#!/bin/bash
2 +#
3 +### BEGIN INIT INFO
4 +# Provides: netdata
5 +# Required-Start: $all
6 +# Should-Start:
7 +# Required-Stop: $all
8 +# Should-Stop:
9 +# Default-Start: 2 3 5
10 +# Default-Stop:
11 +# Short-Description: Start and stop the netdata real-time monitoring server daemon
12 +# Description: Controls the main netdata monitoring server daemon "netdata".
13 +### END INIT INFO
14 +
15 +DAEMON="netdata"
16 +DAEMON_BIN="/usr/sbin/${DAEMON}"
17 +DAEMON_PID="/var/run/${DAEMON}.pid"
18 +DAEMON_ARGS=""
19 +
20 +. /etc/rc.status
21 +rc_reset
22 +
23 +if [ ! -x $DAEMON_BIN ]; then
24 + echo -n >&2 "${DAEMON} binary is not installed. "
25 + rc_status -s
26 + exit 5
27 +fi
28 +
29 +case "$1" in
30 + start)
31 + echo -n "Starting $DAEMON"
32 + /sbin/startproc $DAEMON_BIN $DAEMON_ARGS
33 + rc_status -v
34 + ;;
35 +
36 + stop)
37 + echo -n "Stopping $DAEMON"
38 + /sbin/killproc $DAEMON_BIN
39 + rc_status -v
40 + ;;
41 +
42 + reload)
43 + # netdata: HUP reopen log files, USR1 save DB, USR2 reload health config
44 + echo -n "Reloading $DAEMON config"
45 + /sbin/killproc -USR2 $DAEMON_BIN
46 + ;;
47 +
48 + restart)
49 + $0 stop
50 + $0 start
51 + ;;
52 +
53 + status)
54 + echo -n "Checking $DAEMON"
55 + /sbin/checkproc $DAEMON_BIN
56 + rc_status -v
57 + ;;
58 +
59 + *)
60 + echo "Usage: $0 {start|stop|status|reload|restart}"
61 + exit 1
62 + ;;
63 +
64 +esac
65 +rc_exit