Page 1 of 1

understanding $ARG$ variables

Posted: Sat Aug 18, 2012 10:54 pm
by lraymond
As my journey continues, I want to check some apache stats on a different IP / port than the host. So I created a command for each webserver and things are working, but I want to keep things clean and want to understand how the variables are assigned. My example commands are;

# 'check apache' command ws1
define command{
command_name check_apache-ws1
command_line /usr/lib/nagios/plugins/check_apache2.sh -H 1.1.1.1 -P 81 -t 3 -b /usr/sbin -p /var/run
}

# 'check apache' command ws2
define command{
command_name check_apache-ws2
command_line /usr/lib/nagios/plugins/check_apache2.sh -H 1.1.1.1 -P 82 -t 3 -b /usr/sbin -p /var/run
}


Now I have 7 webservers, then some tomcat ones (which I bet will have more questions) :) but rather than 7 of these, I look higher up at some default ones and see a sample like command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

So I would like to do the same. The IP used will be the same (not the one in the define host) and the port changes (not the one in the _tcpport in the host definition), so my question is how/where can I define a variable so I can have one command, then when I define the service, I can say use_hostgroup webservers and have that port auto inserted vs 7 commands for each server.

Tnx

Re: understanding $ARG$ variables

Posted: Sun Aug 19, 2012 7:49 pm
by jsmurphy
Remember when we talked about doing this with NRPE... custom macros... *nudge* *nudge*

I'm going to assume that's a big enough hint to send you off in the right direction with your apache port conundrum so I'll move on to $argx$. Arguments are simply any text following the command separated by exclamation marks. So $ARG1$ is the first field after the command, $ARG2$ is the second... so on and so forth. This provides you with a way of dynamically building the arguments in your check commands.

Code: Select all

define command{
command_name check_apache-ws1
command_line $USER1$/check_apache2.sh -H $HOSTADDRESS$ $ARG1$

define service{
*usual service stuff*
check_command check_apache-ws1!-P $_HOSTAPACHEPORT$ -t 3 -b /usr/sbin -p /var/run
}
You could also write it as follows and it would be exactly the same when it comes to execution:

Code: Select all

define command{
command_name check_apache-ws1
command_line $USER1$/check_apache2.sh -H $HOSTADDRESS$ $ARG1$ $ARG2$

define service{
*usual service stuff*
check_command check_apache-ws1!-P $_HOSTAPACHEPORT$!-t 3 -b /usr/sbin -p /var/run
}
Make any more sense? I'm not sure I've explained it particularly well.