2020-07-18 19:37:45 +03:00
#!/bin/sh
2016-09-09 15:36:01 +03:00
################################################################
2016-12-03 14:07:02 +10:00
# Instructions: #
# 1. copy this script to /etc/snmp/ and make it executable: #
# chmod +x ups-nut.sh #
# 2. make sure UPS_NAME below matches the name of your UPS #
# 3. edit your snmpd.conf to include this line: #
# extend ups-nut /etc/snmp/ups-nut.sh #
# 4. restart snmpd on the host #
# 5. activate the app for the desired host in LibreNMS #
2016-09-09 15:36:01 +03:00
################################################################
2021-07-27 00:01:03 +01:00
UPS_NAME = " ${ 1 :- APCUPS } "
2016-12-03 14:07:02 +10:00
PATH = $PATH :/usr/bin:/bin
TMP = $( upsc $UPS_NAME 2>/dev/null)
2016-09-09 15:36:01 +03:00
2016-12-03 14:07:02 +10:00
for value in "battery\.charge: [0-9.]+" "battery\.(runtime\.)?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.]+"
2016-09-09 15:36:01 +03:00
do
2021-03-18 12:24:30 +01:00
OUT = $( echo " $TMP " | grep -Eo " $value " | awk '{print $2}' | LANG = C sort | head -n 1)
2016-09-24 20:30:09 +03:00
if [ -n " $OUT " ] ; then
2021-03-18 12:24:30 +01:00
echo " $OUT "
2016-09-24 20:30:09 +03:00
else
echo "Unknown"
fi
2016-09-09 15:36:01 +03:00
done
2020-06-18 17:42:28 +10:00
2022-11-18 21:16:38 +01:00
for value in "ups\.status:[A-Z ]{0,}OL" "ups\.status:[A-Z ]{0,}OB" "ups\.status:[A-Z ]{0,}LB" "ups\.status:[A-Z ]{0,}HB" "ups\.status:[A-Z ]{0,}RB" "ups\.status:[A-Z ]{0,}CHRG" "ups\.status:[A-Z ]{0,}DISCHRG" "ups\.status:[A-Z ]{0,}BYPASS" "ups\.status:[A-Z ]{0,}CAL" "ups\.status:[A-Z ]{0,}OFF" "ups\.status:[A-Z ]{0,}OVER" "ups\.status:[A-Z ]{0,}TRIM" "ups\.status:[A-Z ]{0,}BOOST" "ups\.status:[A-Z ]{0,}FSD" "ups\.alarm:[A-Z ]"
2020-06-18 17:42:28 +10:00
do
2021-03-18 12:24:30 +01:00
UNKNOWN = $( echo " $TMP " | grep -Eo "ups\.status:" )
2020-06-18 17:42:28 +10:00
if [ -z " $UNKNOWN " ] ; then
echo "Unknown"
else
2021-03-18 12:24:30 +01:00
OUT = $( echo " $TMP " | grep -Eo " $value " )
2020-06-18 17:42:28 +10:00
if [ -n " $OUT " ] ; then
echo "1"
else
echo "0"
fi
fi
done
2022-11-18 21:16:38 +01:00