MONITOR UPSS WITH NAGIOS UISNG CUSTOM NAGIOS PLUGINS

sudo upsc <ups-name>@localhost
# NUT (Network UPS Tools) drivers and NUT server must be installed in the host for this plug-in to work.
# details : https://networkupstools.org/
# /home/user/ups/restart_nuts.sh - must restart the NUT drivers and the server (in that order) which will be triggered in case the plug-in is unable to read the values in it's initial try.
#!/bin/bash
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
blank=""
NUT_RESTART="/home/user/ups/restart_nuts.sh"
usage1="Usage: $0 -H <host> -u <ups> -w <warn> -c <crit>"
exitstatus=$STATE_WARNING #default
while test -n "$1"; do
case "$1" in
-c)
crit=$2
shift
;;
-w)
warn=$2
shift
;;
-u)
ups=$2
shift
;;
-h)
echo $usage1;
echo
exit $STATE_UNKNOWN
;;
-H)
host=$2
shift
;;
*)
echo "Unknown argument: $1"
echo $usage1;
echo
exit $STATE_UNKNOWN
;;
esac
shift
done
value=`upsc $ups@$host battery.charge 2>&1 | grep -v '^Init SSL'`#conversion to integer
value=${value/\.*}
#if blank, warning
if [[ $value == $blank ]]; then
echo UPS WARNING - Battery Capacity = $value%
exit $STATE_WARNING;
fi
# value>warn
if [ $value -gt $warn ]; then
echo UPS OK - Battery Capacity = $value%
exit $STATE_OK;
fi
#c<value<=w
if [ $value -gt $crit ]; then
echo UPS WARNING - Battery Capacity = $value%
exit $STATE_WARNING;
fi
#value<c
if [ $value -le $crit ]; then
echo UPS CRITICAL - Battery Capacity = $value%
exit $STATE_CRITICAL;
fi
sudo $NUT_RESTARTvalue=`upsc $ups@$host battery.charge 2>&1 | grep -v '^Init SSL'`#conversion to integer
value=${value/\.*}
# if blank, warning
if [[ $value == $blank ]]; then
echo UPS WARNING - Battery Capacity = $value%
exit $STATE_WARNING;
fi
# value>warn
if [ $value -lt $warn ]; then
echo UPS OK - $ups@$host : Battery Capacity = $value%
exit $STATE_OK;
fi
#c<value<=w
if [ $value -lt $crit ]; then
echo UPS WARNING - $ups@$host : Battery Capacity = $value%
exit $STATE_WARNING;
fi
#value<c
if [ $value -ge $crit ]; then
echo UPS CRITICAL - $ups@$host : Battery Capacity = $value%
exit $STATE_CRITICAL;
fi
echo UPS UNKNOWN - $ups@$host : Battery Capacity = $value%
exit $STATE_UNKNOWN;
#!/bin/bash
sudo systemctl restart nut-driver
sudo systemctl restart nut-server
sudo upsdrvctl start
$ ./check_ups_nut_capacity.sh -H <host> -u <ups> -w <warning_threshold> -c <critical_treshhold>
command[check_ups_battery]=/usr/bin/sudo /usr/local/nagios/libexec/check_ups_nut_capacity -H localhost -u ups3-cp425 -w 50 -c 25
define host {
use linux-server
host_name UPS3-CP425
alias UPS3-CP425
address <IP-Address-of-the-Pi>
max_check_attempts 5
check_period 24x7
notification_interval 30
notification_period 24x7
notifications_enabled 0
}
define service {
use generic-service
host_name UPS3-CP425
service_description Battery Charge pct
check_command check_nrpe!check_ups_battery
contacts adminemail, admintext
}
define service {
use generic-service
host_name UPS3-CP425
service_description Battery Runtime m
check_command check_nrpe!check_ups_runtime
contacts adminemail, admintext
}
define service {
use generic-service
host_name UPS3-CP425
service_description Input Voltage v
check_command check_nrpe!check_ups_voltage
contacts adminemail, admintext
}
define service {
use generic-service
host_name UPS3-CP425
service_description Load pct
check_command check_nrpe!check_ups_load
contacts adminemail, admintext
}
$ ./check_ups_capacity -w 60 -c 35
command[check_ups_capacity]=/usr/bin/sudo /usr/local/nagios/libexec/check_ups_capacity -w 60 -c 35

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store