LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   [Centreon] Passing arguments to my command ? (https://www.linuxquestions.org/questions/linux-software-2/%5Bcentreon%5D-passing-arguments-to-my-command-4175601897/)

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 ?

MrKementari 03-17-2017 03:57 AM

Okay, my bad, I found what was wrong.

I was using macros to give arguments to my command and the good syntax is not:

Quote:

$USER1$/check_nrpe -H $HOSTADDRESS$ -c check_postgres -a "$_ACTION$ $_WARNING$ $_CRITICAL$"
But :

Quote:

$USER1$/check_nrpe -H $HOSTADDRESS$ -c check_postgres -a "$_SERVICEACTION$ $_SERVICEWARNING$ $_SERVICECRITICAL$"
I hope it will be useful to somebody ;-)

Jjanel 03-20-2017 01:34 AM

Cool! You can also help others find this solution,
by using ThreadTools at top, to mark this as 'Solved'.

p.s. Welcome to LQ!


All times are GMT -5. The time now is 06:57 AM.