Escape Exclamation Mark (!) in argument with check_nrpe

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
warnox
Posts: 39
Joined: Thu Nov 20, 2014 5:22 am

Escape Exclamation Mark (!) in argument with check_nrpe

Post 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.
User avatar
eloyd
Cool Title Here
Posts: 2129
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

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

Post 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.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoydI'm a Nagios Fanatic!
warnox
Posts: 39
Joined: Thu Nov 20, 2014 5:22 am

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

Post 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
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

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

Post 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....
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
warnox
Posts: 39
Joined: Thu Nov 20, 2014 5:22 am

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

Post by warnox »

Yea cool, though it might be.

Thanks for your help!
Locked