How to Send Zabbix Alerts to WeChat via a Private API Script
This guide walks you through registering a WeChat public account, cloning and configuring a private WeChat API, creating a PHP alert script, setting up Zabbix media and actions, and finally testing the integration so Zabbix alerts are delivered to WeChat.
1. Register a WeChat public account
Apply for a WeChat public platform account at https://mp.weixin.qq.com/ . One person can register up to five accounts.
After registration, follow Tencent’s prompts, then scan the QR code with your own WeChat to follow the public account.
View the number of users and obtain a user’s WeChat ID by clicking “User” and locating the red ID in the browser.
2. Download and configure the private WeChat API
Clone the repository: git clone https://github.com/lealife/WeiXin-Private-API Copy the files to Zabbix’s alert‑scripts directory and adjust ownership:
# cp -r WeiXin-Private-API/ /usr/local/zabbix/share/zabbix/alertscripts/ # cd /usr/local/zabbix/share/zabbix/alertscripts/WeiXin-Private-API # chown zabbix.zabbix /usr/local/zabbix/share/zabbix/alertscripts/WeiXin-Private-APIEdit config.php to set your WeChat account, password and cache paths:
$G_CONFIG["weiXin"] = array(
'account' => 'WeChat public account login',
'password' => 'WeChat public account password',
'cookiePath' => $G_ROOT . '/cache/cookie',
'webTokenPath' => $G_ROOT . '/cache/webToken',
);Create test.php with the minimal code needed to send a message:
<?php
require "config.php";
require "include/WeiXin.php";
$weiXin = new WeiXin($G_CONFIG['weiXin']);
$testFakeId = "$argv[1]";
$msg = "$argv[3]";
print_r($weiXin->send($testFakeId, "$msg"));Note: $msg = "$argv[3]" is the third argument passed by Zabbix (the alert content).
3. Create the Zabbix alert script
Create a file named weixin in /usr/local/zabbix/share/zabbix/alertscripts/ containing:
/usr/bin/php /usr/local/zabbix/share/zabbix/alertscripts/WeiXin-Private-API/test.php "$1" "$2" "$3"Make the script executable and owned by the Zabbix user:
# chown -R zabbix.zabbix weixin # chmod +x weixin4. Configure Zabbix
Add a new media type (e.g., “WeChat”) and associate it with a user such as the default administrator.
Create an action that uses this media type; the default conditions are sufficient.
Save the configuration.
5. Verify the integration
Trigger a test alert, for example:
# /usr/local/zabbix/share/zabbix/alertscripts/weixin 770373640 "" "hello"The script returns a JSON object with ret => 0 and err_msg => ok. Check the WeChat account and you should receive the alert message, confirming that Zabbix alerts are successfully delivered via WeChat.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
