From fa308bfe3f388f110e9df083d6b2c649fa69472e Mon Sep 17 00:00:00 2001 From: crcro Date: Sat, 24 Sep 2016 20:30:09 +0300 Subject: [PATCH] snmp-extend: ups-nut update 1 (#63) * new code for better matching, snmp-extend compliance * removed unused vars * extra fixes * removed the need of tmp file * removed charge_low, deemed useless by user * removed values that are not plottable * readded ds --- snmp/ups-nut.sh | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/snmp/ups-nut.sh b/snmp/ups-nut.sh index 321ca98..2b67ef6 100755 --- a/snmp/ups-nut.sh +++ b/snmp/ups-nut.sh @@ -1,25 +1,32 @@ #!/usr/bin/env bash ################################################################ -# copy this script to somewhere like /opt and make chmod +x it # -# edit your snmpd.conf and include # -# extend ups-nut /opt/ups-nut.sh # +# copy this script to /etc/snmp/ and make it executable: # +# chmod +x ups-nut.sh # +# ------------------------------------------------------------ # +# edit your snmpd.conf and include: # +# extend ups-nut /etc/snmp/ups-nut.sh # +#--------------------------------------------------------------# # restart snmpd and activate the app for desired host # +#--------------------------------------------------------------# # please make sure you have the path/binaries below # ################################################################ -# Binaries and paths required # -################################################################ BIN_UPSC='/usr/bin/upsc' UPSC_CMD='APCUPS' -BIN_SED='/usr/bin/sed' +BIN_CAT='/usr/bin/cat' +BIN_GREP='/usr/bin/grep' BIN_TR='/usr/bin/tr' BIN_CUT='/usr/bin/cut' ################################################################ # Don't change anything unless you know what are you doing # ################################################################ -CMD1=`$BIN_UPSC $UPSC_CMD | $BIN_SED "1 d" | $BIN_TR '\n' '|' | $BIN_TR -d ' '` -IFS='|' read -r -a array <<< "$CMD1" +TMP=`$BIN_UPSC $UPSC_CMD 2>/dev/null` -for value in 0 1 5 8 11 12 25 26 31 +for value in "battery.charge:[0-9]+" "battery.low:[0-9]+" "battery.runtime:[0-9]+" "battery.voltage:[0-9.]+" "battery.voltage.nominal:[0-9]+" "input.voltage.nominal:[0-9.]+" "input.voltage:[0-9.]+" "ups.load:[0-9]+" do - echo ${array["$value"]} | $BIN_CUT -d ":" -f 2 + OUT=`echo "$TMP" | $BIN_TR -d ' ' | $BIN_GREP -Eow $value | $BIN_CUT -d ":" -f 2` + if [ -n "$OUT" ]; then + echo $OUT + else + echo "Unknown" + fi done