App::Foca::Client - Foca client
App::Foca::Client is the client used to send foca requests to a set of hosts. foca requests are basically HTTP requests that go to each given host and execute a command via the running foca server (see App::Foca::Server).
my $command = shift @ARGV || 'true'; my $port = 6666; my $debug = 1; my $client = App::Foca::Client->new( port => $port, debug => $debug); my @hosts = qw(localhost); my @result = $client->run(\@hosts, $command); die "Not able to collect any data" unless @result; foreach my $host (@result) { my $status = $host->{'ok'} ? 'OK' : 'ERROR'; print "$status: $host->{'hostname'}: $host->{'output'}\n"; } # or.. $client->run(\@hosts, $command, { on_host => \&parse_host}); sub parse_host { my ($host) = @_; my $status = $host->{'ok'} ? 'OK' : 'ERROR'; print "$status: $host->{'hostname'}: $host->{'output'}\n"; }
Max number of connections to do at a time. Defaults 15.
Timeout per host in seconds. Defaults 60 seconds.
TCP/connection timeout. Defaults to 5 seconds.
TCP port where foca server is running.
Turn on debug. Turned off by default.
Runs the HTTP request ($command) to the given foca servers ($hosts). $hosts should be an array reference, use FQDN.
$command
$hosts
By default the method returns an array of hashes. Each hash having the following keys:
In addition the method offers a third parameter, %options that can be used to tie the collection of data of each host and send it to a subroutine. Options are:
%options
Each one of the CODE references will get one argument: the hash described before.
Command should be the full command, just as if you were executing it from your shell (for example: uptime or uptime -V). This method will take care of getting the basename of the command you are calling and look for any extra parameters/arguments, if any parameters/arguments are found then they get sent as a HTTP header, header would be Foca-Cmd-Params.
Copyright (c) 2010-2012 Yahoo! Inc. All rights reserved.
This program is free software. You may copy or redistribute it under the same terms as Perl itself. Please see the LICENSE file included with this project for the terms of the Artistic License under which this project is licensed.
Pablo Fischer (pablo@pablo.com.mx)
To install App::Foca::Server, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::Foca::Server
CPAN shell
perl -MCPAN -e shell install App::Foca::Server
For more information on module installation, please visit the detailed CPAN module installation guide.