From 08b6fd42ea316bba11a472d25c3d5a8be31e0df4 Mon Sep 17 00:00:00 2001 From: Ilya Mashchenko Date: Thu, 16 Apr 2020 15:17:54 +0300 Subject: charts.d/apcupsd: fix ups status check (#8688) This PR changes ups_status_check logic. It is safe to treat all statuses except COMMLOST and SHUTTING DOWN as ok and try to collect data from upses. --- collectors/charts.d.plugin/apcupsd/apcupsd.chart.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'collectors/charts.d.plugin/apcupsd') diff --git a/collectors/charts.d.plugin/apcupsd/apcupsd.chart.sh b/collectors/charts.d.plugin/apcupsd/apcupsd.chart.sh index c66e80d211..014a9c1de5 100644 --- a/collectors/charts.d.plugin/apcupsd/apcupsd.chart.sh +++ b/collectors/charts.d.plugin/apcupsd/apcupsd.chart.sh @@ -26,6 +26,15 @@ apcupsd_get() { run -t $apcupsd_timeout apcaccess status "$1" } +is_ups_alive() { + local status + status="$(apcupsd_get "$1" | sed -e 's/STATUS.*: //' -e 't' -e 'd')" + case "$status" in + "" | "COMMLOST" | "SHUTTING DOWN") return 1 ;; + *) return 0 ;; + esac +} + apcupsd_check() { # this should return: @@ -47,8 +56,7 @@ apcupsd_check() { error "cannot get information for apcupsd server ${host} on ${apcupsd_sources[${host}]}." failed=$((failed + 1)) else - apcupsd_status="$(apcupsd_get ${apcupsd_sources[${host}]} | awk '/^STATUS.*/{ print $3 }')" - if [ "${apcupsd_status}" != "ONLINE" ] && [ "${apcupsd_status}" != "ONBATT" ]; then + if ! is_ups_alive ${apcupsd_sources[${host}]}; then error "APC UPS ${host} on ${apcupsd_sources[${host}]} is not online." failed=$((failed + 1)) else -- cgit v1.2.3