Checking APC UPS battery runtime

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
rdobbsmacu
Posts: 36
Joined: Tue Apr 28, 2015 3:11 pm

Re: Checking APC UPS battery runtime

Post 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.
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Checking APC UPS battery runtime

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
rdobbsmacu
Posts: 36
Joined: Tue Apr 28, 2015 3:11 pm

Re: Checking APC UPS battery runtime

Post 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.
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Checking APC UPS battery runtime

Post by Box293 »

Can you show us your command and service definitions.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
rdobbsmacu
Posts: 36
Joined: Tue Apr 28, 2015 3:11 pm

Re: Checking APC UPS battery runtime

Post 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
You do not have the required permissions to view the files attached to this post.
Last edited by tmcdonald on Thu Dec 17, 2015 3:00 pm, edited 1 time in total.
Reason: Please use [code][/code] tags around code/terminal output
rdobbsmacu
Posts: 36
Joined: Tue Apr 28, 2015 3:11 pm

Re: Checking APC UPS battery runtime

Post 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
Last edited by tmcdonald on Thu Dec 17, 2015 2:59 pm, edited 1 time in total.
Reason: Please use [code][/code] tags around code/terminal output
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Checking APC UPS battery runtime

Post 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
You do not have the required permissions to view the files attached to this post.
Former Nagios Employee
rdobbsmacu
Posts: 36
Joined: Tue Apr 28, 2015 3:11 pm

Re: Checking APC UPS battery runtime

Post 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.
rdobbsmacu
Posts: 36
Joined: Tue Apr 28, 2015 3:11 pm

Re: Checking APC UPS battery runtime

Post 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.
You do not have the required permissions to view the files attached to this post.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Checking APC UPS battery runtime

Post 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?
Former Nagios Employee
Locked