当前位置:网站首页>zabbix email alarm and WeChat alarm
zabbix email alarm and WeChat alarm
2022-08-02 06:45:00 【palm nine】
配置zabbixEmail alerts and WeChat alarm.
一、邮件报警
1. 配置报警媒介类型


点击更新后,再次点击测试


测试成功
2. 创建用户
创建用户组并设置权限


创建用户

添加报警媒介

设置权限


3. 配置动作
1.创建主机组

2.创建模板

3.创建监控项
客户端
[[email protected] ~]# vim /etc/zabbix/zabbix_agent2.conf
###Option: UnsafeUserParameters
#Allow all characters to be passed in arguments to user-defined parameters.
#The following characters are not allowed:
#\ ' " ` * ? [ ] { } ~ $ ! & ; ( ) < > | # @
#Additionally, newline characters are not allowed.
#0 - do not allow
#1 - allow
#
#Mandatory: no
#Range: 0-1
#Default:
#UnsafeUserParameters=0
UnsafeUserParameters=1
###Option: UserParameter
#User-defined parameter to monitor. There can be several user-defined parameters.
#Format: UserParameter=<key>,<shell command>
#See 'zabbix_agentd' directory for examples.
#
#Mandatory: no
#Default:
#UserParameter=
UserParameter=os.login,who | wc -l

5.创建触发器


表达式:
6.创建动作



操作




Remember the template to givenode1主机
测试
Copy session number greater than3
用用户zhangsan登录zabbix
邮箱收件

Remove replication session,警报解除
查看Admin用户
二、微信报警
1. 注册企业微信
链接: https://work.weixin.qq.com/

Self-test also don't add members
2. 添加一个部门
Enter the address book add
Add member selection“Other departments import”

3. 创建一个应用
进入应用管理

Create the rememberAgentID和Secret:
Remember that the enterpriseID:
4. 微信企业号接口调试工具
https://open.work.weixin.qq.com/wwopen/devtool/interface/combine

