Page 1 of 1

Escape Exclamation Mark (!) in argument with check_nrpe

Posted: Thu Nov 20, 2014 5:43 am
by warnox
Hey,

I'm trying to execute the command below from the Nagios server using check_nrpe but the exclamation mark (!) is not getting passed to the remote host. I tried escaping it with a back slash (\) but that doesn't work either.

According to http://nagios.sourceforge.net/docs/3_0/whatsnew.html, escaping is supported in Nagios 3.0.

Code: Select all

# /usr/local/nagios/libexec/check_nrpe -H xxx.xxx.xxx.xxx -c check_winservice -a '--startmode auto --state !running --verbose'
Service state(s): running
Service start modes: auto
Service(s): all
Number of services selected: 50
SERVICE OK - 50 service(s).|'services'=50
If I replace '!running' with '\!running' it only passes through '\'.

Code: Select all

# /usr/local/nagios/libexec/check_nrpe -H 10.44.1.85 -c check_winservice -a '--startmode auto --state \!running --verbose'
Service state(s): \
Service start modes: auto
Service(s): all
Number of services selected: 0
SERVICE OK - 0 service(s).|'services'=0
On the NSClient end I have the following in nsclient.ini.

Code: Select all

check_winservice = scripts\check_winservice.exe $ARG1$ $ARG2$ $ARG3$ $ARG4$ $ARG5$ $ARG6$ $ARG7$
Running the command locally on the client works fine, so it's definitely an escaping problem with check_nrpe.

Thanks for any help.

Re: Escape Exclamation Mark (!) in argument with check_nrpe

Posted: Thu Nov 20, 2014 9:50 am
by eloyd
I hate all that escaping stuff that needs to be done. I'm not saying this will work, and I'm not saying that I've tried this, but here are some ideas:

Put the $ARGx$ variables in double quotes on the client side.

Try double-escapping (meaning, escape the escape) like this: \\\!running

Last-ditch effort is that you could define a one-off check that doesn't pass this information as an arugment, but includes it on the remote side as a hard-coded option.

Re: Escape Exclamation Mark (!) in argument with check_nrpe

Posted: Thu Nov 20, 2014 10:07 am
by warnox
eloyd wrote:I hate all that escaping stuff that needs to be done. I'm not saying this will work, and I'm not saying that I've tried this, but here are some ideas:

Put the $ARGx$ variables in double quotes on the client side.

Try double-escapping (meaning, escape the escape) like this: \\\!running

Last-ditch effort is that you could define a one-off check that doesn't pass this information as an arugment, but includes it on the remote side as a hard-coded option.
Thanks for your quick response and I'm with you on escaping stuff but thought I was just doing something wrong. Anyway, below are the results.

1. Quotes around $ARGx$ didn't work, the command doesn't run properly.

Code: Select all

Unknown option: startmode auto --state \" running
Unknown option: verbose $arg3$ $arg4$ $arg5$ $arg6$ $arg7$
2. Double escaping doesn't work either.

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H xxx.xxx.xxx.xxx -c check_winservice -a '--startmode auto --state \\\!running --critical 0 --verbose'
Service state(s): \\\
3. Yep, that works but I wanted to avoid doing it this way :)

Code: Select all

check_auto_services = scripts\check_winservice.exe --state !running $ARG1$ $ARG2$ $ARG3$ $ARG4$ $ARG5$ $ARG6$

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H xxx.xxx.xxx.xxx -c check_auto_services -a '--startmode auto --critical 0 --verbose'
Service state(s): !running
Service start modes: auto
Service(s): all
Number of services selected: 2
SERVICE CRITICAL - 2 service(s).|'services'=2;;0

Re: Escape Exclamation Mark (!) in argument with check_nrpe

Posted: Thu Nov 20, 2014 5:59 pm
by scottwilkerson
warnox wrote:
3. Yep, that works but I wanted to avoid doing it this way :)

Code: Select all

check_auto_services = scripts\check_winservice.exe --state !running $ARG1$ $ARG2$ $ARG3$ $ARG4$ $ARG5$ $ARG6$

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H xxx.xxx.xxx.xxx -c check_auto_services -a '--startmode auto --critical 0 --verbose'
Service state(s): !running
Service start modes: auto
Service(s): all
Number of services selected: 2
SERVICE CRITICAL - 2 service(s).|'services'=2;;0
Unfortunately with the ! used to break arguments in the nagios config, this is the only way I know of to make this work with a NRPE check....

Re: Escape Exclamation Mark (!) in argument with check_nrpe

Posted: Fri Nov 21, 2014 3:56 am
by warnox
Yea cool, though it might be.

Thanks for your help!