From 0f0ef918907abbe1df5dbee466f7602cf221f376 Mon Sep 17 00:00:00 2001 From: Kevin Duret Date: Mon, 10 Nov 2014 14:38:10 +0100 Subject: [PATCH] Add new modes and some fixes refs #5643 --- database/mssql/mode/backupage.pm | 187 ++++++++++++++++++++++++ database/mssql/mode/blockedprocesses.pm | 4 +- database/mssql/mode/cachehitratio.pm | 5 +- database/mssql/mode/connectedusers.pm | 2 - database/mssql/mode/connectiontime.pm | 17 +-- database/mssql/mode/databasessize.pm | 49 +++++-- database/mssql/mode/deadlocks.pm | 142 ++++++++++++++++++ database/mssql/mode/failedjobs.pm | 37 ++--- database/mssql/mode/lockswaits.pm | 27 ++-- database/mssql/mode/transactions.pm | 7 +- database/mssql/plugin.pm | 3 +- 11 files changed, 405 insertions(+), 75 deletions(-) create mode 100644 database/mssql/mode/backupage.pm create mode 100644 database/mssql/mode/deadlocks.pm diff --git a/database/mssql/mode/backupage.pm b/database/mssql/mode/backupage.pm new file mode 100644 index 000000000..66e3a54fb --- /dev/null +++ b/database/mssql/mode/backupage.pm @@ -0,0 +1,187 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Kevin Duret +# +#################################################################################### + +package database::mssql::mode::backupage; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use Time::HiRes; +use Time::Local; + +my %states = ( + 0 => 'failed', + 1 => 'success', +); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-database:s" => { name => 'filter_database', }, + "skip" => { name => 'skip', }, + "skip-no-backup" => { name => 'skip_no_backup', }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } +} + +sub run { + my ($self, %options) = @_; + # $options{sql} = sqlmode object + $self->{sql} = $options{sql}; + + $self->{output}->output_add(severity => 'OK', + short_msg => "All backups are ok."); + + $self->{sql}->connect(); + + my $count = 0; + my $count_failed = 0; + + my $query = "SELECT D.name AS [database_name], D.recovery_model, BS1.last_backup, BS1.last_duration + FROM sys.databases D + LEFT JOIN ( + SELECT BS.[database_name], + DATEDIFF(HH,MAX(BS.[backup_finish_date]),GETDATE()) AS last_backup, + DATEDIFF(MI,MAX(BS.[backup_start_date]),MAX(BS.[backup_finish_date])) AS last_duration + FROM msdb.dbo.backupset BS + WHERE BS.type = 'D' + GROUP BY BS.[database_name] + ) BS1 ON D.name = BS1.[database_name] + ORDER BY D.[name];"; + $self->{sql}->query(query => $query); + my $result = $self->{sql}->fetchall_arrayref(); + foreach my $row (@$result) { + next if (defined($self->{option_results}->{filter_database}) && $$row[0] !~ /$self->{option_results}->{filter_database}/); + $count++; + #dbt_backup_start: 0x1686303d8 (dtdays=40599, dttime=7316475) Feb 27 2011 6:46:28:250AM + my $last_backup = $$row[2]; + my $backup_duration = $$row[3]; + my $backup_age; + if (!defined($last_backup) || $last_backup =~ /dbt_backup_start: \w+\s+\(dtdays=0, dttime=0\) \(uninitialized\)/) { + if (!defined($self->{option_results}->{skip_no_backup})) { + $self->{output}->output_add(severity => 'Critical', + short_msg => sprintf("No backup found for DB '%s'", $$row[0])); + } + next; + } elsif ($last_backup =~ /dbt_backup_start: \w+\s+\(dtdays=\d+, dttime=\d+\)\s+(\w+)\s+(\d+)\s+(\d+)\s+(\d+):(\d+):(\d+):\d+([AP])/) { + my %months = ("Jan" => 0, "Feb" => 1, "Mar" => 2, "Apr" => 3, "May" => 4, "Jun" => 5, "Jul" => 6, "Aug" => 7, "Sep" => 8, "Oct" => 9, "Nov" => 10, "Dec" => 11); + $backup_age = ( Time::HiRes::time() - Time::Local::timelocal($6, $5, $4 + ($7 eq "A" ? 0 : 12), $2, $months{$1}, $3 - 1900)) / 3600; + $self->{output}->output_add(long_msg => sprintf("DB '%s' backup age : %ds [Duration : %ds]", $$row[0], $backup_age, $backup_duration)); + my $exit_code = $self->{perfdata}->threshold_check(value => $backup_age, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit_code, + short_msg => sprintf("DB '%s' backup age: %ds [Duration : %ds]", $$row[0], $backup_age, $backup_duration)); + $self->{output}->perfdata_add(label => sprintf("db_%s_backup_age",$$row[0]), + unit => 's', + value => $backup_age, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0); + $self->{output}->perfdata_add(label => sprintf("db_%s_backup_duration",$$row[0]), + unit => 's', + value => $backup_duration, + min => 0); + } + next; + } else { + $self->{output}->output_add(severity => 'Unknown', + short_msg => sprintf("Could not parse backup age for DB '%s'", $$row[0])); + next; + } + } + + if(!defined($self->{option_results}->{skip}) && $count == 0) { + $self->{output}->output_add(severity => 'Unknown', + short_msg => "No backup found."); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check MSSQL backup age. + +=over 8 + +=item B<--filter-database> + +Filter database. + +=item B<--skip> + +Return ok if no backup found. + +=item B<--skip-no-backup> + +Skip databases without backup. + +=item B<--warning> + +Threshold warning in seconds. + +=item B<--critical> + +Threshold critical in seconds. + +=back + +=cut diff --git a/database/mssql/mode/blockedprocesses.pm b/database/mssql/mode/blockedprocesses.pm index f2466261e..56c204129 100644 --- a/database/mssql/mode/blockedprocesses.pm +++ b/database/mssql/mode/blockedprocesses.pm @@ -39,8 +39,6 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use Time::HiRes; -use POSIX; sub new { my ($class, %options) = @_; @@ -82,7 +80,7 @@ sub run { my $exit_code = $self->{perfdata}->threshold_check(value => $blocked, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("%i Blocked process(es).", $blocked)); + short_msg => sprintf("%i blocked process(es).", $blocked)); $self->{output}->perfdata_add(label => 'blocked_processes', value => $blocked, warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), diff --git a/database/mssql/mode/cachehitratio.pm b/database/mssql/mode/cachehitratio.pm index 500b8c0c8..4438e354c 100644 --- a/database/mssql/mode/cachehitratio.pm +++ b/database/mssql/mode/cachehitratio.pm @@ -39,8 +39,6 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use Time::HiRes; -use POSIX; sub new { my ($class, %options) = @_; @@ -98,7 +96,8 @@ sub run { $self->{output}->output_add(severity => $exit_code, short_msg => sprintf("Buffer cache hit ratio is %.2f%%", $hitratio)); $self->{output}->perfdata_add(label => 'cache_hitratio', - value => $hitratio, + value => sprintf("%d",$hitratio), + unit => '%', warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), min => 0, diff --git a/database/mssql/mode/connectedusers.pm b/database/mssql/mode/connectedusers.pm index dba6fa36a..0f3eb862f 100644 --- a/database/mssql/mode/connectedusers.pm +++ b/database/mssql/mode/connectedusers.pm @@ -39,8 +39,6 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use Time::HiRes; -use POSIX; sub new { my ($class, %options) = @_; diff --git a/database/mssql/mode/connectiontime.pm b/database/mssql/mode/connectiontime.pm index dd8abd016..f61b5ed28 100644 --- a/database/mssql/mode/connectiontime.pm +++ b/database/mssql/mode/connectiontime.pm @@ -40,7 +40,6 @@ use base qw(centreon::plugins::mode); use strict; use warnings; use Time::HiRes; -use POSIX; sub new { my ($class, %options) = @_; @@ -84,13 +83,13 @@ sub run { $self->{output}->output_add(severity => 'CRITICAL', short_msg => $msg_error); } else { - my $milliseconds = $now2 - $now; - $milliseconds = floor($milliseconds * 1000); - my $exit_code = $self->{perfdata}->threshold_check(value => $milliseconds, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $seconds = sprintf("%.3f", $now2 - $now); + my $exit_code = $self->{perfdata}->threshold_check(value => $seconds, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("Connection established in %.3fs.", $milliseconds / 1000)); - $self->{output}->perfdata_add(label => 'connection_time', unit => 'ms', - value => $milliseconds, + short_msg => sprintf("Connection established in %.3fs.", $seconds)); + $self->{output}->perfdata_add(label => 'connection_time', + value => $seconds, + unit => 's', warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), min => 0); @@ -112,11 +111,11 @@ Check MSSQL connection time. =item B<--warning> -Threshold warning in milliseconds. +Threshold warning in seconds. =item B<--critical> -Threshold critical in milliseconds. +Threshold critical in seconds. =back diff --git a/database/mssql/mode/databasessize.pm b/database/mssql/mode/databasessize.pm index c5085930e..5b0e7a04a 100644 --- a/database/mssql/mode/databasessize.pm +++ b/database/mssql/mode/databasessize.pm @@ -29,7 +29,7 @@ # do not wish to do so, delete this exception statement from your version. # # For more information : contact@centreon.com -# Authors : Stephane Duret +# Authors : Kevin Duret # #################################################################################### @@ -39,8 +39,6 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use Time::HiRes; -use POSIX; sub new { my ($class, %options) = @_; @@ -53,6 +51,7 @@ sub new { "warning:s" => { name => 'warning', }, "critical:s" => { name => 'critical', }, "filter-database:s" => { name => 'filter_database', }, + "free" => { name => 'free', }, }); return $self; @@ -101,20 +100,36 @@ sub run { my $free = convert_bytes($free_brut); my $use = $size - $free; my $percent_use = ($use / $size) * 100; + my $percent_free = 100 - $percent_use; my ($use_value, $use_unit) = $self->{perfdata}->change_bytes(value => $use); - $self->{output}->output_add(long_msg => sprintf("DB '%s' Size: %s Used: %.2f %s (%.2f%%)", $database, $size_brut, $use_value, $use_unit, $percent_use)); - my $exit_code = $self->{perfdata}->threshold_check(value => $percent_use, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("DB '%s' Size: %s Used: %.2f %s (%.2f%%)", $database, $size_brut, $use_value, $use_unit, $percent_use)); + $self->{output}->output_add(long_msg => sprintf("DB '%s' Size: %s Used: %.2f %s (%.2f%%) Free: %s (%.2f%%)", $database, $size_brut, $use_value, $use_unit, $percent_use, $free_brut, $percent_free)); + if (defined($self->{option_results}->{free})) { + my $exit_code = $self->{perfdata}->threshold_check(value => $percent_free, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit_code, + short_msg => sprintf("DB '%s' Size: %s Free: %s (%.2f%%)", $database, $size_brut, $free_brut, $percent_use)); + } + $self->{output}->perfdata_add(label => sprintf("db_%s_free",$database), + unit => 'B', + value => sprintf("%d",$free), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $size, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $size, cast_int => 1), + min => 0, + max => sprintf("%d",$size)); + } else { + my $exit_code = $self->{perfdata}->threshold_check(value => $percent_use, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit_code, + short_msg => sprintf("DB '%s' Size: %s Used: %.2f %s (%.2f%%)", $database, $size_brut, $use_value, $use_unit, $percent_use)); + } + $self->{output}->perfdata_add(label => sprintf("db_%s_used",$database), + unit => 'B', + value => sprintf("%d",$use), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $size, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $size, cast_int => 1), + min => 0, + max => sprintf("%d",$size)); } - $self->{output}->perfdata_add(label => sprintf("used_%s",$database), - unit => 'B', - value => sprintf("%d",$use), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $size, cast_int => 1), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $size, cast_int => 1), - min => 0, - max => $size); } } @@ -160,6 +175,10 @@ Threshold critical in percent used. Filter database. +=item B<--free> + +Check free space instead of used space. + =back =cut diff --git a/database/mssql/mode/deadlocks.pm b/database/mssql/mode/deadlocks.pm new file mode 100644 index 000000000..93e78273b --- /dev/null +++ b/database/mssql/mode/deadlocks.pm @@ -0,0 +1,142 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Kevin Duret +# +#################################################################################### + +package database::mssql::mode::deadlocks; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "warning:s" => { name => 'warning', }, + "critical:s" => { name => 'critical', }, + "filter-database:s" => { name => 'filter_database', }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } +} + +sub run { + my ($self, %options) = @_; + # $options{sql} = sqlmode object + $self->{sql} = $options{sql}; + + $self->{sql}->connect(); + my $query = "SELECT + instance_name, cntr_value + FROM + sys.dm_os_performance_counters + WHERE + object_name = 'SQLServer:Locks' + AND + counter_name = 'Number of Deadlocks/sec%' + "; + + $self->{sql}->query(query => $query); + my $result = $self->{sql}->fetchall_arrayref(); + + my $locks = 0; + + $self->{output}->output_add(severity => 'OK', + short_msg => "0 dead locks/s."); + foreach my $row (@$result) { + next if (defined($self->{option_results}->{filter_database}) && + $$row[0] !~ /$self->{option_results}->{filter_database}/); + $locks += $$row[1]; + } + my $exit_code = $self->{perfdata}->threshold_check(value => $locks, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + $self->{output}->output_add(long_msg => sprintf( "%i dead locks/s.", $locks)); + if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit_code, + short_msg => sprintf("%i dead locks/s.", $locks)); + } + $self->{output}->perfdata_add(label => 'dead_locks', + value => $locks, + unit => '/s', + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check MSSQL dead locks per second + +=over 8 + +=item B<--warning> + +Threshold warning number of dead locks per second. + +=item B<--critical> + +Threshold critical number of dead locks per second. + +=item B<--filter-database> + +Filter database to check. + +=back + +=cut diff --git a/database/mssql/mode/failedjobs.pm b/database/mssql/mode/failedjobs.pm index 7cb3c7226..a477b4fea 100644 --- a/database/mssql/mode/failedjobs.pm +++ b/database/mssql/mode/failedjobs.pm @@ -29,7 +29,7 @@ # do not wish to do so, delete this exception statement from your version. # # For more information : contact@centreon.com -# Authors : Stephane Duret +# Authors : Kevin Duret # #################################################################################### @@ -39,8 +39,6 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use Time::HiRes; -use POSIX; my %states = ( 0 => 'failed', @@ -55,8 +53,6 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, "filter-job:s" => { name => 'filter_job', }, "skip" => { name => 'skip', }, }); @@ -67,15 +63,6 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } } sub run { @@ -87,17 +74,19 @@ sub run { short_msg => "All jobs are ok."); $self->{sql}->connect(); - $self->{sql}->query(query => q{DBCC SQLPERF(LOGSPACE)}); - - my $result = $self->{sql}->fetchall_arrayref(); my $count = 0; my $count_failed = 0; - my $query = "SELECT j.[name] AS [JobName], run_status, h.run_date AS LastRunDate, h.run_time AS LastRunTime FROM msdb.dbo.sysjobhistory h INNER JOIN msdb.dbo.sysjobs j ON h.job_id = j.job_id WHERE j.enabled = 1 AND h.instance_id IN (SELECT MAX(h.instance_id) FROM msdb.dbo.sysjobhistory h GROUP BY (h.job_id))"; + my $query = "SELECT j.[name] AS [JobName], run_status, h.run_date AS LastRunDate, h.run_time AS LastRunTime + FROM msdb.dbo.sysjobhistory h + INNER JOIN msdb.dbo.sysjobs j ON h.job_id = j.job_id + WHERE j.enabled = 1 + AND h.instance_id IN (SELECT MAX(h.instance_id) + FROM msdb.dbo.sysjobhistory h GROUP BY (h.job_id))"; $self->{sql}->query(query => $query); - my $result2 = $self->{sql}->fetchall_arrayref(); - foreach my $row (@$result2) { + my $result = $self->{sql}->fetchall_arrayref(); + foreach my $row (@$result) { next if (defined($self->{option_results}->{filter_job}) && $$row[0] !~ /$self->{option_results}->{filter_job}/); $count++; my $job_name = $$row[0]; @@ -105,17 +94,17 @@ sub run { my $run_date = $$row[2]; $run_date =~ s/(\d{4})(\d{2})(\d{2})/$1-$2-$3/; my $run_time = $$row[3]; - $self->{output}->output_add(long_msg => sprintf("Job %s status %s [Date : %s] [Runtime : %ss]", $job_name, $states{$run_status}, $run_date, $run_time)); + $self->{output}->output_add(long_msg => sprintf("Job '%s' status %s [Date : %s] [Runtime : %ss]", $job_name, $states{$run_status}, $run_date, $run_time)); if ($run_status == 0) { $count_failed++; $self->{output}->output_add(severity => 'Critical', - short_msg => sprintf("Job %s status %s", $job_name, $states{$run_status})); + short_msg => sprintf("Job '%s' status %s", $job_name, $states{$run_status})); } } if(!defined($self->{option_results}->{skip}) && $count == 0) { $self->{output}->output_add(severity => 'Unknown', - short_msg => "Job not found."); + short_msg => "No job found."); } $self->{output}->perfdata_add(label => 'failed_jobs', @@ -139,7 +128,7 @@ Check MSSQL failed jobs. =item B<--filter-job> -Filter database. +Filter job. =item B<--skip> diff --git a/database/mssql/mode/lockswaits.pm b/database/mssql/mode/lockswaits.pm index 531853981..7c1456e0e 100644 --- a/database/mssql/mode/lockswaits.pm +++ b/database/mssql/mode/lockswaits.pm @@ -50,7 +50,7 @@ sub new { { "warning:s" => { name => 'warning', }, "critical:s" => { name => 'critical', }, - "filter:s" => { name => 'filter', }, + "filter-database:s" => { name => 'filter_database', }, }); return $self; @@ -77,7 +77,7 @@ sub run { $self->{sql}->connect(); my $query = "SELECT - cntr_value + instance_name, cntr_value FROM sys.dm_os_performance_counters WHERE @@ -92,21 +92,20 @@ sub run { my $locks = 0; $self->{output}->output_add(severity => 'OK', - short_msg => "0 Locks Waits/sec."); + short_msg => "0 Locks Waits/s."); foreach my $row (@$result) { - print $$row[0]; - next if (defined($self->{option_results}->{filter}) && - $$row[0] !~ /$self->{option_results}->{filter}/); - $locks++; + next if (defined($self->{option_results}->{filter_database}) && + $$row[0] !~ /$self->{option_results}->{filter_database}/); + $locks += $$row[1]; } my $exit_code = $self->{perfdata}->threshold_check(value => $locks, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(long_msg => sprintf( "%i Locks Waits/sec.", $locks)); if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("%i Locks Waits/sec.", $locks)); + short_msg => sprintf("%i Locks Waits/s.", $locks)); } - $self->{output}->perfdata_add(label => 'locks_waits_per_sec', + $self->{output}->perfdata_add(label => 'locks_waits', value => $locks, + unit => '/s', warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), min => 0); @@ -127,15 +126,15 @@ Check MSSQL locks-waits per second =item B<--warning> -Threshold warning number of lock-waits/seconds. +Threshold warning number of lock-waits per second. =item B<--critical> -Threshold critical number of lock-waits/seconds.. +Threshold critical number of lock-waits per second. -=item B<--filter> +=item B<--filter-database> -Filter database to checks. +Filter database to check. =back diff --git a/database/mssql/mode/transactions.pm b/database/mssql/mode/transactions.pm index e62f41b3f..62058c21e 100644 --- a/database/mssql/mode/transactions.pm +++ b/database/mssql/mode/transactions.pm @@ -39,8 +39,6 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use Time::HiRes; -use POSIX; sub new { my ($class, %options) = @_; @@ -89,9 +87,10 @@ sub run { my $exit_code = $self->{perfdata}->threshold_check(value => $transactions, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("%i transaction(s) per second.", $transactions)); - $self->{output}->perfdata_add(label => 'transactions_per_second', + short_msg => sprintf("%i transactions/s.", $transactions)); + $self->{output}->perfdata_add(label => 'transactions', value => $transactions, + unit => '/s', warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), min => 0); diff --git a/database/mssql/plugin.pm b/database/mssql/plugin.pm index ada9513bc..680223c66 100644 --- a/database/mssql/plugin.pm +++ b/database/mssql/plugin.pm @@ -56,7 +56,8 @@ sub new { 'locks-waits' => 'database::mssql::mode::lockswaits', 'transactions' => 'database::mssql::mode::transactions', 'failed-jobs' => 'database::mssql::mode::failedjobs', -# 'backup-age' => 'database::mssql::mode::backupage', + 'dead-locks' => 'database::mssql::mode::deadlocks', + 'backup-age' => 'database::mssql::mode::backupage', # 'availability-group-states' => 'database::mssql::mode::availabilitygroupstates', # 'availability-group-synchronization' => 'database::mssql::mode::availabilitygroupsync', );