This support forum board is for support questions relating to
Nagios XI , our flagship commercial network monitoring solution.
hsmith
Agent Smith
Posts: 3539 Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:
Post
by hsmith » Tue Aug 18, 2015 4:15 pm
eloyd wrote: Look carefully at my sample script for how to do it in a simple case.
Thank you!
perric wrote: Hi All,
I have been away and just got back. Thanks for all replies, etc. I know how to write the data to a file, but I need to figure out how to retrieve the data from a file.
The initial question is resolved.
David
Let us know if eloyd's solution works for you.
Thanks.
Former Nagios Employee.
me.
perric
Posts: 161 Joined: Fri Mar 28, 2014 10:37 am
Post
by perric » Fri Aug 21, 2015 4:34 pm
Eloyd's solution is working great. Sorry - somehow I missed that post.
Thank you. Below is my final script.
David
Code: Select all
#!/bin/bash
#### Collect previous reading from temp files ####
inbound=0
[ -r "/tmp/nagios/$1.in.last" ] && inbound=$(</tmp/nagios/$1.in.last)
outbound=0
[ -r "/tmp/nagios/$1.out.last" ] && outbound=$(</tmp/nagios/$1.out.last)
#### Collect 2nd reading ####
inbound_temp2="$(/usr/local/nagios/libexec/check_snmp $1 -P 2c -C $2 -o 1.3.6.1.2.1.31.1.1.1.6.$4)"
outbound_temp2="$(/usr/local/nagios/libexec/check_snmp $1 -P 2c -C $2 -o 1.3.6.1.2.1.31.1.1.1.10.$4)"
inbound2=`echo $inbound_temp2|grep -oP '(?<=\-)(.*?)(?=\|)'`
outbound2=`echo $outbound_temp2 |grep -oP '(?<=\-)(.*?)(?=\|)'`
#### Save new readings to files for next collection
echo "$inbound2" > /tmp/nagios/$1.in.last
echo "$outbound2" > /tmp/nagios/$1.out.last
### Perform Logic here
inbound_per=$(( (($inbound2 - $inbound) * 8) / ($3 * 1000000)))
outbound_per=$(( (($outbound2 - $outbound) * 8) / ($3 * 1000000)))
total=$(( ($inbound_per + $outbound_per)/2 ))
#echo "Inbound Percent = $inbound_per"
#echo "Outbound Percent = $outbound_per"
#echo "Total Percent = $total"
perfdata="| 'inbound'=$inbound_per%;;;0;100 'outbound'=$outbound_per%;;;0;100"
if [ "$total" -ge "90" ];then
echo "CRITICAL - Total traffic above threshold - $total $perfdata"
exit 2
elif [ "$total" -ge "80" ];then
echo "WARNING - Total traffic above threshold - $total $perfdata"
exit 1
else
echo "OK - Traffic at good percentage $perfdata"
exit 0
fi
eloyd
Cool Title Here
Posts: 2190 Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:
Post
by eloyd » Sat Aug 22, 2015 8:48 am
Glad I could help. As it says below, feel free to nominate me for an MVP award if you think I was helpful!
BanditBBS
Posts: 2474 Joined: Tue May 31, 2011 12:57 pm
Location: Scio, OH
Contact:
Post
by BanditBBS » Sat Aug 22, 2015 7:13 pm
eloyd wrote: Glad I could help. As it says below, feel free to nominate me for an MVP award if you think I was helpful!
No no no, nominate the guy who volunteered first and wrote the script
or....nom us both, lol
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at
BanditBBS - Also check out my Nagios stuff on my personal page at
Bandit's Home and at
github
eloyd
Cool Title Here
Posts: 2190 Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:
Post
by eloyd » Sat Aug 22, 2015 7:40 pm
Haha! Yah, you can nominate Bandit if you want, too.
tmcdonald
Posts: 9117 Joined: Mon Sep 23, 2013 8:40 am
Post
by tmcdonald » Sun Aug 23, 2015 6:53 pm
@perric , are we all clear to close this up now?
Former Nagios employee
perric
Posts: 161 Joined: Fri Mar 28, 2014 10:37 am
Post
by perric » Tue Aug 25, 2015 1:22 pm
Yes, thanks. Good to close.
Zero values (when a device was inaccessible) were causing both negative and positive spikes in the graphs, so I updated the script to accommodate. See below.
David
Code: Select all
#!/bin/bash
#### Collect previous reading from temp files ####
inbound=0
[ -r "/tmp/nagios/$1.in.last" ] && inbound=$(</tmp/nagios/$1.in.last)
outbound=0
[ -r "/tmp/nagios/$1.out.last" ] && outbound=$(</tmp/nagios/$1.out.last)
#### Collect 2nd reading ####
inbound_temp2="$(/usr/local/nagios/libexec/check_snmp $1 -P 2c -C $2 -o 1.3.6.1.2.1.2.2.1.10.$4)"
#1.3.6.1.2.1.31.1.1.1.6.$4)"
outbound_temp2="$(/usr/local/nagios/libexec/check_snmp $1 -P 2c -C $2 -o 1.3.6.1.2.1.2.2.1.16.$4)"
#1.3.6.1.2.1.31.1.1.1.10.$4)"
inbound2=`echo $inbound_temp2|grep -oP '(?<=\-)(.*?)(?=\|)'`
outbound2=`echo $outbound_temp2 |grep -oP '(?<=\-)(.*?)(?=\|)'`
#### Save new readings to files for next collection
echo "$inbound2" > /tmp/nagios/$1.in.last
echo "$outbound2" > /tmp/nagios/$1.out.last
### Perform Logic here
#echo "$inbound"
#echo "$inbound2"
#echo "$outbound"
#echo "$outbound2"
### Avoid spikes caused by zero values, when device is not available
if [ $inbound -eq 0 ] || [ $inbound2 -eq 0 ]
then
$inbound_per=0
else
inbound_per=$(( (($inbound2 - $inbound) * 8) / ($3 * 1000000)))
fi
#echo "$inbound_per"
if [ $outbound -eq 0 ] || [ $outbound2 -eq 0 ]
then
$outbound_per=0
else
outbound_per=$(( (($outbound2 - $outbound) * 8) / ($3 * 1000000)))
fi
#echo "$outbound_per"
total=$(( ($inbound_per + $outbound_per)/2 ))
#echo "Inbound Percent = $inbound_per"
#echo "Outbound Percent = $outbound_per"
#echo "Total Percent = $total"
perfdata="| 'inbound'=$inbound_per%;;;0;100 'outbound'=$outbound_per%;;;0;100"
if [ "$total" -ge "90" ];then
echo "CRITICAL - Total traffic above threshold - $total $perfdata"
exit 2
elif [ "$total" -ge "80" ];then
echo "WARNING - Total traffic above threshold - $total $perfdata"
exit 1
else
echo "OK - Traffic at good percentage $perfdata"
exit 0
fi