zabbix 使用脚本发送邮件

Support for SMTP authentication was not compiled in 网上的文章很乱,说什么升级curl,我升级完之后还是无法使用邮件报警。后来使用zabbix脚本进行报警

zabbix 使用脚本发送邮件

zabbix

服务器系统是centos6.8

zabbix版本是3.0.4

触发发送邮件的时候报错:

Support for SMTP authentication was not compiled in

官网说的是

To make SMTP authentication options available, Zabbix server should be
compiled with the –with-libcurl compilation option with cURL 7.20.0
or higher.

提示:网上的文章很乱,说什么升级curl,我升级完之后还是无法使用邮件报警。后来使用zabbix脚本进行报警

配置如下:

[root@zabbix-server ~]# grep "alertscripts" /application/zabbix/etc/zabbix_server.conf
# AlertScriptsPath=${datadir}/zabbix/alertscripts
AlertScriptsPath=/application/zabbix/share/zabbix/alertscripts

查看存放脚本目录

脚本内容如下:

我们需要安装dos2unix,因为是通过这个命令进行发送脚本 [yum -y install mailx dos2unix ]

↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑美丽的分割线↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

[root@zabbix-server alertscripts]# cat send_email 
#!/bin/bash
email_File=/tmp/email.log
function main(){
        echo "$3" >$email_File
        /usr/bin/dos2unix $email_File
        /bin/mail -s "$2" "$1" <$email_File
}
main "$1" "$2" "$3"
[root@zabbix-server alertscripts]# chmod 755 send_email
[root@zabbix-server alertscripts]# chown zabbix.zabbix send_email 

我们需要配置一下/ect/mail.rc文件

[root@zabbix-server ~]# tail -1 /etc/mail.rc 
set from=cyh@abcdocker.com smtp=smtp.263.net smtp-auth-user=zabbix@itcast.cn smtp-auth-password=1234567 smtp-auth=login


提示:cyh@abcdocker.com是用户名
      1234567         是密码(不是登陆密码,如果使用QQ邮箱或者163都是有一个授权码。企业邮箱好像使用登陆密码就可以)

QQ邮箱配置如下

https://www.lingkb.com/wp-content/uploads/2020/01/1578155735-33faa7c99d1b97e.png-48.6kB

163邮箱配置如下

https://www.lingkb.com/wp-content/uploads/2020/01/1578155735-03104ac917128a6.png-225.8kB

https://www.lingkb.com/wp-content/uploads/2020/01/1578155735-49f3d0818015a35.png-142.3kB

zabbix页面配置

关于zabbix安装可以参考zabbix板块

https://www.lingkb.com/wp-content/uploads/2020/01/1578155735-61573ab5a29456d.png-49.2kB

还需要添加脚本的传参

https://www.lingkb.com/wp-content/uploads/2020/01/1578155736-a7d7abcd34687fe.png-35.3kB

https://www.lingkb.com/wp-content/uploads/2020/01/1578155736-9ed11733d67dc08.png-44.4kB

https://www.lingkb.com/wp-content/uploads/2020/01/1578155736-1959450a51ed7c0.png-45.6kB

设置动作

https://www.lingkb.com/wp-content/uploads/2020/01/1578155736-d27aef6aaf45134.png-42.2kB

https://www.lingkb.com/wp-content/uploads/2020/01/1578155736-1f7410e7cce6941.png-43kB

https://www.lingkb.com/wp-content/uploads/2020/01/1578155736-be9b0486eeff9dd.png-70.6kB

要确保我们默认的发件是zabbix脚本

https://www.lingkb.com/wp-content/uploads/2020/01/1578155736-ad993e3988a5eed.png-33.2kB

设置收件人

https://www.lingkb.com/wp-content/uploads/2020/01/1578155736-3b6612f5484253d.png-27.9kB

https://www.lingkb.com/wp-content/uploads/2020/01/1578155737-31e9636179ba8ea.png-39.8kB

报警

https://www.lingkb.com/wp-content/uploads/2020/01/1578155737-272b8e2168b1f89.png-18.7kB

欢迎评论。
lingkb » zabbix 使用脚本发送邮件