$HOSTNAME$ in commands? (Was: Re: Monitoring a matrix of load-balanced VirtualHosts?)
Andreas Ericsson
ae at op5.se
Wed Aug 31 12:29:24 CEST 2005
Chris Wilson wrote:
> Hi JB,
>
>
>>I've been told to check '{machinename}.foo.com', but - according to
>>docs/macros.html - I can't use $HOSTNAME$ or $HOSTALIAS$ in either
>>host or service checks.
>>
>>My 1st instinct is to do just that - something like
>> check_command check_lb_vhost!$HOSTNAME$.foo.com
>>
>>but it seems I can't. This is more than a bit annoying, and seems a
>>very odd design decision. I can't be the only one who wants this
>>functionality.
>
>
> I agree that that is very odd. The information must be available, and
> you could probably patch Nagios to make those macros work.
>
> Looking at the source code, it should work now. base/checks.c grabs all
> macros for hosts and services before running the check. The only problem
> might be the nesting of macros, which I haven't tried and don't know if
> it works. You could try this:
>
It's for this precise reason that it doesn't work. $HOSTNAME$ is
translated to $ARG1$ in the above example. $ARG1$ is properly expanded
and $HOSTNAME$ (which is an invalid shell variable) is passed to
popen(3) as is, and subsequently dropped by the shell.
> define service {
> use vhost-service
> service_description $HOSTNAME$.bar.com
> check_command my_check_http_on_host!bar.com
> hostgroup_name bar_com_servers
> }
>
> define command {
> command_name my_check_http_on_host
> command_line $USER1$/check_http -I $HOSTADDRESS$ -H
> $HOSTNAME$.$ARG1$
> }
>
This will work, because it isn't nested anymore (although
$HOSTNAME$.$ARG1$ could just as easily be replaced by
$SERVICEDESCRIPTION$ or whatever that macro is called).
> If not, let me know (with details about exactly what happens when you
> try) and I'll have another look. Or maybe a higher guru will.
>
> Cheers, Chris.
--
Andreas Ericsson andreas.ericsson at op5.se
OP5 AB www.op5.se
Lead Developer
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue.
::: Messages without supporting info will risk being sent to /dev/null
More information about the Users
mailing list