Add Firebird plugins
This commit is contained in:
parent
3ec0d3e9c6
commit
d2ed30a87d
|
@ -0,0 +1,338 @@
|
|||
#
|
||||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package database::firebird::firebirdcmd;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = {};
|
||||
bless $self, $class;
|
||||
# $options{options} = options object
|
||||
# $options{output} = output object
|
||||
# $options{exit_value} = integer
|
||||
# $options{noptions} = integer
|
||||
|
||||
if (!defined($options{output})) {
|
||||
print "Class mysqlcmd: Need to specify 'output' argument.\n";
|
||||
exit 3;
|
||||
}
|
||||
if (!defined($options{options})) {
|
||||
$options{output}->add_option_msg(short_msg => "Class Firebirdcmd: Need to specify 'options' argument.");
|
||||
$options{output}->option_exit();
|
||||
}
|
||||
if (!defined($options{noptions})) {
|
||||
$options{options}->add_options(arguments =>
|
||||
{ "firebird-cmd:s" => { name => 'firebird_cmd', default => '/opt/firebird/bin/isql' }
|
||||
"host:s@" => { name => 'host' },
|
||||
"port:s@" => { name => 'port' },
|
||||
"username:s@" => { name => 'username' },
|
||||
"password:s@" => { name => 'password' },
|
||||
"dbname:s@" => { name => 'dbname' },
|
||||
"sql-errors-exit:s" => { name => 'sql_errors_exit', default => 'unknown' },
|
||||
});
|
||||
}
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'MYSQLCMD OPTIONS', once => 1);
|
||||
|
||||
$self->{output} = $options{output};
|
||||
$self->{mode} = $options{mode};
|
||||
$self->{args} = undef;
|
||||
$self->{stdout} = undef;
|
||||
$self->{columns} = undef;
|
||||
$self->{version} = undef;
|
||||
|
||||
$self->{host} = undef;
|
||||
$self->{port} = undef;
|
||||
$self->{dbname} = undef;
|
||||
$self->{username} = undef;
|
||||
$self->{password} = undef;
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
# Method to manage multiples
|
||||
sub set_options {
|
||||
my ($self, %options) = @_;
|
||||
# options{options_result}
|
||||
|
||||
$self->{option_results} = $options{option_results};
|
||||
}
|
||||
|
||||
# Method to manage multiples
|
||||
sub set_defaults {
|
||||
my ($self, %options) = @_;
|
||||
# options{default}
|
||||
|
||||
# Manage default value
|
||||
foreach (keys %{$options{default}}) {
|
||||
if ($_ eq $self->{mode}) {
|
||||
for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) {
|
||||
foreach my $opt (keys %{$options{default}->{$_}[$i]}) {
|
||||
if (!defined($self->{option_results}->{$opt}[$i])) {
|
||||
$self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
# return 1 = ok still data_source
|
||||
# return 0 = no data_source left
|
||||
|
||||
$self->{host} = (defined($self->{option_results}->{host})) ? shift(@{$self->{option_results}->{host}}) : undef;
|
||||
$self->{port} = (defined($self->{option_results}->{port})) ? shift(@{$self->{option_results}->{port}}) : undef;
|
||||
$self->{dbname} = (defined($self->{option_results}->{dbname})) ? shift(@{$self->{option_results}->{dbname}}) : undef;
|
||||
$self->{username} = (defined($self->{option_results}->{username})) ? shift(@{$self->{option_results}->{username}}) : undef;
|
||||
$self->{password} = (defined($self->{option_results}->{password})) ? shift(@{$self->{option_results}->{password}}) : undef;
|
||||
$self->{sql_errors_exit} = $self->{option_results}->{sql_errors_exit};
|
||||
$self->{firebird_cmd} = $self->{option_results}->{firebird_cmd};
|
||||
|
||||
if (!defined($self->{host}) || $self->{host} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify host argument.");
|
||||
$self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
|
||||
}
|
||||
|
||||
$self->{args} = ['--batch', '--raw', '--host', $self->{host}];
|
||||
if (defined($self->{port})) {
|
||||
push @{$self->{args}}, "--port", $self->{port};
|
||||
}
|
||||
if (defined($self->{username})) {
|
||||
push @{$self->{args}}, "--user", $self->{username};
|
||||
}
|
||||
if (defined($self->{password}) && $self->{password} ne '') {
|
||||
push @{$self->{args}}, "-p" . $self->{password};
|
||||
}
|
||||
if (defined($self->{dbname}) && $self->{dbnam} ne '') {
|
||||
push @{$self->{args}}, "--dbname", $self->{dbname};
|
||||
}
|
||||
|
||||
if (scalar(@{$self->{option_results}->{host}}) == 0) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub is_version_minimum {
|
||||
my ($self, %options) = @_;
|
||||
# $options{version} = string version to check
|
||||
|
||||
my @version_src = split /\./, $self->{version};
|
||||
my @versions = split /\./, $options{version};
|
||||
for (my $i = 0; $i < scalar(@versions); $i++) {
|
||||
return 1 if ($versions[$i] eq 'x');
|
||||
return 1 if (!defined($version_src[$i]));
|
||||
$version_src[$i] =~ /^([0-9]*)/;
|
||||
next if ($versions[$i] == int($1));
|
||||
return 0 if ($versions[$i] > int($1));
|
||||
return 1 if ($versions[$i] < int($1));
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub get_id {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = $self->{host};
|
||||
if (defined($self->{port})) {
|
||||
$msg .= ":" . $self->{port};
|
||||
}
|
||||
return $msg;
|
||||
}
|
||||
|
||||
|
||||
sub get_unique_id4save {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = $self->{host};
|
||||
if (defined($self->{port})) {
|
||||
$msg .= ":" . $self->{port};
|
||||
}
|
||||
return md5_hex($msg);
|
||||
}
|
||||
|
||||
sub quote {
|
||||
my $self = shift;
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub command_execution {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my ($lerror, $stdout, $exit_code) = centreon::plugins::misc::backtick(
|
||||
command => $self->{firebird_cmd},
|
||||
arguments => [@{$self->{args}}, '-e', $options{request}],
|
||||
timeout => 30,
|
||||
wait_exit => 1,
|
||||
redirect_stderr => 1
|
||||
);
|
||||
if ($exit_code <= -1000) {
|
||||
if ($exit_code == -1000) {
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => $stdout);
|
||||
}
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
return ($exit_code, $stdout);
|
||||
}
|
||||
|
||||
# Connection initializer
|
||||
sub connect {
|
||||
my ($self, %options) = @_;
|
||||
my $dontquit = (defined($options{dontquit}) && $options{dontquit} == 1) ? 1 : 0;
|
||||
|
||||
(my $exit_code, $self->{stdout}) = $self->command_execution(request => "SHOW VERSION");
|
||||
if ($exit_code != 0) {
|
||||
if ($dontquit == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot connect: " . $self->{stdout});
|
||||
$self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
|
||||
}
|
||||
return (-1, "Cannot connect: " . $self->{stdout});
|
||||
}
|
||||
|
||||
my $row = $self->fetchrow_hashref();
|
||||
$self->{version} = $row->{Value};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub fetchall_arrayref {
|
||||
my ($self, %options) = @_;
|
||||
my $array_ref = [];
|
||||
|
||||
if (!defined($self->{columns})) {
|
||||
$self->{stdout} =~ s/^(.*?)(\n|$)//;
|
||||
@{$self->{columns}} = split(/\t/, $1);
|
||||
}
|
||||
foreach (split /\n/, $self->{stdout}) {
|
||||
push @$array_ref, [map({ s/\\n/\x{0a}/g; s/\\t/\x{09}/g; s/\\/\x{5c}/g; $_; } split(/\t/, $_))];
|
||||
}
|
||||
|
||||
return $array_ref;
|
||||
}
|
||||
|
||||
sub fetchrow_array {
|
||||
my ($self, %options) = @_;
|
||||
my @array_result = ();
|
||||
|
||||
if (!defined($self->{columns})) {
|
||||
$self->{stdout} =~ s/^(.*?)(\n|$)//;
|
||||
@{$self->{columns}} = split(/\t/, $1);
|
||||
}
|
||||
if (($self->{stdout} =~ s/^(.*?)(\n|$)//)) {
|
||||
push @array_result, map({ s/\\n/\x{0a}/g; s/\\t/\x{09}/g; s/\\/\x{5c}/g; $_; } split(/\t/, $1));
|
||||
}
|
||||
|
||||
return @array_result;
|
||||
}
|
||||
|
||||
sub fetchrow_hashref {
|
||||
my ($self, %options) = @_;
|
||||
my $array_result = undef;
|
||||
|
||||
if (!defined($self->{columns})) {
|
||||
$self->{stdout} =~ s/^(.*?)(\n|$)//;
|
||||
@{$self->{columns}} = split(/\t/, $1);
|
||||
}
|
||||
if ($self->{stdout} ne '' && $self->{stdout} =~ s/^(.*?)(\n|$)//) {
|
||||
$array_result = {};
|
||||
my @values = split(/\t/, $1);
|
||||
for (my $i = 0; $i < scalar(@values); $i++) {
|
||||
my $value = $values[$i];
|
||||
$value =~ s/\\n/\x{0a}/g;
|
||||
$value =~ s/\\t/\x{09}/g;
|
||||
$value =~ s/\\/\x{5c}/g;
|
||||
$array_result->{$self->{columns}[$i]} = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $array_result;
|
||||
}
|
||||
|
||||
sub query {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{columns} = undef;
|
||||
(my $exit_code, $self->{stdout}) = $self->command_execution(request => $options{query});
|
||||
|
||||
if ($exit_code != 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot execute query: " . $self->{stdout});
|
||||
$self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
mysqlcmd global
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
mysqlcmd class
|
||||
|
||||
=head1 MYSQLCMD OPTIONS
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--mysql-cmd>
|
||||
|
||||
mysql command (Default: '/usr/bin/mysql').
|
||||
|
||||
=item B<--host>
|
||||
|
||||
Database hostname.
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Database port.
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Database username.
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Database password.
|
||||
|
||||
=item B<--sql-errors-exit>
|
||||
|
||||
Exit code for DB Errors (default: unknown)
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
B<snmp>.
|
||||
|
||||
=cut
|
|
@ -0,0 +1,123 @@
|
|||
#
|
||||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package database::mysql::mode::databasessize;
|
||||
|
||||
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:s" => { name => 'filter', },
|
||||
});
|
||||
|
||||
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();
|
||||
$self->{sql}->query(query => 'SELECT table_schema AS NAME, SUM(data_length+index_length)
|
||||
FROM information_schema.tables
|
||||
GROUP BY table_schema');
|
||||
my $result = $self->{sql}->fetchall_arrayref();
|
||||
|
||||
if (!($self->{sql}->is_version_minimum(version => '5'))) {
|
||||
$self->{output}->add_option_msg(short_msg => "MySQL version '" . $self->{sql}->{version} . "' is not supported.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "All databases are ok.");
|
||||
foreach my $row (@$result) {
|
||||
next if (defined($self->{option_results}->{filter}) &&
|
||||
$$row[0] !~ /$self->{option_results}->{filter}/);
|
||||
|
||||
my $exit_code = $self->{perfdata}->threshold_check(value => $$row[1], threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
|
||||
my ($value, $value_unit) = $self->{perfdata}->change_bytes(value => $$row[1]);
|
||||
$self->{output}->output_add(long_msg => sprintf("DB '" . $$row[0] . "' size: %s%s", $value, $value_unit));
|
||||
if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $exit_code,
|
||||
short_msg => sprintf("DB '" . $$row[0] . "' size: %s%s", $value, $value_unit));
|
||||
}
|
||||
$self->{output}->perfdata_add(label => $$row[0] . '_size', unit => 'B',
|
||||
value => $$row[1],
|
||||
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 MySQL databases size.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning in bytes.
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical in bytes.
|
||||
|
||||
=item B<--filter>
|
||||
|
||||
Filter database to checks.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,117 @@
|
|||
#
|
||||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package database::firebird::mode::iostats;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use POSIX;
|
||||
|
||||
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', },
|
||||
});
|
||||
|
||||
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();
|
||||
|
||||
if (!($self->{sql}->is_version_minimum(version => '1'))) {
|
||||
$self->{output}->add_option_msg(short_msg => "Firebird version '" . $self->{sql}->{version} . "' is not supported (need version >= '5.x').");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{sql}->query(query => q{SELECT MON$PAGE_READS,MON$PAGE_WRITES FROM MON$IO_STATS WHERE MON$STAT_GROUP=0;});
|
||||
my $result = $self->{sql}->fetchall_arrayref();
|
||||
if (!defined($result)) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot get IO Stats.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $page_reads = $$result[0][0];
|
||||
my $page_writes = $$result[0][1];
|
||||
|
||||
my $exit1 = $self->{perfdata}->threshold_check(value => $page_reads, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
my $exit2 = $self->{perfdata}->threshold_check(value => $page_writes, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
|
||||
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("I/O stats : %d/%d",$page_writes, $page_reads ));
|
||||
$self->{output}->perfdata_add(label => 'input', value => $page_writes);
|
||||
$self->{output}->perfdata_add(label => 'output', value => $page_reads);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check MySQL uptime.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning.
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical.
|
||||
|
||||
=item B<--seconds>
|
||||
|
||||
Display uptime in seconds.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,188 @@
|
|||
#
|
||||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package database::firebird::mode::memory;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use DBD::Firebird;
|
||||
|
||||
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', },
|
||||
"seconds" => { name => 'seconds', },
|
||||
});
|
||||
|
||||
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();
|
||||
|
||||
if (!($self->{sql}->is_version_minimum(version => '1'))) {
|
||||
$self->{output}->add_option_msg(short_msg => "Firebird version '" . $self->{sql}->{version} . "' is not supported (need version >= '1.x').");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{sql}->query(query => q{SELECT MON$STAT_GROUP,MON$MEMORY_ALLOCATED,MON$MEMORY_USED FROM MON$MEMORY_USAGE});
|
||||
my $result = $self->{sql}->fetchall_arrayref();
|
||||
if(!defined($result)) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot get memory.");
|
||||
$self->{output}->opion_exit();
|
||||
}
|
||||
|
||||
|
||||
my $mem_allocated;
|
||||
my $attach_used=0;
|
||||
my $prct_attach=0;
|
||||
my $trans_used=0;
|
||||
my $prct_trans;
|
||||
my $stat_used=0;
|
||||
my $prct_stat=0;
|
||||
my $call_used=0;
|
||||
my $prct_call=0;
|
||||
my ($total_value, $total_unit)=(0,0);
|
||||
my ($attach_value, $attach_unit)=(0,0);
|
||||
my ($trans_value, $trans_unit)=(0,0);
|
||||
my ($stat_value, $stat_unit)=(0,0);
|
||||
my ($call_value, $call_unit)= (0,'B');
|
||||
|
||||
foreach my $row (@$result) {
|
||||
next if (defined($self->{option_results}->{filter}) &&
|
||||
$$row[0] !~ /$self->{option_results}->{filter}/);
|
||||
|
||||
|
||||
|
||||
if ($$row[0] == 0) {
|
||||
$mem_allocated = $$row[1];
|
||||
($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $mem_allocated);
|
||||
|
||||
} elsif ($$row[0] ==1) {
|
||||
$attach_used = $attach_used + $$row[2];
|
||||
$prct_attach = $attach_used * 100 / $mem_allocated;
|
||||
($attach_value, $attach_unit) = $self->{perfdata}->change_bytes(value => $attach_used);
|
||||
|
||||
} elsif ($$row[0] == 2) {
|
||||
$trans_used = $trans_used + $$row[2];
|
||||
$prct_trans = $trans_used * 100 / $mem_allocated;
|
||||
($trans_value, $trans_unit) = $self->{perfdata}->change_bytes(value => $trans_used);
|
||||
|
||||
|
||||
} elsif ($$row[0] == 3) {
|
||||
$stat_used = $stat_used + $$row[2];
|
||||
$prct_stat = $stat_used * 100 / $mem_allocated;
|
||||
($stat_value, $stat_unit) = $self->{perfdata}->change_bytes(value => $stat_used);
|
||||
|
||||
} elsif ($$row[0] ==4) {
|
||||
$call_used = $call_used + $$row[2];
|
||||
$prct_call = $call_used * 100 / $mem_allocated;
|
||||
($call_value, $call_unit) = $self->{perfdata}->change_bytes(value => $call_used);
|
||||
|
||||
}
|
||||
}
|
||||
my $mem_used = $attach_used + $trans_used + $stat_used + $call_used;
|
||||
my $prct_used = $mem_used * 100 / $mem_allocated;
|
||||
my ($used_value, $used_unit)=$self->{perfdata}->change_bytes(value => $mem_used);
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{output}->perfdata_add(label => "used", unit => 'B',
|
||||
value => $mem_used,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $mem_allocated, cast_int => 1),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $mem_allocated, cast_int => 1),
|
||||
min => 0, max => $mem_allocated);
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Memory Allocated %s, Total Used %s (%.2f%%)",
|
||||
$total_value . " " . $total_unit,
|
||||
$used_value . " " . $used_unit, $prct_used));
|
||||
$self->{output}->output_add(long_msg => sprintf("Attachement Used %s (%.2f%%)",
|
||||
$attach_value . " " . $attach_unit, $prct_attach));
|
||||
$self->{output}->perfdata_add(label => "attachement", unit => 'B',
|
||||
value => $attach_used);
|
||||
$self->{output}->output_add(long_msg => sprintf("Transaction Used %s (%.2f%%)",
|
||||
$trans_value . " " . $trans_unit, $prct_trans));
|
||||
$self->{output}->perfdata_add(label => "transaction", unit => 'B',
|
||||
value => $trans_used);
|
||||
$self->{output}->output_add(long_msg => sprintf("Statement Used %s (%.2f%%)",
|
||||
$stat_value . " " . $stat_unit, $prct_stat));
|
||||
$self->{output}->perfdata_add(label => "statement", unit => 'B',
|
||||
value => $stat_used);
|
||||
$self->{output}->output_add(long_msg => sprintf("Call Used %s (%.2f%%)",
|
||||
$call_value . " " . $call_unit, $prct_call));
|
||||
$self->{output}->perfdata_add(label => "call", unit => 'B',
|
||||
value => $call_used);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check MySQL uptime.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning.
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical.
|
||||
|
||||
=item B<--seconds>
|
||||
|
||||
Display uptime in seconds.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,145 @@
|
|||
#
|
||||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package database::firebird::mode::queries;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
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:s" => { name => 'warning', },
|
||||
"critical:s" => { name => 'critical', },
|
||||
});
|
||||
$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', 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();
|
||||
}
|
||||
|
||||
$self->{statefile_cache}->check_options(%options);
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{sql} = sqlmode object
|
||||
$self->{sql} = $options{sql};
|
||||
|
||||
$self->{sql}->connect();
|
||||
$self->{sql}->query(query => q{
|
||||
SELECT MON$RECORD_SEQ_READS,MON$RECORD_INSERTS,MON$RECORD_UPDATES,MON$RECORD_DELETES,MON$RECORD_BACKOUTS,MON$RECORD_PURGES,MON$RECORD_EXPUNGES from MON$RECORD_STATS WHERE MON$STAT_GROUP=0
|
||||
});
|
||||
my $result = $self->{sql}->fetchall_arrayref();
|
||||
|
||||
if (!($self->{sql}->is_version_minimum(version => '1'))) {
|
||||
$self->{output}->add_option_msg(short_msg => "Firebird version '" . $self->{sql}->{version} . "' is not supported (need version >= '1').");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $new_datas = {};
|
||||
$self->{statefile_cache}->read(statefile => 'firebird_' . $self->{mode} . '_' . $self->{sql}->get_unique_id4save());
|
||||
my $old_timestamp = $self->{statefile_cache}->get(name => 'last_timestamp');
|
||||
$new_datas->{last_timestamp} = time();
|
||||
|
||||
if (defined($old_timestamp) && $new_datas->{last_timestamp} - $old_timestamp == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Need at least one second between two checks.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my @field = ("seq_reads","inserts","updates","deletes","backouts","purges","expunges");
|
||||
my $i=0;
|
||||
foreach my $name (@field) {
|
||||
|
||||
$new_datas->{$name} = $$result[0][$i];
|
||||
my $old_val = $self->{statefile_cache}->get(name => $name);
|
||||
next if (!defined($old_val) || $$result[0][$i] < $old_val);
|
||||
|
||||
my $value = int(($$result[0][$i] - $old_val) / ($new_datas->{last_timestamp} - $old_timestamp));
|
||||
if ($name ne 'seq_reads') {
|
||||
$self->{output}->perfdata_add(label => $name . '_requests',
|
||||
value => $value,
|
||||
min => 0);
|
||||
$i++;
|
||||
next;
|
||||
}
|
||||
|
||||
my $exit_code = $self->{perfdata}->threshold_check(value => $value, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{output}->output_add(severity => $exit_code,
|
||||
short_msg => sprintf("Total requests = %s", $value));
|
||||
$self->{output}->perfdata_add(label => 'total_requests',
|
||||
value => $value,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
$i++
|
||||
}
|
||||
|
||||
$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 average number of queries executed.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning.
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,139 @@
|
|||
#
|
||||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package database::firebird::mode::slowqueries;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
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:s" => { name => 'warning', },
|
||||
"critical:s" => { name => 'critical', },
|
||||
});
|
||||
$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', 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();
|
||||
}
|
||||
|
||||
$self->{statefile_cache}->check_options(%options);
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{sql} = sqlmode object
|
||||
$self->{sql} = $options{sql};
|
||||
|
||||
$self->{sql}->connect();
|
||||
|
||||
if (!($self->{sql}->is_version_minimum(version => '1'))) {
|
||||
$self->{output}->add_option_msg(short_msg => "Firebird version '" . $self->{sql}->{version} . "' is not supported (need version >= '1.x').");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{sql}->query(query => q{SELECT COUNT(*) FROM MON$STATEMENTS INNER JOIN MON$TRANSACTIONS ON (MON$STATEMENTS.MON$ATTACHMENT_ID = MON$TRANSACTIONS.MON$ATTACHMENT_ID)});
|
||||
my $result = $self->{sql}->fetchrow_array();
|
||||
my $name='slow_query';
|
||||
if (!defined($result)) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot get slow queries.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
|
||||
my $new_datas = {};
|
||||
$self->{statefile_cache}->read(statefile => 'firebird_' . $self->{mode} . '_' . $self->{sql}->get_unique_id4save());
|
||||
my $old_timestamp = $self->{statefile_cache}->get(name => 'last_timestamp');
|
||||
$new_datas->{last_timestamp} = time();
|
||||
|
||||
if (defined($old_timestamp) && $new_datas->{last_timestamp} - $old_timestamp == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Need at least one second between two checks.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$new_datas->{$name} = $result;
|
||||
my $old_val = $self->{statefile_cache}->get(name => $name);
|
||||
if (defined($old_val) && $result >= $old_val) {
|
||||
my $value = sprintf("%.2f", ($result - $old_val) / ($new_datas->{last_timestamp} - $old_timestamp));
|
||||
|
||||
my $exit_code = $self->{perfdata}->threshold_check(value => $value, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{output}->output_add(severity => $exit_code,
|
||||
short_msg => sprintf("%d slow queries in %d seconds (%.2f/sec)",
|
||||
($result - $old_val), ($new_datas->{last_timestamp} - $old_timestamp), $value)
|
||||
);
|
||||
$self->{output}->perfdata_add(label => 'slow_queries_rate',
|
||||
value => $value,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
}
|
||||
|
||||
$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 average number of queries detected as "slow" (per seconds).
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning in queries per seconds.
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical in queries per seconds.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,116 @@
|
|||
#
|
||||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package database::firebird::mode::users;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use DBD::Firebird;
|
||||
|
||||
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', },
|
||||
});
|
||||
|
||||
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();
|
||||
|
||||
if (!($self->{sql}->is_version_minimum(version => '1'))) {
|
||||
$self->{output}->add_option_msg(short_msg => "firebird version '" . $self->{sql}->{version} . "' is not supported (need version >= '5.x').");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{sql}->query(query => q{SELECT COUNT(MON$USER) FROM MON$ATTACHMENTS});
|
||||
my $result = $self->{sql}->fetchrow_array();
|
||||
|
||||
if (!defined($result)) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot get users.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $exit_code = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
my $msg = sprintf("%d user(s) connect to database", $result);
|
||||
|
||||
$self->{output}->output_add(severity => $exit_code,
|
||||
short_msg => $msg);
|
||||
$self->{output}->perfdata_add(label => 'User', value => $result,
|
||||
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 MySQL uptime.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning.
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical.
|
||||
|
||||
=item B<--seconds>
|
||||
|
||||
Display uptime in seconds.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,107 @@
|
|||
#
|
||||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package database::firebird::plugin;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_sql);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
# $options->{options} = options object
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'connection-time' => 'centreon::common::protocols::sql::mode::connectiontime',
|
||||
'memory' => 'database::firebird::mode::memory',
|
||||
'users' => 'database::firebird::mode::users',
|
||||
'io-stats' => 'database::firebird::mode::iostats',
|
||||
'queries' => 'database::firebird::mode::queries',
|
||||
'slow-queries' => 'database::firebird::mode::slowqueries',
|
||||
);
|
||||
$self->{sql_modes}{firebirdcmd} = 'database::firebird::firebirdcmd';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub init {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{options}->add_options(
|
||||
arguments => {
|
||||
'host:s@' => { name => 'db_host' },
|
||||
'port:s@' => { name => 'db_port' },
|
||||
'database:s@' => { name => 'db_name' },
|
||||
}
|
||||
);
|
||||
$self->{options}->parse_options();
|
||||
my $options_result = $self->{options}->get_options();
|
||||
$self->{options}->clean();
|
||||
|
||||
if (defined($options_result->{db_host})) {
|
||||
@{$self->{sqldefault}->{dbi}} = ();
|
||||
@{$self->{sqldefault}->{firebirdcmd}} = ();
|
||||
for (my $i = 0; $i < scalar(@{$options_result->{db_host}}); $i++) {
|
||||
$self->{sqldefault}->{dbi}[$i] = { data_source => 'Firebird:host=' . $options_result->{db_host}[$i] };
|
||||
$self->{sqldefault}->{firebirdcmd}[$i] = { host => $options_result->{db_host}[$i] };
|
||||
if (defined($options_result->{db_port}[$i])) {
|
||||
$self->{sqldefault}->{dbi}[$i]->{data_source} .= ';port=' . $options_result->{db_port}[$i];
|
||||
$self->{sqldefault}->{firebirdcmd}[$i]->{port} = $options_result->{db_port}[$i];
|
||||
}
|
||||
$options_result->{db_name}[$i] = (defined($options_result->{db_name}[$i]) && $options_result->{db_name}[$i] ne '') ? $options_result->{db_name}[$i] : 'firebird';
|
||||
$self->{sqldefault}->{dbi}[$i]->{data_source} .= ';database=' . $options_result->{db_name}[$i];
|
||||
$self->{sqldefault}->{firebirdcmd}[$i]->{dbname} = $options_result->{db_name}[$i];
|
||||
}
|
||||
}
|
||||
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Check Firebird Server.
|
||||
|
||||
=over 8
|
||||
|
||||
You can use following options or options from 'sqlmode' directly.
|
||||
|
||||
=item B<--host>
|
||||
|
||||
Hostname to query.
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Database Server Port.
|
||||
|
||||
=item B<--database>
|
||||
|
||||
Path to Database. (eg:/opt/firebird/examples/empbuild/employee.fdb)
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
Loading…
Reference in New Issue