zabbix uses enterprise WeChat to send messages

Register an enterprise WeChat, https://work.weixin.qq.com/

 

 

There are two ways to receive messages, one is to use corporate WeChat, the other is to use personal WeChat (you need to pay attention to the company account, you need to log in and scan the QR code to invite attention):

 

 

 

Official api description

 

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

 

overall process

 

1: Create a self-built application "Alarm", and then use the company corpid and enterprise application secret to obtain the token, https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$corpid&corpsecret=$corpsecret

 

2: Post data to the interface https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$token with parameters such as token, touser, agentid, content, etc.

 

1. Create a self-built application

 

 

AgentId and Secret will be generated in the self-built application

 

 

Second, first test the connection

 

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

 

Corpid is displayed at the bottom of "My Enterprise", and corpsecret is the value of Secret in the above enterprise application.

 

 

 

If there is an access_token value returned, it means no problem

 

Generate send script in zabbix

 

Example of sending a message:

 

The specific code is as follows:

 

#!/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}')

#Red xxxx part is modified to your own

 

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"

 

test

sh weixin.sh account to send content

Note: Account refers to the user account in the "Address Book" of the enterprise WeChat, which is a unique value, and cannot use the name and English name.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324936943&siteId=291194637