--64- --url- Was: New Threshold Syntax

Stephan <[email protected]> Wed, 02 Oct 2013 19:54:10 +0200
Newsgroups gmane.network.nagios.plugins.devel
Message-ID <[email protected]>
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";
}

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk
_______________________________________________________
Nagios Plugin Development Mailing List Nagiosplug-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Unsubscribe at https://lists.sourceforge.net/lists/listinfo/nagiosplug-devel
::: Please include plugins version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null