服务定义中的 Nagios 变量 $HOSTNAME$

服务定义中的 Nagios 变量 $HOSTNAME$

我收到以下错误:

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)

我的主机/服务定义:

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
        }

我的模板:

    # 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
        }

这是一个相当默认的 Nagios,没有做任何特别的事情。我使用 $HOSTNAME$ 是错误的还是什么?如果我可以获得主机名的变量,那就太好了,更不用说复制粘贴等了:)

谢谢你!

答案1

既然你定义了一个模板 (register 0,您不应指定其运行的主机或主机组;当您稍后use使用模板来指定针对主机或主机组的检查时,您将执行此操作。这是一个从您的示例扩展而来的最小示例:

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
}

相关内容