How to escape special characters in query

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
sureshkraj2012
Posts: 65
Joined: Tue Aug 06, 2013 11:06 pm

How to escape special characters in query

Post 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
jolson
Attack Rabbit
Posts: 2560
Joined: Thu Feb 12, 2015 12:40 pm

Re: How to escape special characters in query

Post 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?
Twits Blog
Show me a man who lives alone and has a perpetually clean kitchen, and 8 times out of 9 I'll show you a man with detestable spiritual qualities.
sureshkraj2012
Posts: 65
Joined: Tue Aug 06, 2013 11:06 pm

Re: How to escape special characters in query

Post 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
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: How to escape special characters in query

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked