[Nagiosplug-devel] --64- --url- Was: New Threshold Syntax
Stephan
Stephan at quantentunnel.de
Wed Oct 2 19:54:10 CEST 2013
Am 30.06.13 19:08, schrieb Jochen Bern:
> And while we're on the subject of "proper" notation involving
> characters that *happen* to be special chars to 90+% of all shells out
> there, and since we're talking about providing a *library* to plugin
> authors: No amount of exegesis on the parameter syntax will ever solve
> as many problems as the simple sentence "for every valid option '--foo
> bar', the plugin will accept '--64-foo baz' and '--url-foo org' to the
> same effect, where 'baz'=base64('bar') and 'org'=urlencode('bar')."
> (Extra points to whoever manages to put matching *EN*coding
> functionality into transport-providing plugins like check_by_ssh. ;-)
> Kind regards, J. Bern
Thanks for that! I remembered it when I had today the issue of having to
supply something like "^(foo|bar|baz)" to one of my scripts.
Since I did not want to add several "new" commandline parameters (I'm
using perl's Getopt::Long), I programmed it like this. After reading my
parameters into my variables, I simply do this loop:
foreach ( $user, $pass, @binds, @placeholders ) { # Those are my parameters
next unless defined $_ and s/^enc:(\w+)://;
$_= decoder($1, $_);
}
sub decoder {
my ($encoding, $str)= @_;
SWITCH: for ($encoding) {
/^url$/i && return uri_unescape($str);
/^64$/ && return decode_base64($str);
}
return "enc:$encoding:$str";
}
More information about the Devel
mailing list