Double escaping in $ARGx$

Andreas Ericsson ae at op5.se
Tue Aug 11 10:30:07 CEST 2009


Ton Voon wrote:
> 
> On 31 Jul 2009, at 16:10, Ethan Galstad wrote:
> 
> Andreas writes:
>> Why use the exclamation mark at all? It's quite straightforward to parse
>> shell-style quoting into arguments, and that way users can just 
>> cut-n-paste
>> the commands to verify that they work (assuming they replace the macros,
>> that is).
> 
> 
> That's wrong. You use execve to avoid the shell quoting and to pass in 
> arguments "as-is" to the plugin without interpretation at the shell 
> level.

I'm well aware of that, but hand-parsing it inside Nagios would not be
difficult, assuming we can still pass commands with sub-shells to the
shell for execution.

The runcmd stuff in nagiosplugins does exactly that, so we could reuse
that (by now thoroughly tested) code.

I've changed my mind about the exclamation mark though, but using it
in a command_line statement for a command object shouldn't mean it
requires escaping. Using it in the check_command part should.

Also, I'd quite like to get a conditional parameter parsing thing for
Nagios, so that one can do something like this:

define command{
   command_name   check_http
   command_line   $USER1/check_http -H $HOSTADDRESS$ $?ARG1:-p$ $ARG1$
}

where '-p' and $ARG1$ only ever get added if they're actually configured.
Possibly also only if they're non-nul strings.

> For instance:
> 
> check_command $USER1$/check_by_ssh!-H!$HOSTADDRESS$!-C!echo $PATH
> 
> The documentation for command definitions would be:
> 
> You need to specify one of command_line or command_exec. The 
> command_line option will take the command specified and pass it to the 
> shell before invoking. This means shell metacharacters need to be 
> escaped appropriately to run as expected. The command_exec option will 
> pass the command as-is to the plugin without any shell expansion.
> 
> 
> A side effect is that you also get a performance boost too:
> 
> nagios at debian:~$ time perl -e 'for $i (1..1000) { system("/bin/true 
> \"\"") }'
> 
> real 0m11.053s
> user 0m1.880s
> sys 0m8.829s
> 
> nagios at debian:~$ time perl -e 'for $i (1..1000) { 
> system("/bin/true","''")) }'
> 
> real 0m5.369s
> user 0m0.872s
> sys 0m3.912s
> 
> 
> The 1st example forces the shell to get invoked (because of the 
> quotation marks) and the 2nd is about 50% faster to invoke the arguments 
> directly. Nagios uses popen but we can convert to a similar routine that 
> the plugins use to capture the stdout using execve.
> 

That's what I had in mind.

-- 
Andreas Ericsson                   andreas.ericsson at op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

Considering the successes of the wars on alcohol, poverty, drugs and
terror, I think we should give some serious thought to declaring war
on peace.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july




More information about the Developers mailing list