原文:http://www.weiruoyu.cn/?p=399
nagios搭建后需要发送邮件,可以使用自带的senmail来发送,但也可以使用单位邮件来发送,下面使用sendEmail来发送
sendEmail简介
主页:http://caspian.dotconf.net/menu/Software/SendEmail/
下载:http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.55.tar.gz
1.下载安装
下载
# wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.55.tar.gz
安装
#tar –zxvf sendEmail-v1.55.tar.gz
#cd sendEmail-v1.55
#cp sendEmail /usr/local/bin
确定sendEmail有执行权限
# ll /usr/local/bin/sendEmail
-rwxr-xr-x 1 root root 77882 06-23 12:15 /usr/local/bin/sendEmail
2.测试
/usr/local/bin/sendEmail -f nagios@test.com -t xxx@qq.com -s mail.test.com -xu nagios -xp 8888 -u test -m testeamil
这里我测试发送者邮箱不能使用@gmail,@126,@qq,应该是-s没有配置对。
发送成功则提示
Jun 28 17:08:09 localhost sendEmail[13380]: Email was sent successfully!
3.与nagios结合
# vi /usr/local/nagios/etc/objects/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: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/local/bin/sendEmail -f nagios@test.com -t $CONTACTEMAIL$ -s mail.test.com -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -xu nagios -xp 8888
}
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/local/bin/sendEmail -f nagios@test.com -t $CONTACTEMAIL$ -s mail.test.com -u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -xu nagios -xp 8888
}
参考:
http://liuxh.blogbus.com/logs/50440509.html
sendEmail乱码解决
1.测试一下中文发送,有的已经支持iso-8859-1编码,但大部分邮箱还是不支持,建议修改
/usr/local/bin/sendEmail -f nagios@test.com -t xxx@gmail.com -s mail.test.com -xu nagios -xp 8888 -u test -m "你好世界"
2.修改编码为utf-8
# vi /usr/local/bin/sendEmail
把"message-charset" 修改为 utf-8
"message-charset" => 'utf-8'
更详细参考:http://www.weiruoyu.cn/?p=399
转载于:https://blog.51cto.com/weiruoyu/911853