From 8cea2ae07167ff8b139463e3fe06084c568cbe4c Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 14 Oct 2019 17:04:16 +0200 Subject: [PATCH] fix mysql longqueries --- .../database/mysql/mode/longqueries.pm | 50 +++++++++++-------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/centreon-plugins/database/mysql/mode/longqueries.pm b/centreon-plugins/database/mysql/mode/longqueries.pm index c46cc4cd5..db10e8911 100644 --- a/centreon-plugins/database/mysql/mode/longqueries.pm +++ b/centreon-plugins/database/mysql/mode/longqueries.pm @@ -29,15 +29,14 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - "seconds:s" => { name => 'seconds', default => 60 }, - "filter-user:s" => { name => 'filter_user' }, - "filter-command:s" => { name => 'filter_command', default => '^(?!(sleep)$)' }, - }); + + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning', }, + 'critical:s' => { name => 'critical', }, + 'seconds:s' => { name => 'seconds', default => 60 }, + 'filter-user:s' => { name => 'filter_user' }, + 'filter-command:s' => { name => 'filter_command', default => '^(?!(sleep)$)' }, + }); return $self; } @@ -84,19 +83,30 @@ sub run { my $exit_code = $self->{perfdata}->threshold_check(value => $long_queries, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("%s queries over %s seconds", - $long_queries, $self->{option_results}->{seconds})); - $self->{output}->perfdata_add(label => 'longqueries', - value => $long_queries, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf( + "%s queries over %s seconds", + $long_queries, $self->{option_results}->{seconds} + ) + ); + $self->{output}->perfdata_add( + label => 'longqueries', + value => $long_queries, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0 + ); for (my $i = 0; $i < 10 && $i < scalar(@queries); $i++) { - $queries[$i]->{query} =~ s/\|/-/mg; - $self->{output}->output_add(long_msg => sprintf("[time: %s] [query: %s]", - $queries[$i]->{time}, substr($queries[$i]->{query}, 0, 1024))); + $queries[$i]->{query} =~ s/\|/-/mg if (defined($queries[$i]->{query})); + $self->{output}->output_add(long_msg => + sprintf( + "[time: %s] [query: %s]", + $queries[$i]->{time}, + defined($queries[$i]->{query}) ? substr($queries[$i]->{query}, 0, 1024) : '-' + ) + ); } $self->{output}->display();