3-1 邮件告警
最后更新于:2022-04-02 07:41:10
#### 停止服务器中的sendmail和postfix服务
```
systemct stop sendmail
systemct disable sendmail
systemctl stop postfix
systemctl disable postfix
```
#### 安装dos2unix转换报警信息
```
有些告警信息需要转换
```
#### 配置发送邮箱验证
vi /etc/mail.rc #编辑,添加以下信息
```shell
set from=xxx@163.com
set smtp=smtp.163.com
set smtp-auth-user=xxx@163.com
set smtp-auth-password=123456
set smtp-auth=login
```
#### 测试
```
echo 'test' |mailx -s 'title' xxx@163.com
```
#### 编写Mail脚本
```shell
#!/bin/sh
FILE=/usr/local/etc/zabbix/alertscripts/log
echo "$3" > $FILE
/usr/bin/dos2unix -k $FILE
/bin/mail -s "$2" $1 < $FILE
```
上传到/usr/local/etc/zabbix/alertscripts/目录,zabbix_server.conf配置中可以修改
#### 添加媒体(Zabbix 3.0增加了3个脚本参数)
```
# 不添加无法报警
https://www.zabbix.com/documentation/3.0/manual/config/notifications/media/script
```
#### 报警排查
```
# mail -v
echo 'test' |mailx -v -s 'title' xxx@163.com
```
';