breah change: hp 3par ssh backend
This commit is contained in:
parent
692c49a93a
commit
fe2916be10
|
@ -22,6 +22,7 @@ package storage::hp::3par::ssh::custom::custom;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
use centreon::plugins::ssh;
|
||||||
use centreon::plugins::misc;
|
use centreon::plugins::misc;
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
|
@ -37,13 +38,10 @@ sub new {
|
||||||
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
|
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
|
||||||
$options{output}->option_exit();
|
$options{output}->option_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!defined($options{noptions})) {
|
if (!defined($options{noptions})) {
|
||||||
$options{options}->add_options(arguments => {
|
$options{options}->add_options(arguments => {
|
||||||
'hostname:s' => { name => 'hostname' },
|
'hostname:s' => { name => 'hostname' },
|
||||||
'ssh-option:s@' => { name => 'ssh_option' },
|
|
||||||
'ssh-path:s' => { name => 'ssh_path' },
|
|
||||||
'ssh-command:s' => { name => 'ssh_command', default => 'ssh' },
|
|
||||||
'timeout:s' => { name => 'timeout', default => 45 },
|
'timeout:s' => { name => 'timeout', default => 45 },
|
||||||
'command:s' => { name => 'command' },
|
'command:s' => { name => 'command' },
|
||||||
'command-path:s' => { name => 'command_path' },
|
'command-path:s' => { name => 'command_path' },
|
||||||
|
@ -54,7 +52,8 @@ sub new {
|
||||||
|
|
||||||
$self->{output} = $options{output};
|
$self->{output} = $options{output};
|
||||||
$self->{mode} = $options{mode};
|
$self->{mode} = $options{mode};
|
||||||
|
$self->{ssh} = centreon::plugins::ssh->new(%options);
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,13 +82,17 @@ sub set_defaults {
|
||||||
sub check_options {
|
sub check_options {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{option_results}->{remote} = 1;
|
$self->{remote} = 1;
|
||||||
if (defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '') {
|
if (defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '') {
|
||||||
$self->{option_results}->{remote} = undef;
|
$self->{remote} = 0;
|
||||||
} elsif (!defined($self->{option_results}->{hostname}) || $self->{option_results}->{hostname} eq '') {
|
} elsif (!defined($self->{option_results}->{hostname}) || $self->{option_results}->{hostname} eq '') {
|
||||||
$self->{output}->add_option_msg(short_msg => "Need to set hostname option.");
|
$self->{output}->add_option_msg(short_msg => "Need to set hostname option.");
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($self->{remote} == 1) {
|
||||||
|
$self->{ssh}->check_options(option_results => $self->{option_results});
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -99,7 +102,7 @@ sub check_options {
|
||||||
##############
|
##############
|
||||||
sub execute_command {
|
sub execute_command {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{ssh_commands} = '';
|
$self->{ssh_commands} = '';
|
||||||
my $append = '';
|
my $append = '';
|
||||||
foreach (@{$options{commands}}) {
|
foreach (@{$options{commands}}) {
|
||||||
|
@ -107,14 +110,28 @@ sub execute_command {
|
||||||
$append = ';';
|
$append = ';';
|
||||||
}
|
}
|
||||||
|
|
||||||
return centreon::plugins::misc::execute(
|
my $content;
|
||||||
ssh_pipe => 1,
|
if ($self->{remote} == 1) {
|
||||||
output => $self->{output},
|
($content) = $self->{ssh}->execute(
|
||||||
options => $self->{option_results},
|
ssh_pipe => 1,
|
||||||
command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $self->{ssh_commands},
|
hostname => $self->{option_results}->{hostname},
|
||||||
command_path => $self->{option_results}->{command_path},
|
command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $self->{ssh_commands},
|
||||||
command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : undef
|
command_path => $self->{option_results}->{command_path},
|
||||||
);
|
command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : undef,
|
||||||
|
timeout => $self->{option_results}->{timeout}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
($content) = centreon::plugins::misc::execute(
|
||||||
|
ssh_pipe => 1,
|
||||||
|
output => $self->{output},
|
||||||
|
options => { timeout => $self->{option_results}->{timeout} },
|
||||||
|
command => $self->{option_results}->{command},
|
||||||
|
command_path => $self->{option_results}->{command_path},
|
||||||
|
command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : undef
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -137,18 +154,6 @@ my ssh
|
||||||
|
|
||||||
Hostname to query.
|
Hostname to query.
|
||||||
|
|
||||||
=item B<--ssh-option>
|
|
||||||
|
|
||||||
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
|
|
||||||
|
|
||||||
=item B<--ssh-path>
|
|
||||||
|
|
||||||
Specify ssh command path (default: none)
|
|
||||||
|
|
||||||
=item B<--ssh-command>
|
|
||||||
|
|
||||||
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
|
|
||||||
|
|
||||||
=item B<--timeout>
|
=item B<--timeout>
|
||||||
|
|
||||||
Timeout in seconds for the command (Default: 45).
|
Timeout in seconds for the command (Default: 45).
|
||||||
|
|
Loading…
Reference in New Issue