Problem with NRPE and monitoring perl plugin

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Jeylox
Posts: 3
Joined: Wed Apr 06, 2016 6:35 pm

Problem with NRPE and monitoring perl plugin

Post by Jeylox »

Hi everybody :)

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)" );

When i execute tje plugin i have an error:
Can't locate object method "warning" via package "Monitoring::Plugin::Getopt" at ./check_oracle_connector line 95.
I don't understand what is the problem "warning" is indeed in the code :cry:


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)" );

}


tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Problem with NRPE and monitoring perl plugin

Post by tmcdonald »

If you're looking for help with Perl, I would suggest asking on the Perl Monks forum: http://www.perlmonks.org/

If you are having an issue with integrating this plugin into a Nagios system, we can assist with that here.
Former Nagios employee
Jeylox
Posts: 3
Joined: Wed Apr 06, 2016 6:35 pm

Re: Problem with NRPE and monitoring perl plugin

Post by Jeylox »

Thank you for the answer :)
In fact the problem is both with nagios and perl.

I'm trying to get a table of performance data into the service state information with the numbre of differents database tables.
For the moment i can receive only one information and i'm wondering if there is something to do in the nagios server or all the problem is in the perl plugin into the client server.

Edit: We have to add performance data but tutorial on internet are not very clear about the subject.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Problem with NRPE and monitoring perl plugin

Post by tmcdonald »

Jeylox wrote:I'm trying to get a table of performance data into the service state information with the numbre of differents database tables.
For the moment i can receive only one information and i'm wondering if there is something to do in the nagios server or all the problem is in the perl plugin into the client server.
Are you having issues with getting the data, or with properly formatting the performance data? We can assist with perfdata, but writing the plugin is something that will need to be done on your end.
Jeylox wrote:We have to add performance data but tutorial on internet are not very clear about the subject.
The performance data is defined in the plugin dev guidelines: https://nagios-plugins.org/doc/guidelines.html#AEN200
Former Nagios employee
Jeylox
Posts: 3
Joined: Wed Apr 06, 2016 6:35 pm

Re: Problem with NRPE and monitoring perl plugin

Post by Jeylox »

In fact i have found the solution.
I wanted to use the "|thing=value;warningval;critival;0;10000" to have the performance data and a graph.

For my main problem i have create a variable for my table and call the table with the table in argument in the nagios server.

Thank you for the help :)
Locked