From 7c4e28bb1dafd228f8c3d8c3ea25b7617acb9a48 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 27 Mar 2017 13:55:06 +0200 Subject: [PATCH] + add system to convert args and use with nrpe --- centreon/plugins/script.pm | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/centreon/plugins/script.pm b/centreon/plugins/script.pm index 33e703b51..b54fc734d 100644 --- a/centreon/plugins/script.pm +++ b/centreon/plugins/script.pm @@ -102,6 +102,7 @@ sub get_plugin { 'version' => { name => 'version' }, 'runas:s' => { name => 'runas' }, 'environment:s%' => { name => 'environment' }, + 'convert-args:s' => { name => 'convert_args' }, } ); $self->{options}->parse_options(); @@ -113,6 +114,7 @@ sub get_plugin { $self->{runas} = $self->{options}->get_option(argument => 'runas' ); $self->{environment} = $self->{options}->get_option(argument => 'environment' ); $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}->plugin(name => $self->{plugin}); @@ -121,6 +123,17 @@ sub get_plugin { $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 { my ($self) = @_; @@ -325,12 +338,11 @@ sub run { $self->display_list_plugin(); $self->{output}->option_exit(); } - if (!defined($self->{plugin}) || $self->{plugin} eq '') { - $self->check_plugin_option(); - } + $self->check_plugin_option() if (!defined($self->{plugin}) || $self->{plugin} eq ''); if (defined($self->{ignore_warn_msg})) { $SIG{__WARN__} = sub {}; } + $self->convert_args() if (defined($self->{convert_args})); $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). +=item B<--convert-args> + +Change strings of arguments. Useful to use '!' in nrpe protocol. +Example: --convert-args='##,!' + =back =head1 DESCRIPTION