+ Add mode 'tablelocks' for informix

This commit is contained in:
Quentin Garnier 2014-01-15 15:21:00 +01:00
parent 8a5e277a45
commit 52227e5f2c
4 changed files with 438 additions and 1 deletions

View File

@ -96,7 +96,6 @@ ORDER BY dbspace
short_msg => 'All dbspaces usage are ok');
}
my $dbquery = {};
my $count = 0;
while ((my $row = $self->{sql}->fetchrow_hashref())) {
my $name = centreon::plugins::misc::trim($row->{dbspace});

View File

@ -0,0 +1,127 @@
################################################################################
# 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 <http://www.gnu.org/licenses>.
#
# 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 : Quentin Garnier <qgarnier@merethis.com>
#
####################################################################################
package database::informix::mode::listdatabases;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::misc;
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 =>
{
"exclude:s" => { name => 'exclude', },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
$self->{sql}->connect();
$self->{sql}->query(query => q{
SELECT name FROM sysdatabases ORDER BY name
});
$self->{list_databases} = [];
while ((my $row = $self->{sql}->fetchrow_hashref())) {
if (defined($self->{option_results}->{exclude}) && $row->{name} !~ /$self->{option_results}->{exclude}/) {
next;
}
push @{$self->{list_databases}}, centreon::plugins::misc::trim($row->{name});
}
}
sub run {
my ($self, %options) = @_;
# $options{sql} = sqlmode object
$self->{sql} = $options{sql};
$self->manage_selection();
$self->{output}->output_add(severity => 'OK',
short_msg => "List of dbspaces: " . join(', ', @{$self->{list_databases}}));
$self->{output}->display();
$self->{output}->exit();
}
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['name']);
}
sub disco_show {
my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{sql} = $options{sql};
$self->manage_selection();
foreach (sort @{$self->{list_databases}}) {
$self->{output}->add_disco_entry(name => $_);
}
}
1;
__END__
=head1 MODE
Display databases.
=over 8
=item B<--exclude>
Filter databases.
=back
=cut

View File

