IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> zabbix设置企业微信告警 -> 正文阅读

[系统运维]zabbix设置企业微信告警

zabbix设置企业微信告警
1、找到alertscripts文件夹路径,修改zabbix_server.conf

[root@zabbixserver ~]# vim /etc/zabbix/zabbix_server.conf 
AlertScriptsPath=/usr/lib/zabbix/alertscripts

2、设置脚本

[root@zabbixserver alertscripts]# vim weixin.sh
#!/bin/bash
CropID='#################'	#企业ID
Secret='#############################'	#创建的应用SecretID
#获取access_token
GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret"
Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F\" '{print $10}')
PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken"
function body () {
     local Meg=$(echo "$@" | cut -d" " -f3-)
         echo """{
            \"touser\" : \"@all\",
            \"msgtype\" : \"text\",   
            \"agentid\" : #######,  #创建的应用AgentID这条说明要去掉
            \"text\" : {           
            \"content\" : \"$Meg\"}   
                }"""
            }
/usr/bin/curl --data-ascii "$(body $1 $2 $3)" $PURL
[root@zabbixserver alertscripts]# chmod 755 weixin.sh

3.、创建告警媒介
在这里插入图片描述
参数
{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
3、测试

[root@zabbixserver alertscripts]# ./weixin.sh 1111 test test
{"errcode":0,"errmsg":"ok","invaliduser":""}

也可以模拟故障看看企业微信有没有收到信息

附上另外两个脚本

#!/bin/bash
CorpID="###############"
#我的企业下面的CorpID
Secret="#############################"
#创建的应用那有Secret
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=#######
#改为AgentId 在创建的应用那里看
local UserID=$1
#发送的用户位于$1的字符串
#local PartyID=
#第一步看的通讯录中的部门ID,可以不用
local Msg=$(echo "$@" | 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

python脚本,centos8需执行

[root@zabbixserver ~]# ln -s /usr/bin/python3 /usr/bin/python
#!/usr/bin/env python
#-*- coding: utf-8 -*-
#date: 2021-07-28
#comment: zabbix接入企业微信报警脚本
import requests
import sys
import os
import json
import logging
corpid='##################' #企业ID
appsecret='#################################'  #secret
agentid=#######  #AgentID
#获取accesstoken
token_url='https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + corpid + '&corpsecret=' + appsecret
req=requests.get(token_url)
accesstoken=req.json()['access_token']
#发送消息
msgsend_url='https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + accesstoken
touser=sys.argv[1]
subject=sys.argv[2]
#toparty='3|4|5|6'
message=sys.argv[3]
params={
        "touser": touser,
#       "toparty": toparty,
        "msgtype": "text",
        "agentid": agentid,
        "text": {
                "content": message
        },
        "safe":0
}
req=requests.post(msgsend_url, data=json.dumps(params))
logging.info('sendto:' + touser + ';;subject:' + subject + ';;message:' + message)
  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章           查看所有文章
加:2021-07-29 14:51:25  更:2021-07-29 14:51:37 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/2 16:56:26-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码