当前位置:网站首页>ZABBIX配置邮件报警和微信报警
ZABBIX配置邮件报警和微信报警
2022-08-02 13:58:00 【雾山雨巫】
在所要监控的主机上进行配置
zabbix_agent2配置文件如下
[[email protected] ~]# vim /etc/zabbix/zabbix_agent2.conf
任意为其添加一个自定义监控项——统计当前系统用户登录数

[[email protected] ~]# systemctl restart zabbix-agent2.service //修改配置后重启服务
[[email protected] ~]# zabbix_get -s 192.168.163.141 -k os.login //在zabbix服务器上测试
3在该主机的模板下为其添加一个监控项、触发器


并新建一个动作


邮件报警
进入web页面,点击管理——报警媒介类型——Email

为发送端设置

测试是否能发送测试邮件


测试成功

创建用户——用户和报警媒介关联,注意创建用户要对服务器群组有读取权限才可以发送邮件



测试是否能够报警——在受监控主机上登录多个用户

收到邮件
减少系统登录用户数后,收到问题已被解决的邮件

企业微信报警
注册企业微信:https://work.weixin.qq.com

记住部门ID

创建应用

创建完成后记住AgentID和Secret

记住企业ID:


填入Secret
[[email protected] ~]# dnf install python36-3.6.8-38.module+el8.5.0+671+195e4563.x86_64 -y
[[email protected] ~]# cd /usr/lib/zabbix/alertscripts/
[[email protected] ~]# cat weixin.sh
#!/bin/bash
CorpID="ww666898ece13c4ebb" # 你的企业id
Secret="A7L42tpVd9i04Y-GGUbFsf-BTy4e9Jdhyns-3eSGsHc" #你的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 weixin.sh
[[email protected] alertscripts]# chown zabbix:zabbix weixin.sh
[[email protected] alertscripts]# systemctl restart zabbix-server.service
测试失败——将报错IP复制
[[email protected] alertscripts]# ./weixin.sh testmessage
{"errcode":60020,"errmsg":"not allow to access from your ip, hint: [1659360173365201395928402], from ip: 222.91.168.57, more info at https://open.work.weixin.qq.com/devtool/query?e=60020"}
进入zabbix应用配置企业可信IP

再次测试——成功
[[email protected] alertscripts]# ./weixin.sh testmessage
{"errcode":0,"errmsg":"ok","msgid":"Dv0oBVNA9p2BIWPODPqgkiaXOYsaY2P0yoJbDMBz_-o4qO_hla9MTKfO9DFt9cl0hmcG9JcsPm70mb2PiGpv-A"}[[email protected] alertscripts]#

回到Zabbix网页界面
创建报警媒介类型


为test1用户添加报警媒介 收件人为部门号

添加动作
人为触发报警 测试消息是否获取

测试状态恢复

边栏推荐
猜你喜欢

二进制中1的个数

如何解决mysql服务无法启动1069

打破文件锁限制,以存储力量助力企业增长新动力
![[C language] Analysis of function recursion (2)](/img/b1/9baa60a69d41a1823ed92001d1b0a0.png)
[C language] Analysis of function recursion (2)
![Embedded system driver primary [2] - based on character device driver _ basic framework](/img/71/4feb9e42fd2ff1bc4a2d49798657b2.png)
Embedded system driver primary [2] - based on character device driver _ basic framework
![[C language] Analysis of function recursion (3)](/img/95/8bd4483cf03db2dc326eb44675bf5a.png)
[C language] Analysis of function recursion (3)

定了!就在7月30日!

网络安全第四次作业

基于深度学习的图像检索方法!
![[C language] Explicit array solution (1)](/img/d2/26e3e64bb07578a6348747c00abb64.png)
[C language] Explicit array solution (1)
随机推荐
Gstreamer Plugin注册流程详解
els 长条碰撞变形判断
【C语言】函数哪些事儿,你真的get到了吗?(1)
Geoffery Hinton:深度学习的下一个大事件
【C语言】细品分支结构——switch语句
删除链表的节点
[C language] Analysis of function recursion (3)
k8s之KubeSphere部署有状态数据库中间件服务 mysql、redis、mongo
2022-08-02日报:2022年7月最热的10篇AI论文
你真的懂单例模式么
els strip collision deformation judgment
多个驻外使领馆发提醒 事关赴华出行、人身财产安全
机器学习——交叉验证法
拯救流浪猫 | 「喵先锋」系列数字版权盲盒明日开抢
[C language] Analysis of function recursion (2)
政策利空对行情没有长期影响,牛市仍将继续 2021-05-19
二极管及其应用
微信小程序-最近动态滚动实现
第二讲 软件生命周期
打破文件锁限制,以存储力量助力企业增长新动力