Centreon + nagios 搭建后需要发送邮件,可以使用自带的senmail来发送,但也可以使用单独邮件来发送,下面使用sendEmail来发送
SendEmail简介
主页:http://caspian.dotconf.net/menu/Software/SendEmail/
下载:http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
#wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
#tar -zxvf sendEmail-v1.56.tar.gz && cd sendEmail-v1.56
#cp sendEmail /usr/local/nagios/libexec/
#chmod 775 /usr/local/nagios/libexec/sendEmail
#chown nagios:nagios /usr/local/nagios/libexec/sendEmail
测试下是否正常
# sendEmail -f centreon@163.com -t admin@qq.com -s smtp.163.com -u "test mail" -m 'this is test mail!' -xu centreon9 -xp 'passwd'
解释:
-f 表示发送者的邮箱
-t 表示接收者的邮箱
-s 表示SMTP服务器的域名或者ip
-u 表示邮件的主题
-xu 表示SMTP验证的用户名
-xp 表示SMTP验证的密码(注意,这个密码貌似有限制,例如我用d!5neyland就不能被正确识别)
-m 表示邮件的内容
如果你不带-m参数的话,就会提示你自行输入.
Reading message body from STDIN because the ‘-m’ option was not used.
If you are manually typing in a message:
- First line must be received within 60 seconds.
- End manual input with a CTRL-D on its own line
输入完成后使用CTRL-D来结束
当然我们也可以将一个文件的内容作为邮件的正文发出去的
那么就可以使用:
cat 文件名 | /usr/local/bin/sendEmail –f nagios@test.com –t yahoon@test.com –s mail.test.com –u “from nagios” –xu nagios –xp 'passwd'
有关sendEmail的用法就讲到这里。
sendEmail乱码解决
测试一下中文发送,有的已经支持iso-8859-1编码,但大部分邮箱还是不支持,建议修改
# vi /usr/local/nagios/libexec/sendEmail
把"message-charset" 修改为 utf-8
"message-charset" => 'utf-8'
Centreon 控制台添加以下四条命令:
host-notification-en
/usr/bin/printf "%b" "***** centreon Notification *****\n\nType:$NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nDate/Time: $DATE$ $TIME$\nInfo: $HOSTOUTPUT$"| $USER1$/sendEmail -f centreon9@163.com -t $CONTACTEMAIL$ -s smtp.163.com -xu centreon9@163.com -xp 'passwd' -u "Host $HOSTSTATE$ alert for $HOSTNAME$ !"
host-notification-cn
/usr/bin/printf "%b" "***** 网络监控系统通知 *****\n\n通知类型:$NOTIFICATIONTYPE$\n主机: $HOSTNAME$\n状态: $HOSTSTATE$\nIP地址: $HOSTADDRESS$\n日期/时间: $DATE$ $TIME$\n详细信息: $HOSTOUTPUT$"| $USER1$/sendEmail -f centreon9@163.com -t $CONTACTEMAIL$ -s smtp.163.com -xu centreon9@163.com -xp 'passwd' -u "主机 $HOSTNAME$ 已经 $HOSTSTATE$ !"
service-notification-en
/usr/bin/printf "%b" "***** centreon Notification *****\n\nNotification Type: $NOTIFICATIONTYPE$\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $DATE$ $TIME$ Additional Info : $SERVICEOUTPUT$" | $USER1$/sendEmail -f centreon9@163.com -t $CONTACTEMAIL$ -s smtp.163.com -u "** $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -xu centreon9@163.com -xp 'passwd'
service-notification-cn
/usr/bin/printf "%b" "***** 网络监控系统通知 *****\n\n通知类型: $NOTIFICATIONTYPE$\n服务: $SERVICEDESC$\n主机: $HOSTALIAS$\nIP地址: $HOSTADDRESS$\n状态: $SERVICESTATE$\n\n日期/时间: $DATE$ $TIME$\n详细信息 : $SERVICEOUTPUT$" | $USER1$/sendEmail -f centreon9@163.com -t $CONTACTEMAIL$ -s smtp.163.com -u "** $NOTIFICATIONTYPE$ 通知 - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -xu centreon9@163.com -xp 'passwd'