I’ve written a bash script wrapper for the check_snmp plugin for two of my check commands. I did this with the help of some online resources and existing bash scripts for check_snmp that a previous icinga user in my organization made. Everything in the script looks right to me, but on the icinga2 dashboard it just displays the usage.
Usage: /usr/lib64/nagios/plugins/check_ML3_power.sh [-H ] [-o ] [-C ]
I’m assuming the arguments I’ve defined in my file for the check command itself aren’t being passed properly when the script runs? I must have made an error in the script.
Here’s my bash script:
#!/bin/bash
#Shell script to map default SNMP output to meaningful description
#For Dell EML ML3 Tape Library power supply states
#Exit codes: OK(0), WARNING(1), CRITICAL(2), UNKNOWN(3)
usage() {
echo “Usage: $0 [-H ] [-o ] [-C ]” 1>&2;
exit 3;
}
while getopts “:H:o:C” option; do
case “${option}” in
H) HOSTIP=${OPTARG};;
o) OID=${OPTARG};;
C) COMMUNITY=${OPTARG};;
*) usage;
esac
done
shift “$((OPTIND-1))”
if [ -z “${HOSTIP}” ] || [ -z “${OID}” ] || [ -z “${COMMUNITY}” ]; then
usage
fi
/usr/lib64/nagios/plugins/check_snmp -H ${HOSTIP} -o ${OID} -C ${COMMUNITY} 2>/dev/null |
awk ‘{print $4}’ |
while read -r line; do
if [[ $line == “2” ]]; then
echo “Power Supply: OK”;
exit 0;
fi
if [[ $line == “3” ]]; then
echo “Power Supply: NOT OK, needs to be checked”;
exit 3;
fi
done
The check command that uses this script (in my commands.conf file):
object CheckCommand “PS1-Status” {
import “plugin-check-command”
command = [ PluginDir + “/check_ML3_power.sh” ]
arguments = {
“-H” = “$address$”
“-C” = “1c1ng@2”
“-o” = “.1.3.6.1.4.1.2.6.257.1.3.2.1.3.1”
“-c” = “3”
“-P” = “2c”
}
}
object CheckCommand “PS2-Status” {
import “plugin-check-command”
command = [ PluginDir + “/check_ML3_power.sh” ]
arguments = {
“-H” = “$address$”
“-C” = “1c1ng@2”
“-o” = “.1.3.6.1.4.1.2.6.257.1.3.2.1.4.1”
“-c” = “3”
“-P” = “2c”
}
}
I’d appreciate any guidance, thanks!