zabbix使用企业微信发消息

注册一个企业微信,https://work.weixin.qq.com/

接收消息有2种方式,一是用企业微信,二是用个人微信(需要关注企业号,需要登录扫描下图邀请关注的二维码):

 

 

 

官方api说明

地址:https://work.weixin.qq.com/api/doc#10167

 

过程

 

一:创建自建应用「报警」,然后用公司corpid和企业应用secret获取token,https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$corpid&corpsecret=$corpsecret

 

二:带着token、touser、agentid、content等参数,向接口https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$token 进行post数据

 

一、创建自建应用

自建应用里会生成AgentId和Secret

二、首先测试连接

 

地址:http://work.weixin.qq.com/api/devtools/devtool.php

 

corpid在「我的企业」最下面显示,corpsecret就是上面的企业应用里的Secret的值

 

如果有返回一个access_token值,就说明没问题

 

在zabbix里生成发送脚本

 

具体的代码如下:

 

#!/bin/bash

access_token=$(/usr/bin/curl -s -G "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=xxxxxxxxx&corpsecret=xxxxxxxxxxxx" | awk -F\" '{print $10}')

#红色xxxx部分修改为你自己的

 

function body() {

        local UserID="$1"

        local PartyID=""

        local AppID="1000002"

        local Msg="$2"

        printf '{\n'

        printf '\t"touser": "'"$UserID"\"",\n"

        printf '\t"toparty": "'"$PartyID"\"",\n"

        printf '\t"msgtype": "text",\n'

        printf '\t"agentid": "'"$AppID"\"",\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)" "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$access_token"

 

测试

sh weixin.sh 账号 发送内容

注意:账号在企业微信「通讯录」里指用户账号,是一个唯一值,不能用姓名和英文名。

转载于:https://www.cnblogs.com/Ghost-bird/p/8961713.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值