(plugin) os::aix::local - add option --ignore-exit-code (#3987)
* (plugin) os::aix::local - add option --ignore-exit-code * (plugin) os::aix::local - add option --ignore-exit-code
This commit is contained in:
parent
5e44d568ef
commit
bea66af713
|
@ -46,7 +46,8 @@ sub new {
|
||||||
'command:s' => { name => 'command' },
|
'command:s' => { name => 'command' },
|
||||||
'command-path:s' => { name => 'command_path' },
|
'command-path:s' => { name => 'command_path' },
|
||||||
'command-options:s' => { name => 'command_options' },
|
'command-options:s' => { name => 'command_options' },
|
||||||
'sudo:s' => { name => 'sudo' }
|
'sudo:s' => { name => 'sudo' },
|
||||||
|
'ignore-exit-code:s' => { name => 'ignore_exit_code' }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$options{options}->add_help(package => __PACKAGE__, sections => 'CLI OPTIONS', once => 1);
|
$options{options}->add_help(package => __PACKAGE__, sections => 'CLI OPTIONS', once => 1);
|
||||||
|
@ -78,6 +79,11 @@ sub check_options {
|
||||||
sub execute_command {
|
sub execute_command {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $no_quit = defined($self->{option_results}->{ignore_exit_code}) && $self->{option_results}->{ignore_exit_code} ne '' ? 1 : 0;
|
||||||
|
if (defined($options{no_quit})) {
|
||||||
|
$no_quit = $options{no_quit};
|
||||||
|
}
|
||||||
|
|
||||||
my ($stdout, $exit_code);
|
my ($stdout, $exit_code);
|
||||||
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
|
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
|
||||||
($stdout, $exit_code) = $self->{ssh}->execute(
|
($stdout, $exit_code) = $self->{ssh}->execute(
|
||||||
|
@ -87,7 +93,7 @@ sub execute_command {
|
||||||
command_path => $self->{option_results}->{command_path},
|
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} : $options{command_options},
|
command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : $options{command_options},
|
||||||
timeout => $self->{option_results}->{timeout},
|
timeout => $self->{option_results}->{timeout},
|
||||||
no_quit => $options{no_quit}
|
no_quit => $no_quit
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
($stdout, $exit_code) = centreon::plugins::misc::execute(
|
($stdout, $exit_code) = centreon::plugins::misc::execute(
|
||||||
|
@ -97,12 +103,18 @@ sub execute_command {
|
||||||
command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $options{command},
|
command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $options{command},
|
||||||
command_path => $self->{option_results}->{command_path},
|
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} : $options{command_options},
|
command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : $options{command_options},
|
||||||
no_quit => $options{no_quit}
|
no_quit => $no_quit
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => "command response: $stdout", debug => 1);
|
$self->{output}->output_add(long_msg => "command response: $stdout", debug => 1);
|
||||||
|
|
||||||
|
if (defined($self->{option_results}->{ignore_exit_code}) && $self->{option_results}->{ignore_exit_code} ne '' &&
|
||||||
|
$exit_code != 0 && $exit_code !~ /$self->{option_results}->{ignore_exit_code}/) {
|
||||||
|
$self->{output}->add_option_msg(short_msg => sprintf('command execution error [exit code: %s]', $exit_code));
|
||||||
|
$self->{output}->option_exit();
|
||||||
|
}
|
||||||
|
|
||||||
return ($stdout, $exit_code);
|
return ($stdout, $exit_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,6 +158,10 @@ Command options.
|
||||||
|
|
||||||
sudo command.
|
sudo command.
|
||||||
|
|
||||||
|
=item B<--ignore-exit-code>
|
||||||
|
|
||||||
|
Don't quit if the exit code matches that option.
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
=head1 DESCRIPTION
|
=head1 DESCRIPTION
|
||||||
|
|
|
@ -113,7 +113,7 @@ sub manage_selection {
|
||||||
);
|
);
|
||||||
|
|
||||||
$self->{storages} = {};
|
$self->{storages} = {};
|
||||||
my @lines = split /\n/, $stdout;
|
my @lines = split(/\n/, $stdout);
|
||||||
# Header not needed
|
# Header not needed
|
||||||
shift @lines;
|
shift @lines;
|
||||||
foreach my $line (@lines) {
|
foreach my $line (@lines) {
|
||||||
|
|
Loading…
Reference in New Issue