From 37c165e2d8e5a4e305650bbdbcb3f2a66a65ec85 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Sat, 1 Jun 2019 08:32:41 +0200 Subject: [PATCH] + Fix dbi error message --- centreon/plugins/dbi.pm | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/centreon/plugins/dbi.pm b/centreon/plugins/dbi.pm index 423ec41ef..690aa318b 100644 --- a/centreon/plugins/dbi.pm +++ b/centreon/plugins/dbi.pm @@ -46,13 +46,13 @@ sub new { } if (!defined($options{noptions})) { - $options{options}->add_options(arguments => - { "datasource:s@" => { name => 'data_source' }, - "username:s@" => { name => 'username' }, - "password:s@" => { name => 'password' }, - "connect-options:s@" => { name => 'connect_options' }, - "sql-errors-exit:s" => { name => 'sql_errors_exit', default => 'unknown' }, - "timeout:i" => { name => 'timeout' }, + $options{options}->add_options(arguments => { + 'datasource:s@' => { name => 'data_source' }, + 'username:s@' => { name => 'username' }, + 'password:s@' => { name => 'password' }, + 'connect-options:s@' => { name => 'connect_options' }, + 'sql-errors-exit:s' => { name => 'sql_errors_exit', default => 'unknown' }, + 'timeout:i' => { name => 'timeout' }, }); } $options{options}->add_help(package => __PACKAGE__, sections => 'DBI OPTIONS', once => 1); @@ -95,7 +95,7 @@ sub handle_ALRM { $self->disconnect(); $self->{output}->output_add(severity => $self->{sql_errors_exit}, - short_msg => "Timeout"); + short_msg => 'Timeout'); $self->{output}->display(); $self->{output}->exit(); } @@ -146,7 +146,7 @@ sub check_options { } if (!defined($self->{data_source}) || $self->{data_source} eq '') { - $self->{output}->add_option_msg(short_msg => "Need to specify data_source arguments."); + $self->{output}->add_option_msg(short_msg => 'Need to specify data_source arguments.'); $self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit}); } if (defined($self->{connect_options}) && $self->{connect_options} ne '') { @@ -228,7 +228,7 @@ sub connect { alarm(0) if (defined($self->{timeout})); if (!defined($self->{instance})) { - my $err_msg = sprintf("Cannot connect: %s", defined($DBI::errstr) ? $DBI::errstr : "(no error string)"); + my $err_msg = sprintf('Cannot connect: %s', defined($DBI::errstr) ? $DBI::errstr : '(no error string)'); if ($dontquit == 0) { $self->{output}->add_option_msg(short_msg => $err_msg); $self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit}); @@ -277,16 +277,16 @@ sub query { $self->{statement_handle} = $self->{instance}->prepare($options{query}); if (!defined($self->{statement_handle})) { return 1 if ($continue_error == 1); + $self->{output}->add_option_msg(short_msg => 'Cannot execute query: ' . $self->{instance}->errstr); $self->disconnect(); - $self->{output}->add_option_msg(short_msg => "Cannot execute query: " . $self->{instance}->errstr); $self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit}); } my $rv = $self->{statement_handle}->execute; if (!$rv) { return 1 if ($continue_error == 1); + $self->{output}->add_option_msg(short_msg => 'Cannot execute query: ' . $self->{statement_handle}->errstr); $self->disconnect(); - $self->{output}->add_option_msg(short_msg => "Cannot execute query: " . $self->{statement_handle}->errstr); $self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit}); }