1

I got the following error:

Error: Could not find any host matching '$HOSTNAME$' (config file '/usr/local/nagios/etc/servers/example.com.cfg', starting on line 136)
Error: Failed to expand host list '$HOSTNAME$' for service 'HTTP' (/usr/local/nagios/etc/servers/example.com.cfg:136)

My host/service definition:

define host{
        use                     linux-server            ; Name of host template to use
                                                        ; This host definition will inherit all variables that are defined
                                                        ; in (or inherited by) the linux-server host template definition.
        host_name               example.com
        alias                   example.com
        address                 127.0.0.1
        }



###############################################################################
###############################################################################
#
# HOST GROUP DEFINITION
#
###############################################################################
###############################################################################

# Define an optional hostgroup for Linux machines

define hostgroup{
        hostgroup_name  linux-servers ; The name of the hostgroup
        alias           Linux Servers ; Long name of the group
        members         example.com     ; Comma separated list of hosts that belong to this group
        }

My template:

    # Local service definition template - This is NOT a real service, just a template!

    define service{
            name                            local-service           ; The name of this service template
            use                             generic-service         ; Inherit default values from the generic-service definition
            max_check_attempts              4                       ; Re-check the service up to 4 times in order to determine its final (hard) state
            check_interval           5                      ; Check the service every 5 minutes under normal conditions
            retry_interval            1                     ; Re-check the service every minute until a hard state can be determined
            register                        0                       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
            }


    define service{
            name http
            check_command                   check_http
            notifications_enabled           0
            service_description             HTTP
            host_name                       $HOSTNAME$
            register                        0
            }

define service{
        use                             local-service,http         ; Name of service template to use
#        host_name                       example.com
        }

It's a fairly default Nagios, didn't do anything special with it. Am I using $HOSTNAME$ wrong or something? Would be nice if I can get a variable for the hostname, much less copy pasting etc :)

Thank you!

  • I hope $HOSTNAME$ can be passed only to commands.cfg, not to the service.cfg. You have to mention the exact hostname. – msp9011 Apr 27 '18 at 8:04
  • I thought something like that, but couldn't find any documentation on it. – Florius Apr 29 '18 at 9:03
0

Since you're defining a template (register 0), you should not specify the host or hostgroup for it to run on; you would do that when you later use the template to specify a check against a host or hostgroup. Here's a minimal example, extended from yours:

define service{
        name                            http-template
        check_command                   check_http
        notifications_enabled           0
        service_description             HTTP
        register                        0
}

define service{
        use                              http-template
        host                             example.com
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.