RC1 omnishell_caller
This commit is contained in:
parent
93938e902b
commit
0bc2b9ddec
|
@ -4,18 +4,86 @@
|
|||
#
|
||||
# (c) Fco de Borja Sánchez <fborja.sanchez@pandorafms.com>
|
||||
#
|
||||
# Usage: omnishell_client "C:\Program Files\pandora_agent\pandora_agent.conf"
|
||||
#
|
||||
################################################################################
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use File::Basename;
|
||||
use lib '/usr/lib/perl5';
|
||||
use PandoraFMS::Tools;
|
||||
use PandoraFMS::PluginTools;
|
||||
use PandoraFMS::Omnishell;
|
||||
|
||||
my %Conf;
|
||||
################################################################################
|
||||
# Definitions
|
||||
################################################################################
|
||||
my $HELP=<<EO_H;
|
||||
Pandora FMS Omnishell client.
|
||||
|
||||
if ($Conf{'debug'} ne '1') {
|
||||
Usage:
|
||||
|
||||
$0 <configuration_file> [-debug 1]
|
||||
|
||||
Where <configuration_file> is your Pandora FMS Agent configuration.
|
||||
*Recommended: use full path.
|
||||
|
||||
Use -debug 1 to get information extra in STDERR
|
||||
|
||||
EO_H
|
||||
|
||||
################################################################################
|
||||
# Parse commands.
|
||||
################################################################################
|
||||
sub read_commands {
|
||||
my ($config, $exp, $line, $file) = @_;
|
||||
|
||||
if (empty($config->{'commands'})) {
|
||||
$config->{'commands'} = {};
|
||||
}
|
||||
|
||||
my ($ref) = $line =~ /$exp\s+(.*)/;
|
||||
$config->{'commands'}->{trim($ref)} = {};
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
################################################################################
|
||||
# MAIN
|
||||
################################################################################
|
||||
my $ConfFile = $ARGV[0];
|
||||
|
||||
my $config = read_configuration({},' ', [
|
||||
{
|
||||
'exp' => 'cmd_file',
|
||||
'target' => \&read_commands
|
||||
},
|
||||
]);
|
||||
|
||||
if (!defined($ConfFile) || !-e $ConfFile) {
|
||||
print $HELP;
|
||||
exit 1;
|
||||
}
|
||||
|
||||
eval {
|
||||
# Check scheduled commands
|
||||
my $omni = new PandoraFMS::Omnishell(\%Conf);
|
||||
$omni->prepare_commands();
|
||||
}
|
||||
my $omnishell = new PandoraFMS::Omnishell(
|
||||
{
|
||||
%{$config},
|
||||
'ConfDir' => dirname($ConfFile)
|
||||
}
|
||||
);
|
||||
|
||||
if (empty($omnishell->run('xml')) && is_enabled($config->{'debug'}) ) {
|
||||
print STDERR $omnishell->get_last_error()."\n";
|
||||
}
|
||||
};
|
||||
if ($@) {
|
||||
if (is_enabled($config->{'debug'})) {
|
||||
print STDERR $@."\n";
|
||||
}
|
||||
exit 1;
|
||||
}
|
||||
|
||||
exit 0;
|
|
@ -213,6 +213,19 @@ sub new {
|
|||
|
||||
my $system = init();
|
||||
my $self = {
|
||||
'server_ip' => 'localhost',
|
||||
'server_path' => '/var/spool/pandora/data_in',
|
||||
'server_port' => 41121,
|
||||
'transfer_mode' => 'tentacle',
|
||||
'transfer_mode_user' => 'apache',
|
||||
'transfer_timeout' => 30,
|
||||
'server_user' => 'pandora',
|
||||
'server_pwd' => '',
|
||||
'server_ssl' => '0',
|
||||
'server_opts' => '',
|
||||
'delayed_startup' => 0,
|
||||
'pandora_nice' => 10,
|
||||
'cron_mode' => 0,
|
||||
'last_error' => undef,
|
||||
%{$system},
|
||||
%{$args},
|
||||
|
@ -225,9 +238,33 @@ sub new {
|
|||
}
|
||||
|
||||
################################################################################
|
||||
# Run process.
|
||||
# Run all, output mode 'xml' will dump to STDOUT and return an array of strings
|
||||
#, any other option will return an array with all results.
|
||||
################################################################################
|
||||
sub run {
|
||||
my ($self, $output_mode) = @_;
|
||||
|
||||
my @results;
|
||||
|
||||
foreach my $ref (keys %{$self->{'commands'}}) {
|
||||
my $rs = $self->runCommand($ref, $output_mode);
|
||||
if ($rs) {
|
||||
push @results, $rs;
|
||||
}
|
||||
}
|
||||
|
||||
if ($output_mode eq 'xml') {
|
||||
print join("\n",@results);
|
||||
}
|
||||
|
||||
return \@results;
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Run command, output mode 'xml' will dump to STDOUT, other will return a hash
|
||||
# with all results.
|
||||
################################################################################
|
||||
sub runCommand {
|
||||
my ($self, $ref, $output_mode) = @_;
|
||||
|
||||
if($self->load_libraries()) {
|
||||
|
|
Loading…
Reference in New Issue