The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

App::Foca::Client - Foca client

DESCRIPTION

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).

EXAMPLE

    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";
    }

Attributes

maxflight

Max number of connections to do at a time. Defaults 15.

timeout

Timeout per host in seconds. Defaults 60 seconds.

connect_timeout

TCP/connection timeout. Defaults to 5 seconds.

port

TCP port where foca server is running.

debug

Turn on debug. Turned off by default.

Methods

run($hosts, $command, %options)

Runs the HTTP request ($command) to the given foca servers ($hosts). $hosts should be an array reference, use FQDN.

By default the method returns an array of hashes. Each hash having the following keys:

ok Boolean. True if command went well or false otherwise.
output output of the command
hostname Hostname.

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:

on_good A CODE reference. Called on every host that succeeded.
on_bad A CODE reference. Called on every host that failed
on_host A CODE reference. Called on every host, succeeded or not.

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

Copyright (c) 2010-2012 Yahoo! Inc. All rights reserved.

LICENSE

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.

AUTHORS

Pablo Fischer (pablo@pablo.com.mx)