From dd5194a7e6329fb6fb05b04164f165ef9c813b82 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Thu, 9 Feb 2023 17:25:00 +0000 Subject: [PATCH] (dbi) handle multiple options for passwordmgr (#4211) --- src/centreon/plugins/dbi.pm | 11 +++++++++-- src/centreon/plugins/passwordmgr/hashicorpvault.pm | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/centreon/plugins/dbi.pm b/src/centreon/plugins/dbi.pm index 8a3f0eeb0..85d0f2923 100644 --- a/src/centreon/plugins/dbi.pm +++ b/src/centreon/plugins/dbi.pm @@ -136,8 +136,15 @@ sub check_options { my ($self, %options) = @_; $self->{data_source} = (defined($self->{option_results}->{data_source})) ? shift(@{$self->{option_results}->{data_source}}) : undef; - $self->{username} = (defined($self->{option_results}->{username})) ? shift(@{$self->{option_results}->{username}}) : undef; - $self->{password} = (defined($self->{option_results}->{password})) ? shift(@{$self->{option_results}->{password}}) : undef; + $self->{username} = undef; + if (defined($self->{option_results}->{username})) { + $self->{username} = ref($self->{option_results}->{username}) eq 'ARRAY' ? shift(@{$self->{option_results}->{username}}) : $self->{option_results}->{username}; + } + $self->{password} = undef; + if (defined($self->{option_results}->{password})) { + $self->{password} = ref($self->{option_results}->{password}) eq 'ARRAY' ? shift(@{$self->{option_results}->{password}}) : $self->{option_results}->{password}; + } + $self->{connect_options} = (defined($self->{option_results}->{connect_options})) ? shift(@{$self->{option_results}->{connect_options}}) : undef; $self->{connect_query} = (defined($self->{option_results}->{connect_query})) ? shift(@{$self->{option_results}->{connect_query}}) : undef; $self->{env} = (defined($self->{option_results}->{env})) ? shift(@{$self->{option_results}->{env}}) : undef; diff --git a/src/centreon/plugins/passwordmgr/hashicorpvault.pm b/src/centreon/plugins/passwordmgr/hashicorpvault.pm index 41fe529af..ca0380ec1 100644 --- a/src/centreon/plugins/passwordmgr/hashicorpvault.pm +++ b/src/centreon/plugins/passwordmgr/hashicorpvault.pm @@ -223,7 +223,7 @@ sub do_map { while ($map =~ /\%\{(.*?)\}/g) { my $sub = ''; $sub = $self->{lookup_values}->{$1} if (defined($self->{lookup_values}->{$1})); - $map =~ s/\%\{$1\}/$sub/g + $map =~ s/\%\{$1\}/$sub/g; } $option =~ s/-/_/g; $options{option_results}->{$option} = $map;