Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add some examples and fixes

  • Loading branch information...
commit 6055b5b3597db0334d2af37f5cdae1e276088bd0 1 parent 0332377
@pfischermx pfischermx authored
View
10 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'
View
31 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";
+}
View
26 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();
+
View
8 lib/App/Foca/Client.pm
@@ -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;
@@ -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+(.+?)$/) {
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.