Combine 2 SNMP Service Checks into a graph & calculation
Re: Combine 2 SNMP Service Checks into a graph & calculation
That should work.
Re: Combine 2 SNMP Service Checks into a graph & calculation
Very ugly script, but here ya go!
Call it whatever you want, for this example, we'll go with "banditisawesome.sh".
Call it like this, ./banditisawesome.sh totalsize warn crit IP, for example: ./banditisawesome.sh 10000000000 80 90 10.197.0.11
Note: I did not try it in action actually using the $4 for IP. I was testing with your example output, but I think my code is good.
Example output:
Call it whatever you want, for this example, we'll go with "banditisawesome.sh".
Call it like this, ./banditisawesome.sh totalsize warn crit IP, for example: ./banditisawesome.sh 10000000000 80 90 10.197.0.11
Code: Select all
#!/bin/bash
inbound_temp="$(/usr/local/nagios/libexec/check_snmp $4 -C public -o 1.3.6.1.2.1.2.2.1.10.15)"
#inbound_temp="SNMP OK - 3788642629 | iso.3.6.1.2.1.2.2.1.10.15=3788642629c"
outbound_temp="$(/usr/local/nagios/libexec/check_snmp $4 -C public -o 1.3.6.1.2.1.2.2.1.16.15)"
#outbound_temp="SNMP OK - 4243923118 | iso.3.6.1.2.1.2.2.1.16.15=4243923118c"
inbound=`echo $inbound_temp|grep -oP '(?<=\-)(.*?)(?=\|)'`
outbound=`echo $outbound_temp |grep -oP '(?<=\-)(.*?)(?=\|)'`
### Perform Logic here
inbound_per=$(echo $inbound $1|awk '{ print $1/$2*100 }')
inbound_per=`printf %.0f $inbound_per`
outbound_per=$(echo $outbound $1|awk '{ print $1/$2*100 }')
outbound_per=`printf %.0f $outbound_per`
total=$(( $inbound_per + $outbound_per ))
#echo "Inbound Percent = $inbound_per"
#echo "Outbound Percent = $outbound_per"
#echo "Total Percent = $total"
perfdata="| 'total'=$total%;$2;$3;0;100 'inbound'=$inbound_per%;;;0;100 'outbound'=$outbound_per%;;;0;100"
if [ "$total" -ge "$3" ];then
echo "CRITICAL - Total traffic above threshold - $total $perfdata"
exit 2
elif [ "$total" -ge "$2" ];then
echo "WARNING - Total traffic above threshold - $total $perfdata"
exit 1
else
echo "OK - Traffic at good percentage $perfdata"
exit 0
fi
Example output:
Code: Select all
WARNING - Total traffic above threshold - 80 | 'total'=80%;80;99;0;100 'inbound'=38%;;;0;100 'outbound'=42%;;;0;1002 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
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
Re: Combine 2 SNMP Service Checks into a graph & calculation
Thanks for posting that BanditBBS!
perric, let us know if that will work for you or if you have any other questions.
perric, let us know if that will work for you or if you have any other questions.
Re: Combine 2 SNMP Service Checks into a graph & calculation
Thanks Bandit. A few questions... sorry, but I am a novice with Nagios.
I understand inbound_temp, inbound, inbound_per, etc., but can you confirm if I am understanding the variables that appear to be "called" or submitted when running the script?
$1 - ?
$2 - Maximum or Total Link speed
$3 - Threshold Level - 80%, for example
$4 - Device IP Address
How does this data appear into a Nagios chart? Is that done via the $perfdata variable that Nagios will receive as the output from this script?
Will Nagios read the WARNING and CRITICAL Values echoed from the script for alerting purposes?
How can I define colors for the chart data, so that my inbound data is one color (ex: red) and outbound is another color (ex: blue)?
David
I understand inbound_temp, inbound, inbound_per, etc., but can you confirm if I am understanding the variables that appear to be "called" or submitted when running the script?
$1 - ?
$2 - Maximum or Total Link speed
$3 - Threshold Level - 80%, for example
$4 - Device IP Address
How does this data appear into a Nagios chart? Is that done via the $perfdata variable that Nagios will receive as the output from this script?
Will Nagios read the WARNING and CRITICAL Values echoed from the script for alerting purposes?
How can I define colors for the chart data, so that my inbound data is one color (ex: red) and outbound is another color (ex: blue)?
David
Re: Combine 2 SNMP Service Checks into a graph & calculation
$1 - Link speedperric wrote:Thanks Bandit. A few questions... sorry, but I am a novice with Nagios.
I understand inbound_temp, inbound, inbound_per, etc., but can you confirm if I am understanding the variables that appear to be "called" or submitted when running the script?
$1 - ?
$2 - Maximum or Total Link speed
$3 - Threshold Level - 80%, for example
$4 - Device IP Address
How does this data appear into a Nagios chart? Is that done via the $perfdata variable that Nagios will receive as the output from this script?
Will Nagios read the WARNING and CRITICAL Values echoed from the script for alerting purposes?
How can I define colors for the chart data, so that my inbound data is one color (ex: red) and outbound is another color (ex: blue)?
David
$2 - Warning threshold for total used speed
$3 - Critical threshold for total used speed
$4 - Device IP address
Yes, $perfdata variable is all the data for the charts to be created. the | designates the end of results, beginning of performance data so nagios can properly parse the data. Nagios doesn't assign WARNING or CRITICAL, that is the job of plugins and nagios just reads that result. The script I wrote adds both inbound and outbound percentage together and alerts based on the $2 and $3 variables.
NagiosXI will auto assign colors to the three charted items(total, in, out)
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
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
Re: Combine 2 SNMP Service Checks into a graph & calculation
What complicated grepping. Why not just awk '{print $3}' to grab the bytes instead of grep -oP? 
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
Re: Combine 2 SNMP Service Checks into a graph & calculation
Oh hush, it works! LOLeloyd wrote:What complicated grepping. Why not just awk '{print $3}' to grab the bytes instead of grep -oP?
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
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
Re: Combine 2 SNMP Service Checks into a graph & calculation
Thanks for the help, Bandit!
@perric, does that answer everything for you? Does the script work as you need?
@perric, does that answer everything for you? Does the script work as you need?
Former Nagios employee
Re: Combine 2 SNMP Service Checks into a graph & calculation
Bandit,
Thanks. I am not getting output so far. I added the script into Nagios as a command. I am assuming that the $1, $2, $3, etc. are arguments that can be passed from Nagios. I also tried changing the variables $1, $2, etc. to $ARG1$, $ARG2$, etc., but no luck.
Here is a screenshot of my service check screen.
When I do a check from the GUI, I get the following:
COMMAND: /usr/local/nagios/libexec/check_cisco_bw.sh 20 50 80 10.192.0.11 15
OUTPUT:
I made one change to the script by adding $5, so I can specify an OID option as an argument.
From CLI, I get the following:
[root@nag1 libexec]# check_cisco_bw.sh 20 0 0 10.192.0.11 15
awk: (FILENAME=- FNR=1) fatal: division by zero attempted
awk: (FILENAME=- FNR=1) fatal: division by zero attempted
CRITICAL - Total traffic above threshold - 0 | 'total'=0%;0;0;0;100 'inbound'=0%;;;0;100 'outbound'=0%;;;0;100
David
Thanks. I am not getting output so far. I added the script into Nagios as a command. I am assuming that the $1, $2, $3, etc. are arguments that can be passed from Nagios. I also tried changing the variables $1, $2, etc. to $ARG1$, $ARG2$, etc., but no luck.
Here is a screenshot of my service check screen.
When I do a check from the GUI, I get the following:
COMMAND: /usr/local/nagios/libexec/check_cisco_bw.sh 20 50 80 10.192.0.11 15
OUTPUT:
I made one change to the script by adding $5, so I can specify an OID option as an argument.
Code: Select all
#!/bin/bash
inbound_temp="$(/usr/local/nagios/libexec/check_snmp $4 -C public -o 1.3.6.1.2.1.2.2.1.10.[b]$5[/b])"
#inbound_temp="SNMP OK - 3788642629 | iso.3.6.1.2.1.2.2.1.10.15=3788642629c"
outbound_temp="$(/usr/local/nagios/libexec/check_snmp $4 -C public -o 1.3.6.1.2.1.2.2.1.16.[b]$5[/b])"
#outbound_temp="SNMP OK - 4243923118 | iso.3.6.1.2.1.2.2.1.16.15=4243923118c"[root@nag1 libexec]# check_cisco_bw.sh 20 0 0 10.192.0.11 15
awk: (FILENAME=- FNR=1) fatal: division by zero attempted
awk: (FILENAME=- FNR=1) fatal: division by zero attempted
CRITICAL - Total traffic above threshold - 0 | 'total'=0%;0;0;0;100 'inbound'=0%;;;0;100 'outbound'=0%;;;0;100
David
You do not have the required permissions to view the files attached to this post.
Re: Combine 2 SNMP Service Checks into a graph & calculation
Whats with the and bolding commands around your $5? Also, according to your example outputs you gave me, the numbers were 3788642629 and 4243923118 so not sure how the first CLI argument you are supplying is only 20. You sure it shouldn't be 20000000000 ?
Try and hardcode the IP address and see if it works also, thats the one thing I changed as I was just using your example outputs and wasn't actually running the check_snmp queries. If that works, let me know and I'll fix whatever I screwed up
I would try it from command line before worrying if it works in Nagios. You could remove the # from some of the echo commands too, just to see what its seeing in parts of the script, maybe add at line 5 That will show you on the CLI what it is getting back from each check_snmp line.
Code: Select all
[b]Code: Select all
[/b]Try and hardcode the IP address and see if it works also, thats the one thing I changed as I was just using your example outputs and wasn't actually running the check_snmp queries. If that works, let me know and I'll fix whatever I screwed up
I would try it from command line before worrying if it works in Nagios. You could remove the # from some of the echo commands too, just to see what its seeing in parts of the script, maybe add at line 5
Code: Select all
echo "inbound_temp = $inbound_temp"
echo "outbound_temp = $outbound_temp"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
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