在 Ubuntu 上使用 sSMTP 配置 nagios 电子邮件通知

在 Ubuntu 上使用 sSMTP 配置 nagios 电子邮件通知

我已经配置了 nagios 电子邮件通知并按照以下步骤操作:

sSMTP 配置:

#apt-get install ssmtp  #vi /etc/ssmtp/ssmtp.conf
[email protected]
mailhub=smtp.gmail.com:587
rewriteDomain=
hostname=mycomputerName
UseTLS=YES
UseSTARTTLS=YES
AuthMethod=LOGIN
[email protected]
AuthPass=sender.email.password
FromLineOverride=YES
#chmod 640 /etc/ssmtp/ssmtp.conf

Nagios 配置:

#vi /etc/nagios3/conf.d/localhost_nagios2.cfg
define host{
          use                     generic-host            ; Name of host template to use
          host_name               localhost
          alias                   localhost
          address                 x.x.x.187
          check_command           check-host-alive
          max_check_attempts      10
          notification_interval   120
         notification_period     24x7
          notification_options    d,r
          contact_groups  admins
  }


 #vi /etc/nagios3/conf.d/timeperiods_nagios2.cfg
 define timeperiod{
         timeperiod_name 24x7
         alias           24 Hours A Day, 7 Days A Week
        sunday          00:00-24:00
         monday          00:00-24:00
         tuesday         00:00-24:00
         wednesday       00:00-24:00
         thursday        00:00-24:00
         friday          00:00-24:00
         saturday        00:00-24:00
 }

 #vi /etc/nagios3/conf.d/contacts_nagios2.cfg
 define contact{
         contact_name                    localhost
         alias                           localhost 
         service_notification_period     24x7
         host_notification_period        24x7
         service_notification_options    w,u,c,r
         host_notification_options       d,r
         service_notification_commands   notify-by-email
         host_notification_commands      host-notify-by-email
         email                           [email protected]
 }
 define contactgroup{
         contactgroup_name       admins
         alias                   Nagios Administrators
         members                 localhost
 }

 #vi /etc/nagios3/conf.d/services_nagios2.cfg
 define service{
         use                             generic-service         
         host_name                       localhost
         service_description             SSH
         is_volatile                     0
         check_period                    24x7
         max_check_attempts              4
         normal_check_interval           5
         retry_check_interval            1
         contact_groups                  admins
         notification_interval           960
         notification_period             24x7
         check_command                   check_ssh
  }

通过电子邮件通知命令:

define command{
        command_name    notify-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios @VERSION@ *****\n \nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$OUTPUT$" | @MAIL_PROG@ -s "** $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}

配置 nagios 后,我重新启动了 SSH,但它没有发送电子邮件通知。

新的

‘notify-host-by-email’ 命令定义

define command{
        command_name    notify-host-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
        }

‘notify-service-by-email’ 命令定义

define command{
        command_name    notify-service-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }

答案1

由于您看到以下行/var/log/maillog

sSMTP[5532]: /etc/ssmtp/ssmtp.conf not found

尽管它存在:

-rw-r----- 1 root mail 682 Aug 9 11:23 /etc/ssmtp/ssmtp.conf

我怀疑你没有将nagios用户添加到mail组中。使用以下命令执行此操作:

# usermod -a -G mail nagios

然后再试一次。

相关内容