Macro Expansion Problem

Jonathan Angliss jon at netdork.net
Sat May 21 03:52:46 CEST 2011


On 05/20/11 16:24, Terry Carmen wrote:
> I'm trying to setup a more-or-less generic host file, but am having
> problems with the %HOSTNAME% macro
>
> If I use this, everything is fine:
>
> define host{
>           host_name               mymachine
>           hostgroups              MyGroup
>           alias                   mymachine
>           address                 10.1.2.100
>           max_check_attempts      5
>           contact_groups          admins
>           check_command           check-host-alive
>           }
>
> define service{
>           use generic-service
>           host_name       mymachine
>           service_description             PING
>           check_command                   check_ping!100.0,20%!500.0,60%
>           }
>
> If I use this, I get "Error: Could not find any host matching '$HOSTALIAS$'"
>
> define host{
>           host_name               mymachine
>           hostgroups              MyGroup
>           alias                   mymachine
>           address                 10.1.2.100
>           max_check_attempts      5
>           contact_groups          admins
>           check_command           check-host-alive
>           }
>
> define service{
>           use generic-service
>           host_name       %HOSTNAME%
>           service_description             PING
>           check_command                   check_ping!100.0,20%!500.0,60%
>           }
>
> I'm probably doing something wrong with the macro, but can't seem to
> figure out what.
>
> Any help would be appreciated.

Of course, $HOSTNAME$ isn't a valid host name.  You need to specify the 
name of a host, or hostgroup.  $HOSTNAME$ is expanded at execution time 
when the check is run, not when Nagios starts.

You are more likely to see it in the define command{} section than 
service.  For example:

define command {
   command_line    $USER1$/check_http -H $HOSTNAME$
   command_name    check_http
}

That's not to say you won't see it defined in a service, but less likely 
than a command.  What made you think $HOSTNAME$ was valid there? If it 
was valid, what value should it take? What are you trying to achieve?

-- 
Jonathan Angliss


------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its 
next-generation tools to help Windows* and Linux* C/C++ and Fortran 
developers boost performance applications - including clusters. 
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
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