I'm trying to create a plugin who will count line of many tables into a tablespace and return the result into monitored value like the partition service ( check_snmp_storage.pl)
I'v already code something like this :
Code: Select all
use strict;
use warnings;
use DBI; # Module DBD pour perl
# Chargement du module
use Monitoring::Plugin;
# Definition de l'environnement
BEGIN {
$ENV{ORACLE_HOME} = "/home/oracle/oracle/product/11.2.0/dbhome_1";
}
# Appel du module et regle de la commande
my $oracle_connector = Monitoring::Plugin->new(
shortname => 'File attente des connecteurs',
usage =>
'Usage : %s [ -c|--critical=<threshold> ] [ -w|--warning=<threshold> ]',
);
# Definition de l'argument warning
$oracle_connector->add_arg(
spec => 'warning|w=f', # Nous acceptons des nombres r▒els
help => 'Exit with WARNING status if less than REQUEST',
label => 'REQUEST',
required => 1,
);
# Definition de l'argument critical
$oracle_connector->add_arg(
spec => 'critical|c=f',
help => 'Exit with CRITICAL status if less than REQUEST',
label => 'REQUEST',
required => 1,
);
# Connection à la base
my $db=DBI->connect("dbi:Oracle:BASE", "user","pass")
or die( $DBI::errstr . "\n" );
my $sql = qq/SELECT COUNT (*) from schema.table1/;
my $sth = $db->prepare($sql);
$sth->execute();
my @row;
while (@row = $sth->fetchrow_array) { # retrieve one row
print join (", ", @row),;
}
$sql = qq/SELECT COUNT (*) from schema.table2/;
$sth = $db->prepare($sql);
$sth->execute();
while (@row = $sth->fetchrow_array) { # retrieve one row
print join(", ", @row), "\n";
}
$sql = qq/SELECT COUNT (*) from schema.table3/;
$sth = $db->prepare($sql);
$sth->execute();
while (@row = $sth->fetchrow_array) { # retrieve one row
print join(", ", @row), "\n";
}
my $nb_fattente = @row;
# Recuperons le code retour en fonction des seuils
my $code_retour = $oracle_connector->check_threshold(
check => @row,
warning => $oracle_connector->opts->warning,
critical => $oracle_connector->opts->critical,
);
$oracle_connector->plugin_exit( $code_retour, "File attente ($nb_fattente)" );
I don't understand what is the problem "warning" is indeed in the codeCan't locate object method "warning" via package "Monitoring::Plugin::Getopt" at ./check_oracle_connector line 95.
I will be thankful is anyone has a clue.
Edit : I have found the problem, $oracle_connector->getopts; was not in the code.
Now my problem is that i want to monitor the numbre of line in tables and see the result like the partition service.
Now my code for the data is like
Code: Select all
my $sql = qq/SELECT COUNT (*) from schema.table1 UNION ALL
SELECT COUNT (*) from schema.table2 UNION ALL
SELECT COUNT (*) from schema.table3/;
my $sth = $db->prepare($sql);
$sth->execute();
my $data = $sth->fetchall_arrayref();
$sth->finish;
foreach $data ( @$data) {
(my $variable1,my $variable2,my $variable3) = @$data;
print "$variable1\n";
# print "$variable2\n";
# print "$variable3\n";
my $code_retour = $oracle_connector->check_threshold(
check => $data,
warning => $oracle_connector->opts->warning,
critical => $oracle_connector->opts->critical,
);
$oracle_connector->plugin_exit( $code_retour, "File attente (@$data)" );
}