Nagios 未能在通知命令中扩展 $CONTACTEMAIL$ 宏

nav*_*aho 5 nagios

我遇到了一个问题,我的 nofication 命令没有扩展 $CONTACTEMAIL$ 宏

(版本 3.2.1 使用 debian 包安装在 debian 挤压上)

me@hostname:/etc/nagiosql# dpkg -l | grep nagios
ii  nagios-images                                          0.7                                   Collection of images and icons for the nagios system
ii  nagios-nrpe-plugin                                     2.12-4                       Nagios Remote Plugin Executor Plugin
ii  nagios-plugins                                         1.4.15-3squeeze1             Plugins for the nagios network monitoring and management system
ii  nagios-plugins-basic                                   1.4.15-3squeeze1             Plugins for the nagios network monitoring and management system
ii  nagios-plugins-standard                                1.4.15-3squeeze1             Plugins for the nagios network monitoring and management system
ii  nagios3                                                3.2.1-2                      A host/service/network monitoring and management system
ii  nagios3-cgi                                            3.2.1-2                      cgi files for nagios3
ii  nagios3-common                                         3.2.1-2                      support files for nagios3
ii  nagios3-core                                           3.2.1-2                      A host/service/network monitoring and management system core files
Run Code Online (Sandbox Code Playgroud)

我的commands.cfg中有这个

define command {
    command_name                    notify_by_email
    command_line                    /usr/bin/printf "%b" "Notification:\t$NOTIFICATIONTYPE$\n\nOccurred:\t$DATETIME$\nHostname:\t$HOSTALIAS$ ($HOSTADDRESS$)\nService:\t$SERVICEDESC$\nState:\t\t$SERVICESTATE$\nDetails:\n\ n$OUTPUT$" | /usr/bin/mail -s "$NOTIFICATIONTYPE$: $HOSTALIAS$/$SERVICEDESC$ -- $SERVICESTATE$" $CONTACTEMAIL$ 
    register                        1
}       
Run Code Online (Sandbox Code Playgroud)

并在contacts.cfg

define contact {
    contact_name                    navaho
    contactgroups                   pagers
    host_notifications_enabled      1
    service_notifications_enabled   1
    host_notification_period        24x7
    service_notification_period     24x7
    host_notification_options       d,u,r,f,s
    service_notification_options    w,u,c,r,s,n
    host_notification_commands      notify_by_email
    service_notification_commands   notify_by_email
    email                           myemail@mydomain.com
    register                        1
    }       
Run Code Online (Sandbox Code Playgroud)

在我的服务配置文件中,我有

define service {
    host_name                       servicehost.mydomain.com
    hostgroup_name                  null
    service_description             SE:
    display_name                    SE:
    check_command                   check_se
    max_check_attempts              5
    check_interval                  5
    retry_interval                  5
    active_checks_enabled           1
    check_period                    24x7
    event_handler                   notify_by_email
    notification_interval           5
    notification_period             24x7
    notification_options            w,u,r,c,s
    notifications_enabled           1
    contacts                        navaho
    contact_groups                  pagers
    register                        1
}       
Run Code Online (Sandbox Code Playgroud)

使用这些配置,如果我关闭 myservicehost 上的 SE: 服务,我希望 nagios 将通知发送到电子邮件地址 myemail@mydomain.com。它没有。

Aug  1 13:56:12 myhostname postfix/cleanup[25382]: 2DC5F28054: message-id=<20110801205612.2DC5F28054@myhostname.mydomain.net>
Aug  1 13:56:12 myhostname postfix/qmgr[22452]: 2DC5F28054: from=<nagios@myhostname.mydomain.net>, size=470, nrcpt=1 (queue active)
Aug  1 13:56:12 myhostname postfix/local[25384]: 2DC5F28054: to=<$@myhostname.mydomain.net>, orig_to=<$>, relay=local, delay=0.07, delays=0.05/0.01/0/0.01, dsn=5.1.1, status=bounced (unknown user: "$")
Aug  1 13:56:12 myhostname postfix/cleanup[25382]: 3B96B28055: message-id=<20110801205612.3B96B28055@myhostname.mydomain.net>
Run Code Online (Sandbox Code Playgroud)

注意 $@myhostname.mydomain.net, orig_to=

当我修改 commands.cfg 中的命令以将其硬编码到我的实际电子邮件中时,它会完美发送

/usr/bin/printf "%b" "Notification:\t$NOTIFICATIONTYPE$\n\nOccurred:\t$DATETIME$\nHostname:\t$HOSTALIAS$ ($HOSTADDRESS$)\nService:\t$SERVICEDESC$\nState:\t\t$SERVICESTATE$\nDetails:\n\ n$OUTPUT$" | /usr/bin/mail -s "$NOTIFICATIONTYPE$: $HOSTALIAS$/$SERVICEDESC$ -- $SERVICESTATE$" myemail@mydomain.com 
Run Code Online (Sandbox Code Playgroud)

我可能会遗漏什么使 nagios 无法扩展 $CONTACTEMAIL$ 宏?

编辑:在下面发布的quanta建议之后,我打开调试并使用按需宏来查看 nagios 正在做什么。虽然我还不能解释为什么,nagios 似乎没有扩展宏,因为它是裸露的。我将 $CONTACTEMAIL$ 更改为 '$CONTACTEMAIL' 并且它开始工作了。

nav*_*aho 1

在下面发布了 Quanta 的建议后,我打开了调试,然后使用按需宏来查看 nagios 实际在做什么。虽然我还无法解释原因,但 nagios 似乎没有扩展宏,因为它是空的。我将 $CONTACTEMAIL$ 更改为“$CONTACTEMAIL$”,它开始工作。奇怪的是,双引号不起作用。

当我更多地使用它时,似乎 $OUTPUT$ 具有未转义的 html,这导致了问题。