Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
nbradshaw45
Posts: 11 Joined: Tue Jan 31, 2017 5:09 pm
Post
by nbradshaw45 » Tue Jan 31, 2017 5:22 pm
Hello -
I needed a way to take a value and divide it by 100 - so I found an article that explained how to use awk to come up with the needed value - and this works great - however, it does not return the warning;critical values.
Code: Select all
[icode]#!/bin/bash
hostaddress=$1
/usr/local/nagios/libexec/check_snmp -H $hostaddress -C R3adM3 -m ALL -o .1.3.6.1.4.1.7309.4.1.1.1.0 | awk -F'|' '{split($1,array_left,"-");} {split($2,array_right,"=");} {print array_left[1]"- "array_left[2]/100"|"array_right[1]"="array_right[2]/100;}'[/icode]
How can I adapt this bash script to use the proper exit codes for warning and critical?
Much appreciated!
rkennedy
Posts: 6579 Joined: Mon Oct 05, 2015 11:45 am
Post
by rkennedy » Tue Jan 31, 2017 5:59 pm
You would need to have the plugin run again, executing normally do display the proper exit code / other data, or write a full on wrapper to handle your logic for warning / critical as well.
Feel free to base it off something like this -
https://github.com/rcknag/nagios-plugin ... netstat.sh
Former Nagios Employee
nbradshaw45
Posts: 11 Joined: Tue Jan 31, 2017 5:09 pm
Post
by nbradshaw45 » Wed Feb 01, 2017 3:08 pm
Thanks for the response -
I have put the plugin together - however, the output is always "CRITICAL - 54". Even when I don't set -w -c...it always returns CRITICAL.
[root@CRLNAGP01 libexec]# ./check_snmp_argus_battery_charge_in_volts.sh 10.150.101.20 -w9000 -c10000
CRITICAL - 54
Code: Select all
#!/bin/bash
hostaddress=$1
#snmp=$(/usr/local/nagios/libexec/check_snmp -H $hostaddress -C R3adM3 -m ALL -o .1.3.6.1.4.1.7309.4.1.1.1.0 | awk -F'|' '{split($1,array_left,"-");} {split($2,array_right,"=");} {print array_left[1]"- "array_left[2]/100"|"array_right[1]"="array_right[2]/100;}')
snmp=$(/usr/local/nagios/libexec/check_snmp -H $hostaddress -C R3adM3 -m ALL -o .1.3.6.1.4.1.7309.4.1.1.1.0 |cut -b 11-14)
#snmp=$(/usr/local/nagios/libexec/check_snmp -H $1 -C 'mycommunity string' -o .1.3.6.1.4.1.7309.4.1.1.1.0|cut -b 11-14)
#snmp=$(/usr/local/nagios/libexec/check_snmp -H $hostaddress -C R3adM3 -m ALL -o .1.3.6.1.4.1.7309.4.1.1.1.0 |cut -b 11-14)
while getopts ":q:c:w:h:u:p" optname
do
case "$optname" in "q") query=$OPTARG
;;
"c") CIRT=$OPTARG
;;
"w") WARN=$OPTARG
;;
"u") user=$OPTARG
;;
"p") pswd=$OPTARG
;;
"h") echo "Useage: check_SQLplus_query -u user -p password -w warning value -c cirtical value"
exit
;;
"?") echo "Unknown option $OPTARG"
exit
;;
":") echo "No argument value for option $OPTARG"
exit
;;
*) # Should not occur
echo "Unknown error while processing options"
exit
;;
esac
done
#value=$snmp
value=$(expr $snmp / 100)
if [[ "$value" -le "$CIRT" ]]
then
echo "OK - $value"
exit 0
elif [[ "$value" -gt "$CIRT" ]] && [[ "$value" -le "$WARN" ]]
then
echo "WARNING - $value"
exit 1
elif [[ "$value" -gt "$WARN" ]]
then
echo "CRITICAL - $value"
exit 2
else
echo "UNKNOWN - $value"
exit 3
fi
rkennedy
Posts: 6579 Joined: Mon Oct 05, 2015 11:45 am
Post
by rkennedy » Wed Feb 01, 2017 4:18 pm
I would add an debug to echo what $snmp is equal to before dividing by 100.
Former Nagios Employee
nbradshaw45
Posts: 11 Joined: Tue Jan 31, 2017 5:09 pm
Post
by nbradshaw45 » Wed Feb 01, 2017 4:21 pm
Thanks for the reply...yes - I can echo the original value just fine.
I think what is going on is that the -w -c flags are not being interpreted by my script...can you take a look and see why it is not passing - mistake in my script I'm Sure.
rkennedy
Posts: 6579 Joined: Mon Oct 05, 2015 11:45 am
Post
by rkennedy » Wed Feb 01, 2017 5:41 pm
Is it debugging to what you'd expect? Try this with spaces after the vars - ./check_snmp_argus_battery_charge_in_volts.sh 10.150.101.20 -w 9000 -c 10000 - to take -w / -c out you could always just get sloppy with $2 and $3.
Former Nagios Employee
tmcdonald
Posts: 9117 Joined: Mon Sep 23, 2013 8:40 am
Post
by tmcdonald » Wed Mar 01, 2017 2:14 pm
Just checking in since we have not heard from you in a while. Did
@rkennedy 's post clear things up or has the issue otherwise been resolved?
Former Nagios employee