@ -0,0 +1,309 @@
################################################################################
# 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 <http://www.gnu.org/licenses>.
#
# 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 : Quentin Garnier <qgarnier@merethis.com>
#
####################################################################################
package database::informix::mode::tablelocks;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::misc;
use centreon::plugins::statefile;
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-deadlks:s" => { name => 'warning_deadlks', },
"critical-deadlks:s" => { name => 'critical_deadlks', },
"warning-lockwts:s" => { name => 'warning_lockwts', },
"critical-lockwts:s" => { name => 'critical_lockwts', },
"warning-lockreqs:s" => { name => 'warning_lockreqs', },
"critical-lockreqs:s" => { name => 'critical_lockreqs', },
"warning-lktouts:s" => { name => 'warning_lktouts', },
"critical-lktouts:s" => { name => 'critical_lktouts', },
"name:s" => { name => 'name', },
"regexp" => { name => 'use_regexp' },
"filter-tables:s" => { name => 'filter_tables' },
"only-databases" => { name => 'only_databases' },
});
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning-deadlks', value => $self->{option_results}->{warning_deadlks})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning-deadlks threshold '" . $self->{option_results}->{warning_deadlks} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical-deadlks', value => $self->{option_results}->{critical_deadlks})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical-deadlks threshold '" . $self->{option_results}->{critical_deadlks} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'warning-lockwts', value => $self->{option_results}->{warning_lockwts})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning-lockwts threshold '" . $self->{option_results}->{warning_lockwts} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical-lockwts', value => $self->{option_results}->{critical_lockwts})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical-lockwts threshold '" . $self->{option_results}->{critical_lockwts} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'warning-lockreqs', value => $self->{option_results}->{warning_lockreqs})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning-lockreqs threshold '" . $self->{option_results}->{warning_lockreqs} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical-lockreqs', value => $self->{option_results}->{critical_lockreqs})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical-lockreqs threshold '" . $self->{option_results}->{critical_lockreqs} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'warning-lktouts', value => $self->{option_results}->{warning_block})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning-lktouts threshold '" . $self->{option_results}->{warning_block} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical-lktouts', value => $self->{option_results}->{critical_lktouts})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical-lktouts threshold '" . $self->{option_results}->{critical_lktouts} . "'.");
$self->{output}->option_exit();
}
$self->{statefile_cache}->check_options(%options);
}
sub run {
my ($self, %options) = @_;
# $options{sql} = sqlmode object
$self->{sql} = $options{sql};
$self->{sql}->connect();
my $query = q{
SELECT dbsname, tabname, deadlks, lockwts, lockreqs, lktouts FROM sysptprof
ORDER BY dbsname, tabname
};
$self->{sql}->query(query => $query);
$self->{output}->output_add(severity => 'OK',
short_msg => 'All database/table locks are ok');
my $new_datas = {};
$self->{statefile_cache}->read(statefile => 'informix_' . $self->{mode} . '_' . $self->{sql}->get_unique_id4save());
my $old_timestamp = $self->{statefile_cache}->get(name => 'last_timestamp');
$new_datas->{last_timestamp} = time();
my $count = 0;
my $db_found = {};
while ((my $row = $self->{sql}->fetchrow_hashref())) {
my $dbname = centreon::plugins::misc::trim($row->{dbsname});
my $tabname = centreon::plugins::misc::trim($row->{tabname});
my $longname = $dbname . '.' . $tabname;
next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && $dbname ne $self->{option_results}->{name});
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && $dbname !~ /$self->{option_results}->{name}/);
next if (defined($self->{option_results}->{filter_tables}) && $longname !~ /$self->{option_results}->{filter_tables}/);
$count++;
my $old_datas = {};
my $get_old_value = 0;
$db_found->{$dbname} = {deadlks => 0, lockwts => 0, lockreqs => 0, lktouts => 0, process => 0} if (!defined($db_found->{$dbname}));
foreach (('deadlks', 'lockwts', 'lockreqs', 'lktouts')) {
$new_datas->{$dbname . '_' . $_} = 0 if (!defined($new_datas->{$dbname . '_' . $_}));
$new_datas->{$dbname . '_' . $_} += $row->{$_};
$new_datas->{$longname . '_' . $_} = $row->{$_};
$old_datas->{$longname . '_' . $_} = $self->{statefile_cache}->get(name => $longname . '_' . $_);
# Restart or onstat -z - we set to 0
$old_datas->{$longname . '_' . $_} = 0 if (defined($old_datas->{$longname . '_' . $_}) && $old_datas->{$longname . '_' . $_} > $new_datas->{$longname . '_' . $_});
# If we have a buffer or not
if (defined($old_datas->{$longname . '_' . $_})) {
$get_old_value = 1;
$db_found->{$dbname}->{$_} += $old_datas->{$longname . '_' . $_};
}
}
# Buffer needed
next if ($get_old_value == 0 || !defined($old_timestamp));
$db_found->{$dbname}->{process} = 1;
next if ($self->{option_results}->{only_databases});
my $diff = {};
foreach (('deadlks', 'lockwts', 'lockreqs', 'lktouts')) {
$diff->{$_} = $new_datas->{$longname . '_' . $_} - $old_datas->{$longname . '_' . $_};
}
my $exit1 = $self->{perfdata}->threshold_check(value => $diff->{deadlks}, threshold => [ { label => 'critical-deadlks', 'exit_litteral' => 'critical' }, { label => 'warning-deadlks', exit_litteral => 'warning' } ]);
my $exit2 = $self->{perfdata}->threshold_check(value => $diff->{lockwts}, threshold => [ { label => 'critical-lockwts', 'exit_litteral' => 'critical' }, { label => 'warning-lockwts', exit_litteral => 'warning' } ]);
my $exit3 = $self->{perfdata}->threshold_check(value => $diff->{lockreqs}, threshold => [ { label => 'critical-lockreqs', 'exit_litteral' => 'critical' }, { label => 'warning-lockreqs', exit_litteral => 'warning' } ]);
my $exit4 = $self->{perfdata}->threshold_check(value => $diff->{lktouts}, threshold => [ { label => 'critical-lktouts', 'exit_litteral' => 'critical' }, { label => 'warning-lktouts', exit_litteral => 'warning' } ]);
my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3, $exit4 ]);
$self->{output}->output_add(long_msg => sprintf("Table '%s': Deadlocks %d, Lock Waits %d, Lock Requests %d, Lock Timeouts %d",
$longname, $diff->{deadlks}, $diff->{lockwts}, $diff->{lockreqs}, $diff->{lktouts}));
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Table '%s': Deadlocks %d, Lock Waits %d, Lock Requests %d, Lock Timeouts %d",
$longname, $diff->{deadlks}, $diff->{lockwts}, $diff->{lockreqs}, $diff->{lktouts}));
}
foreach (('deadlks', 'lockwts', 'lockreqs', 'lktouts')) {
$self->{output}->perfdata_add(label => 'tbl_' . $_ . '_' . $longname,
value => $diff->{$_},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $_),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $_),
min => 0);
}
}
foreach my $dbname (keys %{$db_found}) {
next if ($db_found->{$dbname}->{process} == 0);
my $exit1 = $self->{perfdata}->threshold_check(value => $new_datas->{$dbname . '_deadlks'} - $db_found->{$dbname}->{deadlks}, threshold => [ { label => 'critical-deadlks', 'exit_litteral' => 'critical' }, { label => 'warning-deadlks', exit_litteral => 'warning' } ]);
my $exit2 = $self->{perfdata}->threshold_check(value => $new_datas->{$dbname . '_lockwts'} - $db_found->{$dbname}->{lockwts}, threshold => [ { label => 'critical-lockwts', 'exit_litteral' => 'critical' }, { label => 'warning-lockwts', exit_litteral => 'warning' } ]);
my $exit3 = $self->{perfdata}->threshold_check(value => $new_datas->{$dbname . '_lockreqs'} - $db_found->{$dbname}->{lockreqs}, threshold => [ { label => 'critical-lockreqs', 'exit_litteral' => 'critical' }, { label => 'warning-lockreqs', exit_litteral => 'warning' } ]);
my $exit4 = $self->{perfdata}->threshold_check(value => $new_datas->{$dbname . '_lktouts'} - $db_found->{$dbname}->{lktouts}, threshold => [ { label => 'critical-lktouts', 'exit_litteral' => 'critical' }, { label => 'warning-lktouts', exit_litteral => 'warning' } ]);
my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3, $exit4 ]);
$self->{output}->output_add(long_msg => sprintf("Database '%s': Deadlocks %d, Lock Waits %d, Lock Requests %d, lock timeouts %d",
$dbname,
$new_datas->{$dbname . '_deadlks'} - $db_found->{$dbname}->{deadlks},
$new_datas->{$dbname . '_lockwts'} - $db_found->{$dbname}->{lockwts},
$new_datas->{$dbname . '_lockreqs'} - $db_found->{$dbname}->{lockreqs},
$new_datas->{$dbname . '_lktouts'} - $db_found->{$dbname}->{lktouts}));
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Database '%s': Deadlocks %d, Lock Waits %d, Lock Requests %d, lock timeouts %d",
$dbname,
$new_datas->{$dbname . '_deadlks'} - $db_found->{$dbname}->{deadlks},
$new_datas->{$dbname . '_lockwts'} - $db_found->{$dbname}->{lockwts},
$new_datas->{$dbname . '_lockreqs'} - $db_found->{$dbname}->{lockreqs},
$new_datas->{$dbname . '_lktouts'} - $db_found->{$dbname}->{lktouts}));
}
foreach (('deadlks', 'lockwts', 'lockreqs', 'lktouts')) {
$self->{output}->perfdata_add(label => 'db_' . $_ . '_' . $dbname,
value => $new_datas->{$dbname . '_' . $_} - $db_found->{$dbname}->{$_},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $_),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $_),
min => 0);
}
}
if ($count == 0) {
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Cannot find a table (maybe filters).");
}
$self->{statefile_cache}->write(data => $new_datas);
if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
}
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
Check table locks:
- deadlks: deadlocks.
- lockwts: lock waits.
- lockreqs: lock requests.
- lktouts: lock timeouts.
=over 8
=item B<--warning-deadlks>
Threshold warning 'deadlks' in absolute.
=item B<--critical-deadlks>
Threshold critical 'deadlks' in absolute.
=item B<--warning-lockwts>
Threshold warning 'lockwts' in absolute.
=item B<--critical-lockwts>
Threshold critical 'lockwts' in absolute.
=item B<--warning-lockreqs>
Threshold warning 'lockreqs' in absolute.
=item B<--critical-lockreqs>
Threshold critical 'lockreqs' in absolute.
=item B<--warning-lktouts>
Threshold warning 'lktouts' in absolute.
=item B<--critical-lktouts>
Threshold critical 'lktouts' in absolute.
=item B<--name>
Set the database (empty means 'check all databases').
=item B<--regexp>
Allows to use regexp to filter database (with option --name).
=item B<--filter-tables>
Filter tables (format of a table name: 'sysmater.dual').
=item B<--only-databases>
only check locks globally on database (no output for tables).
=back
=cut

View File

@ -53,9 +53,11 @@ sub new {
'connection-time' => 'database::informix::mode::connectiontime',
'global-cache' => 'database::informix::mode::globalcache',
'list-dbspaces' => 'database::informix::mode::listdbspaces',
'list-databases' => 'database::informix::mode::listdatabases',
'lockoverflow' => 'database::informix::mode::lockoverflow',
'dbspace-usage' => 'database::informix::mode::dbspacesusage',
'sessions' => 'database::informix::mode::sessions',
'table-locks' => 'database::informix::mode::tablelocks',
);
return $self;