Page 1 of 1
Proper escaping?
Posted: Thu Jul 31, 2014 12:08 pm
by BanditBBS
Ok, so I run this from command line:
Code: Select all
/usr/local/nagios/libexec/check_oracle_nrs.sh "select 1 from dual where exists (select p.inst_id, machine, count(distinct spid) from gv\$process p , gv\$session s where p.inst_id=s.inst_id and p.addr=s.paddr group by p.inst_id , machine having count(distinct spid) > 500 );" server.com 1522 PRODEBS
and I get
Notice there are a couple $ that are being escaped and fed to my custom script. My issue now is, I can't figure out how to put this in an argument. In the bash script I have
Code: Select all
TEST=`echo $1| /usr/bin/env LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib ORACLE_HOME=/usr/lib/oracle/11.2/client64 /usr/lib/oracle/11.2/client64/bin/sqlplus -s user/pass@//$2:$3/$4`
CORRECT="no rows selected"
if [[ "$TEST" != *"$CORRECT"* ]]; then
echo "CRITICAL: $TEST"
exit 2
fi
echo "OK: No Rows Selected"
exit 0
If it didn't have the $ inside the sql query this would all be working.
Re: Proper escaping?
Posted: Thu Jul 31, 2014 12:28 pm
by tmcdonald
Single quotes around the sql command instead of double might do it. Remember to then unescape the dollars.
Re: Proper escaping?
Posted: Thu Jul 31, 2014 12:46 pm
by BanditBBS
Still getting errors when configuring in XI.
Code: Select all
define service {
host_name extn-chi-pdb01
service_description PRODEBS - MX_DB_Processes
use extn_generic-service-5
servicegroups extn_prodebs
check_command check_xi_oraclenrs!'select 1 from dual where exists (select p.inst_id, machine, count(distinct spid) from gv$process p , gv$session s where p.inst_id=s.inst_id and p.addr=s.paddr group by p.inst_id , machine having count(distinct spid) > 500 );'!1522!PRODEBS!!!!!
check_period xi_timeperiod_24x7
notification_period xi_timeperiod_24x7
_xiwizard oraclequery
register 1
}
Here is what I see in XI:
Code: Select all
(No output on stdout) stderr: /bin/sh: -c: line 0: unexpected EOF while looking for matching `''
/bin/sh: -c: line 1: syntax error: unexpected end of file
Works fine from command line...any more ideas?
Re: Proper escaping?
Posted: Thu Jul 31, 2014 3:54 pm
by lmiltchev
How did you modify your check command - in the CCM or via Home->Service Detail->Configure-Re-Configure this service? I've seen cases when modifying via "Confiture->Re-configure..." doesn't work, when using ";" semi-colon in the check command. Nagios strips out everything after the ";". It works fine if you use the CCM for mods.
Re: Proper escaping?
Posted: Thu Jul 31, 2014 7:57 pm
by BanditBBS
lmiltchev wrote:How did you modify your check command - in the CCM or via Home->Service Detail->Configure-Re-Configure this service? I've seen cases when modifying via "Confiture->Re-configure..." doesn't work, when using ";" semi-colon in the check command. Nagios strips out everything after the ";". It works fine if you use the CCM for mods.
I used CCM, I rarely use the reconfigure option and right now the testing is a pain because of my 15 minute restart issue. However, I fixed it with your assistance Ludmil. It was the ";" causing the issue. I ended up removing the ; and just adding it in my script
Code: Select all
TEST=`echo "$1;"| /usr/bin/env LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib ORACLE_HOME=/usr/lib/oracle/11.2/client64 /usr/lib/oracle/11.2/client64/bin/sqlplus -s user/pass@//$2:$3/$4`
CORRECT="no rows selected"
if [[ "$TEST" != *"$CORRECT"* ]]; then
echo "CRITICAL: $TEST"
exit 2
fi
echo "OK: No Rows Selected"
#echo "$1"
exit 0
Close this up, issue has been worked around. Feel free to open an internal bug report abotu the ; causing escaping issues if you'd like. With the ; on the end of ARG1 the other ARG's were then ignored when the check ran, it caused all kinds of fun for me.