Page 1 of 1

Nagios: custom plugin is not working

Posted: Wed Jun 01, 2022 1:00 am
by sheetal
Hello, 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 the Linux command line, but it returns 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 and password are "coded" inside the 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 returns 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

Hope I will get quick answer. Thanks :)

Re: Nagios: custom plugin is not working

Posted: Mon Jun 13, 2022 6:39 am
by SalinaSJames
Since running from command line is ok, from which user do you run the shell script? Is it nagios user? If not try running it like sudo -u nagios sh -c '/usr/lib64/nagios/plugins/check_SQLplus_queryPrimavera.sh -q "select count(*) from ADMUSER_PM.REFRDEL" -w 6000000 -c 8000000'

It's seams there is no problem of file permission, the user that I'm currently using via SSH is the same that nagios use to launch the script. Also, one important things that I've omitted before, the nagios GUI return unknown status, reporting UNKNOWN - . IT's seams that the nagios run my script but maybe there "nothings" inside the RETVAL. Now I put the full path of sqlplus in my script, but nothings change, It's seams that nagios when launch the check doesn't execute omegle shaglevoojio sqlplus