nagios邮件报警设置sendEmail 乱码解决

原文: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.下载安装

下载

 
 
  1. # wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.55.tar.gz

安装

 
 
  1. #tar �Czxvf sendEmail-v1.55.tar.gz

  2. #cd sendEmail-v1.55

  3. #cp sendEmail /usr/local/bin


  4. 确定sendEmail有执行权限

  5. # ll /usr/local/bin/sendEmail

  6. -rwxr-xr-x 1 root root 77882 06-23 12:15 /usr/local/bin/sendEmail

2.测试

 
 
  1. /usr/local/bin/sendEmail -f [email protected] -t [email protected] -s mail.test.com -xu nagios -xp 8888 -u test -m testeamil


-f 表示发送者的邮箱
-t 表示接收者的邮箱
-s 表示SMTP服务器的域名或者ip
-u 表示邮件的主题
-xu 表示SMTP验证的用户名
-xp 表示SMTP验证的密码(注意,这个密码貌似有限制,例如我用d!5neyland就不能被正确识别)
-m 表示邮件的内容


这里我测试发送者邮箱不能使用@gmail,@126,@qq,应该是-s没有配置对。

发送成功则提示

 
 
  1. Jun 28 17:08:09 localhost sendEmail[13380]: Email was sent successfully!

3.与nagios结合

 
 
  1. # vi /usr/local/nagios/etc/objects/commands.cfg

注释掉以前的,添加如下

 
 
  1. # 'notify-host-by-email' command definition

  2. define command{

  3. command_name notify-host-by-email

  4. 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 [email protected] -t $CONTACTEMAIL$ -s mail.test.com -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -xu nagios -xp 8888

  5. }

  6. define command{

  7. command_name notify-service-by-email

  8. 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 [email protected] -t $CONTACTEMAIL$ -s mail.test.com -u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -xu nagios -xp 8888

  9. }

参考:

http://liuxh.blogbus.com/logs/50440509.html

sendEmail乱码解决

1.测试一下中文发送,有的已经支持iso-8859-1编码,但大部分邮箱还是不支持,建议修改

 
 
  1. /usr/local/bin/sendEmail -f [email protected] -t [email protected] -s mail.test.com -xu nagios -xp 8888 -u test -m "你好世界"

2.修改编码为utf-8

 
 
  1. # vi /usr/local/bin/sendEmail

把"message-charset" 修改为 utf-8

 
 
  1. "message-charset" => 'utf-8'

更详细参考:http://www.weiruoyu.cn/?p=399


你可能感兴趣的:(邮件,乱码,sendEmail,nagios)