fix new ssh backend custom

This commit is contained in:
garnier-quentin 2020-02-20 15:05:06 +01:00
parent 202e924591
commit 8fead5fb3e
4 changed files with 22 additions and 32 deletions

View File

@ -83,17 +83,10 @@ sub set_defaults {
sub check_options {
my ($self, %options) = @_;
$self->{option_results}->{remote} = 1;
if (defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '') {
$self->{option_results}->{remote} = 0;
} 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}->option_exit();
}
if ($self->{option_results}->{remote} == 1) {
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
$self->{ssh}->check_options(option_results => $self->{option_results});
}
return 0;
}
@ -115,7 +108,7 @@ sub execute_command {
$options{command} . "\n";
my $stdout;
if ($self->{option_results}->{remote} == 1) {
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
($stdout) = $self->{ssh}->execute(
ssh_pipe => 1,
hostname => $self->{option_results}->{hostname},
@ -125,6 +118,10 @@ sub execute_command {
timeout => $self->{option_results}->{timeout}
);
} else {
if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq '') {
$self->{output}->add_option_msg(short_msg => 'please set --hostname option for ssh connection (or --command for local)');
$self->{output}->option_exit();
}
($stdout) = centreon::plugins::misc::execute(
ssh_pipe => 1,
output => $self->{output},

View File

@ -82,18 +82,10 @@ sub set_defaults {
sub check_options {
my ($self, %options) = @_;
$self->{remote} = 1;
if (defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '') {
$self->{remote} = 0;
} 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}->option_exit();
}
if ($self->{remote} == 1) {
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
$self->{ssh}->check_options(option_results => $self->{option_results});
}
return 0;
}
@ -111,7 +103,7 @@ sub execute_command {
}
my $content;
if ($self->{remote} == 1) {
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
($content) = $self->{ssh}->execute(
ssh_pipe => 1,
hostname => $self->{option_results}->{hostname},
@ -121,6 +113,10 @@ sub execute_command {
timeout => $self->{option_results}->{timeout}
);
} else {
if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq '') {
$self->{output}->add_option_msg(short_msg => 'please set --hostname option for ssh connection (or --command for local)');
$self->{output}->option_exit();
}
($content) = centreon::plugins::misc::execute(
ssh_pipe => 1,
output => $self->{output},

View File

@ -82,17 +82,10 @@ sub set_defaults {
sub check_options {
my ($self, %options) = @_;
$self->{remote} = 1;
if (defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '') {
$self->{remote} = 0;
} 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}->option_exit();
}
if ($self->{remote} == 1) {
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
$self->{ssh}->check_options(option_results => $self->{option_results});
}
return 0;
}
@ -108,7 +101,7 @@ sub execute_command {
}
my $content;
if ($self->{remote} == 1) {
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
($content) = $self->{ssh}->execute(
ssh_pipe => 1,
hostname => $self->{option_results}->{hostname},
@ -118,6 +111,10 @@ sub execute_command {
timeout => $self->{option_results}->{timeout}
);
} else {
if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq '') {
$self->{output}->add_option_msg(short_msg => 'please set --hostname option for ssh connection (or --command for local)');
$self->{output}->option_exit();
}
($content) = centreon::plugins::misc::execute(
ssh_pipe => 1,
output => $self->{output},

View File

@ -125,7 +125,7 @@ sub execute_command {
);
} else {
if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq '') {
$self->{output}->add_option_msg(short_msg => 'please set --hostname option for ssh connection (or --command)');
$self->{output}->add_option_msg(short_msg => 'please set --hostname option for ssh connection (or --command for local)');
$self->{output}->option_exit();
}
($content) = centreon::plugins::misc::execute(