<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 31 Jul 2009, at 16:10, Ethan Galstad wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Ton Voon wrote:<br><blockquote type="cite"><span class="Apple-style-span" style="-webkit-text-stroke-width: -1; ">I've raised a bug report in Mantis re: double escaping: <a href="http://tracker.nagios.org/view.php?id=56">http://tracker.nagios.org/view.php?id=56</a></span></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I'm convinced this is bad behaviour, but want some confirmation  <br></blockquote><blockquote type="cite">(Ethan? Andreas?) that this is correct action before I spend the time  <br></blockquote><blockquote type="cite">in making changes, especially as it is likely to break existing  <br></blockquote><blockquote type="cite">configurations too.<br></blockquote><blockquote type="cite"><br></blockquote>I believe this behavior was requested by users quite a while back.<br>Changing it will likely break many configurations.  Better to make sure<br>the current behavior is well documented, than change it I think...</div></blockquote><div><br></div>Can I propose that we have a new nagios.cfg option called "use_backward_compatible_arg_escaping". This will default to 1 on configurations that do not have this set. However, new installs will have this configured in nagios.cfg to 0, so new systems can benefit from more obvious arguments, while older systems from a straight upgrade will work as is.</div><div><br></div><div>I think the change for the sample nagios.cfg will be:</div><div><br></div><div># This option controls the argument escaping for host/service check_command definitions. Only the exclamation mark (!) will</div><div># require escaping - everything else is passed through "as-is" to the check command definition. This simplifies situations where</div><div># there are other escaped characters (such as \ or $). Macros are passed "as-is" to the check command definition but will be expanded</div><div># when expanding the check command</div><div># If you are upgrading, you should set this to 1 to retain existing behaviour</div><div># The default option is 1 if this parameter is not set</div><div>use_backwards_compatible_arg_escaping=0</div><div><br></div><div>The documentation update for the main configuration variables will be:</div><div><br></div><div>If use_backwards_compatible_arg_escaping is set to 0, this will avoid double escaping for arguments in a host/service check_command definition. For example:</div><div><br></div><div>define command {</div><div>command_name check_nrpe</div><div>command_line $USER1$/check_nrpe $ARG1$</div><div>}</div><div><br></div><div>define service {</div><div>...</div><div>check_command check_nrpe!-H windows.opsera.com -c CheckFileSize -a ShowAll 'File:PageFile=c:\\pagefile.sys'</div><div>}</div><div><br></div><div><br></div><div>With use_backward_compatible_arg_escaping=0, the command executed will be: check_nrpe -H windows.opsera.com -c CheckFileSize -a ShowAll 'File:PageFile=c:\\pagefile.sys'</div><div><br></div><div>With use_backward_compatible_arg_escaping=1, the command executed will be: check_nrpe -H windows.opsera.com -c CheckFileSize -a ShowAll 'File:PageFile=c:\pagefile.sys'</div><div><br></div><div><br></div><div><br></div><div>Thomas writes:</div><div><blockquote type="cite">A bit off-topic, but I believe it would be nice to have a way to execute<br>commands directly rather than using the shell. I'm thinking of a<br>different command option that could be used instead of "command_line"...<br>i.e.:<br><br>command_exec $USER1$/check_dummy!1!WARNING: $SERVICEDESC$ is stale.<br><br>Basically, the first argument is the full path to the executable, and<br>following ones are the argument array passed to execve. Bangs (!) would<br>be argument separators (like in service definitions) with maybe the<br>possibility of escaping them (otherwise a bang in a macro can do the trick).<br><br>That would give much more flexibility when complex parameters must be<br>passed.</blockquote></div><div><br></div><div>That's a good idea. I was thinking something like:</div><div><br></div><div>command_arg $USER1$/check_dummy</div><div>command_arg 1</div><div>command_arg WARNING</div><div><br></div><div>But the exclamation mark is a nice way of doing it. In fact, the escaping code would be the same as above, so we can reuse that. I'd like to add this for all host and service check commands as a new feature.</div><div><br></div><div><br></div><div>Andreas writes:</div><div><blockquote type="cite">Why use the exclamation mark at all? It's quite straightforward to parse<br>shell-style quoting into arguments, and that way users can just cut-n-paste<br>the commands to verify that they work (assuming they replace the macros,<br>that is).</blockquote></div><div><br></div><div>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. For instance:</div><div><br></div><div>check_command $USER1$/check_by_ssh!-H!$HOSTADDRESS$!-C!echo $PATH</div><div><br></div><div>The documentation for command definitions would be:</div><div><br></div><div>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. </div><div><br></div><div><br></div><div>A side effect is that you also get a performance boost too:</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; ">nagios@debian:~$ time perl -e 'for $i (1..1000) { system("/bin/true \"\"") }'</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; ">real 0m11.053s</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; ">user 0m1.880s</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; ">sys 0m8.829s</div><div><br></div></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; ">nagios@debian:~$ time perl -e 'for $i (1..1000) { system("/bin/true","''")) }'</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; ">real 0m5.369s</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; ">user 0m0.872s</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; ">sys 0m3.912s</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Helvetica; "><br></div></div></div><div>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.</div><div><br></div><div>Ton</div><div><br></div><div><br></div></body></html>