From 13c837ce9e11ad65726011ec6844a4f03bbda904 Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Tue, 18 Jun 2019 13:23:11 +0200 Subject: [PATCH] enh influxdb and elasticsearch --- .../elasticsearch/restapi/custom/api.pm | 13 +++++---- .../database/influxdb/custom/api.pm | 28 ++++++------------- .../database/influxdb/mode/connectiontime.pm | 4 +-- 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/centreon-plugins/database/elasticsearch/restapi/custom/api.pm b/centreon-plugins/database/elasticsearch/restapi/custom/api.pm index 96532c46a..ae4b1179c 100644 --- a/centreon-plugins/database/elasticsearch/restapi/custom/api.pm +++ b/centreon-plugins/database/elasticsearch/restapi/custom/api.pm @@ -107,13 +107,16 @@ sub build_options_for_httplib { my ($self, %options) = @_; $self->{option_results}->{hostname} = $self->{hostname}; - $self->{option_results}->{timeout} = $self->{timeout}; $self->{option_results}->{port} = $self->{port}; $self->{option_results}->{proto} = $self->{proto}; - $self->{option_results}->{credentials} = 1; - $self->{option_results}->{basic} = 1; - $self->{option_results}->{username} = $self->{username}; - $self->{option_results}->{password} = $self->{password}; + $self->{option_results}->{timeout} = $self->{timeout}; + + if (defined($self->{username}) && $self->{username} ne '') { + $self->{option_results}->{credentials} = 1; + $self->{option_results}->{basic} = 1; + $self->{option_results}->{username} = $self->{username}; + $self->{option_results}->{password} = $self->{password}; + } } sub settings { diff --git a/centreon-plugins/database/influxdb/custom/api.pm b/centreon-plugins/database/influxdb/custom/api.pm index 7ff97275c..21fe4f5c4 100644 --- a/centreon-plugins/database/influxdb/custom/api.pm +++ b/centreon-plugins/database/influxdb/custom/api.pm @@ -47,8 +47,6 @@ sub new { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port' }, "proto:s" => { name => 'proto' }, - "credentials" => { name => 'credentials' }, - "basic" => { name => 'basic' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "timeout:s" => { name => 'timeout' }, @@ -94,8 +92,6 @@ sub check_options { $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; $self->{username} = (defined($self->{option_results}->{username})) ? $self->{option_results}->{username} : undef; $self->{password} = (defined($self->{option_results}->{password})) ? $self->{option_results}->{password} : undef; - $self->{credentials} = (defined($self->{option_results}->{credentials})) ? 1 : undef; - $self->{basic} = (defined($self->{option_results}->{basic})) ? 1 : undef; if (!defined($self->{hostname}) || $self->{hostname} eq '') { $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); @@ -120,13 +116,19 @@ sub build_options_for_httplib { my ($self, %options) = @_; $self->{option_results}->{hostname} = $self->{hostname}; - $self->{option_results}->{timeout} = $self->{timeout}; $self->{option_results}->{port} = $self->{port}; $self->{option_results}->{proto} = $self->{proto}; $self->{option_results}->{timeout} = $self->{timeout}; $self->{option_results}->{warning_status} = ''; $self->{option_results}->{critical_status} = ''; $self->{option_results}->{unknown_status} = '%{http_code} < 200 or %{http_code} >= 300'; + + if (defined($self->{username}) && $self->{username} ne '') { + $self->{option_results}->{credentials} = 1; + $self->{option_results}->{basic} = 1; + $self->{option_results}->{username} = $self->{username}; + $self->{option_results}->{password} = $self->{password}; + } } sub settings { @@ -242,25 +244,13 @@ Port used (Default: 8086) Specify https if needed (Default: 'http') -=item B<--credentials> - -Specify this option if you access webpage with authentication - =item B<--username> -Specify username for authentication (Mandatory if --credentials is specified) +Specify username for authentication. =item B<--password> -Specify password for authentication (Mandatory if --credentials is specified) - -=item B<--basic> - -Specify this option if you access webpage over basic authentication and don't want a '401 UNAUTHORIZED' error to be logged on your webserver. - -Specify this option if you access webpage over hidden basic authentication or you'll get a '404 NOT FOUND' error. - -(Use with --credentials) +Specify password for authentication. =item B<--timeout> diff --git a/centreon-plugins/database/influxdb/mode/connectiontime.pm b/centreon-plugins/database/influxdb/mode/connectiontime.pm index efd36be24..9956bab98 100644 --- a/centreon-plugins/database/influxdb/mode/connectiontime.pm +++ b/centreon-plugins/database/influxdb/mode/connectiontime.pm @@ -84,11 +84,11 @@ Check database connection time. =over 8 -=item B<--warning-connection-time-milliseconds> +=item B<--warning-connection-time> Threshold warning in milliseconds. -=item B<--critical-connection-time-milliseconds>> +=item B<--critical-connection-time> Threshold critical in milliseconds.