From 6aa43340090eba47b2064fbaf6ce572afba5b7f7 Mon Sep 17 00:00:00 2001
From: wxin <15253413025@163.com>
Date: Wed, 14 Aug 2024 22:32:45 +0800
Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?=
=?UTF-8?q?=20/?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
zabbix邮箱报警.md | 144 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 144 insertions(+)
create mode 100644 zabbix邮箱报警.md
diff --git a/zabbix邮箱报警.md b/zabbix邮箱报警.md
new file mode 100644
index 0000000..ebda48e
--- /dev/null
+++ b/zabbix邮箱报警.md
@@ -0,0 +1,144 @@
+
Zabbix邮箱报警
+
+------
+
+
+
+## 一:环境准备
+
+#### 1.监控环境
+
+ zabbix-server正常运行,并且正常对zabbix-agent进行监控
+
+#### 2.注册163邮箱
+
+![image-20230228211319924](https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20230228211319924.png)
+
+ 注册邮箱设置客户端授权密码
+
+![image-20230228211456188](https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20230228211456188.png)
+
+![image-20230228211613622](https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20230228211613622.png)
+
+## 二:邮箱部署
+
+#### 1.软件安装
+
+```shell
+[root@xingdian ~]# yum install mailx -y
+```
+
+#### 2.邮箱配置
+
+```shell
+[root@xingdian ~]# vim /etc/mail.rc
+ set from=lisi@163.com(邮箱地址)
+ set smtp=smtp.163.com(smtp服务器)
+ set smtp-auth-user=lisi@163.com(用户名)
+ set smtp-auth-password=*(授权邮箱密码)
+ set smtp-auth=login
+```
+
+#### 3.发邮件的方式
+
+```shell
+方式1:mailx -s "邮件标题" 收件箱Email < 包含正文的文件
+方式2:cat 包含正文的文件 | mailx -s "邮件标题" 收件箱Email
+方式3:echo "正文内容" | mailx -s "邮件标题" 收件箱Email
+方式4:mailx -s "邮件标题" 收件箱Email,回车按CTRL+D发送
+```
+
+#### 4.手动测试
+
+```shell
+[root@xingdian ~]# mailx -v -s 'hello' 'zhangsan@163.com'
+nihao (回车,然后ctrl+D
+EOT
+或者,将邮件内容放到一个文件中content.txt
+ # cat content.txt | mailx -v -s ‘hello’ ‘zhangsan@163.com’
+```
+
+#### 5.创建告警脚本
+
+```shell
+[root@xingdian ~]# cd /usr/lib/zabbix/alertscripts
+[root@xingdian ~]# vim sendmail.sh
+#!/bin/sh
+echo "$3" | sed s/'\r'//g | mailx -s "$2" $1
+[root@xingdian ~]# chmod u+x sendmail.sh && chown zabbix.zabbix sendmail.sh
+```
+
+
+
+## 三:部署Zabbix监控
+
+#### 1.创建主机群组
+
+#### 2.创建主机
+
+#### 3.创建监控项
+
+ (监控nginx服务是否正常运行)
+
+#### 4.创建触发器
+
+#### 5.创建报警媒介
+
+ 脚本参数:
+
+ {ALERT.SENDTO}
+
+ {ALERT.SUBJECT}
+
+ {ALERT.MESSAGE}
+
+#### 6.创建动作
+
+ 关联触发器
+
+ 添加操作
+
+```shell
+"主题"对应"钉钉告警"媒介中的:{ALERT.SUBJECT}
+"消息"对应"钉钉告警"媒介中的:{ALERT.MESSAGE}
+
+主题:
+
+故障名称(触发器名称):{EVENT.NAME}
+
+消息:
+
+告警主机:{HOSTNAME1}
+告警时间:{EVENT.DATE} {EVENT.TIME}
+告警等级:{TRIGGER.SEVERITY}
+告警信息: {TRIGGER.NAME}
+告警项目:{TRIGGER.KEY1}
+问题详情:{ITEM.NAME}:{ITEM.VALUE}
+当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
+事件ID:{EVENT.ID}
+```
+
+ 添加恢复操作
+
+```shell
+主题:故障恢复:{EVENT.NAME}
+
+消息:
+
+恢复主机:{HOSTNAME1}
+恢复时间:{EVENT.DATE} {EVENT.TIME}
+主机IP:{HOST.IP}
+告警项目:{TRIGGER.KEY1}
+问题详情:{ITEM.NAME}:{ITEM.VALUE}
+当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
+事件ID:{EVENT.ID}
+```
+
+#### 7.用户关联报警媒介
+
+#### 8.模拟报警产生
+
+#### 9.查看报警信息
+
+
+