From 8fead5fb3ea14088d9b43886cf5b92198b2c8f68 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 20 Feb 2020 15:05:06 +0100 Subject: [PATCH] fix new ssh backend custom --- network/paloalto/ssh/custom/cli.pm | 17 +++++++---------- storage/hp/3par/ssh/custom/custom.pm | 18 +++++++----------- storage/hp/storeonce/ssh/custom/custom.pm | 17 +++++++---------- storage/ibm/storwize/ssh/custom/api.pm | 2 +- 4 files changed, 22 insertions(+), 32 deletions(-) diff --git a/network/paloalto/ssh/custom/cli.pm b/network/paloalto/ssh/custom/cli.pm index e406c6501..31df4996a 100644 --- a/network/paloalto/ssh/custom/cli.pm +++ b/network/paloalto/ssh/custom/cli.pm @@ -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}, diff --git a/storage/hp/3par/ssh/custom/custom.pm b/storage/hp/3par/ssh/custom/custom.pm index 59c570056..76939a002 100644 --- a/storage/hp/3par/ssh/custom/custom.pm +++ b/storage/hp/3par/ssh/custom/custom.pm @@ -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}, diff --git a/storage/hp/storeonce/ssh/custom/custom.pm b/storage/hp/storeonce/ssh/custom/custom.pm index ed593dfa9..b9a29ed5b 100644 --- a/storage/hp/storeonce/ssh/custom/custom.pm +++ b/storage/hp/storeonce/ssh/custom/custom.pm @@ -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}, diff --git a/storage/ibm/storwize/ssh/custom/api.pm b/storage/ibm/storwize/ssh/custom/api.pm index 6c9e21b7b..1dc3b16f3 100644 --- a/storage/ibm/storwize/ssh/custom/api.pm +++ b/storage/ibm/storwize/ssh/custom/api.pm @@ -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(