Page 2 of 4
Re: Checking APC UPS battery runtime
Posted: Wed Dec 16, 2015 7:06 pm
by rdobbsmacu
Ok that resolved the command line output but nagios web interface is still displaying as in warning state and 0 Minutes.
Any thoughts?
and thank you for all your help so far.
Re: Checking APC UPS battery runtime
Posted: Wed Dec 16, 2015 7:38 pm
by Box293
Check to make sure valid values are being returned by echoing the varibales:
Code: Select all
echo "runtime: $runtime"
echo "min: $min"
Add these lines after your a and b variables.
Re: Checking APC UPS battery runtime
Posted: Wed Dec 16, 2015 8:16 pm
by rdobbsmacu
Yes those values are returning correctly plus I also echoed stateid in all three sections.
Getting current battery runtime 95 minutes |calls=$runtime;27000;12000
Stateid 0
And nagios interface is showing warning and sending notifications.
Re: Checking APC UPS battery runtime
Posted: Wed Dec 16, 2015 10:54 pm
by Box293
Can you show us your command and service definitions.
Re: Checking APC UPS battery runtime
Posted: Thu Dec 17, 2015 2:44 pm
by rdobbsmacu
Here is the my updated script
Code: Select all
#!/bin/bash
host=$1
runtime=$(/usr/local/nagios/libexec/check_snmp -H $host -C macu-pub -o .1.3.6.1.4.1.318.1.1.1.2.2.3.0|awk '{print $5}'| grep -o '[0-9]*')
echo $runtime
min=$(expr $runtime / 6000);
echo $min
a=27000
b=12000
##### IF else then begining #####
##### OK State #####
if [[ "$runtime" -gt "$a" ]]
then
echo "Current Battery Runtime $(($min)) Minutes""|calles=$runtime;27000;12000"
stateid=0
echo $stateid
######Warning State ######
elif [[ "$runtime" -le "$a" ]]
then
echo "Current Battery Runtime $(($min)) Minutes""|calles=$runtime;27000;12000"
stateid=1
echo $stateid
######Critical State #####
elif [[ "$runtime" -le "$b" ]]
then
echo "Current Battery Runtime $(($min)) Minutes""|calles=$runtime;27000;12000"
stateid=2
echo $stateid
##### End of If Else Then ######
fi
exit $stateid
Here is the command i'm running and the output from the above script
Code: Select all
./check_apc_runtime 172.18.100.65
570000
95
Current Battery Runtime 95 Minutes|calles=570000;27000;12000
0
Here is the a screenshot of the service and command in nagios.
https://support.nagios.com/forum/downlo ... w&id=11444
https://support.nagios.com/forum/downlo ... w&id=11445
Re: Checking APC UPS battery runtime
Posted: Thu Dec 17, 2015 2:56 pm
by rdobbsmacu
I also have another script that i use to verify my equipment closets and rooms don't drop blow a set temperatures. The command line output is right but the nagios interface is also saying it is in a warning state when the temp is above the warning temp by 15 dergrees.
here is my low temp script
Code: Select all
#!/bin/bash
host=$1
temp=$(/usr/local/nagios/libexec/check_snmp -H $host -C macu-pub -o .1.3.6.1.4.1.318.1.1.25.1.2.1.5.1.1|awk '{print $4}'| grep -o '[0-9]*')
a=59
b=48
####### If statement normal ############
if [[ "$temp" -gt "$a" ]]
then
echo "Current Room Temperature is $(($temp))""|calls=$temp;59;48"
stateid=0
#echo $stateid
######## If statement warning ##########
elif [[ "$temp" -le "$a" ]]
then
echo "Currrent Room Temperature is $(($temp))""|calls=$temp;59;48"
stateid=1
#echo $stateid
######### If statement critical #########
elif [[ "$temp" -le "$b" ]]
then
echo "Current Room Temperature is $(($temp))""|calls=$temp;59;48"
stateid=2
#echo $stateid
fi
exit $stateid
Re: Checking APC UPS battery runtime
Posted: Thu Dec 17, 2015 3:24 pm
by rkennedy
Let's try to stick the conversation to the initial script posted, and get that fixed - because they are so related I think it'll fix things all around.
Can you give this a try and let us know the result? -
Code: Select all
#!/bin/bash
host=$1
runtime=$(/usr/local/nagios/libexec/check_snmp -H $host -C macu-pub -o .1.3.6.1.4.1.318.1.1.1.2.2.3.0|awk '{print $5}'| grep -o '[0-9]*')
min=$(expr $runtime / 6000);
a=27000
b=12000
##### IF else then begining #####
##### OK State #####
if [[ "$runtime" -gt "$a" ]]
then
echo "Current Battery Runtime $(($min)) Minutes""|calles=$runtime;27000;12000"
exit 0
######Warning State ######
elif [[ "$runtime" -le "$a" ]]
then
echo "Current Battery Runtime $(($min)) Minutes""|calles=$runtime;27000;12000"
exit 1
######Critical State #####
elif [[ "$runtime" -le "$b" ]]
then
echo "Current Battery Runtime $(($min)) Minutes""|calles=$runtime;27000;12000"
exit 2
##### End of If Else Then ######
##### Catchall else #####
else
echo "Unkown error"
exit 3
fi
##### Catchall close #####
ups-script.PNG
Re: Checking APC UPS battery runtime
Posted: Thu Dec 17, 2015 3:27 pm
by rdobbsmacu
If I run the script from the command line and then right after the script completes I run echo $stateid and get a blank line. Almost like it is not setting the stateid value.
Re: Checking APC UPS battery runtime
Posted: Thu Dec 17, 2015 3:40 pm
by rdobbsmacu
updated the script but the status is still in the warning status .
output from command line
libexec]# ./check_apc_runtime 172.18.100.64
Current Battery Runtime 90 Minutes|calles=540000;27000;12000
https://support.nagios.com/forum/downlo ... 394f1c760l in the warning.
Re: Checking APC UPS battery runtime
Posted: Thu Dec 17, 2015 3:58 pm
by rkennedy
rdobbsmacu wrote:If I run the script from the command line and then right after the script completes I run echo $stateid and get a blank line. Almost like it is not setting the stateid value.
I took out the stateid variable, and lead directly to an exit value in each if statement.
Can you force a check and see if it changes? It looks like the service is checking only every 30 minutes.
Can you post a screenshot of the advanced tab for me to take a look at?