From 73608f86b4c10f72fff991fbf9bfa1a802c2d95c Mon Sep 17 00:00:00 2001 From: Costa Tsaousis Date: Thu, 27 Sep 2018 20:37:52 +0300 Subject: stock configs in /usr/lib/netdata (#4283) * makefiles install configs in /usr/lib/netdata/conf.d; #4182 * stock health config in /usr/lib/netdata/conf.d/health.d * unit test path concatenation * simplified health file management * use stream.conf from stock config if it does not exist in /etc/netdata * indicate loading of user config in function call * load netdata.conf from stock dir if not found in /etc/netdata * added NETDATA_USER_CONFIG_DIR * provide defaults before loading config * charts.d uses stock files * fping now uses the stock config files * tc-qos-helper.sh now uses stock configs * cgroup-name.sh now uses stock configs too * simplified cgroup-name.sh for user and stock config * alarm-notify.sh uses stock configs too * simplified fping plugin configs loading * simplified tc-qos-helper.sh configs loading * added error handling to charts.d.plugin * apps.plugin used stock configs * generalized recursive double-directory configs loading * statsd uses stock configs * node.d.plugin uses stock configs * compile-time decision of netdata default paths for all files * makeself cleans up old stock config files from user configuration directories * fixed makeself typo * netdata-installer.sh removes stock files from user configuration directories * python.d.plugin user/stock configs update * cleanup stock config files from /etc/netdata, only once * python.d.plugin log loaded files * fix permissions of stock config files and provide an "orig" link for quick access * create help link on stock configs migration for static installations * create user config directories * example statsd synthetic charts now state they are examples * updated configs.signatures * spec file * fixes in spec file * fix typo * install netdata after cleaning up stock configs from /etc/netdata * python.d: add cpuidle stock conf --- .gitignore | 8 + CMakeLists.txt | 2 +- build/subst.inc | 3 + conf.d/Makefile.am | 14 +- conf.d/python.d/cpuidle.conf | 40 + conf.d/statsd.d/example.conf | 18 +- configs.signatures | 1 + configure.ac | 1 + makeself/install-or-update.sh | 97 +- makeself/jobs/70-netdata-git.install.sh | 7 - makeself/jobs/99-makeself.install.sh | 21 - netdata-installer.sh | 181 +-- netdata.spec.in | 24 +- plugins.d/Makefile.am | 23 + plugins.d/alarm-notify.sh | 2371 ------------------------------ plugins.d/alarm-notify.sh.in | 2378 +++++++++++++++++++++++++++++++ plugins.d/cgroup-name.sh | 190 --- plugins.d/cgroup-name.sh.in | 196 +++ plugins.d/charts.d.plugin | 714 ---------- plugins.d/charts.d.plugin.in | 743 ++++++++++ plugins.d/fping.plugin | 189 --- plugins.d/fping.plugin.in | 200 +++ plugins.d/node.d.plugin | 294 ---- plugins.d/node.d.plugin.in | 303 ++++ plugins.d/python.d.plugin | 403 ------ plugins.d/python.d.plugin.in | 427 ++++++ plugins.d/tc-qos-helper.sh | 308 ---- plugins.d/tc-qos-helper.sh.in | 315 ++++ src/Makefile.am | 1 + src/apps_plugin.c | 38 +- src/common.c | 209 ++- src/common.h | 10 +- src/health.c | 15 +- src/health.h | 7 +- src/health_config.c | 243 ++-- src/main.c | 79 +- src/rrdhost.c | 2 +- src/statsd.c | 110 +- src/unit_test.c | 42 + 39 files changed, 5301 insertions(+), 4926 deletions(-) create mode 100644 conf.d/python.d/cpuidle.conf delete mode 100755 plugins.d/alarm-notify.sh create mode 100755 plugins.d/alarm-notify.sh.in delete mode 100755 plugins.d/cgroup-name.sh create mode 100755 plugins.d/cgroup-name.sh.in delete mode 100755 plugins.d/charts.d.plugin create mode 100755 plugins.d/charts.d.plugin.in delete mode 100755 plugins.d/fping.plugin create mode 100755 plugins.d/fping.plugin.in delete mode 100755 plugins.d/node.d.plugin create mode 100755 plugins.d/node.d.plugin.in delete mode 100755 plugins.d/python.d.plugin create mode 100755 plugins.d/python.d.plugin.in delete mode 100755 plugins.d/tc-qos-helper.sh create mode 100755 plugins.d/tc-qos-helper.sh.in diff --git a/.gitignore b/.gitignore index aba1c3d5f0..da1f165ae6 100644 --- a/.gitignore +++ b/.gitignore @@ -75,6 +75,14 @@ system/netdata.service system/netdata.plist system/netdata-freebsd +plugins.d/alarm-notify.sh +plugins.d/cgroup-name.sh +plugins.d/charts.d.plugin +plugins.d/fping.plugin +plugins.d/node.d.plugin +plugins.d/python.d.plugin +plugins.d/tc-qos-helper.sh + # installer generated files netdata-uninstaller.sh netdata-updater.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 927495be61..5b91a748bc 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -250,7 +250,7 @@ set(CGROUP_NETWORK_SOURCE_FILES include_directories(AFTER .) -add_definitions(-DHAVE_CONFIG_H -DCACHE_DIR="/var/cache/netdata" -DCONFIG_DIR="/etc/netdata" -DLOG_DIR="/var/log/netdata" -DPLUGINS_DIR="/usr/libexec/netdata" -DWEB_DIR="/usr/share/netdata" -DVARLIB_DIR="/var/lib/netdata") +add_definitions(-DHAVE_CONFIG_H -DCACHE_DIR="/var/cache/netdata" -DCONFIG_DIR="/etc/netdata" -DLIBCONFIG_DIR="/usr/lib/netdata/conf.d" -DLOG_DIR="/var/log/netdata" -DPLUGINS_DIR="/usr/libexec/netdata" -DWEB_DIR="/usr/share/netdata" -DVARLIB_DIR="/var/lib/netdata") add_executable(netdata ${NETDATA_COMMON_FILES} ${NETDATA_LINUX_FILES}) target_link_libraries (netdata m z uuid mnl netfilter_acct ${CMAKE_THREAD_LIBS_INIT}) diff --git a/build/subst.inc b/build/subst.inc index 9682cf882f..8f9ac05518 100644 --- a/build/subst.inc +++ b/build/subst.inc @@ -4,6 +4,9 @@ -e 's#[@]sbindir_POST@#$(sbindir)#g' \ -e 's#[@]sysconfdir_POST@#$(sysconfdir)#g' \ -e 's#[@]pythondir_POST@#$(pythondir)#g' \ + -e 's#[@]configdir_POST@#$(configdir)#g' \ + -e 's#[@]libconfigdir_POST@#$(libconfigdir)#g' \ + -e 's#[@]cachedir_POST@#$(cachedir)#g' \ $< > $@.tmp; then \ mv "$@.tmp" "$@"; \ else \ diff --git a/conf.d/Makefile.am b/conf.d/Makefile.am index cc60ff1dd9..817d366d27 100644 --- a/conf.d/Makefile.am +++ b/conf.d/Makefile.am @@ -4,7 +4,7 @@ # MAINTAINERCLEANFILES= $(srcdir)/Makefile.in -dist_config_DATA = \ +dist_libconfig_DATA = \ apps_groups.conf \ charts.d.conf \ fping.conf \ @@ -15,7 +15,7 @@ dist_config_DATA = \ stream.conf \ $(NULL) -nodeconfigdir=$(configdir)/node.d +nodeconfigdir=$(libconfigdir)/node.d dist_nodeconfig_DATA = \ node.d/README.md \ node.d/fronius.conf.md \ @@ -25,7 +25,7 @@ dist_nodeconfig_DATA = \ node.d/stiebeleltron.conf.md \ $(NULL) -pythonconfigdir=$(configdir)/python.d +pythonconfigdir=$(libconfigdir)/python.d dist_pythonconfig_DATA = \ python.d/apache.conf \ python.d/beanstalk.conf \ @@ -34,6 +34,7 @@ dist_pythonconfig_DATA = \ python.d/ceph.conf \ python.d/chrony.conf \ python.d/couchdb.conf \ + python.d/cpuidle.conf \ python.d/cpufreq.conf \ python.d/dns_query_time.conf \ python.d/dnsdist.conf \ @@ -88,8 +89,7 @@ dist_pythonconfig_DATA = \ python.d/web_log.conf \ $(NULL) -healthconfigdir=$(configdir)/health.d - +healthconfigdir=$(libconfigdir)/health.d dist_healthconfig_DATA = \ health.d/apache.conf \ health.d/apcupsd.conf \ @@ -148,7 +148,7 @@ dist_healthconfig_DATA = \ health.d/zfs.conf \ $(NULL) -chartsconfigdir=$(configdir)/charts.d +chartsconfigdir=$(libconfigdir)/charts.d dist_chartsconfig_DATA = \ charts.d/apache.conf \ charts.d/apcupsd.conf \ @@ -172,7 +172,7 @@ dist_chartsconfig_DATA = \ charts.d/squid.conf \ $(NULL) -statsdconfigdir=$(configdir)/statsd.d +statsdconfigdir=$(libconfigdir)/statsd.d dist_statsdconfig_DATA = \ statsd.d/example.conf \ $(NULL) diff --git a/conf.d/python.d/cpuidle.conf b/conf.d/python.d/cpuidle.conf new file mode 100644 index 0000000000..bc276fcd2a --- /dev/null +++ b/conf.d/python.d/cpuidle.conf @@ -0,0 +1,40 @@ +# netdata python.d.plugin configuration for cpuidle +# +# This file is in YaML format. Generally the format is: +# +# name: value +# +# There are 2 sections: +# - global variables +# - one or more JOBS +# +# JOBS allow you to collect values from multiple sources. +# Each source will have its own set of charts. +# +# JOB parameters have to be indented (using spaces only, example below). + +# ---------------------------------------------------------------------- +# Global Variables +# These variables set the defaults for all JOBs, however each JOB +# may define its own, overriding the defaults. + +# update_every sets the default data collection frequency. +# If unset, the python.d.plugin default is used. +# update_every: 1 + +# priority controls the order of charts at the netdata dashboard. +# Lower numbers move the charts towards the top of the page. +# If unset, the default for python.d.plugin is used. +# priority: 60000 + +# retries sets the number of retries to be made in case of failures. +# If unset, the default for python.d.plugin is used. +# Attempts to restore the service are made once every update_every +# and only if the module has collected values in the past. +# retries: 60 + +# autodetection_retry sets the job re-check interval in seconds. +# The job is not deleted if check fails. +# Attempts to start the job are made once every autodetection_retry. +# This feature is disabled by default. +# autodetection_retry: 0 diff --git a/conf.d/statsd.d/example.conf b/conf.d/statsd.d/example.conf index 0af9dd27dd..f7c12b4ab3 100644 --- a/conf.d/statsd.d/example.conf +++ b/conf.d/statsd.d/example.conf @@ -7,10 +7,10 @@ # give a name for this app # this controls the main menu on the dashboard # and will be the prefix for all charts of the app - name = myapp + name = myexampleapp # match all the metrics of the app - metrics = myapp.* + metrics = myexampleapp.* # shall private charts of these metrics be created? private charts = no @@ -29,10 +29,10 @@ # create a chart -# this is its id - the chart will be named myapp.mychart -[mychart] +# this is its id - the chart will be named myexampleapp.myexamplechart +[myexamplechart] # a name for the chart, similar to the id (2 names for each chart) - name = mychart + name = myexamplechart # the chart title title = my chart title @@ -57,9 +57,9 @@ # events = the number of events for this metric # last = the last value collected # all the others are only valid for histograms and timers - dimension = myapp.metric1 avg average 1 1 - dimension = myapp.metric1 lower min 1 1 - dimension = myapp.metric1 upper max 1 1 - dimension = myapp.metric2 other last 1 1 + dimension = myexampleapp.metric1 avg average 1 1 + dimension = myexampleapp.metric1 lower min 1 1 + dimension = myexampleapp.metric1 upper max 1 1 + dimension = myexampleapp.metric2 other last 1 1 # You can add as many charts as needed diff --git a/configs.signatures b/configs.signatures index 3e546a953f..c084de8cff 100644 --- a/configs.signatures +++ b/configs.signatures @@ -65,6 +65,7 @@ declare -A configs_signatures=( ['111ead4b350593dd69b6f7ac0307b49b']='python.d/httpcheck.conf' ['12a4c7803ae79506a14ea784fea60dce']='health.d/net.conf' ['12d27b9f4d1696c2d49a77ed71d68e6f']='python.d/w1sensor.conf' + ['12e57bea1127933a4fe49ce2e9674f4d']='statsd.d/example.conf' ['13141998a5d71308d9c119834c27bfd3']='python.d.conf' ['13ccf65fd879795f0fcea89ade27c2d0']='health.d/swap.conf' ['13e861a3d2f3075de883994ab54df658']='health.d/megacli.conf' diff --git a/configure.ac b/configure.ac index 9c98adfd67..b60419da01 100644 --- a/configure.ac +++ b/configure.ac @@ -493,6 +493,7 @@ AC_SUBST([chartsdir], ["\$(libexecdir)/netdata/charts.d"]) AC_SUBST([nodedir], ["\$(libexecdir)/netdata/node.d"]) AC_SUBST([pythondir], ["\$(libexecdir)/netdata/python.d"]) AC_SUBST([configdir], ["\$(sysconfdir)/netdata"]) +AC_SUBST([libconfigdir], ["\$(libdir)/netdata/conf.d"]) AC_SUBST([logdir], ["\$(localstatedir)/log/netdata"]) AC_SUBST([pluginsdir], ["\$(libexecdir)/netdata/plugins.d"]) AC_SUBST([webdir]) diff --git a/makeself/install-or-update.sh b/makeself/install-or-update.sh index 6ff03acc09..ce9ca62023 100755 --- a/makeself/install-or-update.sh +++ b/makeself/install-or-update.sh @@ -24,62 +24,49 @@ do shift done +deleted_stock_configs=0 +if [ ! -f "etc/netdata/.installer-cleanup-of-stock-configs-done" ] +then -# ----------------------------------------------------------------------------- -progress "Checking new configuration files" - -declare -A configs_signatures=() -. system/configs.signatures - -if [ ! -d etc/netdata ] - then - run mkdir -p etc/netdata -fi - -md5sum="$(which md5sum 2>/dev/null || command -v md5sum 2>/dev/null || command -v md5 2>/dev/null)" -for x in $(find etc.new -type f) -do - # find it relative filename - f="${x/etc.new\/netdata\//}" - t="${x/etc.new\//etc\/}" - d=$(dirname "${t}") + # ----------------------------------------------------------------------------- + progress "Deleting stock configuration files from user configuration directory" - #echo >&2 "x: ${x}" - #echo >&2 "t: ${t}" - #echo >&2 "d: ${d}" + declare -A configs_signatures=() + source "system/configs.signatures" - if [ ! -d "${d}" ] + if [ ! -d etc/netdata ] then - run mkdir -p "${d}" + run mkdir -p etc/netdata fi - if [ ! -f "${t}" ] - then - run cp "${x}" "${t}" - continue - fi + md5sum="$(which md5sum 2>/dev/null || command -v md5sum 2>/dev/null || command -v md5 2>/dev/null)" + for x in $(find etc -type f) + do + # find it relative filename + f="${x/etc\/netdata\//}" - if [ ! -z "${md5sum}" ] - then - # find the checksum of the existing file - md5="$(cat "${t}" | ${md5sum} | cut -d ' ' -f 1)" - #echo >&2 "md5: ${md5}" + # find the stock filename + t="${f/.conf.old/.conf}" + t="${t/.conf.orig/.conf}" - # check if it matches - if [ "${configs_signatures[${md5}]}" = "${f}" ] + if [ ! -z "${md5sum}" ] then - run cp "${x}" "${t}" + # find the checksum of the existing file + md5="$( ${md5sum} <"${x}" | cut -d ' ' -f 1)" + #echo >&2 "md5: ${md5}" + + # check if it matches + if [ "${configs_signatures[${md5}]}" = "${t}" ] + then + # it matches the default + run rm -f "${x}" + deleted_stock_configs=$(( deleted_stock_configs + 1 )) + fi fi - fi - - if ! [[ "${x}" =~ .*\.orig ]] - then - run mv "${x}" "${t}.orig" - fi -done - -run rm -rf etc.new + done + touch "etc/netdata/.installer-cleanup-of-stock-configs-done" +fi # ----------------------------------------------------------------------------- progress "Add user netdata to required user groups" @@ -166,6 +153,26 @@ dir_should_be_link . var/lib/netdata netdata-dbs dir_should_be_link . var/cache/netdata netdata-metrics dir_should_be_link . var/log/netdata netdata-logs +dir_should_be_link etc/netdata ../../usr/lib/netdata/conf.d orig + +if [ ${deleted_stock_configs} -gt 0 ] +then + dir_should_be_link etc/netdata ../../usr/lib/netdata/conf.d "000.-.USE.THE.orig.LINK.TO.COPY.AND.EDIT.STOCK.CONFIG.FILES" +fi + + +# ----------------------------------------------------------------------------- + +progress "create user config directories" + +for x in "python.d" "charts.d" "node.d" "health.d" "statsd.d" +do + if [ ! -d "etc/netdata/${x}" ] + then + run mkdir -p "etc/netdata/${x}" || exit 1 + fi +done + # ----------------------------------------------------------------------------- progress "fix permissions" diff --git a/makeself/jobs/70-netdata-git.install.sh b/makeself/jobs/70-netdata-git.install.sh index ca1143045e..cb28dd080f 100755 --- a/makeself/jobs/70-netdata-git.install.sh +++ b/makeself/jobs/70-netdata-git.install.sh @@ -13,13 +13,6 @@ else # export CFLAGS="-static -O1 -ggdb -Wall -Wextra -Wformat-signedness" fi -if [ ! -z "${NETDATA_INSTALL_PATH}" -a -d "${NETDATA_INSTALL_PATH}/etc" ] - then - # make sure we don't have an old etc path, so that the installer - # will install all files without examining changes - run mv "${NETDATA_INSTALL_PATH}/etc" "${NETDATA_INSTALL_PATH}/etc.new" -fi - run ./netdata-installer.sh --install "${NETDATA_INSTALL_PARENT}" \ --dont-wait \ --dont-start-it \ diff --git a/makeself/jobs/99-makeself.install.sh b/makeself/jobs/99-makeself.install.sh index ba1c46fb5d..0b828257d5 100755 --- a/makeself/jobs/99-makeself.install.sh +++ b/makeself/jobs/99-makeself.install.sh @@ -72,27 +72,6 @@ EOF run chmod 755 "${NETDATA_INSTALL_PATH}/bin/netdata" -# ----------------------------------------------------------------------------- -# move etc to protect the destination when unpacked - -if [ ! -z "${NETDATA_INSTALL_PATH}" -a -d "${NETDATA_INSTALL_PATH}/etc" ] - then - if [ -d "${NETDATA_INSTALL_PATH}/etc.new" ] - then - run rm -rf "${NETDATA_INSTALL_PATH}/etc.new" || exit 1 - fi - - run mv "${NETDATA_INSTALL_PATH}/etc" \ - "${NETDATA_INSTALL_PATH}/etc.new" || exit 1 - - if [ -f "${NETDATA_INSTALL_PATH}/etc.new/netdata/netdata.conf" ] - then - # delete the generated netdata.conf, so that the static installer will generate a new one - run rm "${NETDATA_INSTALL_PATH}/etc.new/netdata/netdata.conf" - fi -fi - - # ----------------------------------------------------------------------------- # remove the links to allow untaring the archive diff --git a/netdata-installer.sh b/netdata-installer.sh index 738463ee00..0484cb35b6 100755 --- a/netdata-installer.sh +++ b/netdata-installer.sh @@ -492,6 +492,7 @@ progress "Cleanup compilation directory" [ -f src/netdata ] && run make clean + # ----------------------------------------------------------------------------- progress "Compile netdata" @@ -543,79 +544,76 @@ if [ -d "${NETDATA_PREFIX}/etc/netdata" ] fi # ----------------------------------------------------------------------------- -progress "Backup existing netdata configuration before installing it" - -if [ "${BASH_VERSINFO[0]}" -ge "4" ] +deleted_stock_configs=0 +if [ ! -f "${NETDATA_PREFIX}/etc/netdata/.installer-cleanup-of-stock-configs-done" ] then - declare -A configs_signatures=() - if [ -f "configs.signatures" ] - then - source "configs.signatures" || echo >&2 "ERROR: Failed to load configs.signatures !" - fi -fi -config_signature_matches() { - local md5="${1}" file="${2}" + progress "Backup existing netdata configuration before installing it" if [ "${BASH_VERSINFO[0]}" -ge "4" ] - then - [ "${configs_signatures[${md5}]}" = "${file}" ] && return 0 - return 1 + then + declare -A configs_signatures=() + if [ -f "configs.signatures" ] + then + source "configs.signatures" || echo >&2 "ERROR: Failed to load configs.signatures !" + fi fi - if [ -f "configs.signatures" ] - then - grep "\['${md5}'\]='${file}'" "configs.signatures" >/dev/null - return $? - fi + config_signature_matches() { + local md5="${1}" file="${2}" - return 1 -} + if [ "${BASH_VERSINFO[0]}" -ge "4" ] + then + [ "${configs_signatures[${md5}]}" = "${file}" ] && return 0 + return 1 + fi -# backup user configurations -installer_backup_suffix="${PID}.${RANDOM}" -for x in $(find -L "${NETDATA_PREFIX}/etc/netdata" -name '*.conf' -type f) -do - if [ -f "${x}" ] - then - # make a backup of the configuration file - cp -p "${x}" "${x}.old" + if [ -f "configs.signatures" ] + then + grep "\['${md5}'\]='${file}'" "configs.signatures" >/dev/null + return $? + fi - if [ -z "${md5sum}" -o ! -x "${md5sum}" ] + return 1 + } + + # clean up stock config files from the user configuration directory + for x in $(find -L "${NETDATA_PREFIX}/etc/netdata" -type f) + do + if [ -f "${x}" ] then - # we don't have md5sum - keep it - echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RET}is not known to distribution${TPUT_RESET}. Keeping it." - run cp -a "${x}" "${x}.installer_backup.${installer_backup_suffix}" - else # find it relative filename - f="${x/*\/etc\/netdata\//}" - - # find its checksum - md5="$(cat "${x}" | ${md5sum} | cut -d ' ' -f 1)" + f="${x/${NETDATA_PREFIX}\/etc\/netdata\//}" - # copy the original - if [ -f "conf.d/${f}" ] - then - cp "conf.d/${f}" "${x}.orig" - fi + # find the stock filename + t="${f/.conf.installer_backup.*/.conf}" + t="${t/.conf.old/.conf}" + t="${t/.conf.orig/.conf}" - if config_signature_matches "${md5}" "${f}" + if [ -z "${md5sum}" -o ! -x "${md5sum}" ] then - # it is a stock version - don't keep it - echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' is stock version." + # we don't have md5sum - keep it + echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RET}is not known to distribution${TPUT_RESET}. Keeping it." else - # edited by user - keep it - echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RED} has been edited by user${TPUT_RESET}. Keeping it." - run cp -a "${x}" "${x}.installer_backup.${installer_backup_suffix}" + # find its checksum + md5="$(${md5sum} <"${x}" | cut -d ' ' -f 1)" + + if config_signature_matches "${md5}" "${t}" + then + # it is a stock version - remove it + echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' is stock version of '${t}'." + run rm -f "${x}" + deleted_stock_configs=$(( deleted_stock_configs + 1 )) + else + # edited by user - keep it + echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RED} does not match stock of '${t}'${TPUT_RESET}. Keeping it." + fi fi fi + done - elif [ -f "${x}.installer_backup.${installer_backup_suffix}" ] - then - rm -f "${x}.installer_backup.${installer_backup_suffix}" - fi -done - + touch "${NETDATA_PREFIX}/etc/netdata/.installer-cleanup-of-stock-configs-done" +fi # ----------------------------------------------------------------------------- progress "Install netdata" @@ -623,19 +621,6 @@ progress "Install netdata" run make install || exit 1 -# ----------------------------------------------------------------------------- -progress "Restore user edited netdata configuration files" - -for x in $(find -L "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f) -do - if [ -f "${x}.installer_backup.${installer_backup_suffix}" ] - then - run cp -a "${x}.installer_backup.${installer_backup_suffix}" "${x}" && \ - run rm -f "${x}.installer_backup.${installer_backup_suffix}" - fi -done - - # ----------------------------------------------------------------------------- progress "Fix generated files permissions" @@ -709,28 +694,30 @@ NETDATA_LIB_DIR="$( config_option "global" "lib directory" "${NETDATA_PREFIX}/va NETDATA_CACHE_DIR="$( config_option "global" "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )" NETDATA_WEB_DIR="$( config_option "global" "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )" NETDATA_LOG_DIR="$( config_option "global" "log directory" "${NETDATA_PREFIX}/var/log/netdata" )" -NETDATA_CONF_DIR="$( config_option "global" "config directory" "${NETDATA_PREFIX}/etc/netdata" )" +NETDATA_USER_CONFIG_DIR="$( config_option "global" "config directory" "${NETDATA_PREFIX}/etc/netdata" )" +NETDATA_STOCK_CONFIG_DIR="$( config_option "global" "stock config directory" "${NETDATA_PREFIX}/usr/lib/netdata/conf.d" )" NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run" cat <&2 "Creating directory '${NETDATA_CONF_DIR}/${x}'" - run mkdir -p "${NETDATA_CONF_DIR}/${x}" || exit 1 + echo >&2 "Creating directory '${NETDATA_USER_CONFIG_DIR}/${x}'" + run mkdir -p "${NETDATA_USER_CONFIG_DIR}/${x}" || exit 1 + fi +done +run chown -R "${ROOT_USER}:${NETDATA_GROUP}" "${NETDATA_USER_CONFIG_DIR}" +run find "${NETDATA_USER_CONFIG_DIR}" -type f -exec chmod 0640 {} \; +run find "${NETDATA_USER_CONFIG_DIR}" -type d -exec chmod 0755 {} \; + +# --- stock conf dir ---- + +[ ! -d "${NETDATA_STOCK_CONFIG_DIR}" ] && mkdir -p "${NETDATA_STOCK_CONFIG_DIR}" + +helplink="000.-.USE.THE.orig.LINK.TO.COPY.AND.EDIT.STOCK.CONFIG.FILES" +[ ${deleted_stock_configs} -eq 0 ] && helplink="" +for link in "orig" "${helplink}" +do + if [ ! -z "${link}" ] + then + [ -L "${NETDATA_USER_CONFIG_DIR}/${link}" ] && run rm -f "${NETDATA_USER_CONFIG_DIR}/${link}" + run ln -s "${NETDATA_STOCK_CONFIG_DIR}" "${NETDATA_USER_CONFIG_DIR}/${link}" fi done -run chown -R "${ROOT_USER}:${NETDATA_GROUP}" "${NETDATA_CONF_DIR}" -run find "${NETDATA_CONF_DIR}" -type f -exec chmod 0640 {} \; -run find "${NETDATA_CONF_DIR}" -type d -exec chmod 0755 {} \; +run chown -R "${ROOT_USER}:${NETDATA_GROUP}" "${NETDATA_STOCK_CONFIG_DIR}" +run find "${NETDATA_STOCK_CONFIG_DIR}" -type f -exec chmod 0640 {} \; +run find "${NETDATA_STOCK_CONFIG_DIR}" -type d -exec chmod 0755 {} \; # --- web dir ---- diff --git a/netdata.spec.in b/netdata.spec.in index f948e495ff..379088fa11 100644 --- a/netdata.spec.in +++ b/netdata.spec.in @@ -181,17 +181,18 @@ rm -rf "${RPM_BUILD_ROOT}" %defattr(-,root,root) %dir %{_sysconfdir}/%{name} +%dir %{_libdir}/%{name} -%config(noreplace) %{_sysconfdir}/%{name}/*.conf -%config(noreplace) %{_sysconfdir}/%{name}/charts.d/*.conf -%config(noreplace) %{_sysconfdir}/%{name}/health.d/*.conf -#%%config(noreplace) %{_sysconfdir}/%{name}/node.d/*.conf -%config(noreplace) %{_sysconfdir}/%{name}/python.d/*.conf -%config(noreplace) %{_sysconfdir}/%{name}/statsd.d/*.conf -%config(noreplace) %{_sysconfdir}/logrotate.d/%{name} +%config %{_libdir}/%{name}/*.conf +%config %{_libdir}/%{name}/charts.d/*.conf +%config %{_libdir}/%{name}/health.d/*.conf +%config %{_libdir}/%{name}/node.d/*.conf +%config %{_libdir}/%{name}/python.d/*.conf +%config %{_libdir}/%{name}/statsd.d/*.conf +%config %{_sysconfdir}/logrotate.d/%{name} # To be eventually moved to %%_defaultdocdir -%{_sysconfdir}/%{name}/node.d/*.md +%{_libdir}/%{name}/node.d/*.md %{_libexecdir}/%{name} %{_sbindir}/%{name} @@ -215,9 +216,16 @@ rm -rf "${RPM_BUILD_ROOT}" %dir %{_datadir}/%{name} %dir %{_sysconfdir}/%{name}/health.d +%dir %{_libdir}/%{name}/health.d %dir %{_sysconfdir}/%{name}/python.d +%dir %{_libdir}/%{name}/python.d %dir %{_sysconfdir}/%{name}/charts.d +%dir %{_libdir}/%{name}/charts.d %dir %{_sysconfdir}/%{name}/node.d +%dir %{_libdir}/%{name}/node.d +%dir %{_sysconfdir}/%{name}/statsd.d +%dir %{_libdir}/%{name}/statsd.d + %if %{with systemd} %{_unitdir}/netdata.service diff --git a/plugins.d/Makefile.am b/plugins.d/Makefile.am index 1085d053af..904a3fdef8 100644 --- a/plugins.d/Makefile.am +++ b/plugins.d/Makefile.am @@ -3,6 +3,19 @@ # SPDX-License-Identifier: GPL-3.0+ # MAINTAINERCLEANFILES= $(srcdir)/Makefile.in +CLEANFILES = \ + alarm-notify.sh \ + cgroup-name.sh \ + charts.d.plugin \ + fping.plugin \ + node.d.plugin \ + python.d.plugin \ + tc-qos-helper.sh \ + $(NULL) + +include $(top_srcdir)/build/subst.inc + +SUFFIXES = .in dist_plugins_DATA = \ README.md \ @@ -22,3 +35,13 @@ dist_plugins_SCRIPTS = \ tc-qos-helper.sh \ loopsleepms.sh.inc \ $(NULL) + +dist_noinst_DATA = \ + alarm-notify.sh.in \ + cgroup-name.sh.in \ + charts.d.plugin.in \ + fping.plugin.in \ + node.d.plugin.in \ + python.d.plugin.in \ + tc-qos-helper.sh.in \ + $(NULL) diff --git a/plugins.d/alarm-notify.sh b/plugins.d/alarm-notify.sh deleted file mode 100755 index b37e9bfbd9..0000000000 --- a/plugins.d/alarm-notify.sh +++ /dev/null @@ -1,2371 +0,0 @@ -#!/usr/bin/env bash - -# netdata -# real-time performance and health monitoring, done right! -# (C) 2017 Costa Tsaousis -# SPDX-License-Identifier: GPL-3.0+ -# -# Script to send alarm notifications for netdata -# -# Features: -# - multiple notification methods -# - multiple roles per alarm -# - multiple recipients per role -# - severity filtering per recipient -# -# Supported notification methods: -# - emails by @ktsaou -# - slack.com notifications by @ktsaou -# - alerta.io notifications by @kattunga -# - discordapp.com notifications by @lowfive -# - pushover.net notifications by @ktsaou -# - pushbullet.com push notifications by Tiago Peralta @tperalta82 #1070 -# - telegram.org notifications by @hashworks #1002 -# - twilio.com notifications by Levi Blaney @shadycuz #1211 -# - kafka notifications by @ktsaou #1342 -# - pagerduty.com notifications by Jim Cooley @jimcooley #1373 -# - messagebird.com notifications by @tech_no_logical #1453 -# - hipchat notifications by @ktsaou #1561 -# - fleep notifications by @Ferroin -# - custom notifications by @ktsaou -# - syslog messages by @Ferroin -# - Microsoft Team notification by @tioumen - -# ----------------------------------------------------------------------------- -# testing notifications - - -if [ \( "${1}" = "test" -o "${2}" = "test" \) -a "${#}" -le 2 ] -then - if [ "${2}" = "test" ] - then - recipient="${1}" - else - recipient="${2}" - fi - - [ -z "${recipient}" ] && recipient="sysadmin" - - id=1 - last="CLEAR" - test_res=0 - for x in "WARNING" "CRITICAL" "CLEAR" - do - echo >&2 - echo >&2 "# SENDING TEST ${x} ALARM TO ROLE: ${recipient}" - - "${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" - if [ $? -ne 0 ] - then - echo >&2 "# FAILED" - test_res=1 - else - echo >&2 "# OK" - fi - - last="${x}" - id=$((id + 1)) - done - - exit $test_res -fi - -export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin" -export LC_ALL=C - -# ----------------------------------------------------------------------------- - -PROGRAM_NAME="$(basename "${0}")" - -logdate() { - date "+%Y-%m-%d %H:%M:%S" -} - -log() { - local status="${1}" - shift - - echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}" - -} - -warning() { - log WARNING "${@}" -} - -error() { - log ERROR "${@}" -} - -info() { - log INFO "${@}" -} - -fatal() { - log FATAL "${@}" - exit 1 -} - -debug=${NETDATA_ALARM_NOTIFY_DEBUG-0} -debug() { - [ "${debug}" = "1" ] && log DEBUG "${@}" -} - -docurl() { - if [ -z "${curl}" ] - then - error "\${curl} is unset." - return 1 - fi - - if [ "${debug}" = "1" ] - then - echo >&2 "--- BEGIN curl command ---" - printf >&2 "%q " ${curl} "${@}" - echo >&2 - echo >&2 "--- END curl command ---" - - local out=$(mktemp /tmp/netdata-health-alarm-notify-XXXXXXXX) - local code=$(${curl} ${curl_options} --write-out %{http_code} --output "${out}" --silent --show-error "${@}") - local ret=$? - echo >&2 "--- BEGIN received response ---" - cat >&2 "${out}" - echo >&2 - echo >&2 "--- END received response ---" - echo >&2 "RECEIVED HTTP RESPONSE CODE: ${code}" - rm "${out}" - echo "${code}" - return ${ret} - fi - - ${curl} ${curl_options} --write-out %{http_code} --output /dev/null --silent --show-error "${@}" - return $? -} - -# ----------------------------------------------------------------------------- -# this is to be overwritten by the config file - -custom_sender() { - info "not sending custom notification for ${status} of '${host}.${chart}.${name}'" -} - - -# ----------------------------------------------------------------------------- - -# check for BASH v4+ (required for associative arrays) -[ $(( ${BASH_VERSINFO[0]} )) -lt 4 ] && \ - fatal "BASH version 4 or later is required (this is ${BASH_VERSION})." - -# ----------------------------------------------------------------------------- -# defaults to allow running this script by hand - -[ -z "${NETDATA_CONFIG_DIR}" ] && NETDATA_CONFIG_DIR="$(dirname "${0}")/../../../../etc/netdata" -[ -z "${NETDATA_CACHE_DIR}" ] && NETDATA_CACHE_DIR="$(dirname "${0}")/../../../../var/cache/netdata" -[ -z "${NETDATA_REGISTRY_URL}" ] && NETDATA_REGISTRY_URL="https://registry.my-netdata.io" - -# ----------------------------------------------------------------------------- -# parse command line parameters - -roles="${1}" # the roles that should be notified for this event -host="${2}" # the host generated this event -unique_id="${3}" # the unique id of this event -alarm_id="${4}" # the unique id of the alarm that generated this event -event_id="${5}" # the incremental id of the event, for this alarm id -when="${6}" # the timestamp this event occurred -name="${7}" # the name of the alarm, as given in netdata health.d entries -chart="${8}" # the name of the chart (type.id) -family="${9}" # the family of the chart -status="${10}" # the current status : REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL -old_status="${11}" # the previous status: REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL -value="${12}" # the current value of the alarm -old_value="${13}" # the previous value of the alarm -src="${14}" # the line number and file the alarm has been configured -duration="${15}" # the duration in seconds of the previous alarm state -non_clear_duration="${16}" # the total duration in seconds this is/was non-clear -units="${17}" # the units of the value -info="${18}" # a short description of the alarm -value_string="${19}" # friendly value (with units) -old_value_string="${20}" # friendly old value (with units) - -# ----------------------------------------------------------------------------- -# find a suitable hostname to use, if netdata did not supply a hostname - -this_host=$(hostname -s 2>/dev/null) -[ -z "${host}" ] && host="${this_host}" - -# ----------------------------------------------------------------------------- -# screen statuses we don't need to send a notification - -# don't do anything if this is not WARNING, CRITICAL or CLEAR -if [ "${status}" != "WARNING" -a "${status}" != "CRITICAL" -a "${status}" != "CLEAR" ] -then - info "not sending notification for ${status} of '${host}.${chart}.${name}'" - exit 1 -fi - -# don't do anything if this is CLEAR, but it was not WARNING or CRITICAL -if [ "${old_status}" != "WARNING" -a "${old_status}" != "CRITICAL" -a "${status}" = "CLEAR" ] -then - info "not sending notification for ${status} of '${host}.${chart}.${name}' (last status was ${old_status})" - exit 1 -fi - -# ----------------------------------------------------------------------------- -# load configuration - -# By default fetch images from the global public registry. -# This is required by default, since all notification methods need to download -# images via the Internet, and private registries might not be reachable. -# This can be overwritten at the configuration file. -images_base_url="https://registry.my-netdata.io" - -# curl options to use -curl_options="" - -# needed commands -# if empty they will be searched in the system path -curl= -sendmail= - -# enable / disable features -SEND_SLACK="YES" -SEND_MSTEAM="YES" -SEND_ALERTA="YES" -SEND_FLOCK="YES" -SEND_DISCORD="YES" -SEND_PUSHOVER="YES" -SEND_TWILIO="YES" -SEND_HIPCHAT="YES" -SEND_MESSAGEBIRD="YES" -SEND_KAVENEGAR="YES" -SEND_TELEGRAM="YES" -SEND_EMAIL="YES" -SEND_PUSHBULLET="YES" -SEND_KAFKA="YES" -SEND_PD="YES" -SEND_FLEEP="YES" -SEND_IRC="YES" -SEND_AWSSNS="YES" -SEND_SYSLOG="NO" -SEND_CUSTOM="YES" - -# slack configs -SLACK_WEBHOOK_URL= -DEFAULT_RECIPIENT_SLACK= -declare -A role_recipients_slack=() - -# Microsoft Team configs -MSTEAM_WEBHOOK_URL= -DEFAULT_RECIPIENT_MSTEAM= -declare -A role_recipients_msteam=() - -# rocketchat configs -ROCKETCHAT_WEBHOOK_URL= -DEFAULT_RECIPIENT_ROCKETCHAT= -declare -A role_recipients_rocketchat=() - -# alerta configs -ALERTA_WEBHOOK_URL= -ALERTA_API_KEY= -DEFAULT_RECIPIENT_ALERTA= -declare -A role_recipients_alerta=() - -# flock configs -FLOCK_WEBHOOK_URL= -DEFAULT_RECIPIENT_FLOCK= -declare -A role_recipients_flock=() - -# discord configs -DISCORD_WEBHOOK_URL= -DEFAULT_RECIPIENT_DISCORD= -declare -A role_recipients_discord=() - -# pushover configs -PUSHOVER_APP_TOKEN= -DEFAULT_RECIPIENT_PUSHOVER= -declare -A role_recipients_pushover=() - -# pushbullet configs -PUSHBULLET_ACCESS_TOKEN= -PUSHBULLET_SOURCE_DEVICE= -DEFAULT_RECIPIENT_PUSHBULLET= -declare -A role_recipients_pushbullet=() - -# twilio configs -TWILIO_ACCOUNT_SID= -TWILIO_ACCOUNT_TOKEN= -TWILIO_NUMBER= -DEFAULT_RECIPIENT_TWILIO= -declare -A role_recipients_twilio=() - -# hipchat configs -HIPCHAT_SERVER= -HIPCHAT_AUTH_TOKEN= -DEFAULT_RECIPIENT_HIPCHAT= -declare -A role_recipients_hipchat=() - -# messagebird configs -MESSAGEBIRD_ACCESS_KEY= -MESSAGEBIRD_NUMBER= -DEFAULT_RECIPIENT_MESSAGEBIRD= -declare -A role_recipients_messagebird=() - -# kavenegar configs -KAVENEGAR_API_KEY="" -KAVENEGAR_SENDER="" -DEFAULT_RECIPIENT_KAVENEGAR=() -declare -A role_recipients_kavenegar="" - -# telegram configs -TELEGRAM_BOT_TOKEN= -DEFAULT_RECIPIENT_TELEGRAM= -declare -A role_recipients_telegram=() - -# kafka configs -KAFKA_URL= -KAFKA_SENDER_IP= - -# pagerduty.com configs -PD_SERVICE_KEY= -DEFAULT_RECIPIENT_PD= -declare -A role_recipients_pd=() - -# fleep.io configs -FLEEP_SENDER="${host}" -DEFAULT_RECIPIENT_FLEEP= -declare -A role_recipients_fleep=() - -# Amazon SNS configs -DEFAULT_RECIPIENT_AWSSNS= -AWSSNS_MESSAGE_FORMAT= -declare -A role_recipients_awssns=() - -# syslog configs -SYSLOG_FACILITY= -declare -A role_recipients_syslog=() - -# custom configs -DEFAULT_RECIPIENT_CUSTOM= -declare -A role_recipients_custom=() - -# email configs -EMAIL_SENDER= -DEFAULT_RECIPIENT_EMAIL="root" -EMAIL_CHARSET=$(locale charmap 2>/dev/null) -EMAIL_THREADING= -declare -A role_recipients_email=() - -# irc configs -IRC_NICKNAME= -IRC_REALNAME= -DEFAULT_RECIPIENT_IRC= -IRC_NETWORK= -declare -A role_recipients_irc=() - -# load the user configuration -# this will overwrite the variables above -if [ -f "${NETDATA_CONFIG_DIR}/health_alarm_notify.conf" ] - then - source "${NETDATA_CONFIG_DIR}/health_alarm_notify.conf" -else - error "Cannot find file ${NETDATA_CONFIG_DIR}/health_alarm_notify.conf. Using internal defaults." -fi - -# If we didn't autodetect the character set for e-mail and it wasn't -# set by the user, we need to set it to a reasonable default. UTF-8 -# should be correct for almost all modern UNIX systems. -if [ -z ${EMAIL_CHARSET} ] - then - EMAIL_CHARSET="UTF-8" -fi - -# ----------------------------------------------------------------------------- -# filter a recipient based on alarm event severity - -filter_recipient_by_criticality() { - local method="${1}" x="${2}" r s - shift - - r="${x/|*/}" # the recipient - s="${x/*|/}" # the severity required for notifying this recipient - - # no severity filtering for this person - [ "${r}" = "${s}" ] && return 0 - - # the severity is invalid - s="${s^^}" - if [ "${s}" != "CRITICAL" ] - then - error "SEVERITY FILTERING for ${x} VIA ${method}: invalid severity '${s,,}', only 'critical' is supported." - return 0 - fi - - # create the status tracking directory for this user - [ ! -d "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}" ] && \ - mkdir -p "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}" - - case "${status}" in - CRITICAL) - # make sure he will get future notifications for this alarm too - touch "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}" - debug "SEVERITY FILTERING for ${x} VIA ${method}: ALLOW: the alarm is CRITICAL (will now receive next status change)" - return 0 - ;; - - WARNING) - if [ -f "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}" ] - then - # we do not remove the file, so that he will get future notifications of this alarm - debug "SEVERITY FILTERING for ${x} VIA ${method}: ALLOW: recipient has been notified for this alarm in the past (will still receive next status change)" - return 0 - fi - ;; - - *) - if [ -f "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}" ] - then - # remove the file, so that he will only receive notifications for CRITICAL states for this alarm - rm "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}" - debug "SEVERITY FILTERING for ${x} VIA ${method}: ALLOW: recipient has been notified for this alarm (will only receive CRITICAL notifications from now on)" - return 0 - fi - ;; - esac - - debug "SEVERITY FILTERING for ${x} VIA ${method}: BLOCK: recipient should not receive this notification" - return 1 -} - -# ----------------------------------------------------------------------------- -# find the recipients' addresses per method - -declare -A arr_slack=() -declare -A arr_msteam=() -declare -A arr_rocketchat=() -declare -A arr_alerta=() -declare -A arr_flock=() -declare -A arr_discord=() -declare -A arr_pushover=() -declare -A arr_pushbullet=() -declare -A arr_twilio=() -declare -A arr_hipchat=() -declare -A arr_telegram=() -declare -A arr_pd=() -declare -A arr_email=() -declare -A arr_custom=() -declare -A arr_messagebird=() -declare -A arr_kavenegar=() -declare -A arr_fleep=() -declare -A arr_irc=() -declare -A arr_syslog=() -declare -A arr_awssns=() - -# netdata may call us with multiple roles, and roles may have multiple but -# overlapping recipients - so, here we find the unique recipients. -for x in ${roles//,/ } -do - # the roles 'silent' and 'disabled' mean: - # don't send a notification for this role - [ "${x}" = "silent" -o "${x}" = "disabled" ] && continue - - # email - a="${role_recipients_email[${x}]}" - [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_EMAIL}" - for r in ${a//,/ } - do - [ "${r}" != "disabled" ] && filter_recipient_by_criticality email "${r}" && arr_email[${r/|*/}]="1" - done - - # pushover - a="${role_recipients_pushover[${x}]}" - [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_PUSHOVER}" - for r in ${a//,/ } - do - [ "${r}" != "disabled" ] && filter_recipient_by_criticality pushover "${r}" && arr_pushover[${r/|*/}]="1" - done - - # pushbullet - a="${role_recipients_pushbullet[${x}]}" - [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_PUSHBULLET}" - for r in ${a//,/ } - do - [ "${r}" != "disabled" ] && filter_recipient_by_criticality pushbullet "${r}" && arr_pushbullet[${r/|*/}]="1" - done - - # twilio - a="${role_recipients_twilio[${x}]}" - [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_TWILIO}" - for r in ${a//,/ } - do - [ "${r}" != "disabled" ] && filter_recipient_by_criticality twilio "${r}" && arr_twilio[${r/|*/}]="1" - done - - # hipchat - a="${role_recipients_hipchat[${x}]}" - [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_HIPCHAT}" - for r in ${a//,/ } - do - [ "${r}" != "disabled" ] && filter_recipient_by_criticality hipchat "${r}" && arr_hipchat[${r/|*/}]="1" - done - - # messagebird - a="${role_recipients_messagebird[${x}]}" - [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_MESSAGEBIRD}" - for r in ${a//,/ } - do - [ "${r}" != "disabled" ] && filter_recipient_by_criticality messagebird "${r}" && arr_messagebird[${r/|*/}]="1" - done - - # kavenegar - a="${role_recipients_kavenegar[${x}]}" - [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_KAVENEGAR}" - for r in ${a//,/ } - do - [ "${r}" != "disabled" ] && filter_recipient_by_criticality kavenegar "${r}" && arr_kavenegar[${r/|*/}]="1" - done - - # telegram - a="${role_recipients_telegram[${x}]}" - [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_TELEGRAM}" - for r in ${a//,/ } - do - [ "${r}" != "disabled" ] && filter_recipient_by_criticality telegram "${r}" && arr_telegram[${r/|*/}]="1" - done - - # slack - a="${role_recipients_slack[${x}]}" - [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_SLACK}" - for r in ${a//,/ } - do - [ "${r}" != "disabled" ] && filter_recipient_by_criticality slack "${r}" && arr_slack[${r/|*/}]="1" - done - - # Microsoft Team - a="${role_recipients_msteam[${x}]}" - [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_MSTEAM}" - for r in ${a//,/ } - do - [ "${r}" != "disabled" ] && filter_recipient_by_criticality msteam "${r}" && arr_msteam[${r/|*/}]="1" - done - - # rocketchat - a="${role_recipients_rocketchat[${x}]}" - [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_ROCKETCHAT}" - for r in ${a//,/ } - do - [ "${r}" != "disabled" ] && filter_recipient_by_criticality rocketchat "${r}" && arr_rocketchat[${r/|*/}]="1" - done - - # alerta - a="${role_recipients_alerta[${x}]}" - [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_ALERTA}" - for r in ${a//,/ } - do - [ "${r}" != "disabled" ] && filter_recipient_by_criticality alerta "${r}" && arr_alerta[${r/|*/}]="1" - done - - # flock - a="${role_recipients_flock[${x}]}" - [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_FLOCK}" - for r in ${a//,/ } - do - [ "${r}" != "disabled" ] && filter_recipient_by_criticality flock "${r}" && arr_flock[${r/|*/}]="1" - done - - # discord - a="${role_recipients_discord[${x}]}" - [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_DISCORD}" - for r in ${a//,/ } - do - [ "${r}" != "disabled" ] && filter_recipient_by_criticality discord "${r}" && arr_discord[${r/|*/}]="1" - done - - # pagerduty.com - a="${role_recipients_pd[${x}]}" - [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_PD}" - for r in ${a//,/ } - do - [ "${r}" != "disabled" ] && filter_recipient_by_criticality pd "${r}" && arr_pd[${r/|*/}]="1" - done - - # fleep.io - a="${role_recipients_fleep[${x}]}" - [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_FLEEP}" - for r in ${a//,/ } - do - [ "${r}" != "disabled" ] && filter_recipient_by_criticality fleep "${r}" && arr_fleep[${r/|*/}]="1" - done - - # irc - a="${role_recipients_irc[${x}]}" - [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_IRC}" - for r in ${a//,/ } - do - [ "${r}" != "disabled" ] && filter_recipient_by_criticality irc "${r}" && arr_irc[${r/|*/}]="1" - done - - # amazon sns - a="${role_recipients_awssns[${x}]}" - [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_AWSSNS}" - for r in ${a//,/ } - do - [ "${r}" != "disabled" ] && filter_recipient_by_criticality awssns "${r}" && arr_awssns[${r/|*/}]="1" - done - - # syslog - a="${role_recipients_syslog[${x}]}" - [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_SYSLOG}" - for r in ${a//,/ } - do - [ "${r}" != "disabled" ] && filter_recipient_by_criticality syslog "${r}" && arr_syslog[${r/|*/}]="1" - done - - # custom - a="${role_recipients_custom[${x}]}" - [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_CUSTOM}" - for r in ${a//,/ } - do - [ "${r}" != "disabled" ] && filter_recipient_by_criticality custom "${r}" && arr_custom[${r/|*/}]="1" - done - -done - -# build the list of slack recipients (channels) -to_slack="${!arr_slack[*]}" -[ -z "${to_slack}" ] && SEND_SLACK="NO" - -# build the list of Microsoft team recipients (channels) -to_msteam="${!arr_msteam[*]}" -[ -z "${to_msteam}" ] && SEND_MSTEAM="NO" - -# build the list of rocketchat recipients (channels) -to_rocketchat="${!arr_rocketchat[*]}" -[ -z "${to_rocketchat}" ] && SEND_ROCKETCHAT="NO" - -# build the list of alerta recipients (channels) -to_alerta="${!arr_alerta[*]}" -[ -z "${to_alerta}" ] && SEND_ALERTA="NO" - -# build the list of flock recipients (channels) -to_flock="${!arr_flock[*]}" -[ -z "${to_flock}" ] && SEND_FLOCK="NO" - -# build the list of discord recipients (channels) -to_discord="${!arr_discord[*]}" -[ -z "${to_discord}" ] && SEND_DISCORD="NO" - -# build the list of pushover recipients (user tokens) -to_pushover="${!arr_pushover[*]}" -[ -z "${to_pushover}" ] && SEND_PUSHOVER="NO" - -# build the list of pushbulet recipients (user tokens) -to_pushbullet="${!arr_pushbullet[*]}" -[ -z "${to_pushbullet}" ] && SEND_PUSHBULLET="NO" - -# build the list of twilio recipients (phone numbers) -to_twilio="${!arr_twilio[*]}" -[ -z "${to_twilio}" ] && SEND_TWILIO="NO" - -# build the list of hipchat recipients (rooms) -to_hipchat="${!arr_hipchat[*]}" -[ -z "${to_hipchat}" ] && SEND_HIPCHAT="NO" - -# build the list of messagebird recipients (phone numbers) -to_messagebird="${!arr_messagebird[*]}" -[ -z "${to_messagebird}" ] && SEND_MESSAGEBIRD="NO" - -# build the list of kavenegar recipients (phone numbers) -to_kavenegar="${!arr_kavenegar[*]}" -[ -z "${to_kavenegar}" ] && SEND_KAVENEGAR="NO" - -# check array of telegram recipients (chat ids) -to_telegram="${!arr_telegram[*]}" -[ -z "${to_telegram}" ] && SEND_TELEGRAM="NO" - -# build the list of pagerduty recipients (service keys) -to_pd="${!arr_pd[*]}" -[ -z "${to_pd}" ] && SEND_PD="NO" - -# build the list of fleep recipients (conversation webhooks) -to_fleep="${!arr_fleep[*]}" -[ -z "${to_fleep}" ] && SEND_FLEEP="NO" - -# build the list of custom recipients -to_custom="${!arr_custom[*]}" -[ -z "${to_custom}" ] && SEND_CUSTOM="NO" - -# build the list of email recipients (email addresses) -to_email= -for x in "${!arr_email[@]}" -do - [ ! -z "${to_email}" ] && to_email="${to_email}, " - to_email="${to_email}${x}" -done -[ -z "${to_email}" ] && SEND_EMAIL="NO" - -# build the list of irc recipients (channels) -to_irc="${!arr_irc[*]}" -[ -z "${to_irc}" ] && SEND_IRC="NO" - -# build the list of awssns recipients (facilities, servers, and prefixes) -to_awssns="${!arr_awssns[*]}" -[ -z "${to_awssns}" ] && SEND_AWSSNS="NO" - -# build the list of syslog recipients (facilities, servers, and prefixes) -to_syslog="${!arr_syslog[*]}" -[ -z "${to_syslog}" ] && SEND_SYSLOG="NO" - -# ----------------------------------------------------------------------------- -# verify the delivery methods supported - -# check slack -[ -z "${SLACK_WEBHOOK_URL}" ] && SEND_SLACK="NO" - -# check rocketchat -[ -z "${ROCKETCHAT_WEBHOOK_URL}" ] && SEND_ROCKETCHAT="NO" - -# check alerta -[ -z "${ALERTA_WEBHOOK_URL}" ] && SEND_ALERTA="NO" - -# check flock -[ -z "${FLOCK_WEBHOOK_URL}" ] && SEND_FLOCK="NO" - -# check discord -[ -z "${DISCORD_WEBHOOK_URL}" ] && SEND_DISCORD="NO" - -# check pushover -[ -z "${PUSHOVER_APP_TOKEN}" ] && SEND_PUSHOVER="NO" - -# check pushbullet -[ -z "${PUSHBULLET_ACCESS_TOKEN}" ] && SEND_PUSHBULLET="NO" - -# check twilio -[ -z "${TWILIO_ACCOUNT_TOKEN}" -o -z "${TWILIO_ACCOUNT_SID}" -o -z "${TWILIO_NUMBER}" ] && SEND_TWILIO="NO" - -# check hipchat -[ -z "${HIPCHAT_AUTH_TOKEN}" ] && SEND_HIPCHAT="NO" - -# check messagebird -[ -z "${MESSAGEBIRD_ACCESS_KEY}" -o -z "${MESSAGEBIRD_NUMBER}" ] && SEND_MESSAGEBIRD="NO" - -# check kavenegar -[ -z "${KAVENEGAR_API_KEY}" -o -z "${KAVENEGAR_SENDER}" ] && SEND_KAVENEGAR="NO" - -# check telegram -[ -z "${TELEGRAM_BOT_TOKEN}" ] && SEND_TELEGRAM="NO" - -# check kafka -[ -z "${KAFKA_URL}" -o -z "${KAFKA_SENDER_IP}" ] && SEND_KAFKA="NO" - -# check irc -[ -z "${IRC_NETWORK}" ] && SEND_IRC="NO" - -# check fleep -[ -z "${FLEEP_SERVER}" -o -z "${FLEEP_SENDER}" ] && SEND_FLEEP="NO" - -# check pagerduty.com -# if we need pd-send, check for the pd-send command -# https://www.pagerduty.com/docs/guides/agent-install-guide/ -if [ "${SEND_PD}" = "YES" ] - then - pd_send="$(which pd-send 2>/dev/null || command -v pd-send 2>/dev/null)" - if [ -z "${pd_send}" ] - then - error "Cannot find pd-send command in the system path. Disabling pagerduty.com notifications." - SEND_PD="NO" - fi -fi - -# if we need curl, check for the curl command -if [ \( \ - "${SEND_PUSHOVER}" = "YES" \ - -o "${SEND_SLACK}" = "YES" \ - -o "${SEND_ROCKETCHAT}" = "YES" \ - -o "${SEND_ALERTA}" = "YES" \ - -o "${SEND_FLOCK}" = "YES" \ - -o "${SEND_DISCORD}" = "YES" \ - -o "${SEND_HIPCHAT}" = "YES" \ - -o "${SEND_TWILIO}" = "YES" \ - -o "${SEND_MESSAGEBIRD}" = "YES" \ - -o "${SEND_KAVENEGAR}" = "YES" \ - -o "${SEND_TELEGRAM}" = "YES" \ - -o "${SEND_PUSHBULLET}" = "YES" \ - -o "${SEND_KAFKA}" = "YES" \ - -o "${SEND_FLEEP}" = "YES" \ - -o "${SEND_CUSTOM}" = "YES" \ - -o "${SEND_MSTEAM}" = "YES" \ - \) -a -z "${curl}" ] - then - curl="$(which curl 2>/dev/null || command -v curl 2>/dev/null)" - if [ -z "${curl}" ] - then - error "Cannot find curl command in the system path. Disabling all curl based notifications." - SEND_PUSHOVER="NO" - SEND_PUSHBULLET="NO" - SEND_TELEGRAM="NO" - SEND_SLACK="NO" - SEND_MSTEAM="NO" - SEND_ROCKETCHAT="NO" - SEND_ALERTA="NO" - SEND_FLOCK="NO" - SEND_DISCORD="NO" - SEND_TWILIO="NO" - SEND_HIPCHAT="NO" - SEND_MESSAGEBIRD="NO" - SEND_KAVENEGAR="NO" - SEND_KAFKA="NO" - SEND_FLEEP="NO" - SEND_CUSTOM="NO" - fi -fi - -# if we need sendmail, check for the sendmail command -if [ "${SEND_EMAIL}" = "YES" -a -z "${sendmail}" ] - then - sendmail="$(which sendmail 2>/dev/null || command -v sendmail 2>/dev/null)" - if [ -z "${sendmail}" ] - then - debug "Cannot find sendmail command in the system path. Disabling email notifications." - SEND_EMAIL="NO" - fi -fi - -# if we need logger, check for the logger command -if [ "${SEND_SYSLOG}" = "YES" -a -z "${logger}" ] - then - logger="$(which logger 2>/dev/null || command -v logger 2>/dev/null)" - if [ -z "${logger}" ] - then - debug "Cannot find logger command in the system path. Disabling syslog notifications." - SEND_SYSLOG="NO" - fi -fi - -# if we need aws, check for the aws command -if [ "${SEND_AWSSNS}" = "YES" -a -z "${aws}" ] - then - aws="$(which aws 2>/dev/null || command -v aws 2>/dev/null)" - if [ -z "${aws}" ] - then - debug "Cannot find aws command in the system path. Disabling Amazon SNS notifications." - SEND_AWSSNS="NO" - fi -fi - -# check that we have at least a method enabled -if [ "${SEND_EMAIL}" != "YES" \ - -a "${SEND_PUSHOVER}" != "YES" \ - -a "${SEND_TELEGRAM}" != "YES" \ - -a "${SEND_SLACK}" != "YES" \ - -a "${SEND_ROCKETCHAT}" != "YES" \ - -a "${SEND_ALERTA}" != "YES" \ - -a "${SEND_FLOCK}" != "YES" \ - -a "${SEND_DISCORD}" != "YES" \ - -a "${SEND_TWILIO}" != "YES" \ - -a "${SEND_HIPCHAT}" != "YES" \ - -a "${SEND_MESSAGEBIRD}" != "YES" \ - -a "${SEND_KAVENEGAR}" != "YES" \ - -a "${SEND_PUSHBULLET}" != "YES" \ - -a "${SEND_KAFKA}" != "YES" \ - -a "${SEND_PD}" != "YES" \ - -a "${SEND_FLEEP}" != "YES" \ - -a "${SEND_CUSTOM}" != "YES" \ - -a "${SEND_IRC}" != "YES" \ - -a "${SEND_AWSSNS}" != "YES" \ - -a "${SEND_SYSLOG}" != "YES" \ - -a "${SEND_MSTEAM}" != "YES" \ - ] - then - fatal "All notification methods are disabled. Not sending notification for host '${host}', chart '${chart}' to '${roles}' for '${name}' = '${value}' for status '${status}'." -fi - -# ----------------------------------------------------------------------------- -# get the date the alarm happened - -date=$(date --date=@${when} "${date_format}" 2>/dev/null) -[ -z "${date}" ] && date=$(date "${date_format}" 2>/dev/null) -[ -z "${date}" ] && date=$(date --date=@${when} 2>/dev/null) -[ -z "${date}" ] && date=$(date 2>/dev/null) - -# ---------------------------------------------------------------------------- -# prepare some extra headers if we've been asked to thread e-mails -if [ "${SEND_EMAIL}" == "YES" -a "${EMAIL_THREADING}" == "YES" ] ; then - email_thread_headers="In-Reply-To: <${chart}-${name}@${host}>\nReferences: <${chart}-${name}@${host}>" -else - email_thread_headers= -fi - -# ----------------------------------------------------------------------------- -# function to URL encode a string - -urlencode() { - local string="${1}" strlen encoded pos c o - - strlen=${#string} - for (( pos=0 ; pos$ ]] - then - # the name includes double quotes - sender_email="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)" - sender_name="$(echo "${EMAIL_SENDER}" | cut -d '"' -f 2)" - elif [[ "${EMAIL_SENDER}" =~ ^\'.*\'\ \<.*\>$ ]] - then - # the name includes single quotes - sender_email="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)" - sender_name="$(echo "${EMAIL_SENDER}" | cut -d "'" -f 2)" - elif [[ "${EMAIL_SENDER}" =~ ^.*\ \<.*\>$ ]] - then - # the name does not have any quotes - sender_email="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)" - sender_name="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 1)" - fi - fi - - [ ! -z "${sender_email}" ] && opts+=(-f "${sender_email}") - [ ! -z "${sender_name}" ] && opts+=(-F "${sender_name}") - - if [ "${debug}" = "1" ] - then - echo >&2 "--- BEGIN sendmail command ---" - printf >&2 "%q " "${sendmail}" -t "${opts[@]}" - echo >&2 - echo >&2 "--- END sendmail command ---" - fi - - "${sendmail}" -t "${opts[@]}" - ret=$? - - if [ ${ret} -eq 0 ] - then - info "sent email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}'" - return 0 - else - error "failed to send email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}' with error code ${ret}." - return 1 - fi - fi - - return 1 -} - -# ----------------------------------------------------------------------------- -# pushover sender - -send_pushover() { - local apptoken="${1}" usertokens="${2}" when="${3}" url="${4}" status="${5}" title="${6}" message="${7}" httpcode sent=0 user priority - - if [ "${SEND_PUSHOVER}" = "YES" -a ! -z "${apptoken}" -a ! -z "${usertokens}" -a ! -z "${title}" -a ! -z "${message}" ] - then - - # https://pushover.net/api - priority=-2 - case "${status}" in - CLEAR) priority=-1;; # low priority: no sound or vibration - WARNING) priority=0;; # normal priority: respect quiet hours - CRITICAL) priority=1;; # high priority: bypass quiet hours - *) priority=-2;; # lowest priority: no notification at all - esac - - for user in ${usertokens} - do - httpcode=$(docurl \ - --form-string "token=${apptoken}" \ - --form-string "user=${user}" \ - --form-string "html=1" \ - --form-string "title=${title}" \ - --form-string "message=${message}" \ - --form-string "timestamp=${when}" \ - --form-string "url=${url}" \ - --form-string "url_title=Open netdata dashboard to view the alarm" \ - --form-string "priority=${priority}" \ - https://api.pushover.net/1/mes