Chooser - A system for choosing a value for something. Takes a string composed of various tests, arguements, and etc and returns a value based on it.
Version 2.0.0
Takes a string composed of various tests, arguements, and etc and returns a value based on it. See FORMATTING for more information on the string.
use Chooser; #The first tests if /test/ matches the hostname. If it does # a value of test is set with a wieght of 42. This makes #it heavier so even if another is matched, this will be returned. # #The second test checks to make sure that no interfaces have a #CIDR of 192.168.0.0/16. If it does a value of not192168 is returned. # #The third tests if my $string="hostregex|1|test|42|regex=test\n". "cidr|0|not192168|1|cidr=192.168.0.0/16". "defgateway|0|19216801|1|ip=192.168.0.1" my ($success, $choosen) = choose($string); if(!$success){ print "The choosen value is '".$choosen."'\n"; }else{ print "Chooser hit a error processing...\n".$string."\n"; }; ...
chooose
This function is used for running a chooser string. See FORMATING for information on the string passed to it.
If any of the lines in the string contain errors, choose returns a error.
There are three returned values. The first return is a bolean for if it succedded or not. The second is the choosen value. The third is the wieght of the returned value.
$variable=data <check>|<expect>|<value>|<wieght>|<arg0>=<argValue0>|<arg1>=<argValue1>...
'|' is used a delimiter and there is no whitespace.
For information on the support checks, see the CHECK sections.
The expect section is the expected turn value for a check. Unless stated other wise it is going to be '0' for false and '1' for true.
The value is the return value for if it is true. The eventual returned one is choosen by the wieght. The highest number takes presdence. If equal, the last value is used.
The wieght is the way for the returned value.
The args are every thing after the wieght. Any thing before the first '=' is considered part of the variable name. The variable name is case sensitive. Everything after the first '=' is considered part of the value of the variable.
Both the values and arg values support templating. Templating is done via Text::NeatTemplate.
In regards to a choosen value matching /\%eval\{.*\}/, '%eval{' is removed as well as the trailing '}' and it is evaled. So for example '%eval{return "44";}' would set the value to '44'.
Any line that starts with a '$' is a variable. These can be included in stuff via the template system.
This checks if a specific interface or any of them have a address that matches a given CIDR.
The arguement "cidr" is CIDR to be matched.
The arguement "if" is optional arguement for the interface.
This checks the routing table for the default route and compares it to passed variable.
The arguement "ip" is used for the default gateway.
This runs some perl code. This requires two things being returned. The first thing that needs returned is success of check. This is if the if there as a error or not with the check. It needs to return true or the choose function returns with an error condition. The second returned value is the value that is checked against expect value.
The arguement "eval" is the arguement that contains the code used for this.
This runs a regex over the hostname and turns true if it matches.
The arguement "regex" is the regex to use.
This tests to see if a flag created by netident is present. The directory used is the default netident flag directory, unless the enviromental variable 'NETIDENTFLAGDIR' is set.
The arguement "flag" is used to specify the flag to look for.
This test pings a IP to make sure it is in the ARP table and then checks to see if the MAC maches.
The IP to ping
The MAC to check for.
To get the values to for the subject and issure, use the code below and use everything after /\: /.
use IO::Socket::SSL; my $client->new($host.':'.$port); print $client->dump_peer_certificate;
The required values are listed below.
host port subject
For more information about most of these options, please see the documentation for IO::Socket::SSL for the new method.
The CA file to use.
CA path to use.
Check to see if it has been revoked.
The cipher list to use.
The CRL file to use.
This is either the hostname or IP address to connect to.
This is the port to connect to.
This is the subject name to check for. To get what this should be, run the code below.
The verify mode to use.
The name to use to verify the hostname.
The scheme to use when verifying the hostname.
The SSL version to use.
Templating for choosen values and arg values is done using Text::NeatTemplate.
All enviromental variables have 'ENV' appended to them in the hash ref that is passed to Text::NeatTemplate.
This is the hostname of the machine it is running on.
This inserts a "\n".
This is the returned value of a check. This is only present if a value is being processed.
This inserts a '|'.
This is the raw value string. This is only present if a value is being processed.
This adds in any variables.
Zane C. Bowers, <vvelox at vvelox.net>
<vvelox at vvelox.net>
Please report any bugs or feature requests to bug-chooser at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Chooser. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-chooser at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Chooser
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Chooser
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Chooser
CPAN Ratings
http://cpanratings.perl.org/d/Chooser
Search CPAN
http://search.cpan.org/dist/Chooser
Copyright 2009 Zane C. Bowers, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Chooser, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Chooser
CPAN shell
perl -MCPAN -e shell install Chooser
For more information on module installation, please visit the detailed CPAN module installation guide.