其他分享
首页 > 其他分享> > zabbix邮箱告警配置

zabbix邮箱告警配置

作者:互联网

zabbix邮箱告警配置

环境介绍

类型 IP地址 主机名 系统版本
服务端 192.168.209.130 zabbix CentOS stream 8
客户端 192.168.209.131 agentd CentOS stream 8

本地邮箱告警

本地邮箱配置

[root@zabbix ~]# yum -y install mailx postfix
[root@zabbix ~]# systemctl enable postfix.service --now

//修改主机域名,否则邮件会被邮箱删除
[root@zabbix ~]# hostnamectl set-hostname zabbix.example.com
[root@zabbix ~]# bash
[root@zabbix ~]# hostname
zabbix.example.com

//测试
[root@zabbix ~]# echo 'afdsafgd'|mail -s 'sadasd' yueshen233@126.com

![image](https://www.icode9.com/i/l/?n=20&i=blog/2262478/202104/2262478-20210427230137073-1243746681.png)

本地邮箱脚本告警配置

本地邮箱告警脚本目录默认是/usr/local/share/zabbix/alertscripts

//设置脚本告警目录
[root@zabbix ~]# vim /usr/local/etc/zabbix_server.conf

# Mandatory: no
# Default:
 AlertScriptsPath=${datadir}/zabbix/alertscripts  //取消注释

### Option: ExternalScripts
#       Full path to location of external scripts.
#       Default depends on compilation options.
#       To see the default path run command "zabbix_server --help".
#
# Mandatory: no
# Default:
 ExternalScripts=${datadir}/zabbix/externalscripts //取消注释

//重启服务
[root@zabbix ~]# pkill zabbix
[root@zabbix ~]# zabbix_server 
[root@zabbix ~]# zabbix_agentd 

//编写脚本  
[root@zabbix ~]# cd /usr/local/share/zabbix/alertscripts/  
[root@zabbix alertscripts]# vim sendmail.sh
#!/bin/bash

MESSAGE=$(echo $2 | tr "\r\n" "\n")
SUBJECT=$(echo $3 | tr "\r\n" "\n")
MAILTO=$1

echo "$MESSAGE" | mail -s "$SUBJECT" $MAILTO

//添加脚本执行权限  
[root@zabbix alertscripts]# chmod +x sendmail.sh

//测试
[root@zabbix ~]# su - zabbix -s /bin/bash
su: warning: cannot change directory to /home/zabbix: No such file or directory
[zabbix@zabbix root]$ cd /usr/local/share/zabbix/alertscripts/
[zabbix@zabbix alertscripts]$ ./sendmail.sh yueshen233@126.com '123456' 'asssss'

![image](https://www.icode9.com/i/l/?n=20&i=blog/2262478/202104/2262478-20210427230149269-1282988088.png)

配置zabbix Media types

添加媒介
image
image
添加媒介信息
image
设置收件人
image
image
设置动作
image
image
image

第三方邮箱网页告警

第三方邮箱+脚本告警

标签:root,zabbix,alertscripts,邮箱,告警,com
来源: https://www.cnblogs.com/sarenn/p/14711346.html