Browse Source

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 4 years ago
parent
commit
08b6fd42ea
1 changed files with 10 additions and 2 deletions
  1. 10 2
      collectors/charts.d.plugin/apcupsd/apcupsd.chart.sh

+ 10 - 2
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