Skip to content
This repository has been archived by the owner on Apr 16, 2019. It is now read-only.

Commit

Permalink
Add some examples and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pfischermx committed Aug 1, 2012
1 parent 0332377 commit 6055b5b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
10 changes: 10 additions & 0 deletions examples/example_commands.yaml
@@ -0,0 +1,10 @@
commands_dirs:
- /some/path/over/there/bin

commands:
df_path:
cmd: '/bin/df {%foca_args%} | tail -n1'
uptime:
cmd: '/usr/bin/uptime'
'true':
cmd: '/bin/true'
31 changes: 31 additions & 0 deletions examples/foca-client
@@ -0,0 +1,31 @@
#!/usr/local/bin/perl
#
# foca-client
#
# Author(s): Pablo Fischer (pablo@pablo.com.mx)
# Created: 08/01/2012 12:43:34 AM UTC 12:43:34 AM

use strict;
use warnings;
use Data::Dumper;
use FindBin;
use lib "$FindBin::RealBin/../lib/";
use App::Foca::Client;

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";
}
26 changes: 26 additions & 0 deletions examples/foca-server
@@ -0,0 +1,26 @@
#!/usr/local/bin/perl
#
# foca-server
#
# Author(s): Pablo Fischer (pablo@pablo.com.mx)
# Created: 08/01/2012 12:43:34 AM UTC 12:43:34 AM

use strict;
use warnings;
use Data::Dumper;
use FindBin;
use lib "$FindBin::RealBin/../lib/";
use App::Foca::Server;

my $port = 6666;
my $timeout = 60;
my $commands = "$FindBin::RealBin/example_commands.yaml";
my $debug = 1;

my $server = App::Foca::Server->new(
port => $port,
commands_file => $commands,
commands_timeout => $timeout,
debug => $debug);
$server->run_server();

8 changes: 4 additions & 4 deletions lib/App/Foca/Client.pm
Expand Up @@ -20,6 +20,7 @@ use strict;
use warnings;
use Data::Dumper;
use FindBin;
use HTTP::Response;
use Moose;
use Parallel::ForkManager;
use WWW::Curl::Easy;
Expand Down Expand Up @@ -122,8 +123,10 @@ sub run {
my ($self, $hosts, $command, $options) = @_;

# Some basic verification
log_die("No hosts were given") unless $hosts;
log_die("Hosts are not an array ref") unless (ref $hosts eq 'ARRAY');
log_die("No command was given") unless $command;

# Ok, get the command args and params
my ($foca_cmd, $foca_args) = ($command, '');
if ($command =~ /(.+?)\s+(.+?)$/) {
Expand Down Expand Up @@ -177,9 +180,6 @@ sub run {
ref $options->{'on_host'} eq 'CODE';
});

my $ua = new LWP::UserAgent;
$ua->timeout($self->{'timeout'});

foreach my $host (@{$hosts}) {
$pm->start($host) and next;

Expand Down

0 comments on commit 6055b5b

Please sign in to comment.