Hello everybody, i'm a poor lost soul who is looking for the help of a perl master. I'm trying to create a RNPE plugin in nagios to monitor database tables but i'm a little lost with the perl script. I have done a Union all in sql to have all data i need and shut the connection, i used a foreach to analyse data in each line with a condition that return a warning code if the value is too high. The real problem is that i have only the 1st line and other line are not analyse in my loop. I will be gratefull if someone as a clue about the problem.
#!/usr/bin/perl use strict; use warnings; use DBI; #Activer le 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 règle de la commande my $oracle_connector = Monitoring::Plugin->new( shortname => 'File attente de datatable', usage => 'Usage : %s [ -c|--critical=<threshold> ] [ -w|--warning=<threshol +d> ]', ); # Définition 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, ); # Définition 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, ); $oracle_connector->getopts; # Connection à la base my $db=DBI->connect("dbi:Oracle:AXIBASE", "AXINX","AXINX") or die( $DBI::errstr . "\n" ); # Requetes SQL 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"; 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)" +); }
[root@BAC libexec]# ./check_oracle_connector -w 10 -c 20 File attente de datatable CRITICAL - File attente (170)
Edit: Finally i create a variable for my table and each time i have the return code of the plugin exit only for the table i asked. Thank you everyone for the help :)

In reply to Creating a perl script for database monitoring by Jeylox

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.