<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
    <version>5.0</version>
    <date>2020-05-23T00:00:00Z</date>
    <media_types>
        <media_type>
            <name>ZBX Viewer</name>
            <type>WEBHOOK</type>
            <parameters>
                <parameter>
                    <name>endpoint</name>
                    <value>https://zbx.vovanys.com/push/sendPush_json.php</value>
                </parameter>
                <parameter>
                    <name>message</name>
                    <value>{ALERT.MESSAGE}</value>
                </parameter>
                <parameter>
                    <name>title</name>
                    <value>{ALERT.SUBJECT}</value>
                </parameter>
                <parameter>
                    <name>token</name>
                    <value>{ALERT.SENDTO}</value>
                </parameter>
            </parameters>
            <script>try {&#13;
    var params = JSON.parse(value),&#13;
        request = new CurlHttpRequest(),&#13;
        data,&#13;
        response;&#13;
&#13;
    if (typeof params.HTTPProxy === 'string' &amp;&amp; params.HTTPProxy.trim() !== '') {&#13;
        request.SetProxy(params.HTTPProxy);&#13;
    }&#13;
&#13;
    data = {&#13;
        token: params.token,&#13;
        title: params.title,&#13;
        desc: params.message&#13;
    };&#13;
&#13;
    data = JSON.stringify(data);&#13;
    Zabbix.Log(4, '[ ZBXViewer Webhook ] Sending request: ' + params.endpoint + '\n' + data);&#13;
&#13;
    request.AddHeader('Content-Type: application/json');&#13;
    response = request.Post(params.endpoint, data);&#13;
&#13;
    Zabbix.Log(4, '[ ZBXViewer Webhook ] Received response with status code ' + request.Status() + '\n' + response);&#13;
&#13;
    if (response !== null) {&#13;
        try {&#13;
            response = JSON.parse(response);&#13;
        }&#13;
        catch (error) {&#13;
            Zabbix.Log(4, '[ ZBXViewer Webhook ] Failed to parse response received from ZBXViewer');&#13;
            response = null;&#13;
        }&#13;
    }&#13;
&#13;
    if (request.Status() != 200) {&#13;
        if (response !== null &amp;&amp; typeof response === 'object' &amp;&amp; typeof response.errors === 'object'&#13;
                &amp;&amp; typeof response.errors[0] === 'string') {&#13;
            throw response.errors[0];&#13;
        }&#13;
        else {&#13;
            throw 'Unknown error. Check debug log for more information.';&#13;
        }&#13;
    }&#13;
&#13;
    return 'OK';&#13;
}&#13;
catch (error) {&#13;
    Zabbix.Log(4, '[ ZBXViewer Webhook ] ZBXViewer notification failed: ' + error);&#13;
    throw 'ZBXViewer notification failed: ' + error;&#13;
}</script>
            <description>Please refer to setup guide here: https://zbx.vovanys.com/push/&#13;
&#13;
Set token parameter with to your ZBXViewer application key.&#13;
When assigning ZBXViewer media to the Zabbix user - add user key into send to field.</description>
        </media_type>
    </media_types>
</zabbix_export>

