add separator option for --manage-returns

This commit is contained in:
Fabien Rendu 2019-11-05 13:23:56 +01:00
parent ac30ba1223
commit 3ff05ca7ad
2 changed files with 12 additions and 2 deletions

View File

@ -44,6 +44,7 @@ sub new {
"command-path:s" => { name => 'command_path' }, "command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options' }, "command-options:s" => { name => 'command_options' },
"manage-returns:s" => { name => 'manage_returns', default => '' }, "manage-returns:s" => { name => 'manage_returns', default => '' },
"separator:s" => { name => 'separator', default => '#' },
}); });
$self->{manage_returns} = {}; $self->{manage_returns} = {};
return $self; return $self;
@ -58,7 +59,7 @@ sub check_options {
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
foreach my $entry (split(/#/, $self->{option_results}->{manage_returns})) { foreach my $entry (split(/$self->{option_results}->{separator}/, $self->{option_results}->{manage_returns})) {
next if (!($entry =~ /(.*?),(.*?),(.*)/)); next if (!($entry =~ /(.*?),(.*?),(.*)/));
next if (!$self->{output}->is_litteral_status(status => $2)); next if (!$self->{output}->is_litteral_status(status => $2));
if ($1 ne '') { if ($1 ne '') {
@ -122,6 +123,10 @@ Check command returns.
Set action according command exit code. Set action according command exit code.
Example: 0,OK,File xxx exist#1,CRITICAL,File xxx not exist#,UNKNOWN,Command problem Example: 0,OK,File xxx exist#1,CRITICAL,File xxx not exist#,UNKNOWN,Command problem
=item B<--separator>
Set the separator used in --manage-returns (default : #)
=item B<--remote> =item B<--remote>
Execute command remotely in 'ssh'. Execute command remotely in 'ssh'.

View File

@ -44,6 +44,7 @@ sub new {
"command-path:s" => { name => 'command_path' }, "command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options' }, "command-options:s" => { name => 'command_options' },
"manage-returns:s" => { name => 'manage_returns', default => '' }, "manage-returns:s" => { name => 'manage_returns', default => '' },
"separator:s" => { name => 'separator', default => '#' },
}); });
$self->{manage_returns} = {}; $self->{manage_returns} = {};
return $self; return $self;
@ -58,7 +59,7 @@ sub check_options {
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
foreach my $entry (split(/#/, $self->{option_results}->{manage_returns})) { foreach my $entry (split(/$self->{option_results}->{separator}/, $self->{option_results}->{manage_returns})) {
next if (!($entry =~ /(.*?),(.*?),(.*)/)); next if (!($entry =~ /(.*?),(.*?),(.*)/));
next if (!$self->{output}->is_litteral_status(status => $2)); next if (!$self->{output}->is_litteral_status(status => $2));
if ($1 ne '') { if ($1 ne '') {
@ -122,6 +123,10 @@ Check command returns.
Set action according command exit code. Set action according command exit code.
Example: 0,OK,File xxx exist#1,CRITICAL,File xxx not exist#,UNKNOWN,Command problem Example: 0,OK,File xxx exist#1,CRITICAL,File xxx not exist#,UNKNOWN,Command problem
=item B<--separator>
Set the separator used in --manage-returns (default : #)
=item B<--remote> =item B<--remote>
Execute command remotely in 'ssh'. Execute command remotely in 'ssh'.