Nagios 是一个在linux及unix环境下运行的监控系统和网络的应用程序,既然是监控的,当然出现了警告的事件得解决Sendmail的,请看下文。
1、检查commands.cfg
# 'notify-host-by-email' command definition
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification
Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTA
DDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $
NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
# 'notify-service-by-email' command definition
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$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert:
$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
这是正确的命令配置,其中最重要的就是/bin/mail后边的命令配置
2、mqueue
[root@localhost mqueue]# pwd
/var/spool/mqueue
[root@localhost mqueue]# ll
total 8
-rw------- 1 root smmsp 8 Nov 18 20:54 dfmAICsFQj009878
-rw------- 1 root smmsp 901 Nov 18 21:56 qfmAICsFQj009878
[root@localhost mqueue]#
这个目录存储的是邮件发送队列,如果这个里边满了不但会影响程序的运行,而且sendmail容易死掉,所以必要的时候要删除。
3、修改access
[root@localhost mail]# pwd
/etc/mail
[root@localhost mail]# vi access
# Check the /usr/share/doc/sendmail/README.cf file for a description
# of the format of this file. (search for access_db in that file)
# The /usr/share/doc/sendmail/README.cf is part of the sendmail-doc
# package.
#
# by default we allow relaying from localhost...
Connect:localhost.localdomain RELAY
Connect:localhost RELAY
Connect:127.0.0.1 RELAY
Connect:192.168.0 RELAY
Connect: RELAY
Connect:1.1.1 RELAY
Connect:nagios@localhost.localdomain RELAY
Connect:root@localhost RELAY
然后执行makemap hash access < access
或者是makemap -v hash /etc/mail/access.db < /etc/mail/access
4、[root@localhost spool]# pwd
/var/spool
chmod 777 mqueue
我的邮箱是163.com。
5、检查所传送的电子邮件是否送出,或滞留在邮件服务器中
语法:/usr/lib/sendmail -bp
若屏幕显示为“Mail queue is empty” 的信息,表示mail 已送出。
6、检查邮件发送过程
在Sendmail邮件服务器上执行下面的命令.
# echo testing | /usr/sbin/sendmail -v someone@somedomain.com
7、sendmail日志
[root@localhost log]# pwd
/var/log
vi maillog就可以看了,出现任何错误都可以看到。
阅读完本文,能从本文找到Nagios中告警邮件,得做七大步,加油吧!