From d4dd00f58a502c9ca4b63e36ce6bc7a9945dc63c Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Tue, 27 Mar 2018 22:28:21 +0100 Subject: New upstream version 1.10.0+dfsg --- charts.d/apcupsd.chart.sh | 104 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 72 insertions(+), 32 deletions(-) (limited to 'charts.d/apcupsd.chart.sh') diff --git a/charts.d/apcupsd.chart.sh b/charts.d/apcupsd.chart.sh index 46a86101c..9878fd36c 100644 --- a/charts.d/apcupsd.chart.sh +++ b/charts.d/apcupsd.chart.sh @@ -6,8 +6,12 @@ # GPL v3+ # -apcupsd_ip=127.0.0.1 -apcupsd_port=3551 +apcupsd_ip= +apcupsd_port= + +declare -A apcupsd_sources=( + ["local"]="127.0.0.1:3551" +) # how frequently to collect UPS data apcupsd_update_every=10 @@ -18,7 +22,7 @@ apcupsd_timeout=3 apcupsd_priority=90000 apcupsd_get() { - run -t $apcupsd_timeout apcaccess status "$1:$2" + run -t $apcupsd_timeout apcaccess status "$1" } apcupsd_check() { @@ -29,52 +33,76 @@ apcupsd_check() { require_cmd apcaccess || return 1 - run apcupsd_get $apcupsd_ip $apcupsd_port >/dev/null - if [ $? -ne 0 ] - then - error "cannot get information for apcupsd server." - return 1 - elif [ $(apcupsd_get $apcupsd_ip $apcupsd_port | awk '/^STATUS.*/{ print $3 }') != "ONLINE" ] - then - error "APC UPS not online." - return 1 + # backwards compatibility + if [ "${apcupsd_ip}:${apcupsd_port}" != ":" ] + then + apcupsd_sources["local"]="${apcupsd_ip}:${apcupsd_port}" fi + local host working=0 failed=0 + for host in "${!apcupsd_sources[@]}" + do + run apcupsd_get "${apcupsd_sources[${host}]}" >/dev/null + if [ $? -ne 0 ] + then + error "cannot get information for apcupsd server ${host} on ${apcupsd_sources[${host}]}." + failed=$((failed + 1)) + elif [ $(apcupsd_get "${apcupsd_sources[${host}]}" | awk '/^STATUS.*/{ print $3 }') != "ONLINE" ] + then + error "APC UPS ${host} on ${apcupsd_sources[${host}]} is not online." + failed=$((failed + 1)) + else + working=$((working + 1)) + fi + done + + if [ ${working} -eq 0 ] + then + error "No APC UPSes found available." + return 1 + fi + return 0 } apcupsd_create() { - # create the charts - cat <