Nagios 无法在通知命令中扩展 $CONTACTEMAIL$ 宏

Nagios 无法在通知命令中扩展 $CONTACTEMAIL$ 宏

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

(使用 debian 软件包在 debian squeeze 上安装版本 3.2.1)

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

我的 command.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
}       

并在 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                           [email protected]
    register                        1
    }       

在我的服务配置文件中

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
}       

有了这些配置,我预计 nagios 会将通知发送到电子邮件地址[电子邮件保护],如果我关闭 myservicehost 上的 SE: 服务。但不会。

Aug  1 13:56:12 myhostname postfix/cleanup[25382]: 2DC5F28054: message-id=<[email protected]>
Aug  1 13:56:12 myhostname postfix/qmgr[22452]: 2DC5F28054: from=<[email protected]>, size=470, nrcpt=1 (queue active)
Aug  1 13:56:12 myhostname postfix/local[25384]: 2DC5F28054: to=<[email protected]>, 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=<[email protected]>

注意[电子邮件保护], 原始=

当我修改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$" [email protected] 

我可能遗漏了什么导致 nagios 无法扩展 $CONTACTEMAIL$ 宏?

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

答案1

  • 打开调试级别以仔细查看nagios.log
  • 尝试使用按需宏$CONTACTEMAIL:navaho$来查看是否有效

答案2

问题在于service_notification_options中的“n”:

http://nagios.sourceforge.net/docs/3_0/objectdefinitions.html

service_notification_options:如果您指定 n(无)作为选项,则联系人将不会收到任何类型的服务通知。

答案3

您的 contacts.cfg 中有错误。从列表中
删除代表...的nservice_notification_optionsnnone

像这样:

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
    host_notification_commands      notify_by_email
    service_notification_commands   notify_by_email
    email                           [email protected]
    register                        1
    } 

答案4

尝试在 command.cfg 中的命令行中将 $CONTACTEMAIL$ 放在引号中

相关内容