@cryptotaxi247 / netdata-1 / commits / 08b6fd42e

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.

Ilya Mashchenko committed Apr 16, 2020 at 15:17 UTC 08b6fd42ea316bba11a472d25c3d5a8be31e0df4
1 file changed +10 -2
collectors/charts.d.plugin/apcupsd/apcupsd.chart.sh
+10 -2
@@ -26,6 +26,15 @@ apcupsd_get() {
26 run -t $apcupsd_timeout apcaccess status "$1"
27 }
28
29 +is_ups_alive() {
30 + local status
31 + status="$(apcupsd_get "$1" | sed -e 's/STATUS.*: //' -e 't' -e 'd')"
32 + case "$status" in
33 + "" | "COMMLOST" | "SHUTTING DOWN") return 1 ;;
34 + *) return 0 ;;
35 + esac
36 +}
37 +
38 apcupsd_check() {
39
40 # this should return:
@@ -47,8 +56,7 @@ apcupsd_check() {
56 error "cannot get information for apcupsd server ${host} on ${apcupsd_sources[${host}]}."
57 failed=$((failed + 1))
58 else
50 - apcupsd_status="$(apcupsd_get ${apcupsd_sources[${host}]} | awk '/^STATUS.*/{ print $3 }')"
51 - if [ "${apcupsd_status}" != "ONLINE" ] && [ "${apcupsd_status}" != "ONBATT" ]; then
59 + if ! is_ups_alive ${apcupsd_sources[${host}]}; then
60 error "APC UPS ${host} on ${apcupsd_sources[${host}]} is not online."
61 failed=$((failed + 1))
62 else