Page 1 of 1

How to escape special characters in query

Posted: Fri May 22, 2015 9:44 am
by sureshkraj2012
Hello,

I am trying to execute below command in Nagios server but it shows below error though the query works well locally and dont_blame_nrpe set to 1.

[test1@Nagios_server ~]$ /usr/local/nagios/libexec/check_nrpe -H postdb.domain.COM -t 80 -u -c check_postgres -a '--dbuser=postgres --dbname=db12 --dbpass=pos0!23 --port=5432 --action=custom_query --query="select count (date_created) as result from msg where DATE_CREATED >= (now() - INTERVAL '6 hour') and channel_id ='12v' and status ilike 'complete';" -c 2001 --reverse --showperf=1 --include=result --PGBINDIR=/opt/pgsql93/bin/'
CHECK_NRPE: Received 0 bytes from daemon. Check the remote server logs for error messages.

Command declared in postgres server:

command[check_postgres]=/usr/lib64/nagios/plugins/check_postgres.pl $ARG1$ $ARG2$ $ARG3$

Log message in the postgres DB server

May 22 08:41:11 postdb nrpe[17904]: Error: Request contained illegal metachars!
May 22 08:41:11 postdb nrpe[17904]: Client request was invalid, bailing out...

Please help to resolve the problem

Re: How to escape special characters in query

Posted: Fri May 22, 2015 11:41 am
by jolson
In a case like this, it's quite possibly easier to manage the configuration on the client side of things. Since you stated that the query works well locally, it'd be a simple matter of adding it to nrpe.cfg and calling that command from Nagios. Let me know if you need further elaboration.

If you would like to stick with your current method, I would try stripping our pieces of your command until we figure out where exactly it's failing:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H postdb.domain.COM -t 80 -u -c check_postgres -a "--dbuser=postgres --dbname=db12 --dbpass=pos0!23 --port=5432"
Does the above return proper output?

Re: How to escape special characters in query

Posted: Sat May 23, 2015 12:34 pm
by sureshkraj2012
Yes. It returns output

/usr/local/nagios/libexec/check_nrpe -H postdb.domain.COM -t 80 -u -c check_postgres -a "--dbuser=postgres --dbname=db12 --dbpass=pos0!23 --port=5432 --action=connection --PGBINDIR=/opt/pgsql93/bin/"
POSTGRES_CONNECTION OK: DB "db12" version 9.3.5 | time=0.10s

Re: How to escape special characters in query

Posted: Sun May 24, 2015 10:48 pm
by Box293
sureshkraj2012 wrote:--dbpass=pos0!23
The exclamation mark ! in your password is the cause of the problem. Either change the password or put the password into a user macro.