summaryrefslogtreecommitdiffstats
path: root/collectors/charts.d.plugin/charts.d.plugin.in
diff options
context:
space:
mode:
Diffstat (limited to 'collectors/charts.d.plugin/charts.d.plugin.in')
-rwxr-xr-xcollectors/charts.d.plugin/charts.d.plugin.in158
1 files changed, 108 insertions, 50 deletions
diff --git a/collectors/charts.d.plugin/charts.d.plugin.in b/collectors/charts.d.plugin/charts.d.plugin.in
index 34a5a656e..4e64b7e23 100755
--- a/collectors/charts.d.plugin/charts.d.plugin.in
+++ b/collectors/charts.d.plugin/charts.d.plugin.in
@@ -13,27 +13,115 @@
# each will have a different config file and modules configuration directory.
#
-export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
+export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin:@sbindir_POST@"
PROGRAM_FILE="$0"
-PROGRAM_NAME="$(basename $0)"
-PROGRAM_NAME="${PROGRAM_NAME/.plugin/}"
MODULE_NAME="main"
-LOG_LEVEL_ERR=1
-LOG_LEVEL_WARN=2
-LOG_LEVEL_INFO=3
-LOG_LEVEL="$LOG_LEVEL_INFO"
-
-set_log_severity_level() {
- case ${NETDATA_LOG_SEVERITY_LEVEL,,} in
- "info") LOG_LEVEL="$LOG_LEVEL_INFO";;
- "warn" | "warning") LOG_LEVEL="$LOG_LEVEL_WARN";;
- "err" | "error") LOG_LEVEL="$LOG_LEVEL_ERR";;
+# -----------------------------------------------------------------------------
+# logging
+
+PROGRAM_NAME="$(basename "${0}")"
+SHORT_PROGRAM_NAME="${PROGRAM_NAME/.plugin/}"
+
+# these should be the same with syslog() priorities
+NDLP_EMERG=0 # system is unusable
+NDLP_ALERT=1 # action must be taken immediately
+NDLP_CRIT=2 # critical conditions
+NDLP_ERR=3 # error conditions
+NDLP_WARN=4 # warning conditions
+NDLP_NOTICE=5 # normal but significant condition
+NDLP_INFO=6 # informational
+NDLP_DEBUG=7 # debug-level messages
+
+# the max (numerically) log level we will log
+LOG_LEVEL=$NDLP_INFO
+
+set_log_min_priority() {
+ case "${NETDATA_LOG_LEVEL,,}" in
+ "emerg" | "emergency")
+ LOG_LEVEL=$NDLP_EMERG
+ ;;
+
+ "alert")
+ LOG_LEVEL=$NDLP_ALERT
+ ;;
+
+ "crit" | "critical")
+ LOG_LEVEL=$NDLP_CRIT
+ ;;
+
+ "err" | "error")
+ LOG_LEVEL=$NDLP_ERR
+ ;;
+
+ "warn" | "warning")
+ LOG_LEVEL=$NDLP_WARN
+ ;;
+
+ "notice")
+ LOG_LEVEL=$NDLP_NOTICE
+ ;;
+
+ "info")
+ LOG_LEVEL=$NDLP_INFO
+ ;;
+
+ "debug")
+ LOG_LEVEL=$NDLP_DEBUG
+ ;;
esac
}
-set_log_severity_level
+set_log_min_priority
+
+log() {
+ local level="${1}"
+ shift 1
+
+ [[ -n "$level" && -n "$LOG_LEVEL" && "$level" -gt "$LOG_LEVEL" ]] && return
+
+ systemd-cat-native --log-as-netdata --newline="--NEWLINE--" <<EOFLOG
+INVOCATION_ID=${NETDATA_INVOCATION_ID}
+SYSLOG_IDENTIFIER=${PROGRAM_NAME}
+PRIORITY=${level}
+THREAD_TAG=charts.d.plugin
+ND_LOG_SOURCE=collector
+MESSAGE=${MODULE_NAME}: ${*//\\n/--NEWLINE--}
+
+EOFLOG
+ # AN EMPTY LINE IS NEEDED ABOVE
+}
+
+info() {
+ log "$NDLP_INFO" "${@}"
+}
+
+warning() {
+ log "$NDLP_WARN" "${@}"
+}
+
+error() {
+ log "$NDLP_ERR" "${@}"
+}
+
+fatal() {
+ log "$NDLP_ALERT" "${@}"
+ echo "DISABLE"
+ exit 1
+}
+
+debug() {
+ [ "$debug" = "1" ] && log "$NDLP_DEBUG" "${@}"
+}
+
+# -----------------------------------------------------------------------------
+# check for BASH v4+ (required for associative arrays)
+
+if [ ${BASH_VERSINFO[0]} -lt 4 ]; then
+ echo >&2 "BASH version 4 or later is required (this is ${BASH_VERSION})."
+ exit 1
+fi
# -----------------------------------------------------------------------------
# create temp dir
@@ -62,39 +150,6 @@ logdate() {
date "+%Y-%m-%d %H:%M:%S"
}
-log() {
- local status="${1}"
- shift
-
- echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${MODULE_NAME}: ${*}"
-
-}
-
-info() {
- [[ -n "$LOG_LEVEL" && "$LOG_LEVEL_INFO" -gt "$LOG_LEVEL" ]] && return
- log INFO "${@}"
-}
-
-warning() {
- [[ -n "$LOG_LEVEL" && "$LOG_LEVEL_WARN" -gt "$LOG_LEVEL" ]] && return
- log WARNING "${@}"
-}
-
-error() {
- [[ -n "$LOG_LEVEL" && "$LOG_LEVEL_ERR" -gt "$LOG_LEVEL" ]] && return
- log ERROR "${@}"
-}
-
-fatal() {
- log FATAL "${@}"
- echo "DISABLE"
- exit 1
-}
-
-debug() {
- [ $debug -eq 1 ] && log DEBUG "${@}"
-}
-
# -----------------------------------------------------------------------------
# check a few commands
@@ -137,8 +192,8 @@ info "started from '$PROGRAM_FILE' with options: $*"
[ -z "${NETDATA_STOCK_CONFIG_DIR}" ] && NETDATA_STOCK_CONFIG_DIR="@libconfigdir_POST@"
pluginsd="${NETDATA_PLUGINS_DIR}"
-stockconfd="${NETDATA_STOCK_CONFIG_DIR}/${PROGRAM_NAME}"
-userconfd="${NETDATA_USER_CONFIG_DIR}/${PROGRAM_NAME}"
+stockconfd="${NETDATA_STOCK_CONFIG_DIR}/${SHORT_PROGRAM_NAME}"
+userconfd="${NETDATA_USER_CONFIG_DIR}/${SHORT_PROGRAM_NAME}"
olduserconfd="${NETDATA_USER_CONFIG_DIR}"
chartsd="$pluginsd/../charts.d"
@@ -194,12 +249,14 @@ while [ ! -z "$1" ]; do
if [ "$1" = "debug" -o "$1" = "all" ]; then
debug=1
+ LOG_LEVEL=$NDLP_DEBUG
shift
continue
fi
if [ -f "$chartsd/$1.chart.sh" ]; then
debug=1
+ LOG_LEVEL=$NDLP_DEBUG
chart_only="$(echo $1.chart.sh | sed "s/\.chart\.sh$//g")"
shift
continue
@@ -207,6 +264,7 @@ while [ ! -z "$1" ]; do
if [ -f "$chartsd/$1" ]; then
debug=1
+ LOG_LEVEL=$NDLP_DEBUG
chart_only="$(echo $1 | sed "s/\.chart\.sh$//g")"
shift
continue
@@ -247,7 +305,7 @@ source "$pluginsd/loopsleepms.sh.inc"
# -----------------------------------------------------------------------------
# load my configuration
-for myconfig in "${NETDATA_STOCK_CONFIG_DIR}/${PROGRAM_NAME}.conf" "${NETDATA_USER_CONFIG_DIR}/${PROGRAM_NAME}.conf"; do
+for myconfig in "${NETDATA_STOCK_CONFIG_DIR}/${SHORT_PROGRAM_NAME}.conf" "${NETDATA_USER_CONFIG_DIR}/${SHORT_PROGRAM_NAME}.conf"; do
if [ -f "$myconfig" ]; then
source "$myconfig"
if [ $? -ne 0 ]; then