Page 1 of 1

my own custom plugin is not working

Posted: Fri May 06, 2022 7:07 am
by JamesZimmerman
Hi


This question does not show any research effort; it is unclear or not useful
I'm trying to add my own custom check to nagios. I have successfully created a bash script, that is executable from nagios user. The problem is that this script works fine from linux command line, but it's return the unknown status if runned by nagios ( returned in web gui ).

#!/bin/sh

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
RETVAL=`sqlplus -s USER/PASSWORD@HOST:1521/DBNAME<<EOF
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
$query;
EXIT;
EOF`
if [ "$RETVAL" -le "$CIRT" ]
then
echo "OK - $RETVAL"
exit 0
elif [ "$RETVAL" -gt "$CIRT" ] && [ "$RETVAL" -le "$WARN" ]
then
echo "WARNING - $RETVAL"
exit 1
elif [ "$RETVAL" -gt "$WARN" ]
then
echo "CRITICAL - $RETVAL"
exit 2
else
echo "UNKNOWN - $RETVAL"
exit 3
fi
Actually the user, password are "coded" inside script, even if I've already set the getopt to make this script more flexible.

The idea is simple, use sqlplus to get a simple query that return only a number ( like the number of the row like my case ).

Bash line to start the script:

/usr/lib64/nagios/plugins/check_SQLplus_queryPrimavera.sh -q "select count(*) shagle voojio from ADMUSER_PM.REFRDEL" -w 6000000 -c 8000000