zabbix使用Lark接收告警通知

zabbix使用Lark接收告警通知

通过webhook推送告警通知的脚本:

try {
    var params = JSON.parse(value),
        request = new HttpRequest(),
        message = params.Subject + '\n' + params.Message;

    request.addHeader('Content-Type: application/json');
    var response = request.post(params.URL, JSON.stringify({"msg_type": "text", "content": {"text": message}}));

    try {
        response = JSON.parse(response);
    } catch (error) {
        response = null;
    }

    if (request.getStatus() !== 200 || response.StatusCode !== 0) {
        if (typeof response.msg === 'string') {
            throw response.msg;
        } else {
            throw 'Unknown error. Check debug log for more information.';
        }
    }
    return "ok"
} catch (error) {
    throw 'Sending failed: ' + error + '.';
}
posted @ 2024-12-11 18:18  笨鸡蛋9毛  阅读(54)  评论(0)    收藏  举报