#!/usr/bin/perl ################################################################################ # Pandora FMS Omnishell client. # # (c) Fco de Borja Sánchez # # Usage: omnishell_client "C:\Program Files\pandora_agent\pandora_agent.conf" # ################################################################################ use strict; use warnings; use File::Basename; BEGIN { push @INC, '/usr/lib/perl5'; } # NOTE: The binary compiled with PAR::Packer for Pandora FMS doesn't work well # with JSON:XS, probably because JSON::Backend::XS is defined in the __DATA__ # section of JSON.pm and that doesn't work well with PAR::Filter. If this # becomes a bottleneck, a workaround would be possible (e.g., redefining # JSON::Backend::XS here). BEGIN { $ENV{PERL_JSON_BACKEND} = 'JSON::PP' }; use PandoraFMS::PluginTools; use PandoraFMS::Omnishell; ################################################################################ # Definitions ################################################################################ my $HELP=< [-debug 1] Where 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 0; } if(!-d dirname($ConfFile).'\commands') { mkdir(dirname($ConfFile).'\commands'); } eval { # Check scheduled 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 0; } exit 0;