MrKementari |
03-16-2017 04:49 AM |
[Centreon] Passing arguments to my command ?
Hi guys :)
I'm trying to monitor Postgres through this check : https://bucardo.org/wiki/Check_postgres
But I'm experiencing some issues. I had some troubles using directly this check so I wrote a tiny shell script which calls the perl file :
Code:
#!/usr/bin/perl
####################################################################################################
# ---- PostGres Monitoring Script ----
# Version: 1.0
# Date : 15/03/2017
# Usage : check_postgres_.pl $ARG1 $ARG2 $ARG3
# Arguments : $ARG1=>action,$ARG2=>warning,$ARG3=>critical
####################################################################################################
# getting number of parameters
$num_args = $#ARGV +1;
$cr = 0;
# if 0 arguments => error
if ($num_args == 0) {
print 'Aucun argument defini ! Usage: check_postgres_.pl $ARG1 $ARG2 $ARG3';
print "\n";
$cr = 1;
}
# if 1 argument only, set action
elsif ($num_args == 1) {
$commande = "sudo su - postgres -c '/usr/lib/nagios/plugins/LaPoste/check_postgres.pl --action=$ARGV[0]'";
$cr = system $commande;
}
# if 3 arguments, set action and warning/critical fields
elsif ($num_args == 3) {
$commande = "sudo su - postgres -c '/usr/lib/nagios/plugins/LaPoste/check_postgres.pl --action=$ARGV[0] --warning=$ARGV[1] --critical=$ARGV[2]'";
$cr = system $commande;
}
else {
print 'Plus de 3 arguments definis ! Usage: check_postgres_LaPoste.pl $ARG1 $ARG2 $ARG3';
print "\n";
$cr = 1;
}
exit $cr;
In my nagios config file, my command is defined like this :
Code:
command[check_postgres]=/usr/lib/nagios/plugins/LaPoste/check_postgres_.pl $ARG1$ $ARG2$ $ARG3$
And into Centreon, here is the command definition :
Code:
$USER1$/check_nrpe -H $HOSTADDRESS$ -c check_postgres -a "$_ACTION$ $_WARNING$ $_CRITICAL$"
I created my services but I have the following message on Centreon :
Code:
WARNING - Aucun argument defini ! Usage: check_postgres_.pl $ARG1 $ARG2 $ARG3
...which means my script detected 0 arguments.
What's wrong ? Could you help ?
|