LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-16-2017, 04:49 AM   #1
MrKementari
LQ Newbie
 
Registered: Mar 2017
Posts: 4

Rep: Reputation: Disabled
[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 ?

Last edited by MrKementari; 03-17-2017 at 03:58 AM. Reason: Problem solved
 
Old 03-17-2017, 03:57 AM   #2
MrKementari
LQ Newbie
 
Registered: Mar 2017
Posts: 4

Original Poster
Rep: Reputation: Disabled
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 ;-)
 
Old 03-20-2017, 01:34 AM   #3
Jjanel
Member
 
Registered: Jun 2016
Distribution: any&all, in VBox; Ol'UnixCLI; NO GUI resources
Posts: 999
Blog Entries: 12

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

p.s. Welcome to LQ!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
passing an array as command line arguments? etika Linux - Newbie 5 04-03-2011 12:40 PM
Passing command line arguments jason_m Programming 4 08-26-2010 10:36 PM
passing arguments to system command nathan Programming 1 12-17-2009 03:46 AM
Passing a text file to the command line as arguments wimnat Linux - General 2 12-05-2005 08:09 AM
passing a list of arguments to a command hdagelic Linux - General 2 05-09-2005 09:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration