zabbix邮件告警

zabbix邮件告警调用第三方邮件服务来发送邮件。

[root@tiandong ~]# yum install mailx -y

修改配置文件

[root@tiandong ~]# vim /etc/mail.rc
67 set from=15600857257@163.com smtp=smtp.163.com
 68 set smtp-auth-user=15600857257@163.com
 69 set smtp-auth-password=密码(邮箱的密码)
 70 set smtp-auth=login

测试一下邮件是否能够发送出去:

[root@tiandong ~]# echo "test" | mailx -s 'test linux' 1127000483@qq.com
在邮箱查看:

在zabbix服务端写脚本自动发送邮件:

[root@tiandong ~]# cd /usr/local/zabbix/share/zabbix/alertscripts/
[root@tiandong alertscripts]# vim sendmail.sh
#!/bin/bash
messages=`echo $3 | tr ' ' ' '`
subject=`echo $2 | tr ' ' ' '`
echo "${messages}" | mail -s "${subject}" $1 >>/tmp/sendmail.log 2>&1
[root@tiandong alertscripts]# chmod +x sendmail.sh
[root@tiandong alertscripts]# chown zabbix.zabbix sendmail.sh

修改主配置文件让服务能读到这个脚本

[root@tiandong ~]# vim /usr/local/zabbix/etc/zabbix_server.conf

448 AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts
测试一下脚本是否可以发送邮件:

[root@tiandong ~]# /usr/local/zabbix/share/zabbix/alertscripts/sendmail.sh 1127000483@qq.com "this topic" "this is content"

脚本是可以发送邮件的,然后在页面配置。

 

 

 

 

 此时来触发告警验证是否能自动发送邮件。

[root@winter ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        18G  5.7G   11G  35% /
tmpfs           491M     0  491M   0% /dev/shm
/dev/sda1       485M   34M  426M   8% /boot
[root@winter ~]# dd if=/dev/zero of=/boot/test.txt bs=1M count=410
410+0 records in
410+0 records out
429916160 bytes (430 MB) copied, 3.11281 s, 138 MB/s
[root@winter ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        18G  5.7G   11G  35% /
tmpfs           491M     0  491M   0% /dev/shm
/dev/sda1       485M  444M   16M  97% /boot

此时页面上已经有报警了

查看是否能收到邮件:

到此zabbix邮件告警配置完成。

有什么问题烦请和博主联系。

QQ:1127000483

原文地址:https://www.cnblogs.com/winter1519/p/9823383.html