Operations 3 min read

Configuring Zabbix Alert Notifications via WeChat Using a Shell Script

This guide explains how to create and deploy a Bash script that retrieves a WeChat corporate token and sends Zabbix alarm messages to all users through the WeChat API, enabling automated monitoring alerts via the corporate WeChat platform.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
Configuring Zabbix Alert Notifications via WeChat Using a Shell Script

This document provides step‑by‑step instructions for configuring Zabbix to send alert notifications through WeChat by using a custom shell script.

Step 1 – Create the script file : In the Zabbix alert scripts directory ( /usr/lib/zabbix/alertscripts ), create a new file named sendWeChat.sh (e.g., cd /usr/lib/zabbix/alertscripts && vim sendWeChat.sh ).

Step 2 – Script content : The script must contain the following sections (replace the placeholders with your corporate ID and secret):

#!/bin/bash
# Filename:    sendWeChat.sh
# Revision:    1.0
# Date:        2015/09/08
# Author:      Json
# Description: Zabbix WeChat alert script
# Notes:       WeChat alert

CropID=企业号的CropID   # replace with your corporate ID
Secret=企业号的Secret   # replace with your corporate secret

GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret"
Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F\" '{print $4}')
PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken"
Content=$3

/usr/bin/curl --data-ascii '{ "touser": "@all", "toparty": " @all ","msgtype": "text","agentid": "1","text": {"content": "'${Content}'"},"safe":"0"}' $PURL

Explanation :

The script first builds the token request URL ( GURL ) and obtains an access token ( Gtoken ) using curl and awk .

It then constructs the message‑sending URL ( PURL ) and reads the alert text from the third argument ( $3 ).

Finally, it posts a JSON payload to the WeChat API to broadcast the alert to all users.

After saving the script, ensure it is executable ( chmod +x sendWeChat.sh ) and configure Zabbix to call it as an alert script, passing the desired alert content as the third parameter.

MonitoringOperationsAlertingWeChatShell ScriptZabbix
Practical DevOps Architecture
Written by

Practical DevOps Architecture

Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.