+ add system to convert args and use with nrpe

This commit is contained in:
garnier-quentin 2017-03-27 13:55:06 +02:00
parent 888f3570eb
commit b58363b8ab

View File

@ -102,6 +102,7 @@ sub get_plugin {
'version' => { name => 'version' }, 'version' => { name => 'version' },
'runas:s' => { name => 'runas' }, 'runas:s' => { name => 'runas' },
'environment:s%' => { name => 'environment' }, 'environment:s%' => { name => 'environment' },
'convert-args:s' => { name => 'convert_args' },
} ); } );
$self->{options}->parse_options(); $self->{options}->parse_options();
@ -113,6 +114,7 @@ sub get_plugin {
$self->{runas} = $self->{options}->get_option(argument => 'runas' ); $self->{runas} = $self->{options}->get_option(argument => 'runas' );
$self->{environment} = $self->{options}->get_option(argument => 'environment' ); $self->{environment} = $self->{options}->get_option(argument => 'environment' );
$self->{ignore_warn_msg} = $self->{options}->get_option(argument => 'ignore_warn_msg' ); $self->{ignore_warn_msg} = $self->{options}->get_option(argument => 'ignore_warn_msg' );
$self->{convert_args} = $self->{options}->get_option(argument => 'convert_args' );
$self->{output}->mode(name => $self->{mode}); $self->{output}->mode(name => $self->{mode});
$self->{output}->plugin(name => $self->{plugin}); $self->{output}->plugin(name => $self->{plugin});
@ -121,6 +123,17 @@ sub get_plugin {
$self->{options}->clean(); $self->{options}->clean();
} }
sub convert_args {
my ($self) = @_;
if ($self->{convert_args} =~ /^(.+?),(.*)/) {
my ($search, $replace) = ($1, $2);
for (my $i = 0; $i < $#ARGV; $i++) {
$ARGV[$i] =~ s/$search/$replace/g;
}
}
}
sub display_local_help { sub display_local_help {
my ($self) = @_; my ($self) = @_;
@ -325,12 +338,11 @@ sub run {
$self->display_list_plugin(); $self->display_list_plugin();
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
if (!defined($self->{plugin}) || $self->{plugin} eq '') { $self->check_plugin_option() if (!defined($self->{plugin}) || $self->{plugin} eq '');
$self->check_plugin_option();
}
if (defined($self->{ignore_warn_msg})) { if (defined($self->{ignore_warn_msg})) {
$SIG{__WARN__} = sub {}; $SIG{__WARN__} = sub {};
} }
$self->convert_args() if (defined($self->{convert_args}));
$self->check_relaunch(); $self->check_relaunch();
@ -387,6 +399,11 @@ Run the script as a different user (prefer to use directly the good user).
Set environment variables for the script (prefer to set it before running it for better performance). Set environment variables for the script (prefer to set it before running it for better performance).
=item B<--convert-args>
Change strings of arguments. Useful to use '!' in nrpe protocol.
Example: --convert-args='##,!'
=back =back
=head1 DESCRIPTION =head1 DESCRIPTION