Configuring WeCom Webhook Notifications in Zabbix 7.0

Zabbix 7.0 introduced stricter validation for custom media type scripts, which frequently breaks legacy webhook implementations designed for earlier releases. To restore Enterprise WeChat (WeCom) group robot notifications, the JavaScript execution block must be updated to align with the current HttpRequest API and payload expectations.

Navigate to Alerts > Media types and create a new entry. Set the type to Webhook. The configuration requires a single parameter named Token, which corresponds to the key query string extracted from your WeCom robot webhook URL. Additional parameters like Subject, Message, and To should be mapped to their respective Zabbix macro values in the action operations.

The following JavaScript handles the HTTP POST request, payload serialization, and response validation:

var WecomBot = {
    apiKey: null,
    recipient: null,
    payload: null,
    contentType: null,

    dispatch: function() {
        var endpoint = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=' + WecomBot.apiKey;
        var requestBody = {
            msgtype: 'markdown',
            markdown: {
                content: WecomBot.payload
            }
        };

        if (WecomBot.contentType && ['Markdown', 'HTML'].indexOf(WecomBot.contentType) !== -1) {
            requestBody.parse_mode = WecomBot.contentType;
        }

        var client = new HttpRequest();
        client.addHeader('Content-Type: application/json');
        var serializedData = JSON.stringify(requestBody);

        Zabbix.log(3, '[WecomWebhook] Target: ' + endpoint.replace(WecomBot.apiKey, '***'));
        Zabbix.log(3, '[WecomWebhook] Body: ' + serializedData);

        var rawResponse = client.post(endpoint, serializedData);
        var httpStatus = client.getStatus();

        Zabbix.log(3, '[WecomWebhook] HTTP Status: ' + httpStatus);
        Zabbix.log(3, '[WecomWebhook] Raw Reply: ' + rawResponse);

        var parsedReply;
        try {
            parsedReply = JSON.parse(rawResponse);
        } catch (e) {
            parsedReply = null;
            Zabbix.log(1, '[WecomWebhook] JSON parse failure');
        }

        if (httpStatus !== 200 || !parsedReply || parsedReply.errcode !== 0) {
            var errorMsg = parsedReply && parsedReply.errmsg ? parsedReply.errmsg : 'Unexpected API response';
            throw 'Delivery failed: ' + errorMsg;
        }
    }
};

try {
    var input = JSON.parse(value);

    if (!input.Token) {
        throw 'Missing required parameter: Token';
    }

    WecomBot.apiKey = input.Token;
    WecomBot.contentType = input.ParseMode || null;
    WecomBot.recipient = input.To || '';
    WecomBot.payload = input.Subject + '\n' + input.Message;

    WecomBot.dispatch();
    return 'OK';
} catch (err) {
    Zabbix.log(1, '[WecomWebhook] Execution halted: ' + err);
    throw 'Notification error: ' + err;
}

To notify specific group members, WeCom suports the mentioned_mobile_list field within the markdown payload. Modify the requestBody construction to include an array of registered phone numbers when targeting individuals:

markdown: {
    content: WecomBot.payload,
    mentioned_mobile_list: ['13800138000', '13900139000']
}

Message formatting relies on Zabbix macros combined with WeCom's supported Markdown syntax. The following templates cover problem detection, recovery, and manual acknowledgment events.

Problem Notification Template

### 🚨 Zabbix Alert Triggered
---
**Trigger:** <font color="#FF0000">{TRIGGER.NAME}</font>
**Timestamp:** {EVENT.DATE} {EVENT.TIME}
**Severity:** {TRIGGER.SEVERITY}
**Last Value:** {ITEM.LASTVALUE}
**Host Address:** {HOST.IP}
**Host Label:** {HOST.NAME}
**Duration:** {EVENT.AGE}
**Acknowledged:** {EVENT.ACK.STATUS}
---
**Current State:** <font color="#F56C6C">{EVENT.STATUS}</font>

Recovery Notification Template

### ✅ Zabbix Issue Resolved
---
**Trigger:** <font color="#67C23A">{TRIGGER.NAME} (Recovered)</font>
**Recovery Time:** {EVENT.RECOVERY.DATE} {EVENT.RECOVERY.TIME}
**Severity:** {TRIGGER.SEVERITY}
**Last Value:** {ITEM.LASTVALUE}
**Host Address:** {HOST.IP}
**Host Label:** {HOST.NAME}
**Duration:** {EVENT.AGE}
**Acknowledged:** {EVENT.ACK.STATUS}
---
**Current State:** <font color="#02b340">{EVENT.STATUS}</font>

Update/Acknowledgment Template

### ⚠️ Zabbix Event Updated
---
**Action:** <font color="#67C23A">{USER.FULLNAME} acknowledged the incident</font>
**Update Time:** {ACK.DATE} {ACK.TIME}
**Severity:** {TRIGGER.SEVERITY}
**Last Value:** {ITEM.LASTVALUE}
**Host Address:** {HOST.IP}
**Host Label:** {HOST.NAME}
**Duration:** {EVENT.AGE}
**Notes:** {ACK.MESSAGE}
**Acknowledged:** {EVENT.ACK.STATUS} ✅
---
**Current State:** <font color="#F56C6C">{EVENT.STATUS}</font>

Assign these templates to the corresponding Message templates section within the Webhook media type configuration. Insure the Subject and Message macros in the Zabbix action operations map correctly to the script's expected input structure.

Tags: Zabbix WeCom Webhook Alerting javascript

Posted on Wed, 13 May 2026 02:39:18 +0000 by IMP_TWI