App-Foca

 view release on metacpan or  search on metacpan

lib/App/Foca/Client.pm  view on Meta::CPAN

#
# App::Foca::Client
#
# Author(s): Pablo Fischer (pablo@pablo.com.mx)
# Created: 06/19/2012 08:53:33 PM UTC 08:53:33 PM
package App::Foca::Client;

=head1 NAME

App::Foca::Client - Foca client

=head1 DESCRIPTION

L<App::Foca::Client> is the client used to send I<foca> requests to
a set of hosts. I<foca> requests are basically HTTP requests that go to each
given host and execute a command via the running I<foca> server (see
L<App::Foca::Server>).

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

=cut
use strict;
use warnings;
use Data::Dumper;
use FindBin;
use HTTP::Response;
use Moose;
use Parallel::ForkManager;
use WWW::Curl::Easy;
use YAML::Syck qw(LoadFile);
# Foca libs/modules
use App::Foca::Tools::Logger;

=head1 Attributes

=over 4

=item B<maxflight>

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

=cut
has 'maxflight' => (
    is          => 'rw',
    isa         => 'Int',
    default     => 15);

=item B<timeout>

Timeout per host in seconds. Defaults 60 seconds.

=cut
has 'timeout' => (
    is          => 'rw',
    isa         => 'Int',
    default     => 60);

=item B<connect_timeout>

TCP/connection timeout. Defaults to 5 seconds.

=cut
has 'connect_timeout' => (
    is          => 'rw',
    isa         => 'Int',
    default     => 5);

=item B<port>

TCP port where foca server is running.

=cut
has 'port' => (
    is          => 'rw',
    isa         => 'Int');

=item B<debug>

Turn on debug. Turned off by default.

=cut
has 'debug' => (
    is          => 'rw',
    isa         => 'Bool',



( run in 0.512 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )