diff options
author | Ilya Mashchenko <ilya@netdata.cloud> | 2020-04-16 15:17:54 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-16 15:17:54 +0300 |
commit | 08b6fd42ea316bba11a472d25c3d5a8be31e0df4 (patch) | |
tree | e3614d4b074f4964463a6989bc52e3015377e3c7 /collectors | |
parent | 2e7292a1a07c9a5e4ffed6d4a05b2d5c6cfc1aae (diff) |
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.
Diffstat (limited to 'collectors')
-rw-r--r-- | collectors/charts.d.plugin/apcupsd/apcupsd.chart.sh | 12 |
1 files changed, 10 insertions, 2 deletions
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 |