点击调用接口,显示OK即可
5. 配置脚本
服务端操作
[[email protected] ~]# dnf provides */pip3
Last metadata expiration check: 2:32:57 ago on Mon 01 Aug 2022 02:07:36 PM CST.
python3-pip-9.0.3-22.el8.rocky.0.noarch : A tool for installing and managing Python3 packages
Repo : appstream
Matched from:
Filename : /usr/share/bash-completion/completions/pip3
python36-3.6.8-38.module+el8.5.0+671+195e4563.x86_64 : Interpreter of the Python programming language
Repo : appstream
Matched from:
Filename : /usr/bin/pip3
python38-pip-19.3.1-5.module+el8.6.0+794+eba84017.noarch : A tool for installing and managing Python3 packages
Repo : appstream
Matched from:
Filename : /usr/bin/pip3
python39-pip-20.2.4-7.module+el8.6.0+795+de4edbcc.noarch : A tool for installing and managing Python3 packages
Repo : appstream
Matched from:
Filename : /usr/bin/pip3
[[email protected] ~]# dnf install python36-3.6.8-38.module+el8.5.0+671+195e4563.x86_64
Into the specified directory to createshell脚本
[[email protected] ~]# cd /usr/lib/zabbix/alertscripts/
[[email protected] alertscripts]# vim webchat.sh
[[email protected] alertscripts]# cat webchat.sh
#!/bin/bash
CorpID="wwd5931acb806b41890c" # 你的企业id
Secret="BbUbI_g_4zwvgYjlRinxBu5V_xK8R1VRT-QiNLYW5O0" #你的SecretID
GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CorpID&corpsecret=$Secret"
Token=$(/usr/bin/curl -s -G $GURL |awk -F\": '{print $4}'|awk -F\" '{print $2}')
# echo $Token
PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Token"
function body(){
local int agentid=1000002 # 你的agentdid
local UserID="@all" # 发送的用户ID
local PartyID=1 # 部门ID
local Msg=$(echo "[email protected]" | cut -d" " -f3-) # 发送给所有人
printf '{\n'
printf '\t"touser": "'"$UserID"\"",\n"
printf '\t"toparty": "'"$PartyID"\"",\n"
printf '\t"msgtype": "text",\n'
printf '\t"agentid": "'"$agentid"\"",\n"
printf '\t"text": {\n'
printf '\t\t"content": "'"$Msg"\""\n"
printf '\t},\n'
printf '\t"safe":"0"\n'
printf '}\n'
}
/usr/bin/curl --data-ascii "$(body $1 $2 $3)" $PURL
[[email protected] alertscripts]# chmod +x webchat.sh
[[email protected] alertscripts]# chown zabbix.zabbix webchat.sh
[[email protected] alertscripts]# systemctl restart zabbix-server.service
[[email protected] alertscripts]# ./webchat.sh test123
{"errcode":60020,"errmsg":"not allow to access from your ip, hint
[1659346334640291099389903], from ip: 111.19.34.233, more info at
https://open.work.weixin.qq.com/devtool/query?e=60020"}[[email protected] alertscripts]#
发现错误60020
Copy the url to view
https://open.work.weixin.qq.com/devtool/query?e=60020
进入应用管理>zabbix>企业可信IP
解决
[[email protected] alertscripts]# ./webchat.sh test123
{"errcode":0,"errmsg":"ok","msgid":"WpLDpQFMGSE843kRbNhgXXSkwRSv4Pitw4mtejX
IhGXxyByCLpHVi7TlK_didEkdb87tsQm5phjff8_ueWBWQ"}[[email protected] alertscripts]#
6. zabbix webInterface configuration WeChat alarm
进入:管理 > 报警媒介类型 > 创建媒体类型:
脚本参数
{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}


主题
故障{TRIGGER.STATUS},服务器:{HOSTNAME1}发生: {TRIGGER.NAME}故障!
消息
告警主机:{HOSTNAME1}
告警时间:{EVENT.DATE} {EVENT.TIME}
告警等级:{TRIGGER.SEVERITY}
告警信息: {TRIGGER.NAME}
告警项目:{TRIGGER.KEY1}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件ID:{EVENT.ID}
Add a resume
主题
恢复{TRIGGER.STATUS}, 服务器:{HOSTNAME1}: {TRIGGER.NAME}已恢复!
消息
告警主机:{HOSTNAME1}
告警时间:{EVENT.DATE} {EVENT.TIME}
告警等级:{TRIGGER.SEVERITY}
告警信息: {TRIGGER.NAME}
告警项目:{TRIGGER.KEY1}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件ID:{EVENT.ID}

7. Users and medium of alarm correlation

8.Configuration action and operation




9.Man-made trigger test


恢复
邮件
边栏推荐
- How to perform concurrent calculation (stability test and stress test)?
- APT + Transform to realize multi module Application distributed Application life cycle
- Contents of encoding-indexes.js file printed with Bluetooth:
- 51 MCU peripherals: DS18B20
- 分布式文件存储服务器之Minio对象存储技术参考指南
- 【合集- 行业解决方案】如何搭建高性能的数据加速与数据编排平台
- Introduction to coredns
- Node installation and configuration of environment variables
- Polar Parametrization for Vision-based Surround-View 3D Detection 论文笔记
- 使用jOOQ 3.14合成外键在视图上写隐式连接
猜你喜欢
随机推荐
51 MCU Peripherals: Infrared Communication
Practice on optimizing startup performance of VS Code
上海交大牵手淘宝成立媒体计算实验室:推动视频超分等关键技术发展
Nacos数据库配置
How to perform concurrent calculation (stability test and stress test)?
Meta公司内部项目-RaptorX:将Presto性能提升10倍
What is the most important ability of a programmer?
MySQL联合查询(多表查询)
Stress testing and performance analysis of node projects
Smart people's game improvement: Chapter 3, Lesson 2: "Number of Tongtong" (number)
保证家里和企业中的WIFI安全-附AC与AP组网实验
The international top conference OSDI included Taobao system papers for the first time, and the device-cloud collaborative intelligence was recommended by the keynote speech of the conference
BGP experiment (route reflector, federation, route optimization)
Polar Parametrization for Vision-based Surround-View 3D Detection 论文笔记
Difference between npm and yarn
zabbix邮件报警和微信报警
Kingdee International: Lost in half a year and last year, how does the business model of frantically burning money continue
Analysis of the source code of the JS UI framework of Hongmeng system
家用 NAS 服务器(4)| MergerFS和SnapRaid数据定时备份
Home NAS server (4) | MergerFS and SnapRaid data backup









