START TRANSACTION;
INSERT INTO role (roleid,name,type,readonly) values ('1','User role','1','0');
INSERT INTO role (roleid,name,type,readonly) values ('2','Admin role','2','0');
INSERT INTO role (roleid,name,type,readonly) values ('3','Super admin role','3','1');
INSERT INTO role (roleid,name,type,readonly) values ('4','Guest role','1','0');
INSERT INTO users (userid,username,name,surname,passwd,url,autologin,autologout,refresh,rows_per_page,roleid) values ('1','Admin','Zabbix','Administrator','$2y$10$92nDno4n0Zm7Ej7Jfsz8WukBfgSS/U0QkIuu8WkJPihXBb2A1UrEK','','1','0','30s','50','3');
INSERT INTO users (userid,username,name,surname,passwd,url,autologin,autologout,refresh,rows_per_page,roleid) values ('2','guest','','','$2y$10$89otZrRNmde97rIyzclecuk6LwKAsHN0BcvoOKGjbT.BwMBfm7G06','','0','15m','30s','50','4');
INSERT INTO hstgrp (groupid,name,internal,flags,uuid) values ('1','Templates','0','0','7df96b18c230490a9a0a9e2307226338');
INSERT INTO hstgrp (groupid,name,internal,flags,uuid) values ('2','Linux servers','0','0','dc579cd7a1a34222933f24f52a68bcd8');
INSERT INTO hstgrp (groupid,name,internal,flags,uuid) values ('4','Zabbix servers','0','0','6f6799aa69e844b4b3918f779f2abf08');
INSERT INTO hstgrp (groupid,name,internal,flags,uuid) values ('5','Discovered hosts','1','0','f2481361f99448eea617b7b1d4765566');
INSERT INTO hstgrp (groupid,name,internal,flags,uuid) values ('6','Virtual machines','0','0','137f19e6e2dc4219b33553b812627bc2');
INSERT INTO hstgrp (groupid,name,internal,flags,uuid) values ('7','Hypervisors','0','0','1b837a3c078647049a0c00c61b4d57b5');
INSERT INTO hstgrp (groupid,name,internal,flags,uuid) values ('8','Templates/Modules','0','0','57b7ae836ca64446ba2c296389c009b7');
INSERT INTO hstgrp (groupid,name,internal,flags,uuid) values ('9','Templates/Network devices','0','0','36bff6c29af64692839d077febfc7079');
INSERT INTO hstgrp (groupid,name,internal,flags,uuid) values ('10','Templates/Operating systems','0','0','846977d1dfed4968bc5f8bdb363285bc');
INSERT INTO hstgrp (groupid,name,internal,flags,uuid) values ('11','Templates/Server hardware','0','0','e960332b3f6c46a1956486d4f3f99fce');
INSERT INTO hstgrp (groupid,name,internal,flags,uuid) values ('12','Templates/Applications','0','0','a571c0d144b14fd4a87a9d9b2aa9fcd6');
INSERT INTO hstgrp (groupid,name,internal,flags,uuid) values ('13','Templates/Databases','0','0','748ad4d098d447d492bb935c907f652f');
INSERT INTO hstgrp (groupid,name,internal,flags,uuid) values ('14','Templates/Virtualization','0','0','02e4df4f20b848e79267641790f241da');
INSERT INTO hstgrp (groupid,name,internal,flags,uuid) values ('15','Templates/Telephony','0','0','1d12408342854fd5a4436dd6d5d1bd4a');
INSERT INTO hstgrp (groupid,name,internal,flags,uuid) values ('16','Templates/SAN','0','0','7c2cb727f85b492d88cd56e17127c64d');
INSERT INTO hstgrp (groupid,name,internal,flags,uuid) values ('17','Templates/Video surveillance','0','0','d37f71c7e3f7469bab645852a69a2018');
INSERT INTO hstgrp (groupid,name,internal,flags,uuid) values ('18','Templates/Power','0','0','3dcd5bbe90534f9e8eb5c2d53756af63');
INSERT INTO hstgrp (groupid,name,internal,flags,uuid) values ('19','Templates/Cloud','0','0','c2c162144c2d4c5491c8801193af4945');
INSERT INTO drules (druleid,proxy_hostid,name,iprange,delay,status) values ('2',NULL,'Local network','192.168.0.1-254','1h','1');
INSERT INTO dchecks (dcheckid,druleid,type,key_,snmp_community,ports,snmpv3_securityname,snmpv3_securitylevel,snmpv3_authpassphrase,snmpv3_privpassphrase,uniq,snmpv3_authprotocol,snmpv3_privprotocol,snmpv3_contextname,host_source,name_source) values ('2','2','9','system.uname','','10050','','0','','','0','0','0','','1','0');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('1','0','Email','mail.example.com','example.com','zabbix@example.com','','','','','0','25','0','0','0','0','','1','3','10s','0','','30s','0','0','','','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('3','2','SMS','','','','','/dev/ttyS0','','','0','25','0','0','0','0','','1','3','10s','1','','30s','0','0','','','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('4','0','Email (HTML)','mail.example.com','example.com','zabbix@example.com','','','','','0','25','0','0','0','0','','1','3','10s','1','','30s','0','0','','','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('5','4','Mattermost','','','','','','','','0','25','0','0','0','0','','1','1','10s','1',E'var SEVERITY_COLORS = [
    ''#97AAB3'', ''#7499FF'', ''#FFC859'',
    ''#FFA059'', ''#E97659'', ''#E45959''
];

var RESOLVE_COLOR = ''#009900'';

var SEND_MODE_HANDLERS = {
    alarm: handlerAlarm,
    event: handlerEvent
};

if (!String.prototype.format) {
    String.prototype.format = function() {
        var args = arguments;

        return this.replace(/{(\\d+)}/g, function(match, number) {
            return number in args
                ? args[number]
                : match
            ;
        });
    };
}

function isEventProblem(params) {
    return params.event_value == 1
        && params.event_update_status == 0
    ;
}

function isEventUpdate(params) {
    return params.event_value == 1
        && params.event_update_status == 1
    ;
}

function isEventResolve(params) {
    return params.event_value == 0;
}

function getPermalink(mattermost_url, team_name, postid) {
    return ''{0}/{1}/pl/{2}''.format(
        mattermost_url.replace(/\\/+$/, ''''),
        team_name,
        postid
    );
}

function getChannel(send_to) {
    switch (true) {
        case /.+\\/#.+/.test(send_to):
            return getChannelByName(send_to);

        case /@.+/.test(send_to):
            return getDirectChannel(send_to);

        default:
            return getChannelByID(send_to);
    }
}

function getChannelByName(send_to) {
    var team_chan = send_to
        .trim()
        .split(''/#'');

    var resp = JSON.parse(req.get(
        Mattermost.channel_byname.format(team_chan[0], team_chan[1]),
        JSON.stringify(fields)
    )
    );

    if (req.getStatus() != 200) {
        throw ''[{0}] {1}''.format(resp.status_code, resp.message);
    }

    return resp;
}

function getDirectChannel(send_to) {
    Zabbix.log(5, ''[ Mattermost Webhook ] Call {0}({1})''.format(
        arguments.callee.name,
        JSON.stringify(arguments)
    ));

    var teamUser = send_to
            .trim()
            .split(''/@''),
        bot = getBotUser(),
        user = getUserByName(teamUser[1]);

    var resp = JSON.parse(req.post(
        Mattermost.direct_channel,
        JSON.stringify([bot.id, user.id])
    )
    );

    Zabbix.log(5, ''[ Mattermost Webhook ] Result {0}: {1}''.format(
        arguments.callee.name,
        JSON.stringify(resp)
    ));

    if (req.getStatus() != 201) {
        throw ''[{0}] {1}''.format(resp.status_code, resp.message);
    }

    resp.team_name = teamUser[0];

    return resp;
}

function getChannelByID(channelID) {
    Zabbix.log(5, ''[ Mattermost Webhook ] Call {0}({1})''.format(
        arguments.callee.name,
        JSON.stringify(arguments)
    ));

    var resp = JSON.parse(req.get(
        Mattermost.get_channel.format(channelID),
        JSON.stringify(fields)
    )
    );

    Zabbix.log(5, ''[ Mattermost Webhook ] Result {0}: {1}''.format(
        arguments.callee.name,
        JSON.stringify(resp)
    ));

    if (req.getStatus() != 200) {
        throw ''[{0}] {1}''.format(resp.status_code, resp.message);
    }

    return resp;
}

function getBotUser() {
    Zabbix.log(5, ''[ Mattermost Webhook ] Call {0}({1})''.format(
        arguments.callee.name,
        JSON.stringify(arguments)
    ));

    var resp = JSON.parse(req.get(
        Mattermost.bot_user,
        JSON.stringify(fields)
    )
    );

    Zabbix.log(5, ''[ Mattermost Webhook ] Result {0}: {1}''.format(
        arguments.callee.name,
        JSON.stringify(resp)
    ));

    if (req.getStatus() != 200) {
        throw ''[{0}] {1}''.format(resp.status_code, resp.message);
    }

    return resp;
}

function getUserByName(userName) {
    Zabbix.log(5, ''[ Mattermost Webhook ] Call {0}({1})''.format(
        arguments.callee.name,
        JSON.stringify(arguments)
    ));

    var resp = JSON.parse(req.get(
        Mattermost.user_byname.format(userName),
        JSON.stringify(fields)
    )
    );

    Zabbix.log(5, ''[ Mattermost Webhook ] Result {0}: {1}''.format(
        arguments.callee.name,
        JSON.stringify(resp)
    ));

    if (req.getStatus() != 200) {
        throw ''[{0}] {1}''.format(resp.status_code, resp.message);
    }

    return resp;
}

function getTeamByID(teamID) {
    Zabbix.log(5, ''[ Mattermost Webhook ] Call {0}({1})''.format(
        arguments.callee.name,
        JSON.stringify(arguments)
    ));

    var resp = JSON.parse(req.get(
        Mattermost.get_team.format(teamID),
        JSON.stringify(fields)
    )
    );

    Zabbix.log(5, ''[ Mattermost Webhook ] Result {0}: {1}''.format(
        arguments.callee.name,
        JSON.stringify(resp)
    ));

    if (req.getStatus() != 200) {
        throw ''[{0}] {1}''.format(resp.status_code, resp.message);
    }

    return resp;
}

function createProblemURL(zabbix_url, triggerid, eventid, event_source) {
    var problem_url = '''';
    if (event_source === ''0'') {
        problem_url = ''{0}/tr_events.php?triggerid={1}&eventid={2}''
            .format(
                zabbix_url,
                triggerid,
                eventid
            );
    }
    else {
        problem_url = zabbix_url;
    }

    return problem_url;
}

function getTagValue(event_tags, key) {
    var pattern = new RegExp(''('' + key + '':.+)'');
    var tagValue = event_tags
        .split('','')
        .filter(function (v) {
            return v.match(pattern);
        })
        .map(function (v) {
            return v.split('':'')[1];
        })[0]
        || 0;

    return tagValue;
}

function handlerAlarm(req, params) {
    var channel = getChannel(params.send_to);
    var fields = {
        channel_id: channel.id,
        props: {}
    };

    if (isEventProblem(params)) {
        var team_name = channel.team_name
            ? channel.team_name
            : getTeamByID(channel.team_id).name;

        fields.props.attachments = [
            createMessage(
                SEVERITY_COLORS[params.event_nseverity] || 0,
                params.event_date,
                params.event_time,
                createProblemURL(params.zabbix_url, params.trigger_id, params.event_id, params.event_source)
            )
        ];

        var resp = JSON.parse(req.post(
            Mattermost.post_message,
            JSON.stringify(fields)
        )
        );

        if (req.getStatus() != 201) {
            throw ''[{0}] {1}''.format(resp.status_code, resp.message);
        }

        result.tags.__mattermost_post_id = resp.id;
        result.tags.__mattermost_channel_id = channel.id;
        result.tags.__mattermost_channel_name = channel.name;
        result.tags.__mattermost_message_link = getPermalink(
            params.mattermost_url,
            team_name,
            resp.id
        );

    }
    else if (isEventUpdate(params)) {
        fields.root_id = getTagValue(params.event_tags, ''mattermost_post_id'');

        if (params.event_source === ''0'') {}
        fields.props.attachments = [
            createMessage(
                SEVERITY_COLORS[params.event_nseverity] || 0,
                params.event_update_date,
                params.event_update_time,
                createProblemURL(params.zabbix_url, params.trigger_id, params.event_id, params.event_source),
                true
            )
        ];

        resp = JSON.parse(req.post(
            Mattermost.post_message, JSON.stringify(fields)
        )
        );

        if (req.getStatus() != 201) {
            throw ''[{0}] {1}''.format(resp.status_code, resp.message);
        }

    }
    else if (isEventResolve(params)) {
        fields.channel_id = getTagValue(params.event_tags, ''mattermost_channel_id'');
        fields.id = getTagValue(params.event_tags, ''mattermost_post_id'');
        fields.props.attachments = [
            createMessage(
                RESOLVE_COLOR,
                params.event_date,
                params.event_time,
                createProblemURL(params.zabbix_url, params.trigger_id, params.event_id, params.event_source)
            )
        ];

        var post_id = getTagValue(params.event_tags, ''mattermost_post_id'');

        resp = JSON.parse(req.put(
            Mattermost.chat_update.format(post_id),
            JSON.stringify(fields)
        )
        );

        if (req.getStatus() != 200) {
            throw ''[{0}] {1}''.format(resp.status_code, resp.message);
        }
    }
}

function handlerEvent(req, params) {
    var channel = getChannel(params.send_to);
    var fields = {
        channel_id: channel.id,
        props: {}
    };

    if (isEventProblem(params)) {
        var team_name = channel.team_name
            ? channel.team_name
            : getTeamByID(channel.team_id).name;

        fields.props.attachments = [
            createMessage(
                SEVERITY_COLORS[params.event_nseverity] || 0,
                params.event_date,
                params.event_time,
                createProblemURL(params.zabbix_url, params.trigger_id, params.event_id, params.event_source)
            )
        ];

        var resp = JSON.parse(req.post(Mattermost.post_message, JSON.stringify(fields)));

        if (req.getStatus() != 201) {
            throw ''[{0}] {1}''.format(resp.status_code, resp.message);
        }

        result.tags.__mattermost_channel_name = channel.name;
        result.tags.__mattermost_message_link = getPermalink(
            params.mattermost_url,
            team_name,
            resp.id
        );

    }
    else if (isEventUpdate(params)) {
        fields.props.attachments = [
            createMessage(
                SEVERITY_COLORS[params.event_nseverity] || 0,
                params.event_update_date,
                params.event_update_time,
                createProblemURL(params.zabbix_url, params.trigger_id, params.event_id, params.event_source),
                false
            )
        ];

        resp = JSON.parse(req.post(Mattermost.post_message, JSON.stringify(fields)));

        if (req.getStatus() != 201) {
            throw ''[{0}] {1}''.format(resp.status_code, resp.message);
        }

    }
    else if (isEventResolve(params)) {
        fields.props.attachments = [
            createMessage(
                RESOLVE_COLOR,
                params.event_recovery_date,
                params.event_recovery_time,
                createProblemURL(params.zabbix_url, params.trigger_id, params.event_id, params.event_source)
            )
        ];

        resp = JSON.parse(req.post(Mattermost.post_message, JSON.stringify(fields)));

        if (req.getStatus() != 201) {
            throw ''[{0}] {1}''.format(resp.status_code, resp.message);
        }
    }
}

function createMessage(
    event_severity_color,
    event_date,
    event_time,
    problem_url,
    isShort
) {
    var message = {
        fallbac: params.alert_subject,
        title: params.alert_subject,
        color: event_severity_color,
        title_link: problem_url,
        footer: problem_url,

        fields: [
            {
                title: ''Host'',
                value: ''{0} [{1}]''.format(params.host_name, params.host_ip),
                short: true
            },
            {
                title: ''Event time'',
                value: ''{0} {1}''.format(event_date, event_time),
                short: true
            }
        ],
    };

    
    if (params.event_source === ''0'') {
        message.fields.push(
            {
                title: ''Severity'',
                value: params.event_severity,
                short: true
            },
            {
                title: ''Opdata'',
                value: params.event_opdata,
                short: true
            }
        );
    }

    if (!isShort && params.event_source === ''0'') {
        message.fields.push(
            {
                title: ''Event tags'',
                value: ''`{0}`''.format(params.event_tags.replace(/__.+?:(.+?,|.+)/g, '''') || ''None''),
                short: true
            },
            {
                title: ''Trigger description'',
                value: params.trigger_description,
                short: true
            }
        );
    }

    if (params.event_source !== ''0'' || params.event_update_status === ''1'') {
        message.fields.push(
            {
                title: ''Details'',
                value: params.alert_message,
                short: false
            }
        );
    }

    return message;
}

function validateParams(params) {
    if (typeof params.bot_token !== ''string'' || params.bot_token.trim() === '''') {
        throw ''Field "bot_token" cannot be empty'';
    }

    if (isNaN(params.event_id)) {
        throw ''Field "event_id" is not a number'';
    }

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: "'' + params.event_source + ''".\\nMust be 0-3.'';
    }

    if (params.event_source !== ''0'') {
        params.event_nseverity = ''0'';
        params.event_severity = ''Not classified'';
        params.event_update_status = ''0'';
        params.send_mode = ''event'';
    }

    if (params.event_source === ''1'' || params.event_source === ''2'') {
        params.event_value = ''1'';
    }

    if (params.event_source === ''1'') {
        params.host_name = params.discovery_host_dns;
        params.host_ip = params.discovery_host_ip;
    }

    if ([0, 1, 2, 3, 4, 5].indexOf(parseInt(params.event_nseverity)) === -1) {
        throw ''Incorrect "event_nseverity" parameter given: '' + params.event_nseverity + ''\\nMust be 0-5.'';
    }

    if (typeof params.event_severity !== ''string'' || params.event_severity.trim() === '''') {
        throw ''Field "event_severity" cannot be empty'';
    }

    if (params.event_update_status !== ''0'' && params.event_update_status !== ''1'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }

    if (params.event_value !== ''0'' && params.event_value !== ''1'') {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    if (typeof params.host_ip !== ''string'' || params.host_ip.trim() === '''') {
        throw ''Field "host_ip" cannot be empty'';
    }

    if (typeof params.host_name !== ''string'' || params.host_name.trim() === '''') {
        throw ''Field "host_name" cannot be empty'';
    }

    if (typeof params.mattermost_url !== ''string'' || params.mattermost_url.trim() === '''') {
        throw ''Field "mattermost_url" cannot be empty'';
    }

    if (!/^(http|https):\\/\\/.+/.test(params.mattermost_url)) {
        throw ''Field "mattermost_url" must contain a schema'';
    }

    if ([''alarm'', ''event''].indexOf(params.send_mode) === -1) {
        throw ''Incorrect "send_mode" parameter given: '' + params.send_mode + ''\\nMust be "alarm" or "event".'';
    }

    if (typeof params.send_to !== ''string'' || params.send_to.trim() === '''') {
        throw ''Field "send_to" cannot be empty'';
    }

    if (isNaN(params.trigger_id) && params.event_source === ''0'') {
        throw ''field "trigger_id" is not a number'';
    }

    if (typeof params.zabbix_url !== ''string'' || params.zabbix_url.trim() === '''') {
        throw ''Field "zabbix_url" cannot be empty'';
    }

    if (!/^(http|https):\\/\\/.+/.test(params.zabbix_url)) {
        throw ''Field "zabbix_url" must contain a schema'';
    }

}

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

    validateParams(params);

    var req = new HttpRequest(),
        fields = {},
        result = {tags: {}};

    if (typeof params.HTTPProxy === ''string'' && params.HTTPProxy.trim() !== '''') {
        req.setProxy(params.HTTPProxy);
    }

    req.addHeader(''Content-Type: application/json; charset=utf-8'');
    req.addHeader(''Authorization: Bearer '' + params.bot_token);

    params.mattermost_url = params.mattermost_url.replace(/\\/+$/, '''');
    params.zabbix_url = params.zabbix_url.replace(/\\/+$/, '''');

    var APIEndpoint = params.mattermost_url + ''/api/v4/'';

    var Mattermost = {
        post_message: APIEndpoint + ''posts'',
        get_channel: APIEndpoint + ''channels/{0}'',
        get_team: APIEndpoint + ''teams/{0}'',
        chat_update: APIEndpoint + ''posts/{0}'',
        direct_channel: APIEndpoint + ''channels/direct'',
        channel_byname: APIEndpoint + ''teams/name/{0}/channels/name/{1}'',
        user_byname: APIEndpoint + ''users/username/{0}'',
        bot_user: APIEndpoint + ''users/me''

    };

    params.send_mode = params.send_mode.toLowerCase();
    params.send_mode = params.send_mode in SEND_MODE_HANDLERS
        ? params.send_mode
        : ''alarm'';

    SEND_MODE_HANDLERS[params.send_mode](req, params);

    if (params.event_source === ''0'') {
        return JSON.stringify(result);
    }
    else {
        return ''OK'';
    }
}
catch (error) {
    Zabbix.log(4, ''[ Mattermost Webhook ] Mattermost notification failed: '' + error);
    throw ''Mattermost notification failed: '' + error;
}','30s','1','1','{EVENT.TAGS.__mattermost_message_link}','Open in Mattermost: {EVENT.TAGS.__mattermost_channel_name}','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('6','4','Opsgenie','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var method,
    Media = {
    params: {},
    name: '''',
    labels: [],
    HTTPProxy: '''',

    setParams: function (params) {
        if (typeof params !== ''object'') {
            return;
        }

        Media.params = params;
        Media.params.api += Media.params.api.endsWith(''/'') ? '''' : ''/'';
        Media.params.web += Media.params.web.endsWith(''/'') ? '''' : ''/'';
    },

    setProxy: function (HTTPProxy) {
        if (typeof HTTPProxy !== ''undefined'' && HTTPProxy.trim() !== '''') {
            Media.HTTPProxy = HTTPProxy;
        }
    },

    setTags: function(event_tags_json) {
        if (typeof event_tags_json !== ''undefined'' && event_tags_json !== ''''
                && event_tags_json !== ''{EVENT.TAGSJSON}'') {

            try {
                var tags = JSON.parse(event_tags_json),
                    label;

                tags.forEach(function (tag) {
                    if (typeof tag.tag === ''string'') {
                        label = (tag.tag + (typeof tag.value !== ''undefined''
                                && tag.value !== '''' ? ('':'' + tag.value) : '''')).replace(/\\s/g, ''_'');
                        Media.labels.push(label);
                    }
                });
            }
            catch (error) {
                Zabbix.log(4, ''[ '' + Media.name + '' Webhook ] Failed to parse "event_tags_json" param'');
            }
        }
    },

    request: function (method, query, data, allow_404) {
        if (typeof(allow_404) === ''undefined'') {
            allow_404 = false;
        }

        [''api'', ''token''].forEach(function (field) {
            if (typeof Media.params !== ''object'' || typeof Media.params[field] === ''undefined''
                    || Media.params[field] === '''') {
                throw ''Required '' + Media.name + '' param is not set: "'' + field + ''".'';
            }
        });

        var response,
            url = Media.params.api + query,
            request = new HttpRequest();

        request.addHeader(''Content-Type: application/json'');
        request.addHeader(''Authorization: '' + Media.params.token);
        request.setProxy(Media.HTTPProxy);

        if (typeof data !== ''undefined'') {
            data = JSON.stringify(data);
        }

        Zabbix.log(4, ''[ '' + Media.name + '' Webhook ] Sending request: '' +
            url + ((typeof data === ''string'') ? (''\\n'' + data) : ''''));

        switch (method) {
            case ''get'':
                response = request.get(url, data);
                break;

            case ''post'':
                response = request.post(url, data);
                break;

            case ''put'':
                response = request.put(url, data);
                break;

            default:
                throw ''Unsupported HTTP request method: '' + method;
        }

        Zabbix.log(4, ''[ '' + Media.name + '' Webhook ] Received response with status code '' +
            request.getStatus() + ''\\n'' + response);

        if (response !== null) {
            try {
                response = JSON.parse(response);
            }
            catch (error) {
                Zabbix.log(4, ''[ '' + Media.name + '' Webhook ] Failed to parse response.'');
                response = null;
            }
        }

        if ((request.getStatus() < 200 || request.getStatus() >= 300)
                && (!allow_404 || request.getStatus() !== 404)) {
            var message = ''Request failed with status code '' + request.getStatus();

            if (response !== null) {
                if (typeof response.errors === ''object'' && Object.keys(response.errors).length > 0) {
                    message += '': '' + JSON.stringify(response.errors);
                }
                else if (typeof response.errorMessages === ''object'' && Object.keys(response.errorMessages).length > 0) {
                    message += '': '' + JSON.stringify(response.errorMessages);
                }
                else if (typeof response.message === ''string'') {
                    message += '': '' + response.message;
                }
            }

            throw message + '' Check debug log for more information.'';
        }

        return {
            status: request.getStatus(),
            response: response
        };
    },

    getAlertId: function (requestId) {
        status_counter = params.status_counter || 25; 
        do {
            resp = Media.request(''get'', ''requests/'' + requestId, undefined, true);
        status_counter -= 1;            
        }
        while ( status_counter > 0 && 
            ( 
            typeof resp.response !== ''object'' || 
            typeof resp.response.data === ''undefined'' ||
            resp.response.data.success === false &&
                !resp.response.data.status.includes("There is no open alert") &&
                !resp.response.data.status.includes("Alert is already")
            ) 
        );

        if (typeof resp.response !== ''object'' || typeof resp.response.data === ''undefined'') {
            throw ''Cannot get '' + Media.name + '' issue ID. Check debug log for more information.'';
        }
        else if (resp.response.data.success === false ) {
            throw Media.name + '': Operation status ('' + resp.response.data.status + '')'';
        }

        return resp;
    }
};

try {
    var result = {tags: {}},
        params = JSON.parse(value),
        media = {},
        fields = {},
        resp = {},
        responders = [],
        tags = [],
        required_params = [
            ''alert_subject'',
            ''alert_message'',
            ''event_id'',
            ''event_source'',
            ''event_value'',
            ''event_update_status'',
            ''opsgenie_api'',
            ''opsgenie_web'',
            ''opsgenie_token''
        ],
        severities = [
            ''not_classified'',
            ''information'',
            ''warning'',
            ''average'',
            ''high'',
            ''disaster'',
            ''resolved'',
            ''default''
        ],
        priority;

    Object.keys(params)
        .forEach(function (key) {
            if (required_params.indexOf(key) !== -1 && params[key].trim() === '''') {
                throw ''Parameter "'' + key + ''" cannot be empty.'';
            }
            if (key.startsWith(''opsgenie_'')) {
                media[key.substring(9)] = params[key];
            }
        });

    // Possible values of event_source:
    // 0 - Trigger, 1 - Discovery, 2 - Autoregistration, 3 - Internal.
    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: "'' + params.event_source + ''".\\nMust be 0-3.'';
    }

    // Check event_value for trigger-based and internal events.
    // Possible values: 1 for problem, 0 for recovering
    if (params.event_value !== ''0'' && params.event_value !== ''1''
        && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    // Check event_update_status only for trigger-based events.
    // Possible values: 0 - Webhook was called because of problem/recovery event, 1 - Update operation.
    if (params.event_source === ''0'' && params.event_update_status !== ''0'' && params.event_update_status !== ''1'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }

    // Check event_id for a numeric value.
    if (isNaN(parseInt(params.event_id)) || params.event_id < 1) {
        throw ''Incorrect "event_id" parameter given: '' + params.event_id + ''\\nMust be a positive number.'';
    }

    if ((params.event_source === ''1'' || params.event_source === ''2'')  && params.event_value === ''0'') {
        throw ''Recovery operations are supported only for Trigger and Internal actions.'';
    }

    if ([0, 1, 2, 3, 4, 5].indexOf(parseInt(params.event_nseverity)) === -1) {
        params.event_nseverity = ''7'';
    }

    if (params.event_value === ''0'') {
        params.event_nseverity = ''6'';
    }

    priority = params[''severity_'' + severities[params.event_nseverity]];
    params.zbxurl = params.zbxurl + (params.zbxurl.endsWith(''/'') ? '''' : ''/'');

    Media.name = ''Opsgenie'';
    Media.setParams(media);
    Media.params.token = ''GenieKey '' + Media.params.token;
    Media.setProxy(params.HTTPProxy);
    Media.setTags(params.event_tags_json); // Set Media.labels

    // Create an issue.
    // Numeric value of the event that triggered an action (1 for problem, 0 for recovering).
    // Numeric value of the problem update status. Possible values:
    // 0 - Webhook was called because of problem/recovery event, 1 - Update operation.
    if ((params.event_source == 0 && params.event_value == 1 && params.event_update_status == 0)
            || (params.event_source == 3 && params.event_value == 1)
            || params.event_source == 1 || params.event_source == 2) {
        fields.message = params.alert_subject;
        fields.alias = params.event_id;
        fields.description = params.alert_message;
        fields.priority = priority;
        fields.source = ''Zabbix'';

        if (params.event_source === ''0'') {
            fields.details = {
                ''Zabbix server'': params.zbxurl,
                Problem: params.zbxurl + ''tr_events.php?triggerid='' + params.trigger_id + ''&eventid='' + params.event_id
            };
        }
        else {
            fields.details = {''Zabbix server'': params.zbxurl};
        }

        if (typeof params.opsgenie_teams === ''string'') {
            responders = params.opsgenie_teams.split('','');
            fields.responders = responders.map(function(team) {
                return {type: ''team'', name: team.trim()};
            });
        }

        fields.tags = Media.labels;
        if (typeof params.opsgenie_tags === ''string'') {
            tags = params.opsgenie_tags.split('','');
            tags.forEach(function(item) {
                fields.tags.push(item.trim());
            });
        }

        resp = Media.request(''post'', '''', fields);
        if (typeof resp.response !== ''object'' || typeof resp.response.result === ''undefined'') {
            throw ''Cannot create '' + Media.name + '' issue. Check debug log for more information.'';
        }

        if (resp.status === 202) {
            resp = Media.getAlertId(resp.response.requestId);
            if (params.event_source == 0 && params.event_value == 1 && params.event_update_status == 0) {
                result.tags.__zbx_ops_issuekey = resp.response.data.alertId;
                result.tags.__zbx_ops_issuelink = Media.params.web + ''alert/detail/'' + resp.response.data.alertId;
            }
        }
        else {
            throw Media.name + '' response code is unexpected. Check debug log for more information.'';
        }
    }
    // Update or close the created issue.
    else {
        fields.user = (params.event_value != 0) ? params.zbxuser : '''';
        fields.note = params.alert_message;
        if ( [0, 3].indexOf(parseInt(params.event_source)) > -1  && params.event_value == 0 ) {
            // skip sending of close request from update operation(mandatory when both update & recovery operations are defined in action)  
            method = params.event_update_status == 0 ? "close" : "skip";
        }
        else if ( params.event_source == 0 && params.event_value == 1 && params.event_update_status == 1 && params.event_update_action.includes(''acknowledged'')) {
            method = params.event_update_action.includes(''unacknowledged'') ? "unacknowledge" : "acknowledge";
        }
        else {
            method = "notes";
        }

        if (method !== "skip") {
        resp = Media.request(''post'', params.event_id + ''/'' + method +''?identifierType=alias'', fields);

        if (typeof resp.response !== ''object'' || typeof resp.response.result === ''undefined'') {
            throw ''Cannot update '' + Media.name + '' issue. Check debug log for more information.'';
        }

        if (resp.status === 202) {
            resp = Media.getAlertId(resp.response.requestId);
        }
        else {
            throw Media.name + '' response code is unexpected. Check debug log for more information.'';
        }
    }
    }
    return JSON.stringify(result);
}
catch (error) {
    Zabbix.log(3, ''[ '' + Media.name + '' Webhook ] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','1','1','{EVENT.TAGS.__zbx_ops_issuelink}','Opsgenie: {EVENT.TAGS.__zbx_ops_issuekey}','Please refer to https://docs.opsgenie.com/docs/alert-api and https://www.zabbix.com/documentation/6.0/manual/config/notifications/media/webhook#example_scripts.
  
Set global macro {$ZABBIX.URL} with your Zabbix server URL.
Add dedicated user with media type "Opsgenie".
Change the values of the variables opsgenie_api (https://api.opsgenie.com/v2/alerts or https://api.eu.opsgenie.com/v2/alerts),
opsgenie_web (for example, https://myzabbix.app.opsgenie.com), opsgenie_token.');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('7','4','PagerDuty','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'try {

    var params = JSON.parse(value),
        req = new HttpRequest(),
        fields = {},
        resp = '''';

    // Correspondence between the PagerDuty and Zabbix severity level
    var severityMapping = [
        ''info'',    // Not classified
        ''info'',    // Information
        ''warning'', // Warning
        ''warning'', // Average
        ''error'',   // High
        ''critical'' // Disaster
    ];

    if (!severityMapping[params.severity]) {
        params.severity = ''0'';
    }

    if (typeof params.HTTPProxy === ''string'' && params.HTTPProxy.trim() !== '''') {
        req.setProxy(params.HTTPProxy);
    }

    if (isNaN(parseInt(params.eventid)) || params.eventid < 1) {
        throw ''incorrect value for variable "eventid". The value must be a positive number.'';
    }
    if (params.eventname.length < 1) {
        throw ''incorrect value for variable "eventname". The value must be a non-empty string.'';
    }
    if (isNaN(parseInt(params.severity)) || (params.severity < 0 && params.severity > 5)) {
        throw ''incorrect value for variable "severity". The value must be a number 0..5.'';
    }

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: "'' + params.event_source + ''".\\nMust be 0-3.'';
    }
    // Check {EVENT.VALUE} for trigger-based and internal events.
    if (params.eventvalue !== ''0'' && params.eventvalue !== ''1''
        && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "eventvalue" parameter given: "'' + params.eventvalue + ''".\\nMust be 0 or 1.'';
    }

    if (params.event_source === ''0'') {
        if (params.hostname.length < 1) {
            throw ''incorrect value for variable "hostname". The value must be a non-empty string.'';
        }
        if (isNaN(parseInt(params.triggerid)) || params.triggerid < 1) {
            throw ''incorrect value for variable "triggerid". The value must be a positive number.'';
        }
        if (params.eventack != ''Yes'' && params.eventack != ''No'') {
            throw ''incorrect value for variable "eventack". The value must be Yes or No.'';
        }
        if (isNaN(parseInt(params.eventupdate)) || (params.eventupdate < 0 || params.eventupdate > 1)) {
            throw ''incorrect value for variable "eventupdate". The value must be 0 or 1.'';
        }
    }



    req.addHeader(''Content-Type: application/json'');

    fields.routing_key = params.token;
    fields.dedup_key = params.eventid;

    if (((params.eventvalue == 1) && (params.eventupdate == 0)) || params.event_source !== ''0'') {
        fields.event_action = ''trigger'';
        fields.payload = {
            summary: params.eventname,
            source: (params.event_source === ''1'') ? ''Discovery'' : params.hostname + '' : '' + params.hostip,
            severity: severityMapping[params.severity],
        };
        
        if (params.event_source === ''0'') {
            fields.payload.custom_details = {
                ''Event date'': params.eventdate,
                ''Event time'': params.eventtime,
                ''Trigger description'': params.triggerdesc,
                ''Trigger opdata'': params.triggeropdata,
                ''Event tags'': params.eventtags,
                ''Event host'': params.hostname,
                ''Event host ip'': params.hostip
            };
            fields.links = [{
                href: params.url + ''/tr_events.php?triggerid='' + params.triggerid + ''&eventid='' + params.eventid,
                text: ''Event link''
            }];
        }
        else {
            fields.payload.custom_details = {
                ''Alert message'': params.alert_message
            };
        }

        fields.client = ''Zabbix'';
        fields.client_url = params.url;
    }
    else if ((params.eventvalue == 1) && (params.eventupdate == 1) && (params.eventack == ''Yes''))
        fields.event_action = ''acknowledge'';
    else if (params.eventvalue == 0)
        fields.event_action = ''resolve'';
    else
        throw ''incorrect values. Update message without ack will not be sent.'';

    Zabbix.log(4, ''[PagerDuty Webhook] Sending request:'' + JSON.stringify(fields));
    resp = req.post(''https://events.pagerduty.com/v2/enqueue'',
        JSON.stringify(fields)
    );
    Zabbix.log(4, ''[PagerDuty Webhook] Receiving response:'' + resp);

    try {
        resp = JSON.parse(resp);
    }
    catch (error) {
        throw ''incorrect response. PagerDuty returned a non-JSON object.'';
    }

    if (req.getStatus() != 202) {
        if (typeof resp === ''object'' && typeof resp.errors === ''object'' && typeof resp.errors[0] === ''string'') {
            throw resp.errors[0];
        }
        else {
            throw ''Unknown error.'';
        }
    }

    if (resp.status != ''success'') {
        throw ''Unknown error.'';
    }

    return ''OK'';
}
catch (error) {
    Zabbix.log(3, ''[PagerDuty Webhook] Notification failed : '' + error);
    throw ''PagerDuty notification failed : '' + error;
}','30s','0','0','','','Please refer to https://v2.developer.pagerduty.com/docs/send-an-event-events-api-v2 and https://www.zabbix.com/documentation/6.0/manual/config/notifications/media/webhook#example_scripts.
  
Set global macro {$ZABBIX.URL} with your Zabbix server URL.
Add a dedicated user with the media type "PagerDuty" and place the integration key in the "token" parameter to integrate into the service.');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('8','4','Pushover','','','','','','','','0','25','0','0','0','0','','0','3','10s','1',E'try {
    var params = JSON.parse(value),
        request = new HttpRequest(),
        data,
        response,
        severities = [
            {name: ''not_classified'', color: ''#97AAB3''},
            {name: ''information'', color: ''#7499FF''},
            {name: ''warning'', color: ''#FFC859''},
            {name: ''average'', color: ''#FFA059''},
            {name: ''high'', color: ''#E97659''},
            {name: ''disaster'', color: ''#E45959''},
            {name: ''resolved'', color: ''#009900''},
            {name: ''default'', color: ''#000000''}
        ],
        priority;

    if (typeof params.HTTPProxy === ''string'' && params.HTTPProxy.trim() !== '''') {
        request.setProxy(params.HTTPProxy);
    }

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: "'' + params.event_source + ''".\\nMust be 0-3.'';
    }

    if (params.event_value !== ''0'' && params.event_value !== ''1''
        && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    if ([0, 1, 2, 3, 4, 5].indexOf(parseInt(params.event_nseverity)) === -1) {
        params.event_nseverity = ''7'';
    }

    if (params.event_value === ''0'') {
        params.event_nseverity = ''6'';
    }

    priority = params[''priority_'' + severities[params.event_nseverity].name] || params.priority_default;

    if (isNaN(priority) || priority < -2 || priority > 2) {
        throw ''"priority" should be -2..2'';
    }

    if (params.event_source === ''0'' && isNaN(params.triggerid)) {
        throw ''field "triggerid" is not a number'';
    }

    if (isNaN(params.eventid)) {
        throw ''field "eventid" is not a number'';
    }

    if (typeof params.message !== ''string'' || params.message.trim() === '''') {
        throw ''field "message" cannot be empty'';
    }

    data = {
        token: params.token,
        user: params.user,
        title: params.title,
        message: params.message,
        url: (params.event_source === ''0'') 
            ? params.url + ''/tr_events.php?triggerid='' + params.triggerid + ''&eventid='' + params.eventid
            : params.url,
        url_title: params.url_title,
        priority: priority
    };

    if (priority == 2) {
        if (isNaN(params.retry) || params.retry < 30) {
            throw ''field "retry" should be a number with value of at least 30 if "priority" is set to 2'';
        }

        if (isNaN(params.expire) || params.expire > 10800) {
            throw ''field "expire" should be a number with value of at most 10800 if "priority" is set to 2'';
        }

        data.retry = params.retry;
        data.expire = params.expire;
    }

    data = JSON.stringify(data);
    Zabbix.log(4, ''[ Pushover Webhook ] Sending request: '' + params.endpoint + ''\\n'' + data);

    request.addHeader(''Content-Type: application/json'');
    response = request.post(params.endpoint, data);

    Zabbix.log(4, ''[ Pushover Webhook ] Received response with status code '' + request.getStatus() + ''\\n'' + response);

    if (response !== null) {
        try {
            response = JSON.parse(response);
        }
        catch (error) {
            Zabbix.log(4, ''[ Pushover Webhook ] Failed to parse response received from Pushover'');
            response = null;
        }
    }

    if (request.getStatus() != 200 || response === null || typeof response !== ''object'' || response.status !== 1) {
        if (response !== null && typeof response === ''object'' && typeof response.errors === ''object''
                && typeof response.errors[0] === ''string'') {
            throw response.errors[0];
        }
        else {
            throw ''Unknown error. Check debug log for more information.'';
        }
    }

    return ''OK'';
}
catch (error) {
    Zabbix.log(4, ''[ Pushover Webhook ] Pushover notification failed: '' + error);
    throw ''Pushover notification failed: '' + error;
}','30s','0','0','','','Please refer to setup guide here: https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/pushover

Set token parameter with to your Pushover application key.
When assigning Pushover media to the Zabbix user - add user key into send to field.');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('9','4','Slack','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var SEVERITY_COLORS = [
    ''#97AAB3'', ''#7499FF'', ''#FFC859'',
    ''#FFA059'', ''#E97659'', ''#E45959''
];

var RESOLVE_COLOR = ''#009900'';

var SLACK_MODE_HANDLERS = {
    alarm: handlerAlarm,
    event: handlerEvent
};


if (!String.prototype.format) {
    String.prototype.format = function() {
        var args = arguments;

        return this.replace(/{(\\d+)}/g, function(match, number) {
            return number in args
                ? args[number]
                : match
            ;
        });
    };
}

function isEventProblem(params) {
    return params.event_value == 1
        && params.event_update_status == 0
    ;
}

function isEventUpdate(params) {
    return params.event_value == 1
        && params.event_update_status == 1
    ;
}

function isEventResolve(params) {
    return params.event_value == 0;
}

function getPermalink(channelId, messageTimestamp) {
    var req = new HttpRequest();

    if (typeof params.HTTPProxy === ''string'' && params.HTTPProxy.trim() !== '''') {
        req.setProxy(params.HTTPProxy);
    }

    req.addHeader(''Content-Type: application/x-www-form-urlencoded; charset=utf-8'');
    req.addHeader(''Authorization: Bearer '' + params.bot_token);

    var query = ''{0}?channel={1}&message_ts={2}''.format(
            Slack.getPermalink,
            encodeURIComponent(channelId),
            encodeURIComponent(messageTimestamp)),
        resp = JSON.parse(req.get(query));

    if (req.getStatus() != 200 || !resp.ok || resp.ok === ''false'') {
        throw ''message was created, but getting message link was failed with reason "'' + resp.error + ''"'';
    }

    return resp.permalink;
}

function createProblemURL(zabbix_url, triggerid, eventid, event_source) {
    var problem_url = '''';
    if (event_source === ''0'') {
        problem_url = ''{0}/tr_events.php?triggerid={1}&eventid={2}''
            .format(
                zabbix_url,
                triggerid,
                eventid
            );
    }
    else {
        problem_url = zabbix_url;
    }

    return problem_url;
}

function handlerAlarm(params) {
    var fields = {
        channel: params.channel,
        as_user: params.slack_as_user,
    };

    if (isEventProblem(params)) {
        fields.attachments = [
            createMessage(
                SEVERITY_COLORS[params.event_nseverity] || 0,
                params.event_date,
                params.event_time,
                createProblemURL(params.zabbix_url, params.trigger_id, params.event_id, params.event_source)
            )
        ];

        var resp = JSON.parse(req.post(Slack.postMessage, JSON.stringify(fields)));

        if (req.getStatus() != 200 || !resp.ok || resp.ok === ''false'') {
            throw resp.error;
        }

        result.tags = {
            [''__message_ts_'' + params.channel]: resp.ts,
            [''__channel_id_'' + params.channel]: resp.channel,
            [''__message_link_'' + params.channel]: getPermalink(resp.channel, resp.ts),
        };

    }
    else if (isEventUpdate(params)) {
        try {
            var channel_event_tags = JSON.parse(params.event_tags);
        } catch (error) {
            throw ''Cannot process event tags: '' + error;
        }

        if (Array.isArray(channel_event_tags)) {
            for (i in channel_event_tags) {
                if (channel_event_tags[i].tag.includes(''__message_ts_'' + params.channel)) {
                    fields.thread_ts = channel_event_tags[i].value;
                    break;
                }
            }
        }

        fields.attachments = [
            createMessage(
                SEVERITY_COLORS[params.event_nseverity] || 0,
                params.event_update_date,
                params.event_update_time,
                createProblemURL(params.zabbix_url, params.trigger_id, params.event_id, params.event_source),
                true
            )
        ];

        resp = JSON.parse(req.post(Slack.postMessage, JSON.stringify(fields)));

        if (req.getStatus() != 200 || !resp.ok || resp.ok === ''false'') {
            throw resp.error;
        }

    }
    else if (isEventResolve(params)) {

        fields.text = '''';

        try {
            var channel_event_tags = JSON.parse(params.event_tags);
        } catch (error) {
            throw ''Cannot process event tags: '' + error;
        }

        if (Array.isArray(channel_event_tags)) {
            for (i in channel_event_tags) {
                if (channel_event_tags[i].tag.includes(''__channel_id_'' + params.channel)) {
                    fields.channel = channel_event_tags[i].value;
                    continue;
                }
                if (channel_event_tags[i].tag.includes(''__message_ts_'' + params.channel)) {
                    fields.ts = channel_event_tags[i].value;
                }
            }
        }

        fields.attachments = [
            createMessage(
                RESOLVE_COLOR,
                params.event_date,
                params.event_time,
                createProblemURL(params.zabbix_url, params.trigger_id, params.event_id, params.event_source)
            )
        ];

        resp = JSON.parse(req.post(Slack.chatUpdate, JSON.stringify(fields)));
        if (req.getStatus() != 200 || !resp.ok || resp.ok === ''false'') {
            throw resp.error;
        }
    }
}

function handlerEvent(params) {
    var fields = {
        channel: params.channel,
        as_user: params.slack_as_user
    };

    if (isEventProblem(params)) {
        fields.attachments = [
            createMessage(
                SEVERITY_COLORS[params.event_nseverity] || 0,
                params.event_date,
                params.event_time,
                createProblemURL(params.zabbix_url, params.trigger_id, params.event_id, params.event_source)
            )
        ];

        var resp = JSON.parse(req.post(Slack.postMessage, JSON.stringify(fields)));

        if (req.getStatus() != 200 || !resp.ok || resp.ok === ''false'') {
            throw resp.error;
        }

        result.tags = {
            [''__message_link_'' + params.channel]: getPermalink(resp.channel, resp.ts)
        }

    }
    else if (isEventUpdate(params)) {
        fields.attachments = [
            createMessage(
                SEVERITY_COLORS[params.event_nseverity] || 0,
                params.event_update_date,
                params.event_update_time,
                createProblemURL(params.zabbix_url, params.trigger_id, params.event_id, params.event_source),
                false
            )
        ];

        resp = JSON.parse(req.post(Slack.postMessage, JSON.stringify(fields)));

        if (req.getStatus() != 200 || !resp.ok || resp.ok === ''false'') {
            throw resp.error;
        }

    }
    else if (isEventResolve(params)) {
        fields.attachments = [
            createMessage(
                RESOLVE_COLOR,
                params.event_recovery_date,
                params.event_recovery_time,
                createProblemURL(params.zabbix_url, params.trigger_id, params.event_id, params.event_source)
            )
        ];

        resp = JSON.parse(req.post(Slack.postMessage, JSON.stringify(fields)));

        if (req.getStatus() != 200 || !resp.ok || resp.ok === ''false'') {
            throw resp.error;
        }
    }
}

function createMessage(
    event_severity_color,
    event_date,
    event_time,
    problem_url,
    isShort,
    messageText
) {
    var message = {
        fallback: params.alert_subject,
        title: params.alert_subject,
        color: event_severity_color,
        title_link: problem_url,
        pretext: messageText || '''',

        fields: [
            {
                title: ''Host'',
                value: ''{0} [{1}]''.format(params.host_name, params.host_conn),
                short: true
            },
            {
                title: ''Event time'',
                value: ''{0} {1}''.format(event_date, event_time),
                short: true
            }
        ],
    };

    if (params.event_source === ''0'') {
        message.fields.push(
            {
                title: ''Severity'',
                value: params.event_severity,
                short: true
            },
            {
                title: ''Opdata'',
                value: params.event_opdata,
                short: true
            }
        );
    }

    if (!isShort  && params.event_source === ''0'') {
        message[''actions''] = [
            {
                type: ''button'',
                text: ''Open in Zabbix'',
                url: problem_url
            }
        ];

        message.fields.push(
            {
                title: ''Event tags'',
                value: JSON.parse(params.event_tags).filter(function (e) { return !e.tag.includes(''__'') }).map(function (e) { return e.tag + '': '' + e.value }).join(''\\n'') || ''None'',
                short: true
            },
            {
                title: ''Trigger description'',
                value: params.trigger_description,
                short: true
            }
        );
    }

    if (params.event_source !== ''0'' || params.event_update_status === ''1'') {
        message.fields.push(
            {
                title: ''Details'',
                value: params.alert_message,
                short: false
            }
        );
    }

    return message;
}

function validateParams(params) {
    if (typeof params.bot_token !== ''string'' || params.bot_token.trim() === '''') {
        throw ''Field "bot_token" cannot be empty'';
    }

    if (typeof params.channel !== ''string'' || params.channel.trim() === '''') {
        throw ''Field "channel" cannot be empty'';
    }

    if (isNaN(params.event_id)) {
        throw ''Field "event_id" is not a number'';
    }

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: "'' + params.event_source + ''".\\nMust be 0-3.'';
    }

    if (params.event_source !== ''0'') {
        params.event_nseverity = ''0'';
        params.event_severity = ''Not classified'';
        params.event_update_status = ''0'';
        params.slack_mode = ''event'';
    }

    if (params.event_source === ''1'' || params.event_source === ''2'') {
        params.event_value = ''1'';
    }

    if (params.event_source === ''1'') {
        params.host_name = params.discovery_host_dns;
        params.host_ip = params.discovery_host_ip;
    }

    if (!~[0, 1, 2, 3, 4, 5].indexOf(parseInt(params.event_nseverity))) {
        throw ''Incorrect "event_nseverity" parameter given: '' + params.event_nseverity + ''\\nMust be 0-5.'';
    }

    if (typeof params.event_severity !== ''string'' || params.event_severity.trim() === '''') {
        throw ''Field "event_severity" cannot be empty'';
    }

    if (params.event_update_status !== ''0'' && params.event_update_status !== ''1'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }

    if (params.event_value !== ''0'' && params.event_value !== ''1'') {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    if (typeof params.host_conn !== ''string'' || params.host_conn.trim() === '''') {
        throw ''Field "host_conn" cannot be empty'';
    }

    if (typeof params.host_name !== ''string'' || params.host_name.trim() === '''') {
        throw ''Field "host_name" cannot be empty'';
    }

    if (!~[''true'', ''false''].indexOf(params.slack_as_user.toLowerCase())) {
        throw ''Incorrect "slack_as_user" parameter given: '' + params.slack_as_user + ''\\nMust be "true" or "false".'';
    }

    if (!~[''alarm'', ''event''].indexOf(params.slack_mode)) {
        throw ''Incorrect "slack_mode" parameter given: '' + params.slack_mode + ''\\nMust be "alarm" or "event".'';
    }

    if (isNaN(params.trigger_id) && params.event_source === ''0'') {
        throw ''field "trigger_id" is not a number'';
    }

    if (typeof params.zabbix_url !== ''string'' || params.zabbix_url.trim() === '''') {
        throw ''Field "zabbix_url" cannot be empty'';
    }

    if (!/^(http|https):\\/\\/.+/.test(params.zabbix_url)) {
        throw ''Field "zabbix_url" must contain a schema'';
    }
}

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

    validateParams(params);

    var req = new HttpRequest(),
        result = {tags: {}};

    if (typeof params.HTTPProxy === ''string'' && params.HTTPProxy.trim() !== '''') {
        req.setProxy(params.HTTPProxy);
    }

    req.addHeader(''Content-Type: application/json; charset=utf-8'');
    req.addHeader(''Authorization: Bearer '' + params.bot_token);

    var slack_endpoint = ''https://slack.com/api/'';

    var Slack = {
        postMessage: slack_endpoint + ''chat.postMessage'',
        getPermalink: slack_endpoint + ''chat.getPermalink'',
        chatUpdate: slack_endpoint + ''chat.update''
    };

    params.slack_mode = params.slack_mode.toLowerCase();
    params.slack_mode = params.slack_mode in SLACK_MODE_HANDLERS
        ? params.slack_mode
        : ''alarm'';

    SLACK_MODE_HANDLERS[params.slack_mode](params);

    if (params.event_source === ''0'') {
        return JSON.stringify(result);
    }
    else {
        return ''OK'';
    }
}
catch (error) {
    Zabbix.log(4, ''[ Slack Webhook ] Slack notification failed : '' + error);
    throw ''Slack notification failed : '' + error;
}','30s','1','0','','','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('10','4','Discord','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var SEVERITY_COLORS = [
    ''#97AAB3'', // Not classified.
    ''#7499FF'', // Information.
    ''#FFC859'', // Warning.
    ''#FFA059'', // Average.
    ''#E97659'', // High.
    ''#E45959'', // Disaster.
    ''#009900''  // Resolved.
];

function stringTruncate(str, len) {
    return str.length > len ? str.substring(0, len - 3) + ''...'' : str;
}

try {
    Zabbix.log(4, ''[ Discord Webhook ] Executed with params: '' + value);

    var params = JSON.parse(value);

    if (!params.discord_endpoint) {
        throw ''Cannot get discord_endpoint'';
    }
    else {
        params.discord_endpoint = params.discord_endpoint.replace(''/api/'', ''/api/v7/'') + ''?wait=True'';
    }

    params.zabbix_url = (params.zabbix_url.endsWith(''/''))
        ? params.zabbix_url.slice(0, -1) : params.zabbix_url;

    if ([0, 1, 2, 3, 4].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: "'' + params.event_source + ''".\\nMust be 0-4.'';
    }

    // Set params to true for non trigger-based events.
    if (params.event_source !== ''0'') {
        params.use_default_message = ''true'';
        params.event_nseverity = ''0'';
    }

    // Check {EVENT.VALUE} for trigger-based and internal events.
    if (params.event_value !== ''0'' && params.event_value !== ''1''
        && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "event_value" parameter given: "'' + params.event_value + ''".\\nMust be 0 or 1.'';
    }

    // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
    if (params.event_update_status !== ''0'' && params.event_update_status !== ''1'' && params.event_source === ''0'') {
        throw ''Incorrect "event_update_status" parameter given: "'' + params.event_update_status + ''".\\nMust be 0 or 1.'';
    }

    if (params.event_value == 0) {
        params.event_nseverity = ''6'';
    }

    if (!SEVERITY_COLORS[params.event_nseverity]) {
        throw ''Incorrect "event_nseverity" parameter given: '' + params.event_nseverity + ''\\nMust be 0-5.'';
    }

    var color = parseInt(SEVERITY_COLORS[params.event_nseverity].replace(''#'', ''''), 16),
        fields = [],
        body = {
            embeds: [
                {
                    color: color || 0,
                    url: (params.event_source === ''0'')
                        ? params.zabbix_url + ''/tr_events.php?triggerid='' + params.trigger_id +
                            ''&eventid='' + params.event_id
                        : params.zabbix_url
                }
            ]
        };

    // Default message from {ALERT.MESSAGE}.
    if (params.use_default_message.toLowerCase() == ''true'') {
        body.embeds[0].title = stringTruncate(params.alert_subject, 256);
        body.embeds[0].description = stringTruncate(params.alert_message, 2048);
    }
    else {
        fields.push(
            {
                name: ''Host'',
                value: params.host_name + '' ['' + params.host_ip + '']''
            }
        );

        // Resolved message.
        if (params.event_value == 0 && params.event_update_status == 0) {
            body.embeds[0].title = stringTruncate(''OK: '' + params.event_name, 256);
            fields.push(
                {
                    name: ''Recovery time'',
                    value: params.event_recovery_time + '' '' + params.event_recovery_date,
                    inline: ''True''
                }
            );
        }

        // Problem message.
        else if (params.event_value == 1 && params.event_update_status == 0) {
            body.embeds[0].title = stringTruncate(''PROBLEM: '' + params.event_name, 256);
            fields.push(
                {
                    name: ''Event time'',
                    value: params.event_time + '' '' + params.event_date,
                    inline: ''True''
                }
            );
        }

        // Update message.
        else if (params.event_update_status == 1) {
            body.embeds[0].title = stringTruncate(''UPDATE: '' + params.event_name, 256);
            body.embeds[0].description = params.event_update_user + '' '' + params.event_update_action + ''.'';

            if (params.event_update_message) {
                body.embeds[0].description += '' Comment:\\n>>> '' + params.event_update_message;
            }

            body.embeds[0].description = stringTruncate(body.embeds[0].description, 2048);

            fields.push(
                {
                    name: ''Event update time'',
                    value: params.event_update_time + '' '' + params.event_update_date,
                    inline: ''True''
                }
            );
        }

        fields.push(
            {
                name: ''Severity'',
                value: params.event_severity,
                inline: ''True''
            }
        );

        if (params.event_opdata) {
            fields.push(
                {
                    name: ''Operational data'',
                    value: stringTruncate(params.event_opdata, 1024),
                    inline: ''True''
                }
            );
        }

        if (params.event_value == 1 && params.event_update_status == 0 && params.trigger_description) {
            fields.push(
                {
                    name: ''Trigger description'',
                    value: stringTruncate(params.trigger_description, 1024)
                }
            );
        }

        body.embeds[0].footer = {
            text: ''Event ID: '' + params.event_id
        };

        if (params.event_tags) {
            body.embeds[0].footer.text += ''\\nEvent tags: '' + params.event_tags;
        }
        body.embeds[0].footer.text = stringTruncate(body.embeds[0].footer.text, 2048);
    }

    if (fields.length > 0) {
        body.embeds[0].fields = fields;
    }

    var req = new HttpRequest();

    if (typeof params.HTTPProxy === ''string'' && params.HTTPProxy.trim() !== '''') {
        req.setProxy(params.HTTPProxy);
    }

    req.addHeader(''Content-Type: application/json'');

    var resp = req.post(params.discord_endpoint, JSON.stringify(body)),
        data = JSON.parse(resp);

    Zabbix.log(4, ''[ Discord Webhook ] JSON: '' + JSON.stringify(body));
    Zabbix.log(4, ''[ Discord Webhook ] Response: '' + resp);

    if (data.id) {
        return resp;
    }
    else {
        var message = ((typeof data.message === ''string'') ? data.message : ''Unknown error'');

        Zabbix.log(3, ''[ Discord Webhook ] FAILED with response: '' + resp);
        throw message + ''. For more details check zabbix server log.'';
    }
}
catch (error) {
    Zabbix.log(3, ''[ Discord Webhook ] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','0','0','','','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('11','4','SIGNL4','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'// SIGNL4 Webhook
try {
    var response,
        payload,
        params = JSON.parse(value),
        endpoint = ''https://connect.signl4.com/webhook/'',
        request = new HttpRequest();

    if (typeof params.HTTPProxy === ''string'' && params.HTTPProxy.trim() !== '''') {
        request.setProxy(params.HTTPProxy);
    }

    if (typeof params.teamsecret === ''string'' && params.teamsecret.trim() !== '''') {
        endpoint += params.teamsecret;
        delete params.teamsecret;
    }
    else {
        throw ''The team secret of your SIGNL4 team cannot be empty.'';
    }

    if (typeof params.Severity === ''string'' && params.Severity === ''{EVENT.SEVERITY}'') {
        params.Severity = ''Not classified'';
    }

if (typeof params.User === ''string'' && params.User === ''{USER.FULLNAME}'') {
        params.User = '''';
    }

if (typeof params.Event_Update_Action === ''string'' && params.Event_Update_Action === ''{EVENT.UPDATE.ACTION}'') {
        params.Event_Update_Action = '''';
    }

// Assemble X-S4-ExternalID for two-way integration
// Format: "ZabbixEventID: 222 ZabbixURL: https://your-zabbix-server/zabbix/"
params[''X-S4-ExternalID''] = ''ZabbixEventID: '' + params.Event_ID;
if (typeof params.Zabbix_URL === ''string'' && params.Zabbix_URL.indexOf(''http'') == 0) {
// Make sure the URL ends with ''/''
if (params.Zabbix_URL.charAt(params.Zabbix_URL.length - 1) != ''/'') {
params.Zabbix_URL = params.Zabbix_URL + ''/'';
}

params[''X-S4-ExternalID''] = params[''X-S4-ExternalID''] + '' ZabbixURL: '' +  params.Zabbix_URL;

// Add Link parameter
params[''Link''] = params.Zabbix_URL + "tr_events.php?triggerid="+params.Trigger_ID + "&eventid=" + params.Event_ID;
}

// Check if this is a new problem or a recovery
if (params.Trigger_Status == ''OK'') {
params[''X-S4-Status''] = ''resolved'';
}
else {
params[''X-S4-Status''] = ''new'';
}

    payload = JSON.stringify(params);
    Zabbix.log(4, ''[ SIGNL4 Webhook ] Sending request: '' + payload);

    request.addHeader(''Content-Type: application/json'');
    response = request.post(endpoint, ''payload='' + payload);

    Zabbix.log(4, ''[ SIGNL4 Webhook ] Received response with status code '' +
            request.getStatus() + ''\\n'' + response
    );

    if (request.getStatus() !== 201) {
        throw ''Request failed with status code '' + request.getStatus() +
                ''. Check debug log for more information.'';
    }

    return ''OK'';
}
catch (error) {
    Zabbix.log(4, ''[ SIGNL4 Webhook ] ERROR: '' + error);

    throw ''Sending failed: '' + error;
}','30s','0','0','','','SIGNL4 is a mobile alert notification app for powerful alerting, alert management and mobile assignment of work items. It offers alerting via app push, SMS and voice calls including escalations, tracking, and duty scheduling.

Get the app at https://www.signl4.com.

Find out more including an integration video here: https://www.signl4.com/blog/portfolio_item/zabbix-mobile-alert-notification-duty-schedule-escalation/');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('12','4','Jira','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var Jira = {
    params: {},

    setParams: function (params) {
        if (typeof params !== ''object'') {
            return;
        }

        Jira.params = params;
        if (typeof Jira.params.url === ''string'') {
            if (!Jira.params.url.endsWith(''/'')) {
                Jira.params.url += ''/'';
            }

            Jira.params.url += ''rest/api/latest/'';
        }
    },

    setProxy: function (HTTPProxy) {
        Jira.HTTPProxy = HTTPProxy;
    },

    setTags: function(event_tags_json) {
        if (typeof event_tags_json !== ''undefined'' && event_tags_json !== ''''
            && event_tags_json !== ''{EVENT.TAGSJSON}'') {
            try {
                var tags = JSON.parse(event_tags_json),
                    label;

                Jira.labels = [];

                tags.forEach(function (tag) {
                    if (typeof tag.tag !== ''undefined'' && typeof tag.value !== ''undefined''
                        && !tag.tag.startsWith(''__zbx'')) {
                        label = (tag.tag + (tag.value ? ('':'' + tag.value) : '''')).replace(/\\s/g, ''_'');
                        if (label.length < 256) {
                            Jira.labels.push(label);
                        }
                    }
                });
            }
            catch (error) {
                // Code is not missing here.
            }
        }
    },

    escapeMarkup: function (str) {
        var length = str.length,
            result = '''',
            markup = [''{'', ''|'', ''}'', ''~'', ''_'', ''\\\\'', ''['', '']'', ''^'', ''<'', ''>'', ''?'', ''!'', ''#'', ''+'', ''*'', ''&''];

        for (var i = 0; i < length; i++) {
            var char = str[i];

            result += (markup.indexOf(char) !== -1) ? (''&#'' + str[i].charCodeAt() + '';'') : char;
        }

        return result;
    },

    addCustomFields: function (data, fields) {
        if (typeof fields === ''object'' && Object.keys(fields).length) {
            var schema = Jira.getSchema(),
                path = [''projects'', 0, ''issuetypes'', 0, ''fields''],
                field;

            while ((field = path.shift()) !== undefined) {
                schema = schema[field];
                if (typeof schema === ''undefined'') {
                    schema = null;
                    break;
                }
            }

            if (schema) {
                Object.keys(fields)
                    .forEach(function(field) {
                        if (typeof schema[field] === ''object'' && typeof schema[field].schema === ''object'') {
                            switch (schema[field].schema.type) {
                                case ''number'':
                                    data.fields[field] = parseInt(fields[field]);
                                    break;

                                case ''datetime'':
                                    if (fields[field].match(/\\d+[.-]\\d+[.-]\\d+T\\d+:\\d+:\\d+/) !== null) {
                                        data.fields[field] = fields[field].replace(/\\./g, ''-'');
                                    }
                                    break;

                                case ''option'':
                                    data.fields[field] = {value: fields[field]};
                                    break;

                                case ''array'':
                                    if (schema[field].schema.items === ''option'') {
                                        data.fields[field] = [{value: fields[field]}];
                                    }
                                    else {
                                        data.fields[field] = [fields[field]];
                                    }
                                    break;

                                default:
                                    data.fields[field] = fields[field];
                            }
                        }
                    });
            }
            else {
                Zabbix.log(4, ''[ Jira Webhook ] Failed to retrieve field schema.'');
            }
        }

        return data;
    },

    request: function (method, query, data) {
        [''url'', ''user'', ''password'', ''project_key'', ''issue_type''].forEach(function (field) {
            if (typeof Jira.params !== ''object'' || typeof Jira.params[field] === ''undefined''
                || Jira.params[field] === '''' ) {
                throw ''Required Jira param is not set: "'' + field + ''".'';
            }
        });

        var response,
            url = Jira.params.url + query,
            request = new HttpRequest();

        request.addHeader(''Content-Type: application/json'');
        request.addHeader(''Authorization: Basic '' + btoa(Jira.params.user + '':'' + Jira.params.password));

        if (typeof Jira.HTTPProxy !== ''undefined'' && Jira.HTTPProxy !== '''') {
            request.setProxy(Jira.HTTPProxy);
        }

        if (typeof data !== ''undefined'') {
            data = JSON.stringify(data);
        }

        Zabbix.log(4, ''[ Jira Webhook ] Sending request: '' + url + ((typeof data === ''string'') ? (''\\n'' + data) : ''''));

        switch (method) {
            case ''get'':
                response = request.get(url, data);
                break;

            case ''post'':
                response = request.post(url, data);
                break;

            case ''put'':
                response = request.put(url, data);
                break;

            default:
                throw ''Unsupported HTTP request method: '' + method;
        }

        Zabbix.log(4, ''[ Jira Webhook ] Received response with status code '' + request.getStatus() + ''\\n'' + response);

        if (response !== null) {
            try {
                response = JSON.parse(response);
            }
            catch (error) {
                Zabbix.log(4, ''[ Jira Webhook ] Failed to parse response received from Jira'');
                response = null;
            }
        }

        if (request.getStatus() < 200 || request.getStatus() >= 300) {
            var message = ''Request failed with status code '' + request.getStatus();

            if (response !== null && typeof response.errors !== ''undefined''
                && Object.keys(response.errors).length > 0) {
                message += '': '' + JSON.stringify(response.errors);
            }
            else if (response !== null && typeof response.errorMessages !== ''undefined''
                && Object.keys(response.errorMessages).length > 0) {
                message += '': '' + JSON.stringify(response.errorMessages);
            }

            throw message + '' Check debug log for more information.'';
        }

        return {
            status: request.getStatus(),
            response: response
        };
    },

    getSchema: function() {
        var result = Jira.request(''get'', ''issue/createmeta?expand=projects.issuetypes.fields&projectKeys='' +
            encodeURIComponent(Jira.params.project_key) + ''&issuetypeNames='' +
            encodeURIComponent(Jira.params.issue_type));

        return result.response;
    },

    createIssue: function(summary, description, fields) {
        var data = {
            fields: {
                project: {
                    key: Jira.params.project_key
                },
                issuetype: {
                    name: Jira.params.issue_type
                },
                summary: summary,
                description: description
            }
        };

        if (Jira.labels && Jira.labels.length > 0) {
            data.fields.labels = Jira.labels;
        }
        var result = Jira.request(''post'', ''issue'', Jira.addCustomFields(data, fields));

        if (typeof result.response !== ''object'' || typeof result.response.key === ''undefined'') {
            throw ''Cannot create Jira issue. Check debug log for more information.'';
        }

        return result.response.key;
    },

    updateIssue: function(summary, fields, update) {
        var data = {fields: {}};

        if (summary) {
            data.fields.summary = summary;
        }

        Jira.request(''put'', ''issue/'' + encodeURIComponent(Jira.params.issue_key), Jira.addCustomFields(data, fields));
        Jira.commentIssue(update);
    },

    commentIssue: function(update) {
        var data = {};

        if (typeof update === ''string'') {
            data.body = update;
            Jira.request(''post'', ''issue/'' + encodeURIComponent(Jira.params.issue_key) + ''/comment'', data);
        }
        else if (update.status === ''1'') {
            data.body = update.user + '' '' + update.action + ''.'';

            if (update.message) {
                data.body += ''\\nMessage: {quote}'' + Jira.escapeMarkup(update.message) + ''{quote}'';
            }

            Jira.request(''post'', ''issue/'' + encodeURIComponent(Jira.params.issue_key) + ''/comment'', data);
        }
    }
};

try {
    var params = JSON.parse(value),
        fields = {},
        jira = {},
        update = {},
        result = {tags: {}},
        required_params = [''alert_subject'', ''summary'', ''event_recovery_value'', ''event_source'', ''event_value''];

    Object.keys(params)
        .forEach(function (key) {
            if (key.startsWith(''jira_'')) {
                jira[key.substring(5)] = params[key];
            }
            else if (key.startsWith(''customfield_'')) {
                fields[key] = params[key];
            }
            else if (key.startsWith(''event_update_'')) {
                update[key.substring(13)] = params[key];
            }
            else if (required_params.indexOf(key) !== -1 && params[key] === '''') {
                throw ''Parameter "'' + key + ''" can\\''t be empty.'';
            }
        });

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: '' + params.event_source + ''\\nMust be 0-3.'';
    }

    // Check {EVENT.VALUE} for trigger-based and internal events.
    if (params.event_value !== ''0'' && params.event_value !== ''1''
        && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
    if (params.event_update_status !== ''0'' && params.event_update_status !== ''1'' && params.event_source === ''0'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }

    if (params.event_source !== ''0'' && params.event_recovery_value === ''0'') {
        throw ''Recovery operations are supported only for trigger-based actions.'';
    }

    Jira.setParams(jira);
    Jira.setProxy(params.HTTPProxy);
    Jira.setTags(params.event_tags_json);

    // Create issue for non trigger-based events.
    if (params.event_source !== ''0'' && params.event_recovery_value !== ''0'') {
        Jira.createIssue(params.alert_subject, params.alert_message);
    }
    // Create issue for trigger-based events.
    else if (params.event_value === ''1'' && update.status === ''0'' && !jira.issue_key.startsWith(jira.project_key)) {
        var key = Jira.createIssue(params.alert_subject,
            (Object.keys(fields).length ? params.trigger_description : params.alert_message), fields);


        result.tags.__zbx_jira_issuekey = key;
        result.tags.__zbx_jira_issuelink = params.jira_url +
            (params.jira_url.endsWith(''/'') ? '''' : ''/'') + ''browse/'' + key;
    }
    // Update created issue for trigger-based event.
    else {
        if (!jira.issue_key.startsWith(jira.project_key)) {
            throw ''Incorrect Issue key given: '' + jira.issue_key;
        }
        Jira.updateIssue(params.alert_subject, fields,
            ((params.event_value === ''0'' && !Object.keys(fields).length)
                ? params.alert_message : update));
    }

    return JSON.stringify(result);
}
catch (error) {
    Zabbix.log(3, ''[ Jira Webhook ] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','1','1','{EVENT.TAGS.__zbx_jira_issuelink}','Jira: {EVENT.TAGS.__zbx_jira_issuekey}','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('13','4','Jira with CustomFields','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var Jira = {
    params: {},

    setParams: function (params) {
        if (typeof params !== ''object'') {
            return;
        }

        Jira.params = params;
        if (typeof Jira.params.url === ''string'') {
            if (!Jira.params.url.endsWith(''/'')) {
                Jira.params.url += ''/'';
            }

            Jira.params.url += ''rest/api/latest/'';
        }
    },

    setProxy: function (HTTPProxy) {
        Jira.HTTPProxy = HTTPProxy;
    },

    setTags: function(event_tags_json) {
        if (typeof event_tags_json !== ''undefined'' && event_tags_json !== ''''
            && event_tags_json !== ''{EVENT.TAGSJSON}'') {
            try {
                var tags = JSON.parse(event_tags_json),
                    label;

                Jira.labels = [];

                tags.forEach(function (tag) {
                    if (typeof tag.tag !== ''undefined'' && typeof tag.value !== ''undefined'' ) {
                        label = (tag.tag + (tag.value ? ('':'' + tag.value) : '''')).replace(/\\s/g, ''_'');
                        if (label.length < 256) {
                            Jira.labels.push(label);
                        }
                    }
                });
            }
            catch (error) {
                // Code is not missing here.
            }
        }
    },

    escapeMarkup: function (str) {
        var length = str.length,
            result = '''',
            markup = [''{'', ''|'', ''}'', ''~'', ''_'', ''\\\\'', ''['', '']'', ''^'', ''<'', ''>'', ''?'', ''!'', ''#'', ''+'', ''*'', ''&''];

        for (var i = 0; i < length; i++) {
            var char = str[i];

            result += (markup.indexOf(char) !== -1) ? (''&#'' + str[i].charCodeAt() + '';'') : char;
        }

        return result;
    },

    addCustomFields: function (data, fields) {
        if (typeof fields === ''object'' && Object.keys(fields).length) {
            var schema = Jira.getSchema(),
                path = [''projects'', 0, ''issuetypes'', 0, ''fields''],
                field;

            while ((field = path.shift()) !== undefined) {
                schema = schema[field];
                if (typeof schema === ''undefined'') {
                    schema = null;
                    break;
                }
            }

            if (schema) {
                Object.keys(fields)
                    .forEach(function(field) {
                        data.fields[field] = fields[field];

                        if (typeof schema[field] === ''object'' && typeof schema[field].schema === ''object''
                            && (schema[field].schema.type === ''number'' || schema[field].schema.type === ''datetime'')) {
                            switch (schema[field].schema.type) {
                                case ''number'':
                                    data.fields[field] = parseInt(fields[field]);
                                    break;

                                case ''datetime'':
                                    if (fields[field].match(/\\d+[.-]\\d+[.-]\\d+T\\d+:\\d+:\\d+/) !== null) {
                                        data.fields[field] = fields[field].replace(/\\./g, ''-'');
                                    }
                                    else {
                                        delete data.fields[field];
                                    }
                                    break;
                            }
                        }
                    });
            }
            else {
                Zabbix.Log(4, ''[ Jira Webhook ] Failed to retrieve field schema.'');
            }
        }

        return data;
    },

    request: function (method, query, data) {
        [''url'', ''user'', ''password'', ''project_key'', ''issue_type''].forEach(function (field) {
            if (typeof Jira.params !== ''object'' || typeof Jira.params[field] === ''undefined''
                || Jira.params[field] === '''' ) {
                throw ''Required Jira param is not set: "'' + field + ''".'';
            }
        });

        var response,
            url = Jira.params.url + query,
            request = new CurlHttpRequest();

        request.AddHeader(''Content-Type: application/json'');
        request.AddHeader(''Authorization: Basic '' + btoa(Jira.params.user + '':'' + Jira.params.password));

        if (typeof Jira.HTTPProxy !== ''undefined'' && Jira.HTTPProxy !== '''') {
            request.SetProxy(Jira.HTTPProxy);
        }

        if (typeof data !== ''undefined'') {
            data = JSON.stringify(data);
        }

        Zabbix.Log(4, ''[ Jira Webhook ] Sending request: '' + url + ((typeof data === ''string'') ? (''\\n'' + data) : ''''));

        switch (method) {
            case ''get'':
                response = request.Get(url, data);
                break;

            case ''post'':
                response = request.Post(url, data);
                break;

            case ''put'':
                response = request.Put(url, data);
                break;

            default:
                throw ''Unsupported HTTP request method: '' + method;
        }

        Zabbix.Log(4, ''[ Jira Webhook ] Received response with status code '' + request.Status() + ''\\n'' + response);

        if (response !== null) {
            try {
                response = JSON.parse(response);
            }
            catch (error) {
                Zabbix.Log(4, ''[ Jira Webhook ] Failed to parse response received from Jira'');
                response = null;
            }
        }

        if (request.Status() < 200 || request.Status() >= 300) {
            var message = ''Request failed with status code '' + request.Status();

            if (response !== null && typeof response.errors !== ''undefined''
                && Object.keys(response.errors).length > 0) {
                message += '': '' + JSON.stringify(response.errors);
            }
            else if (response !== null && typeof response.errorMessages !== ''undefined''
                && Object.keys(response.errorMessages).length > 0) {
                message += '': '' + JSON.stringify(response.errorMessages);
            }

            throw message + '' Check debug log for more information.'';
        }

        return {
            status: request.Status(),
            response: response
        };
    },

    getSchema: function() {
        var result = Jira.request(''get'', ''issue/createmeta?expand=projects.issuetypes.fields&projectKeys='' +
                Jira.params.project_key + ''&issuetypeNames='' + Jira.params.issue_type);

        return result.response;
    },

    createIssue: function(summary, description, fields) {
        var data = {
            fields: {
                project: {
                    key: Jira.params.project_key
                },
                issuetype: {
                    name: Jira.params.issue_type
                },
                summary: summary,
                description: description
            }
        };

        if (Jira.labels && Jira.labels.length > 0) {
            data.fields.labels = Jira.labels;
        }
        var result = Jira.request(''post'', ''issue'', Jira.addCustomFields(data, fields));

        if (typeof result.response !== ''object'' || typeof result.response.key === ''undefined'') {
            throw ''Cannot create Jira issue. Check debug log for more information.'';
        }

        return result.response.key;
    },

    updateIssue: function(summary, fields, update) {
        var data = {fields: {}};

        if (summary) {
            data.fields.summary = summary;
        }

        Jira.request(''put'', ''issue/'' + Jira.params.issue_key, Jira.addCustomFields(data, fields));
        Jira.commentIssue(update);
    },

    commentIssue: function(update) {
        var data = {};

        if (typeof update === ''string'') {
            data.body = update;
            Jira.request(''post'', ''issue/'' + Jira.params.issue_key + ''/comment'', data);
        }
        else if (update.status === ''1'') {
            data.body = update.user + '' '' + update.action + ''.'';

            if (update.message) {
                data.body += ''\\nMessage: {quote}'' + Jira.escapeMarkup(update.message) + ''{quote}'';
            }

            Jira.request(''post'', ''issue/'' + Jira.params.issue_key + ''/comment'', data);
        }
    }
};

try {
    var params = JSON.parse(value),
        fields = {},
        jira = {},
        update = {},
        result = {tags: {}},
        required_params = [''alert_subject'', ''summary'', ''event_recovery_value'', ''event_source'', ''event_value''];

    Object.keys(params)
        .forEach(function (key) {
            if (key.startsWith(''jira_'')) {
                jira[key.substring(5)] = params[key];
            }
            else if (key.startsWith(''customfield_'')) {
                fields[key] = params[key];
            }
            else if (key.startsWith(''event_update_'')) {
                update[key.substring(13)] = params[key];
            }
            else if (required_params.indexOf(key) !== -1 && params[key] === '''') {
                throw ''Parameter "'' + key + ''" can\\''t be empty.'';
            }
        });

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: '' + params.event_source + ''\\nMust be 0-3.'';
    }

    // Check {EVENT.VALUE} for trigger-based and internal events.
    if (params.event_value !== ''0'' && params.event_value !== ''1''
        && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
    if (params.event_update_status !== ''0'' && params.event_update_status !== ''1'' && params.event_source === ''0'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }

    if (params.event_source !== ''0'' && params.event_recovery_value === ''0'') {
        throw ''Recovery operations are supported only for trigger-based actions.'';
    }

    Jira.setParams(jira);
    Jira.setProxy(params.HTTPProxy);
    Jira.setTags(params.event_tags_json);

    // Create issue for non trigger-based events.
    if (params.event_source !== ''0'' && params.event_recovery_value !== ''0'') {
        Jira.createIssue(params.alert_subject, params.alert_message);
    }
    // Create issue for trigger-based events.
    else if (params.event_value === ''1'' && update.status === ''0'' && !jira.issue_key.startsWith(jira.project_key)) {
        var key = Jira.createIssue(params.alert_subject,
            (Object.keys(fields).length ? params.trigger_description : params.alert_message), fields);


        result.tags.__zbx_jira_issuekey = key;
        result.tags.__zbx_jira_issuelink = params.jira_url +
            (params.jira_url.endsWith(''/'') ? '''' : ''/'') + ''browse/'' + key;
    }
    // Update created issue for trigger-based event.
    else {
        if (!jira.issue_key.startsWith(jira.project_key)) {
            throw ''Incorrect Issue key given: '' + jira.issue_key;
        }
        Jira.updateIssue(params.alert_subject, fields,
            ((params.event_value === ''0'' && !Object.keys(fields).length)
                ? params.alert_message : update));
    }

    return JSON.stringify(result);
}
catch (error) {
    Zabbix.Log(3, ''[ Jira Webhook ] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','1','1','{EVENT.TAGS.__zbx_jira_issuelink}','Jira: {EVENT.TAGS.__zbx_jira_issuekey}','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('14','4','MS Teams','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var SEVERITY_COLORS = [
    ''#97AAB3'', // Not classified.
    ''#7499FF'', // Information.
    ''#FFC859'', // Warning.
    ''#FFA059'', // Average.
    ''#E97659'', // High.
    ''#E45959'', // Disaster.
    ''#009900'', // Resolved.
    ''#000000''  // Default.
];

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

    if (typeof params.teams_endpoint !== ''string'' || params.teams_endpoint.trim() === '''') {
        throw ''Cannot get teams_endpoint'';
    }
    else if (!params.teams_endpoint.startsWith(''http'')) {
        throw ''Invalid MS Teams webhook URL: '' + params.teams_endpoint;
    }

    params.zabbix_url = (params.zabbix_url.endsWith(''/''))
        ? params.zabbix_url.slice(0, -1) : params.zabbix_url;

    if ([0, 1, 2, 3, 4].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: "'' + params.event_source + ''".\\nMust be 0-4.'';
    }

    // Set "use_default_message" to true for non trigger-based events.
    if (params.event_source !== ''0'') {
        params.use_default_message = ''true'';
    }

    // Check {EVENT.VALUE} for trigger-based and internal events.
    if (params.event_value !== ''0'' && params.event_value !== ''1''
            && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "event_value" parameter given: "'' + params.event_value + ''".\\nMust be 0 or 1.'';
    }

    // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
    if (params.event_update_status !== ''0'' && params.event_update_status !== ''1'' && params.event_source === ''0'') {
        throw ''Incorrect "event_update_status" parameter given: "'' + params.event_update_status + ''".\\nMust be 0 or 1.'';
    }

    if (params.event_value == 0) {
        params.event_nseverity = ''6'';
    }

    if (!SEVERITY_COLORS[params.event_nseverity]) {
        params.event_nseverity = ''7'';
    }

    var request = new HttpRequest(),
        facts = [],
        body = {
            themeColor: SEVERITY_COLORS[params.event_nseverity].replace(''#'', ''''),
            summary: params.alert_subject,
            sections: [
                {
                    markdown: ''false'',
                    activityTitle: params.alert_subject,
                    text: (params.use_default_message.toLowerCase() == ''true'')
                        ? params.alert_message
                        : params.trigger_description
                }
            ],
            potentialAction: [
                {
                    ''@type'': ''OpenUri'',
                    name: (params.event_source === ''0'')
                        ? ''Event Info''
                        : ''Zabbix Home'',
                    targets: [
                        {
                            os: ''default'',
                            uri: (params.event_source === ''0'')
                                ? params.zabbix_url + ''/tr_events.php?triggerid='' +
                                    params.trigger_id + ''&eventid='' + params.event_id
                                : params.zabbix_url
                        }
                    ]
                }
            ]
        };

    if (params.use_default_message.toLowerCase() !== ''true'') {
        // Problem message.
        if (params.event_value === ''1'' && params.event_update_status === ''0'') {
            facts.push({
                name: ''Event time'',
                value: params.event_time + '' '' + params.event_date
            });
            facts.push({
                name: ''Host'',
                value: params.host_name + '' ['' + params.host_ip + '']''
            });
        }
        // Update message.
        else if (params.event_update_status === ''1'') {
            body.sections[0].text = params.event_update_user + '' '' + params.event_update_action + ''.'';

            if (params.event_update_message) {
                body.sections[0].text += ''<br>Message:<br>'' + params.event_update_message;
            }
            facts.push({
                name: ''Event update time'',
                value: params.event_update_time + '' '' + params.event_update_date
            });
            facts.push({
                name: ''Host'',
                value: params.host_name + '' ['' + params.host_ip + '']''
            });
        }
        // Resolved message.
        else {
            facts.push({
                name: ''Recovery time'',
                value: params.event_recovery_time + '' '' + params.event_recovery_date
            });
            facts.push({
                name: ''Host'',
                value: params.host_name + '' ['' + params.host_ip + '']''
            });
        }

        if (params.event_severity && params.event_severity !== ''{EVENT.SEVERITY}'') {
            facts.push({
                name: ''Severity'',
                value: params.event_severity
            });
        }

        if (params.event_opdata && params.event_opdata !== ''{EVENT.OPDATA}'') {
            facts.push({
                name: ''Operational data'',
                value: params.event_opdata
            });
        }

        if (params.event_tags && params.event_tags !== ''{EVENT.TAGS}'') {
            facts.push({
                name: ''Event tags'',
                value: params.event_tags
            });
        }

        Object.keys(params)
            .forEach(function (key) {
                if (key.startsWith(''fact_'') && params[key] !== '''') {
                    facts.push({
                        name: key.substring(5),
                        value: params[key]
                    });
                }
                else if (key.startsWith(''openUri_'') && params[key] !== '''' && !params[key].startsWith(''{'')) {
                    body.potentialAction.push({
                        ''@type'': ''OpenUri'',
                        name: key.substring(8),
                        targets: [
                            {
                                os: ''default'',
                                uri: params[key]
                            }
                        ]
                    });
                }
            });
        body.sections[0].facts = facts;
    }

    body.sections[0].text = body.sections[0].text.replace(/(?:\\r\\n|\\r|\\n)/g, ''<br>'');

    request.addHeader(''Content-Type: application/json'');

    if (typeof params.HTTPProxy === ''string'' && params.HTTPProxy !== '''') {
        request.setProxy(params.HTTPProxy);
    }

    Zabbix.log(4, ''[ MS Teams Webhook ] JSON: '' + JSON.stringify(body));

    var response = request.post(params.teams_endpoint, JSON.stringify(body));

    Zabbix.log(4, ''[ MS Teams Webhook ] Response: '' + response);

    if (response === ''1'') {
        return ''OK'';
    }
    else {
        Zabbix.log(4, ''[ MS Teams Webhook ] FAILED with response: '' + response);
        throw response;
    }
}
catch (error) {
    Zabbix.log(3, ''[ MS Teams Webhook ] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','0','0','','','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('15','4','Redmine','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var Redmine = {
    params: {},

    setParams: function (params) {
        if (typeof params !== ''object'') {
            return;
        }

        Redmine.params = params;
        if (typeof Redmine.params.url === ''string'') {
            if (!Redmine.params.url.endsWith(''/'')) {
                Redmine.params.url += ''/'';
            }
        }
    },

    addCustomFields: function (data, fields) {
        if (typeof fields === ''object'' && Object.keys(fields).length) {

            data.issue.custom_fields = [];
            Object.keys(fields)
                .forEach(function (field) {
                    var field_value = fields[field];

                    if (field_value !== undefined) {
                        data.issue.custom_fields.push({ id: field, value: field_value });
                    }
                });

        }
        return data;
    },

    request: function (method, query, data) {
        [''url'', ''access_key''].forEach(function (field) {
            if (typeof Redmine.params !== ''object'' || typeof Redmine.params[field] === ''undefined''
                || Redmine.params[field] === '''' ) {
                throw ''Required param is not set: "'' + field + ''".'';
            }
        });

        var response,
            url = Redmine.params.url + query,
            request = new HttpRequest();

        if (typeof Redmine.HTTPProxy === ''string'' && Redmine.HTTPProxy.trim() !== '''') {
            request.setProxy(Redmine.HTTPProxy);
        }

        request.addHeader(''Content-Type: application/json'');
        request.addHeader(''X-Redmine-API-Key: '' + Redmine.params.access_key);

        if (typeof data !== ''undefined'') {
            data = JSON.stringify(data);
        }

        Zabbix.log(4, ''[ Redmine Webhook ] Sending request: '' +
            url + ((typeof data === ''string'') ? ('' '' + data) : ''''));

        switch (method) {
            case ''get'':
                response = request.get(url, data);
                break;

            case ''post'':
                response = request.post(url, data);
                break;

            case ''put'':
                response = request.put(url, data);
                break;

            default:
                throw ''Unsupported HTTP request method: '' + method;
        }

        Zabbix.log(4, ''[ Redmine Webhook ] Received response with status code '' + request.getStatus() + '': '' + response);

        if (response !== null) {
            try {
                response = JSON.parse(response);
            }
            catch (error) {
                Zabbix.log(4, ''[ Redmine Webhook ] Failed to parse response received from Redmine'');
                response = null;
            }
        }

        if (request.getStatus() < 200 || request.getStatus() >= 300) {
            var message = ''Request failed with status code '' + request.getStatus();

            if (response !== null && typeof response.errors !== ''undefined''
                && Object.keys(response.errors).length > 0) {
                message += '': '' + JSON.stringify(response.errors);
            }
            else if (response !== null && typeof response.errorMessages !== ''undefined''
                && Object.keys(response.errorMessages).length > 0) {
                message += '': '' + JSON.stringify(response.errorMessages);
            }

            throw message + '' Check debug log for more information.'';
        }

        return {
            status: request.getStatus(),
            response: response
        };
    },

    getProjectID: function(name) {
        var result = Redmine.request(''get'', ''projects.json''),
            project_id;

        if (result.response) {
            var projects = result.response.projects || [];

            for (var i in projects) {
                if (projects[i].name === name) {
                    project_id = projects[i].id;
                    break;
                }
            }
        }
        else {
            Zabbix.log(4, ''[ Redmine Webhook ] Failed to retrieve project data.'');
        }

        if (typeof project_id === ''undefined'') {
            throw ''Cannot find project with name: '' + name;
        }

        return project_id;
    },

    createIssue: function(subject, description, priority, fields) {
        var project_id = /^\\d+$/.test(Redmine.params.project)
                ? Redmine.params.project
                : Redmine.getProjectID(Redmine.params.project),
            data = {
                issue: {
                    project_id: project_id,
                    tracker_id: Redmine.params.tracker_id,
                    subject: subject,
                    description: description
                }
            },
            result;

        if (priority) {
            data.issue.priority_id = priority;
        }

        result = Redmine.request(''post'', ''issues.json'', Redmine.addCustomFields(data, fields));

        if (typeof result.response !== ''object''
            || typeof result.response.issue.id === ''undefined''
            || result.status != 201) {
            throw ''Cannot create Redmine issue. Check debug log for more information.'';
        }

        return result.response.issue.id;
    },

    updateIssue: function (note, fields, status) {
        var data = {
            issue: {
                notes: note || ''''
            }
        };

        if (status) {
            data.issue.status_id = status;
        }

        Redmine.request(''put'', ''issues/'' + Redmine.params.issue_key + ''.json'', Redmine.addCustomFields(data, fields));
    }

};

try {
    var params = JSON.parse(value),
        params_redmine = {},
        params_fields = {},
        params_update = {},
        result = {tags: {}},
        required_params = [
            ''alert_subject'', ''tracker_id'', ''project'',
            ''event_source'', ''event_value'',  ''event_update_status''
        ],
        severities = [
            {name: ''not_classified'', color: ''#97AAB3''},
            {name: ''information'', color: ''#7499FF''},
            {name: ''warning'', color: ''#FFC859''},
            {name: ''average'', color: ''#FFA059''},
            {name: ''high'', color: ''#E97659''},
            {name: ''disaster'', color: ''#E45959''},
            {name: ''resolved'', color: ''#009900''},
            {name: null, color: ''#000000''}
        ],
        priority;

    Object.keys(params)
        .forEach(function (key) {
            if (key.startsWith(''redmine_'')) {
                params_redmine[key.substring(8)] = params[key];
            }
            else if (key.startsWith(''customfield_'')) {
                params_fields[key.substring(12)] = params[key];
            }
            else if (key.startsWith(''event_update_'')) {
                params_update[key.substring(13)] = params[key];
            }
            else if (required_params.indexOf(key) !== -1 && params[key].trim() === '''') {
                throw ''Parameter "'' + key + ''" cannot be empty.'';
            }
        });

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: '' + params.event_source + ''\\nMust be 0-3.'';
    }

    // Check {EVENT.VALUE} for trigger-based and internal events.
    if (params.event_value !== ''0'' && params.event_value !== ''1''
        && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
    if (params.event_source === ''0'' && params.event_update_status !== ''0'' && params.event_update_status !== ''1'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }


    if (typeof params_redmine.close_status_id === ''string'' && params_redmine.close_status_id.trim() !== '''' && !parseInt(params_redmine.close_status_id, 10)) {
        throw ''Incorrect "redmine_close_status_id" parameter given! Must be an integer.'';
    }

    if (params.event_source !== ''0'' && params.event_value === ''0'') {
        throw ''Recovery operations are supported only for trigger-based actions.'';
    }

    if (params.event_source === ''0''
        && ((params.event_value === ''1'' && params.event_update_status === ''1'')
            || (params.event_value === ''0''
                && (params.event_update_status === ''0'' || params.event_update_status === ''1'')))
        && (isNaN(parseInt(params.redmine_issue_key)) || parseInt(params.redmine_issue_key) < 1 )) {
        throw ''Incorrect "redmine_issue_key" parameter given: '' + params.redmine_issue_key +
            ''\\nMust be positive integer.'';
    }

    if ([0, 1, 2, 3, 4, 5].indexOf(parseInt(params.event_nseverity)) === -1) {
        params.event_nseverity = ''7'';
    }

    if (params.event_value === ''0'') {
        params.event_nseverity = ''6'';
    }

    priority = params[''severity_'' + severities[params.event_nseverity].name];
    priority = priority && priority.trim() || severities[7].name;

    Redmine.setParams(params_redmine);
    Redmine.HTTPProxy = params.HTTPProxy;

    // Create issue for non trigger-based events.
    if (params.event_source !== ''0''
        && params.event_value !== ''0'') {
        Redmine.createIssue(params.alert_subject, params.alert_message, priority);
    }
    // Create issue for trigger-based events.
    else if (params.event_value === ''1'' && params_update.status === ''0'') {
        var issue_id = Redmine.createIssue(params.alert_subject,
            params.alert_subject + ''\\n'' + params.alert_message + ''\\n'' +
            params.zabbix_url + (params.zabbix_url.endsWith(''/'') ? '''' : ''/'') +
            ''tr_events.php?triggerid='' + params.trigger_id + ''&eventid='' + params.event_id + ''\\n'',
            priority,
            params_fields);

        result.tags.__zbx_redmine_issue_id = issue_id;
        result.tags.__zbx_redmine_issuelink = params.redmine_url +
            (params.redmine_url.endsWith(''/'') ? '''' : ''/'') + ''issues/'' + issue_id;
    }
    // Close issue if parameter close_status_id is set and it is a recovery operation
    else if (params.event_value === ''0'' && typeof params_redmine.close_status_id === ''string'' && params_redmine.close_status_id.trim() !== '''') {
        Redmine.updateIssue(params.alert_subject + ''\\n'' + params.alert_message, params_fields, params_redmine.close_status_id);
    }
    // Update created issue for trigger-based event.
    else {
        Redmine.updateIssue(params.alert_subject + ''\\n'' + params.alert_message, params_fields);
    }

    return JSON.stringify(result);
}
catch (error) {
    Zabbix.log(3, ''[ Redmine Webhook ] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','1','1','{EVENT.TAGS.__zbx_redmine_issuelink}','Redmine: issue #{EVENT.TAGS.__zbx_redmine_issue_id}','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('16','4','Telegram','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var Telegram = {
    token: null,
    to: null,
    message: null,
    proxy: null,
    parse_mode: null,

    escapeMarkup: function (str, mode) {
        switch (mode) {
            case ''markdown'':
                return str.replace(/([_*\\[`])/g, ''\\\\$&'');

            case ''markdownv2'':
                return str.replace(/([_*\\[\\]()~`>#+\\-=|{}.!])/g, ''\\\\$&'');

            default:
                return str;
        }
    },

    sendMessage: function () {
        var params = {
            chat_id: Telegram.to,
            text: Telegram.message,
            disable_web_page_preview: true,
            disable_notification: false
        },
        data,
        response,
        request = new HttpRequest(),
        url = ''https://api.telegram.org/bot'' + Telegram.token + ''/sendMessage'';

        if (Telegram.parse_mode !== null) {
            params[''parse_mode''] = Telegram.parse_mode;
        }

        if (Telegram.proxy) {
            request.setProxy(Telegram.proxy);
        }

        request.addHeader(''Content-Type: application/json'');
        data = JSON.stringify(params);

        // Remove replace() function if you want to see the exposed token in the log file.
        Zabbix.log(4, ''[Telegram Webhook] URL: '' + url.replace(Telegram.token, ''<TOKEN>''));
        Zabbix.log(4, ''[Telegram Webhook] params: '' + data);
        response = request.post(url, data);
        Zabbix.log(4, ''[Telegram Webhook] HTTP code: '' + request.getStatus());

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

        if (request.getStatus() !== 200 || typeof response.ok !== ''boolean'' || response.ok !== true) {
            if (typeof response.description === ''string'') {
                throw response.description;
            }
            else {
                throw ''Unknown error. Check debug log for more information.'';
            }
        }
    }
};

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

    if (typeof params.Token === ''undefined'') {
        throw ''Incorrect value is given for parameter "Token": parameter is missing'';
    }

    Telegram.token = params.Token;

    if (params.HTTPProxy) {
        Telegram.proxy = params.HTTPProxy;
    } 

    params.ParseMode = params.ParseMode.toLowerCase();
    
    if ([''markdown'', ''html'', ''markdownv2''].indexOf(params.ParseMode) !== -1) {
        Telegram.parse_mode = params.ParseMode;
    }

    Telegram.to = params.To;
    Telegram.message = params.Subject + ''\\n'' + params.Message;

    if ([''markdown'', ''markdownv2''].indexOf(params.ParseMode) !== -1) {
        Telegram.message = Telegram.escapeMarkup(Telegram.message, params.ParseMode);
    }

    Telegram.sendMessage();

    return ''OK'';
}
catch (error) {
    Zabbix.log(4, ''[Telegram Webhook] notification failed: '' + error);
    throw ''Sending failed: '' + error + ''.'';
}','10s','0','0','','','https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/telegram

1. Register bot: send "/newbot" to @BotFather and follow instructions
2. Copy and paste the obtained token into the "Token" field above
3. If you want to send personal notifications, you need to get chat id of the user you want to send messages to:
    3.1. Send "/getid" to "@myidbot" in Telegram messenger
    3.2. Copy returned chat id and save it in the "Telegram Webhook" media for the user
    3.3. Ask the user to send "/start" to your bot (Telegram bot won''t send anything to the user without it)
4. If you want to send group notifications, you need to get group id of the group you want to send messages to:
    4.1. Add "@myidbot" to your group
    4.2. Send "/getgroupid@myidbot" in your group
    4.3. Copy returned group id save it in the "Telegram Webhook" media for the user you created for  group notifications
    4.4. Send "/start@your_bot_name_here" in your group (Telegram bot won''t send anything to the group without it)');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('17','4','Zendesk','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var Zendesk = {
    params: {},

    setParams: function (params) {
        if (typeof params !== ''object'') {
            return;
        }

        Zendesk.params = params;
        if (typeof Zendesk.params.url === ''string'') {
            if (!Zendesk.params.url.endsWith(''/'')) {
                Zendesk.params.url += ''/'';
            }
            Zendesk.params.url += ''api/v2/'';
        }
    },

    addCustomFields: function (data, fields) {
        if (typeof fields === ''object'' && Object.keys(fields).length) {
            var schema = Zendesk.getSchema(),
                arr = [],
                i,
                n;

            if (schema) {
                Object.keys(fields)
                    .forEach(function(field) {
                        for (i = 0, n = schema.ticket_fields.length; i < n; i++) {
                            if (schema.ticket_fields[i].id == field
                                && [''text'', ''integer'', ''date''].indexOf(schema.ticket_fields[i].type) !== -1){

                                switch (schema.ticket_fields[i].type) {
                                    case ''integer'':
                                        fields[field] = parseInt(fields[field]);
                                        break;
                                    case ''date'':
                                        if (fields[field].match(/^\\d{4}[.-]\\d{2}[.-]\\d{2}$/) !== null) {
                                            fields[field] = fields[field].replace(/\\./g, ''-'');
                                        }
                                        else {
                                            fields[field] = '''';
                                        }
                                        break;
                                }

                                arr.push({id: field, value: fields[field]});
                                break;
                            }
                        }
                    });

                if (arr.length) {
                    data.ticket[''custom_fields''] = arr;
                }
            }
            else {
                Zabbix.log(4, ''[Zendesk Webhook] Failed to retrieve field schema.'');
            }
        }

        return data;
    },

    request: function (method, query, data) {
        [''url'', ''token'', ''type''].forEach(function (field) {
            if (typeof Zendesk.params !== ''object'' || typeof Zendesk.params[field] === ''undefined'') {
                throw ''Required Zendesk param is not set: '' + field + ''\\n'' + Zendesk.params[field];
            }
        });

        var response,
            url = Zendesk.params.url + query,
            request = new HttpRequest();

        if (typeof Zendesk.HTTPProxy === ''string'' && Zendesk.HTTPProxy.trim() !== '''') {
            request.setProxy(Zendesk.HTTPProxy);
        }

        request.addHeader(''Content-Type: application/json'');
        request.addHeader(''Authorization: Basic '' + btoa(Zendesk.params.token));

        if (typeof data !== ''undefined'') {
            data = JSON.stringify(data);
        }

        Zabbix.log(4, ''[Zendesk Webhook] Sending request: '' + url + ((typeof data === ''string'') ? ('' '' + data) : ''''));

        switch (method) {
            case ''get'':
                response = request.get(url, data);
                break;

            case ''post'':
                response = request.post(url, data);
                break;

            case ''put'':
                response = request.put(url, data);
                break;

            default:
                throw ''Unsupported HTTP request method: '' + method;
        }

        Zabbix.log(4, ''[Zendesk Webhook] Received response with status code '' + request.getStatus() + ''. '' + response);

        if (response !== null) {
            try {
                response = JSON.parse(response);
            }
            catch (error) {
                Zabbix.log(4, ''[Zendesk Webhook] Failed to parse response received from Zendesk.'');
            }
        }

        if (request.getStatus() < 200 || request.getStatus() >= 300) {
            var message = ''Request failed with status code '' + request.getStatus();

            if (response !== null && typeof response.error !== ''undefined''
                && Object.keys(response.error).length > 0) {
                message += '': '' + JSON.stringify(response.error);
            }
            else if (response !== null && typeof response.description !== ''undefined''
                && Object.keys(response.description).length > 0) {
                message += '': '' + JSON.stringify(response.description);
            }
            else {
                message += ''. '' + response;
            }
            throw message + ''. Check debug log for more information.'';
        }

        return {
            status: request.getStatus(),
            response: response
        };
    },

    getSchema: function() {
        var result = Zendesk.request(''get'', ''ticket_fields.json'');

        return result.response;
    },

    createIssue: function(data, fields) {
        var result = Zendesk.request(''post'', ''tickets.json'', Zendesk.addCustomFields(data, fields));

        if (typeof result.response !== ''object'' || typeof result.response.ticket.id === ''undefined''
            || result.status != 201) {
            throw ''Cannot create Zendesk issue. Check debug log for more information.'';
        }

        return result.response.ticket.id;
    },

    updateIssue: function(data, fields) {
        Zendesk.request(''put'', ''tickets/'' + Zendesk.params.issue_key + ''.json'', Zendesk.addCustomFields(data, fields));
    }
};

try {
    var params = JSON.parse(value),
        fields = {},
        zendesk = {},
        update = {},
        data = {},
        result = {tags: {}},
        required_params = [
            ''alert_subject'',
            ''alert_message'',
            ''event_id'',
            ''event_source'',
            ''event_value'',
            ''event_update_status''
        ],
        severities = [
            {name: ''not_classified'', color: ''#97AAB3''},
            {name: ''information'', color: ''#7499FF''},
            {name: ''warning'', color: ''#FFC859''},
            {name: ''average'', color: ''#FFA059''},
            {name: ''high'', color: ''#E97659''},
            {name: ''disaster'', color: ''#E45959''},
            {name: ''resolved'', color: ''#009900''},
            {name: ''default'', color: ''#000000''}
        ],
        priority;

    Object.keys(params)
        .forEach(function (key) {
            if (key.startsWith(''zendesk_'')) {
                zendesk[key.substring(8)] = params[key];
            }
            else if (key.startsWith(''customfield_'')) {
                fields[key.substring(12)] = params[key];
            }
            else if (key.startsWith(''event_update_'')) {
                update[key.substring(13)] = params[key];
            }
            else if (required_params.indexOf(key) !== -1 && params[key].trim() === '''') {
                throw ''Parameter '' + key + '' cannot be empty.'';
            }
        });

    // Possible values: question, incident, problems, task
    if ([''question'', ''incident'', ''problem'', ''task''].indexOf(params.zendesk_type) === -1) {
        throw ''Incorrect "zendesk_type" parameter given: '' + params.zendesk_type +
            ''\\nMust be one of question, incident, problem, task.'';
    }

    // Possible values: 0 - Trigger, 1 - Discovery, 2 - Autoregistration, 3 - Internal.
    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: '' + params.event_source + ''\\nMust be 0-3.'';
    }

    // Check {EVENT.VALUE} for trigger-based and internal events.
    // Possible values: 1 for problem, 0 for recovering
    if (params.event_value !== ''0'' && params.event_value !== ''1''
        && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
    // Possible values: 0 - Webhook was called because of problem/recovery event, 1 - Update operation.
    if (params.event_source === ''0'' && params.event_update_status !== ''0'' && params.event_update_status !== ''1'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }

    if (params.event_source !== ''0'' && params.event_value === ''0'') {
        throw ''Recovery operations are supported only for trigger-based actions.'';
    }

    // Zendesk_issue_key must be a positive integer if an update action is being performed.
    if (params.event_source === ''0'' && ((params.event_value === ''1'' && params.event_update_status === ''1'')
        || (params.event_value === ''0'' && (params.event_update_status === ''0'' || params.event_update_status === ''1'')))
        && (isNaN(parseInt(params.zendesk_issue_key)) || parseInt(params.zendesk_issue_key) < 1 )) {
        throw ''Incorrect "zendesk_issue_key" parameter given: '' + params.zendesk_issue_key +
            ''\\nMust be positive integer.'';
    }

    if ([0, 1, 2, 3, 4, 5].indexOf(parseInt(params.event_nseverity)) === -1) {
        params.event_nseverity = ''7'';
    }

    if (params.event_value === ''0'') {
        params.event_nseverity = ''6'';
    }

    priority = params[''severity_'' + severities[params.event_nseverity].name] || severities[7].name;

    Zendesk.setParams(zendesk);
    Zendesk.HTTPProxy = params.HTTPProxy;

    // Create issue for non trigger-based events.
    if (params.event_source !== ''0'' && params.event_value !== ''0'') {
        data = {
            ticket: {
                external_id: params.event_id,
                type: Zendesk.params.type,
                status: ''new'',
                subject: params.alert_subject,
                comment: {
                    body: params.alert_message,
                    public: ''false''
                },
                priority: priority,
                tags: params.event_tags
            }
        };

        Zendesk.createIssue(data, fields);
    }
    // Create issue for trigger-based events.
    else if (params.event_value === ''1'' && update.status === ''0'') {
        data = {
            ticket: {
                external_id: params.event_id,
                type: Zendesk.params.type,
                status: ''new'',
                subject: params.alert_subject,
                comment: {
                    body: params.zbxurl + (params.zbxurl.endsWith(''/'') ? '''' : ''/'') + ''tr_events.php?triggerid='' +
                        params.trigger_id + ''&eventid='' + params.event_id + ''\\n'' + params.alert_message,
                    public: ''false''
                },
                priority: priority,
                tags: params.event_tags
            }
        };
        var key = Zendesk.createIssue(data, fields);

        result.tags.__zbx_zdk_issuekey = key;
        result.tags.__zbx_zdk_issuelink = params.zendesk_url +
            (params.zendesk_url.endsWith(''/'') ? '''' : ''/'') + ''agent/tickets/'' + key;
    }
    // Update created issue for trigger-based event.
    else {
        data = {
            ticket: {
                type: Zendesk.params.type,
                subject: params.alert_subject,
                comment: {
                    body: params.alert_message,
                    public: ''false''
                }
            }
        };

        Zendesk.updateIssue(data, fields);
    }

    return JSON.stringify(result);
}
catch (error) {
    Zabbix.log(3, ''[Zendesk Webhook] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','1','1','{EVENT.TAGS.__zbx_zdk_issuelink}','Zendesk: {EVENT.TAGS.__zbx_zdk_issuekey}','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('18','4','ServiceNow','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var ServiceNow = {
    params: {},

    setParams: function (params) {
        if (typeof params !== ''object'') {
            return;
        }

        ServiceNow.params = params;
        if (typeof ServiceNow.params.url === ''string'') {
            if (!ServiceNow.params.url.endsWith(''/'')) {
                ServiceNow.params.url += ''/'';
            }

            ServiceNow.params.url += ''api/now/table/incident'';
        }
    },

    setProxy: function (HTTPProxy) {
        ServiceNow.HTTPProxy = HTTPProxy;
    },

    setFields: function (data, fields) {
        if (typeof fields === ''object'' && Object.keys(fields).length) {
            Object.keys(fields)
                .forEach(function(field) {
                    data[field] = (fields[field].match(/^\\d{4}\\.\\d{2}\\.\\d{2}$/) !== null)
                        ? fields[field].replace(/\\./g, ''-'')
                        : fields[field];
                });
        }
    },

    request: function (method, data) {
        [''url'', ''user'', ''password''].forEach(function (field) {
            if (typeof ServiceNow.params !== ''object'' || typeof ServiceNow.params[field] === ''undefined''
                || ServiceNow.params[field] === '''' ) {
                throw ''Required ServiceNow param is not set: "'' + field + ''".'';
            }
        });

        var response,
            url = ServiceNow.params.url,
            request = new HttpRequest();

        request.addHeader(''Content-Type: application/json'');
        request.addHeader(''Authorization: Basic '' + btoa(ServiceNow.params.user + '':'' + ServiceNow.params.password));

        if (typeof ServiceNow.HTTPProxy !== ''undefined'' && ServiceNow.HTTPProxy !== '''') {
            request.setProxy(ServiceNow.HTTPProxy);
        }

        if (typeof data !== ''undefined'') {
            data = JSON.stringify(data);
        }

        Zabbix.log(4, ''[ ServiceNow Webhook ] Sending request: '' + url + ((typeof data === ''string'')
            ? (''\\n'' + data)
            : ''''));

        switch (method) {
            case ''get'':
                response = request.get(url, data);
                break;

            case ''post'':
                response = request.post(url, data);
                break;

            case ''put'':
                response = request.put(url, data);
                break;

            default:
                throw ''Unsupported HTTP request method: '' + method;
        }

        Zabbix.log(4, ''[ ServiceNow Webhook ] Received response with status code '' +
            request.getStatus() + ''\\n'' + response);

        if (response !== null) {
            try {
                response = JSON.parse(response);
            }
            catch (error) {
                Zabbix.log(4, ''[ ServiceNow Webhook ] Failed to parse response received from ServiceNow'');
                response = null;
            }
        }

        if (request.getStatus() < 200 || request.getStatus() >= 300) {
            var message = ''Request failed with status code '' + request.getStatus();

            if (response !== null && typeof response.error.message !== ''undefined''
                && Object.keys(response.error).length > 0) {
                message += '': '' + JSON.stringify(response.error.message);
            }

            throw message + '' Check debug log for more information.'';
        }
        else if (typeof response.result !== ''object'' || typeof response.result.sys_id === ''undefined'') {
            throw ''Cannot create ServiceNow incident. Check debug log for more information.'';
        }

        return response.result;
    }
};

try {
    var params = JSON.parse(value),
        fields = {},
        servicenow = {},
        data = {},
        result = {tags: {}},
        required_params = [
            ''alert_subject'', ''alert_message'', ''event_source'', ''event_value'',
            ''event_update_status'', ''event_recovery_value'', ''event_nseverity''
        ],
        severities = [
            {name: ''not_classified'', color: ''#97AAB3''},
            {name: ''information'', color: ''#7499FF''},
            {name: ''warning'', color: ''#FFC859''},
            {name: ''average'', color: ''#FFA059''},
            {name: ''high'', color: ''#E97659''},
            {name: ''disaster'', color: ''#E45959''},
            {name: ''resolved'', color: ''#009900''},
            {name: ''default'', color: ''#000000''}
        ],
        method = ''post'',
        process_tags = true;

    Object.keys(params)
        .forEach(function (key) {
            if (key.startsWith(''servicenow_'')) {
                servicenow[key.substring(11)] = params[key];
            }
            else if (key.startsWith(''u_'')) {
                fields[key] = params[key];
            }
            else if (required_params.indexOf(key) !== -1 && params[key] === '''') {
                throw ''Parameter "'' + key + ''" can\\''t be empty.'';
            }
        });

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: '' + params.event_source + ''\\nMust be 0-3.'';
    }

    if ([0, 1, 2, 3, 4, 5].indexOf(parseInt(params.event_nseverity)) === -1) {
        params.event_nseverity = ''7'';
    }

    // Check {EVENT.VALUE} for trigger-based and internal events.
    if (params.event_value !== ''0'' && params.event_value !== ''1''
        && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
    if (params.event_update_status !== ''0'' && params.event_update_status !== ''1'' && params.event_source === ''0'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }

    if (params.event_source !== ''0'' && params.event_recovery_value === ''0'') {
        throw ''Recovery operations are supported only for trigger-based actions.'';
    }

    data.short_description = params.alert_subject;
    data.description = params.alert_message;
    data.comments = params.alert_message;

    if (typeof params[''urgency_for_'' + severities[params.event_nseverity].name] !== ''undefined'') {
        data.urgency = params[''urgency_for_'' + severities[params.event_nseverity].name];
    }

    ServiceNow.setParams(servicenow);
    ServiceNow.setProxy(params.HTTPProxy);
    ServiceNow.setFields(data, fields);

    if (params.event_source === ''0'' && (params.event_value === ''0'' || params.event_update_status === ''1'')) {
        process_tags = false;
        method = ''put'';
        delete data.description;
        delete data.urgency;
        ServiceNow.params.url += ''/'' + params.servicenow_sys_id;
    }

    var response = ServiceNow.request(method, data);

    if (process_tags) {
        result.tags.__zbx_servicenow_sys_id = response.sys_id;
        result.tags.__zbx_servicenow_link = params.servicenow_url +
            (params.servicenow_url.endsWith(''/'') ? '''' : ''/'') + ''incident.do?sys_id='' + response.sys_id;
        result.tags.__zbx_servicenow_number = response.number;
    }

    return JSON.stringify(result);
}
catch (error) {
    Zabbix.log(3, ''[ ServiceNow Webhook ] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','1','1','{EVENT.TAGS.__zbx_servicenow_link}','ServiceNow: {EVENT.TAGS.__zbx_servicenow_number}','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('19','4','Zammad','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var Zammad = {
    params: {},

    setParams: function (params) {
        if (typeof params !== ''object'') {
            return;
        }

        Zammad.params = params;
        if (typeof Zammad.params.url === ''string'') {
            if (!Zammad.params.url.endsWith(''/'')) {
                Zammad.params.url += ''/'';
            }
        }
    },

    request: function (method, query, data) {
        [''url'', ''access_token''].forEach(function (field) {
            if (typeof Zammad.params !== ''object'' || typeof Zammad.params[field] === ''undefined''
                || Zammad.params[field] === '''' ) {
                throw ''Required param is not set: "'' + field + ''".'';
            }
        });

        var response,
            url = Zammad.params.url + query,
            request = new HttpRequest();

        if (typeof Zammad.HTTPProxy === ''string'' && Zammad.HTTPProxy.trim() !== '''') {
            request.setProxy(Zammad.HTTPProxy);
        }

        request.addHeader(''Content-Type: application/json'');
        request.addHeader(''Authorization: Token token='' + Zammad.params.access_token);

        if (typeof data !== ''undefined'') {
            data = JSON.stringify(data);
        }

        Zabbix.log(4, ''[ Zammad Webhook ] Sending request: '' +
            url + ((typeof data === ''string'') ? ('' '' + data) : ''''));

        switch (method) {
            case ''get'':
                response = request.get(url, data);
                break;

            case ''post'':
                response = request.post(url, data);
                break;

            case ''put'':
                response = request.put(url, data);
                break;

            default:
                throw ''Unsupported HTTP request method: '' + method;
        }

        Zabbix.log(4, ''[ Zammad Webhook ] Received response with status code '' + request.getStatus() + '': '' + response);

        if (response !== null) {
            try {
                response = JSON.parse(response);
            }
            catch (error) {
                Zabbix.log(4, ''[ Zammad Webhook ] Failed to parse response received from Zammad'');
                response = null;
            }
        }

        if (request.getStatus() < 200 || request.getStatus() >= 300) {
            var message = ''Request failed with status code '' + request.getStatus();

            if (response !== null && typeof response.errors !== ''undefined''
                && Object.keys(response.errors).length > 0) {
                message += '': '' + JSON.stringify(response.errors);
            }
            else if (response !== null && typeof response.errorMessages !== ''undefined''
                && Object.keys(response.errorMessages).length > 0) {
                message += '': '' + JSON.stringify(response.errorMessages);
            }

            throw message + '' Check debug log for more information.'';
        }

        return {
            status: request.getStatus(),
            response: response
        };
    },

    setTicketTags: function (tags, ticket_id) {
        var data = {
            item: '''',
            object: ''Ticket'',
            o_id: ticket_id
        };

        try {
            var tags_json = JSON.parse(tags),
                result;

            for (var i in tags_json) {

                if (tags_json[i].value) {
                    data.item = tags_json[i].tag + ": " + tags_json[i].value;
                } else {
                    data.item = tags_json[i].tag;
                }
                result = Zammad.request(''post'', ''api/v1/tags/add'', data);

                if (typeof result.response !== ''object'' || result.status != 200) {
                    Zabbix.log(4, ''[ Zammad Webhook ] Cannot add ticket tag:'' + tags_json[i].tag);
                }
            }
        }
        catch (error) {
            Zabbix.log(4, ''[ Zammad Webhook ] Failed to add ticket tags:'' + error);
        }

        return;
    },

    createTicket: function(subject, message, priority) {
        var data = {
                title: subject,
                group: ''Users'',
                article: {
                    subject: subject,
                    body: message,
                    type: ''note'',
                    internal: false
                },
                customer: Zammad.params.customer
            },
            result;

        if (priority) {
            data.priority_id = priority;
        }

        result = Zammad.request(''post'', ''api/v1/tickets'', data);

        if (typeof result.response !== ''object''
            || typeof result.response.id === ''undefined''
            || result.status != 201) {
            throw ''Cannot create Zammad ticket. Check debug log for more information.'';
        }

        return result.response.id;
    },

    updateTicket: function(subject, message) {
        var data = {
            ticket_id: Zammad.params.ticket_id,
            subject: subject,
            body: message || '''',
            type: ''note'',
            internal: false
        };

        result = Zammad.request(''post'', ''api/v1/ticket_articles'', data);

        if (typeof result.response !== ''object''
            || typeof result.response.id === ''undefined''
            || result.status != 201) {
            throw ''Cannot update Zammad ticket. Check debug log for more information.'';
        }
    }
};

try {
    var params = JSON.parse(value),
        params_zammad = {},
        params_update = {},
        result = {tags: {}},
        required_params = [
            ''alert_subject'', ''customer'',
            ''event_source'', ''event_value'',
            ''event_update_status''
        ],
        severities = [
            {name: ''not_classified'', color: ''#97AAB3''},
            {name: ''information'', color: ''#7499FF''},
            {name: ''warning'', color: ''#FFC859''},
            {name: ''average'', color: ''#FFA059''},
            {name: ''high'', color: ''#E97659''},
            {name: ''disaster'', color: ''#E45959''},
            {name: ''resolved'', color: ''#009900''},
            {name: null, color: ''#000000''}
        ],
        priority;

    Object.keys(params)
        .forEach(function (key) {
            if (key.startsWith(''zammad_'')) {
                params_zammad[key.substring(7)] = params[key].trim();
            }
            else if (key.startsWith(''event_update_'')) {
                params_update[key.substring(13)] = params[key];
            }
            else if (required_params.indexOf(key) !== -1 && params[key].trim() === '''') {
                throw ''Parameter "'' + key + ''" cannot be empty.'';
            }
        });

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: '' + params.event_source + ''\\nMust be 0-3.'';
    }

    // Check {EVENT.VALUE} for trigger-based and internal events.
    if (params.event_value !== ''0'' && params.event_value !== ''1''
        && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
    if (params.event_source === ''0'' && params.event_update_status !== ''0'' && params.event_update_status !== ''1'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }

    if (params.event_source !== ''0'' && params.event_value === ''0'') {
        throw ''Recovery operations are supported only for trigger-based actions.'';
    }

    if (params.event_source === ''0''
        && ((params.event_value === ''1'' && params.event_update_status === ''1'')
            || (params.event_value === ''0''
                && (params.event_update_status === ''0'' || params.event_update_status === ''1'')))
        && (isNaN(parseInt(params.zammad_ticket_id)) || parseInt(params.zammad_ticket_id) < 1 )) {
        throw ''Incorrect "zammad_ticket_id" parameter given: '' + params.zammad_ticket_id +
            ''\\nMust be positive integer.'';
    }

    if ([0, 1, 2, 3, 4, 5].indexOf(parseInt(params.event_nseverity)) === -1) {
        params.event_nseverity = ''7'';
    }

    if (params.event_value === ''0'') {
        params.event_nseverity = ''6'';
    }

    priority = params[''severity_'' + severities[params.event_nseverity].name];
    priority = priority && priority.trim() || severities[7].name;

    Zammad.setParams(params_zammad);
    Zammad.HTTPProxy = params.HTTPProxy;

    // Create ticket for non trigger-based events.
    if (params.event_source !== ''0''
        && params.event_value !== ''0'') {
        Zammad.createTicket(params.alert_subject, params.alert_message, priority, params.event_tags);
    }
    // Create ticket for trigger-based events.
    else if (params.event_value === ''1'' && params_update.status === ''0'') {
        var ticket_id = Zammad.createTicket(params.alert_subject,
            params.alert_subject + ''\\n'' + params.alert_message + ''\\n'' +
            params.zabbix_url + (params.zabbix_url.endsWith(''/'') ? '''' : ''/'') +
            ''tr_events.php?triggerid='' + params.trigger_id + ''&eventid='' + params.event_id + ''\\n'',
            priority);

        result.tags.__zbx_zammad_ticket_id = ticket_id;
        result.tags.__zbx_zammad_ticketlink = params.zammad_url +
            (params.zammad_url.endsWith(''/'') ? '''' : ''/'') + ''#ticket/zoom/'' + ticket_id;

        if (Zammad.params.enable_tags.toLowerCase() === ''true'') {
            Zammad.setTicketTags(params.event_tags, ticket_id);
        }
    }
    // Update created ticket for trigger-based event.
    else {
        Zammad.updateTicket(params.alert_subject, params.alert_message);
    }

    return JSON.stringify(result);
}
catch (error) {
    Zabbix.log(3, ''[ Zammad Webhook ] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','1','1','{EVENT.TAGS.__zbx_zammad_ticketlink}','Zammad: ticket #{EVENT.TAGS.__zbx_zammad_ticket_id}','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('20','4','Jira ServiceDesk','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var Jira = {
    params: {},
    schema: {},

    setParams: function (params) {
        if (typeof params !== ''object'') {
            return;
        }

        Jira.params = params;
        if (typeof Jira.params.url === ''string'') {
            if (!Jira.params.url.endsWith(''/'')) {
                Jira.params.url += ''/'';
            }

            Jira.params.url += ''rest/servicedeskapi/'';
        }
    },

    setProxy: function (HTTPProxy) {
        Jira.HTTPProxy = HTTPProxy;
    },

    setTags: function(event_tags_json) {
        if (!Jira.schema) {
            Zabbix.log(4, ''[ Jira Service Desk Webhook ] Cannot add labels because failed to retrieve field schema.'');

            return;
        }

        var block = Jira.schema.requestTypeFields.filter(function(object) {
            return object.fieldId == ''labels'';
        });

        if (block[0] && typeof event_tags_json !== ''undefined'' && event_tags_json !== ''''
            && event_tags_json !== ''{EVENT.TAGSJSON}'') {
            try {
                var tags = JSON.parse(event_tags_json),
                    label;

                Jira.labels = [];

                tags.forEach(function (tag) {
                    if (typeof tag.tag !== ''undefined'' && typeof tag.value !== ''undefined'' ) {
                        label = (tag.tag + (tag.value ? ('':'' + tag.value) : '''')).replace(/\\s/g, ''_'');
                        if (label.length < 255) {
                            Jira.labels.push(label);
                        }
                    }
                });
            }
            catch (error) {
                // Code is not missing here.
            }
        }
    },

    addCustomFields: function (data, fields) {
        if (typeof fields === ''object'' && Object.keys(fields).length) {
            if (Jira.schema) {
                Object.keys(fields)
                    .forEach(function(field) {
                        data.requestFieldValues[field] = fields[field];

                        var block = Jira.schema.requestTypeFields.filter(function(object) {
                            return object.fieldId == field;
                        });

                        if (typeof block[0] === ''object'' && typeof block[0].jiraSchema === ''object''
                            && (block[0].jiraSchema.type === ''number'' || block[0].jiraSchema.type === ''datetime'')) {
                            switch (block[0].jiraSchema.type) {
                                case ''number'':
                                    data.requestFieldValues[field] = parseInt(fields[field]);
                                    break;

                                case ''datetime'':
                                    if (fields[field].match(/\\d+[.-]\\d+[.-]\\d+T\\d+:\\d+:\\d+/) !== null) {
                                        data.requestFieldValues[field] = fields[field].replace(/\\./g, ''-'');
                                    }
                                    else {
                                        delete data.requestFieldValues[field];
                                    }
                                    break;
                            }
                        }
                    });
            }
            else {
                Zabbix.log(4, ''[ Jira Service Desk Webhook ] Cannot add custom fields'' +
                    ''because failed to retrieve field schema.'');
            }
        }

        return data;
    },

    request: function (method, query, data) {
        [''url'', ''user'', ''password'', ''servicedesk_id'', ''request_type_id''].forEach(function (field) {
            if (typeof Jira.params !== ''object'' || typeof Jira.params[field] === ''undefined''
                || Jira.params[field] === '''' ) {
                throw ''Required Jira param is not set: "'' + field + ''".'';
            }
        });

        var response,
            url = Jira.params.url + query,
            request = new HttpRequest();

        request.addHeader(''Content-Type: application/json'');
        request.addHeader(''Authorization: Basic '' + btoa(Jira.params.user + '':'' + Jira.params.password));
        request.addHeader(''X-ExperimentalApi: opt-in'');

        if (typeof Jira.HTTPProxy !== ''undefined'' && Jira.HTTPProxy !== '''') {
            request.setProxy(Jira.HTTPProxy);
        }

        if (typeof data !== ''undefined'') {
            data = JSON.stringify(data);
        }

        Zabbix.log(4, ''[ Jira Service Desk Webhook ] Sending request: '' + url +
            ((typeof data === ''string'') ? (''\\n'' + data) : ''''));

        switch (method) {
            case ''get'':
                response = request.get(url, data);
                break;

            case ''post'':
                response = request.post(url, data);
                break;

            case ''put'':
                response = request.put(url, data);
                break;

            default:
                throw ''Unsupported HTTP request method: '' + method;
        }

        Zabbix.log(4, ''[ Jira Service Desk Webhook ] Received response with status code '' +
            request.getStatus() + ''\\n'' + response);

        if (response !== null) {
            try {
                response = JSON.parse(response);
            }
            catch (error) {
                Zabbix.log(4, ''[ Jira Service Desk Webhook ] Failed to parse response received from Jira'');
                response = null;
            }
        }

        if (request.getStatus() < 200 || request.getStatus() >= 300) {
            var message = ''Request failed with status code '' + request.getStatus();

            if (response !== null && typeof response.errors !== ''undefined''
                && Object.keys(response.errors).length > 0) {
                message += '': '' + JSON.stringify(response.errors);
            }
            else if (response !== null && typeof response.errorMessage !== ''undefined''
                && Object.keys(response.errorMessage).length > 0) {
                message += '': '' + JSON.stringify(response.errorMessage);
            }

            throw message + '' Check debug log for more information.'';
        }

        return {
            status: request.getStatus(),
            response: response
        };
    },

    getSchema: function() {
        var result = Jira.request(''get'', ''servicedesk/'' + Jira.params.servicedesk_id + ''/requesttype/'' +
            Jira.params.request_type_id + ''/field'');

        if (typeof Jira.schema !== ''object'' && typeof Jira.schema.requestTypeFields !== ''object'') {
            Jira.schema = null;
        }
        else {
            Jira.schema = result.response;
        }
    },

    createRequest: function(summary, description, fields) {
        var data = {
            serviceDeskId: Jira.params.servicedesk_id,
            requestTypeId: Jira.params.request_type_id,
            requestFieldValues: {
                summary: summary,
                description: description
            }
        };

        if (Jira.labels && Jira.labels.length > 0) {
            data.requestFieldValues.labels = Jira.labels;
        }
        var result = Jira.request(''post'', ''request'', Jira.addCustomFields(data, fields));

        if (typeof result.response !== ''object'' || typeof result.response.issueKey === ''undefined'') {
            throw ''Cannot create Jira request. Check debug log for more information.'';
        }

        return result.response.issueKey;
    }
};

try {
    var params = JSON.parse(value),
        fields = {},
        jira = {},
        comment = {public: true},
        result = {tags: {}},
        required_params = [
            ''alert_subject'', ''alert_message'', ''event_source'', ''event_value'',
            ''event_update_status'', ''event_recovery_value''
        ];

    Object.keys(params)
        .forEach(function (key) {
            if (key.startsWith(''jira_'')) {
                jira[key.substring(5)] = params[key];
            }
            else if (key.startsWith(''customfield_'')) {
                fields[key] = params[key];
            }
            else if (required_params.indexOf(key) !== -1 && params[key] === '''') {
                throw ''Parameter "'' + key + ''" cannot be empty.'';
            }
        });

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: '' + params.event_source + ''\\nMust be 0-3.'';
    }

    // Check {EVENT.VALUE} for trigger-based and internal events.
    if (params.event_value !== ''0'' && params.event_value !== ''1''
        && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
    if (params.event_update_status !== ''0'' && params.event_update_status !== ''1'' && params.event_source === ''0'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }

    if (params.event_source !== ''0'' && params.event_recovery_value === ''0'') {
        throw ''Recovery operations are supported only for trigger-based actions.'';
    }

    Jira.setParams(jira);
    Jira.setProxy(params.HTTPProxy);
    Jira.getSchema();
    Jira.setTags(params.event_tags_json);

    // Create request for non trigger-based events.
    if (params.event_source !== ''0'' && params.event_recovery_value !== ''0'') {
        Jira.createRequest(params.alert_subject, params.alert_message);
    }
    // Create request for trigger-based events.
    else if (params.event_value === ''1'' && params.event_update_status === ''0''
        && jira.request_key === ''{EVENT.TAGS.__zbx_jira_requestkey}'') {
        var key = Jira.createRequest(params.alert_subject, params.alert_message, fields);

        result.tags.__zbx_jira_requestkey = key;
        result.tags.__zbx_jira_requestlink = params.jira_url +
            (params.jira_url.endsWith(''/'') ? '''' : ''/'') + ''browse/'' + key;
    }
    // Comment created request for trigger-based event.
    else {
        if (jira.request_key === ''{EVENT.TAGS.__zbx_jira_requestkey}'' || jira.request_key.trim() === '''') {
            throw ''Incorrect Request key given: '' + jira.request_key;
        }
        comment.body = params.alert_message;
        Jira.request(''post'', ''request/'' + Jira.params.request_key + ''/comment'', comment);
    }

    return JSON.stringify(result);
}
catch (error) {
    Zabbix.log(3, ''[ Jira Service Desk Webhook ] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','1','1','{EVENT.TAGS.__zbx_jira_requestlink}','Jira ServiceDesk: {EVENT.TAGS.__zbx_jira_requestkey}','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('21','4','OTRS','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var OTRS = {
    params: {},
    entrypoint: ''nph-genericinterface.pl/Webservice/ZabbixTicketConnector/Ticket'',

    setParams: function (params) {
        if (typeof params !== ''object'') {
            return;
        }

        OTRS.params = params;
        if (typeof OTRS.params.url === ''string'') {
            if (!OTRS.params.url.endsWith(''/'')) {
                OTRS.params.url += ''/'';
            }
        }
    },

    addDynamicFields: function (data, fields) {
        if (typeof fields === ''object'' && Object.keys(fields).length) {
            data.DynamicField = [];

            Object.keys(fields)
                .forEach(function(field) {
                    if (field !== undefined) {
                        if (fields[field].match(/^\\d{4}[.-]\\d{2}[.-]\\d{2}$/)) {
                            fields[field] = fields[field].replace(/\\./g, ''-'');
                        }

                        data.DynamicField.push({Name: field, Value: fields[field]});
                    }
                });
        }

        return data;
    },

    request: function (method, query, data) {
        [''url'', ''auth_user'', ''auth_password'', ''queue'',
            ''customer'', ''ticket_state'', ''default_priority_id'', ''time_unit''].forEach(function (field) {
            if (typeof OTRS.params !== ''object'' || typeof OTRS.params[field] === ''undefined''
                || OTRS.params[field] === '''' ) {
                throw ''Required param is not set: "'' + field + ''".'';
            }
        });

        var response,
            request = new HttpRequest(),
            url = OTRS.params.url + query +
                ''?UserLogin='' + encodeURIComponent(OTRS.params.auth_user) +
                ''&Password='' + encodeURIComponent(OTRS.params.auth_password);

        if (typeof OTRS.HTTPProxy !== ''undefined'' && OTRS.HTTPProxy.trim() !== '''') {
            request.setProxy(OTRS.HTTPProxy);
        }

        request.addHeader(''Content-Type: application/json'');

        if (typeof data !== ''undefined'') {
            data = JSON.stringify(data);
        }

        Zabbix.log(4, ''[ OTRS Webhook ] Sending request: '' +
            url + ((typeof data === ''string'') ? ('' '' + data) : ''''));

        switch (method) {
            case ''get'':
                response = request.get(url, data);
                break;

            case ''post'':
                response = request.post(url, data);
                break;

            case ''put'':
                response = request.put(url, data);
                break;

            default:
                throw ''Unsupported HTTP request method: '' + method;
        }

        Zabbix.log(4, ''[ OTRS Webhook ] Received response with status code '' + request.getStatus() + '': '' + response);

        if (request.getStatus() < 200 || request.getStatus() >= 300) {
            var message = ''Request failed with status code '' + request.getStatus();

            message += '': '' + response;
            throw message + '' Check debug log for more information.'';
        }

        if (response !== null) {
            try {
                response = JSON.parse(response);
            }
            catch (error) {
                Zabbix.log(4, ''[ OTRS Webhook ] Failed to parse response received from OTRS'');
                response = null;
            }
        }

        if (typeof response.Error !== ''undefined''
            && Object.keys(response.Error).length > 0) {
            message = ''Request failed: '' + JSON.stringify(response.Error);
        }


        return {
            status: request.getStatus(),
            response: response
        };
    },

    createTicket: function(subject, message, priority, fields) {
        var result,
            data = {
                Ticket: {
                    Title: subject,
                    Queue: OTRS.params.queue,
                    State: OTRS.params.ticket_state,
                    PriorityID: priority || OTRS.params.default_priority_id,
                    CustomerUser: OTRS.params.customer
                },
                Article: {
                    Subject: subject,
                    Body: message,
                    TimeUnit: OTRS.params.time_unit,
                    ContentType: ''text/plain; charset=utf8''
                }
            };

        result = OTRS.request(''post'', OTRS.entrypoint, OTRS.addDynamicFields(data, fields));

        if (typeof result.response !== ''object''
            || typeof result.response.TicketID === ''undefined''
            || result.status != 200) {
            throw ''Cannot create OTRS ticket. Check debug log for more information.'';
        }

        return result.response.TicketID;
    },

    updateTicket: function(subject, message) {
        var result,
            data = {
                Article: {
                    Subject: subject,
                    Body: message || '''',
                    TimeUnit: OTRS.params.time_unit,
                    ContentType: ''text/plain; charset=utf8''
                }
            };

        result = OTRS.request(''put'', OTRS.entrypoint + ''/'' + encodeURIComponent(OTRS.params.ticket_id), data);

        if (typeof result.response !== ''object''
            || typeof result.response.TicketID === ''undefined''
            || result.status != 200) {
            throw ''Cannot update OTRS ticket. Check debug log for more information.'';
        }
    }
};

try {
    var params = JSON.parse(value),
        params_otrs = {},
        params_fields = {},
        params_update = {},
        result = {tags: {}},
        required_params = [
            ''alert_subject'', ''event_source'',
            ''event_value'',  ''event_update_status''
        ],
        severities = [
            {name: ''not_classified'', color: ''#97AAB3''},
            {name: ''information'', color: ''#7499FF''},
            {name: ''warning'', color: ''#FFC859''},
            {name: ''average'', color: ''#FFA059''},
            {name: ''high'', color: ''#E97659''},
            {name: ''disaster'', color: ''#E45959''},
            {name: ''resolved'', color: ''#009900''},
            {name: null, color: ''#000000''}
        ],
        priority;

    Object.keys(params)
        .forEach(function (key) {
            if (key.startsWith(''otrs_'')) {
                params_otrs[key.substring(5)] = params[key];
            }
            else if (key.startsWith(''dynamicfield_'')) {
                params_fields[key.substring(13)] = params[key];
            }
            else if (key.startsWith(''event_update_'')) {
                params_update[key.substring(13)] = params[key];
            }
            else if (required_params.indexOf(key) !== -1 && params[key].trim() === '''') {
                throw ''Parameter "'' + key + ''" cannot be empty.'';
            }
        });

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: '' + params.event_source + ''\\nMust be 0-3.'';
    }

    // Check {EVENT.VALUE} for trigger-based and internal events.
    if (params.event_value !== ''0'' && params.event_value !== ''1''
        && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
    if (params.event_source === ''0'' && params.event_update_status !== ''0'' && params.event_update_status !== ''1'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }

    if (params.event_source !== ''0'' && params.event_value === ''0'') {
        throw ''Recovery operations are supported only for trigger-based actions.'';
    }

    if (params.event_source === ''0''
        && ((params.event_value === ''1'' && params.event_update_status === ''1'')
            || (params.event_value === ''0''
                && (params.event_update_status === ''0'' || params.event_update_status === ''1'')))
        && (isNaN(parseInt(params.otrs_ticket_id)) || parseInt(params.otrs_ticket_id) < 1 )) {
        throw ''Incorrect "otrs_ticket_id" parameter given: '' + params.otrs_ticket_id +
            ''\\nMust be positive integer.'';
    }

    if ([0, 1, 2, 3, 4, 5].indexOf(parseInt(params.event_nseverity)) === -1) {
        params.event_nseverity = ''7'';
    }

    if (params.event_value === ''0'') {
        params.event_nseverity = ''6'';
    }

    priority = params[''severity_'' + severities[params.event_nseverity].name];
    priority = priority && priority.trim() || severities[7].name;

    OTRS.setParams(params_otrs);
    OTRS.HTTPProxy = params.HTTPProxy;

    // Create ticket for non trigger-based events.
    if (params.event_source !== ''0''
        && params.event_value !== ''0'') {
        OTRS.createTicket(params.alert_subject, params.alert_message, priority);
    }
    // Create ticket for trigger-based events.
    else if (params.event_value === ''1'' && params_update.status === ''0'') {
        var ticket_id = OTRS.createTicket(params.alert_subject,
            params.alert_subject + ''\\n'' + params.alert_message + ''\\n'' +
            params.zabbix_url + (params.zabbix_url.endsWith(''/'') ? '''' : ''/'') +
            ''tr_events.php?triggerid='' + params.trigger_id + ''&eventid='' + params.event_id + ''\\n'',
            priority,
            params_fields);

        result.tags.__zbx_otrs_ticket_id = ticket_id;
        result.tags.__zbx_otrs_ticketlink = params.otrs_url +
            (params.otrs_url.endsWith(''/'') ? '''' : ''/'') + ''index.pl?Action=AgentTicketZoom;TicketID='' + ticket_id;
    }
    // Update created ticket for trigger-based event.
    else {
        OTRS.updateTicket(params.alert_subject, params.alert_message);
    }

    return JSON.stringify(result);
}
catch (error) {
    Zabbix.log(3, ''[ OTRS Webhook ] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','1','1','{EVENT.TAGS.__zbx_otrs_ticketlink}','OTRS: ticket #{EVENT.TAGS.__zbx_otrs_ticket_id}','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('22','4','iLert','','','','','','','','0','25','0','0','0','0','','1','3','10s','1','try {
    var result = { tags: {} },
        params = JSON.parse(value),
        req = new HttpRequest(),
        resp = '''';

    if (typeof params.HTTPProxy === ''string'' && params.HTTPProxy.trim() !== '''') {
        req.setProxy(params.HTTPProxy);
    }
    var alertSourceKey = params[''.ILERT.ALERT.SOURCE.KEY''];
    if (!alertSourceKey || (typeof alertSourceKey === ''string'' && alertSourceKey.trim() === '''')) {
        throw ''incorrect value for variable "ILERT.ALERT.SOURCE.KEY". The value must be a non-empty string.'';
    }
    delete params[''.ILERT.ALERT.SOURCE.KEY''];
    
    var ilertApiBaseURL = "https://api.ilert.com";
    var reqURL = encodeURI(ilertApiBaseURL + "/api/v1/events/zabbix-mt/" + alertSourceKey)

    var incidentKey = "zabbix-" + params[''EVENT.ID''];
    var incidentViewURL = ilertApiBaseURL + "/api/v1/incidents/resolve-ik/" + alertSourceKey + "/" + incidentKey;

    req.addHeader(''Accept: application/json'');
    req.addHeader(''Content-Type: application/json'');

    Zabbix.log(4, ''[iLert Webhook] Sending request:'' + JSON.stringify(params));
    resp = req.post(reqURL, JSON.stringify(params));
    Zabbix.log(4, ''[iLert Webhook] Receiving response:'' + resp);

    try {
        resp = JSON.parse(resp);
    }
    catch (error) {
        throw ''incorrect response. iLert returned a non-JSON object.'';
    }

    if (req.getStatus() == 200) {
        result.tags.__ilert_incident_url = incidentViewURL;
        return JSON.stringify(result);
    }

    if (req.getStatus() == 400 && typeof resp === ''object'' && typeof resp.code === ''string'') {
        if (resp.code === ''NO_OPEN_INCIDENT_WITH_KEY'') {
          return JSON.stringify(result);
        }
        if (resp.code === ''INCIDENT_ALREADY_ACCEPTED'') {
          result.tags.__ilert_incident_url = incidentViewURL;
          return JSON.stringify(result);
        }
    }

    if (typeof resp === ''object'' && typeof resp.message === ''string'') {
        throw resp.message;
    }
    else {
        throw ''Unknown error.'';
    }
}
catch (error) {
    Zabbix.log(3, ''[iLert Webhook] Notification failed : '' + error);
    throw ''iLert notification failed : '' + error;
}','30s','1','1','{EVENT.TAGS.__ilert_incident_url}','iLert incident','Please refer to https://docs.ilert.com/integrations/zabbix/native 
  
Set global macro {$ZABBIX.URL} with your Zabbix server URL.
Add a dedicated user with the media type "iLert". You can also rewrite the incident summary via ".ILERT.INCIDENT.SUMMARY" parameter or leave it empty to use the standard pattern.');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('23','4','SolarWinds Service Desk','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var SolarWinds = {
    params: {},

    setParams: function (params) {
        if (typeof params !== ''object'') {
            return;
        }

        SolarWinds.params = params;
        SolarWinds.params.endpoint = ''https://api.samanage.com/'';
    },

    setProxy: function (HTTPProxy) {
        SolarWinds.HTTPProxy = HTTPProxy;
    },

    addCustomFields: function (data, fields) {
        if (typeof data.incident === ''object'' && typeof fields === ''object'' && Object.keys(fields).length) {
            if (typeof fields.sw_fields === ''object'' && Object.keys(fields.sw_fields).length) {
                Object.keys(fields.sw_fields)
                    .forEach(function(field) {
                        try {
                            data.incident[field] = JSON.parse(fields.sw_fields[field]);
                        }
                        catch (error) {
                            data.incident[field] = fields.sw_fields[field];
                        }
                    });
            }

            if (typeof fields.sw_customfields === ''object'' && Object.keys(fields.sw_customfields).length) {
                data.incident.custom_fields_values = {custom_fields_value: []};
                Object.keys(fields.sw_customfields)
                    .forEach(function(field) {
                        data.incident.custom_fields_values.custom_fields_value.push({
                            name: field,
                            value: fields.sw_customfields[field]
                        });
                    });
            }
        }

        return data;
    },

    request: function (method, query, data) {
        [''token''].forEach(function (field) {
            if (typeof SolarWinds.params !== ''object'' || typeof SolarWinds.params[field] === ''undefined''
                || SolarWinds.params[field] === '''' ) {
                throw ''Required SolarWinds param is not set: "'' + field + ''".'';
            }
        });

        var response,
            url = SolarWinds.params.endpoint + query,
            request = new HttpRequest();

        request.addHeader(''Content-Type: application/json'');
        request.addHeader(''X-Samanage-Authorization: Bearer '' + SolarWinds.params.token);
        request.addHeader(''Accept: application/vnd.samanage.v2.1+json'');

        if (typeof SolarWinds.HTTPProxy !== ''undefined'' && SolarWinds.HTTPProxy !== '''') {
            request.setProxy(SolarWinds.HTTPProxy);
        }

        if (typeof data !== ''undefined'') {
            data = JSON.stringify(data);
        }

        Zabbix.log(4, ''[ SolarWinds SD Webhook ] Sending request: '' + url + ((typeof data === ''string'')
            ? (''\\n'' + data)
            : ''''));

        switch (method) {
            case ''get'':
                response = request.get(url, data);
                break;

            case ''post'':
                response = request.post(url, data);
                break;

            case ''put'':
                response = request.put(url, data);
                break;

            default:
                throw ''Unsupported HTTP request method: '' + method;
        }

        Zabbix.log(4, ''[ SolarWinds SD Webhook ] Received response with status code '' + request.getStatus() +
            ''\\n'' + response);

        if (response !== null) {
            try {
                response = JSON.parse(response);
            }
            catch (error) {
                Zabbix.log(4, ''[ SolarWinds SD Webhook ] Failed to parse response received from SolarWinds'');
                response = null;
            }
        }

        if (request.getStatus() < 200 || request.getStatus() >= 300) {
            var message = ''Request failed with status code '' + request.getStatus();

            if (response !== null && typeof response.error !== ''undefined''
                && Object.keys(response.error).length > 0) {
                message += '': '' + JSON.stringify(response.error);
            }
            else if (response !== null && typeof response === ''object''
                && Object.keys(response).length > 0) {
                Object.keys(response)
                    .forEach(function(field) {
                        message += ''\\n'' + field + '': '' + response[field][0];
                    });
            }

            throw message + '' Check debug log for more information.'';
        }

        return {
            status: request.getStatus(),
            response: response
        };
    },

    createIncident: function(name, description, fields) {
        var data = {
            incident: {
                name: name,
                description: description,
                priority: SolarWinds.params.priority
            }
        };

        var result = SolarWinds.request(''post'', ''incidents.json'', SolarWinds.addCustomFields(data, fields));

        if (typeof result.response !== ''object'' || typeof result.response.id === ''undefined'') {
            throw ''Cannot create SolarWinds incident. Check debug log for more information.'';
        }

        return result.response.id;
    },

    updateIncident: function(name, fields, message) {
        var data = {
            incident: {
                name: name,
                priority: SolarWinds.params.priority
            }
        };

        SolarWinds.request(
            ''put'',
            ''incidents/'' + SolarWinds.params.incident_id + ''.json'',
            SolarWinds.addCustomFields(data, fields));

        SolarWinds.commenIncident(message);
    },

    commenIncident: function(message) {
        var data = {
            comment: {
                body: message
            }
        };

        SolarWinds.request(''post'', ''incidents/'' + SolarWinds.params.incident_id + ''/comments.json'', data);
    }
};

try {
    var params = JSON.parse(value),
        fields = {},
        samanage = {},
        result = {tags: {}},
        required_params = [''alert_subject'', ''event_recovery_value'', ''event_source'', ''event_value'', ''priority_default''],
        severities = [
            {name: ''not_classified''},
            {name: ''information''},
            {name: ''warning''},
            {name: ''average''},
            {name: ''high''},
            {name: ''disaster''},
            {name: ''resolved''},
            {name: ''default''}
        ];

    fields.sw_fields = {};
    fields.sw_customfields = {};

    Object.keys(params)
        .forEach(function (key) {
            if (key.startsWith(''samanage_'')) {
                samanage[key.substring(9)] = params[key];
            }
            else if (key.startsWith(''sw_field_'')) {
                fields.sw_fields[key.substring(9)] = params[key];
            }
            else if (key.startsWith(''sw_customfield_'')) {
                fields.sw_customfields[key.substring(15)] = params[key];
            }
            else if (required_params.indexOf(key) !== -1 && params[key] === '''') {
                throw ''Parameter "'' + key + ''" can\\''t be empty.'';
            }
        });

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: '' + params.event_source + ''\\nMust be 0-3.'';
    }

    // Check {EVENT.VALUE} for trigger-based and internal events.
    if (params.event_value !== ''0'' && params.event_value !== ''1''
        && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
    if (params.event_update_status !== ''0'' && params.event_update_status !== ''1'' && params.event_source === ''0'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }

    if (params.event_source !== ''0'' && params.event_recovery_value === ''0'') {
        throw ''Recovery operations are supported only for trigger-based actions.'';
    }

    if ([0, 1, 2, 3, 4, 5].indexOf(parseInt(params.event_nseverity)) === -1) {
        params.event_nseverity = ''7'';
    }

    if (params.event_value === ''0'') {
        params.event_nseverity = ''6'';
    }

    samanage.priority = params[''priority_'' + severities[params.event_nseverity].name] || params.priority_default;

    SolarWinds.setParams(samanage);
    SolarWinds.setProxy(params.HTTPProxy);

    // Create incident for non trigger-based events.
    if (params.event_source !== ''0'' && params.event_recovery_value !== ''0'') {
        SolarWinds.createIncident(params.alert_subject, params.alert_message);
    }
    // Create incident for trigger-based events.
    else if (params.event_value === ''1'' && params.event_update_status === ''0''
            && samanage.incident_id === ''{EVENT.TAGS.__zbx_solarwinds_inc_id}'') {
        var key = SolarWinds.createIncident(params.alert_subject, params.alert_message, fields);


        result.tags.__zbx_solarwinds_inc_id = key;
        result.tags.__zbx_solarwinds_inc_link = params.samanage_url +
            (params.samanage_url.endsWith(''/'') ? '''' : ''/'') + ''incidents/'' + key;
    }
    // Update created incident for trigger-based event.
    else {
        if (samanage.incident_id === ''{EVENT.TAGS.__zbx_solarwinds_inc_id}'' || samanage.incident_id === '''') {
            throw ''Incorrect incident key given: '' + samanage.incident_id;
        }
        if (!params.alert_message) {
            throw ''Parameter "alert_message" can\\''t be empty.'';
        }
        SolarWinds.updateIncident(params.alert_subject, fields, params.alert_message);
    }

    if (params.event_source === ''0'') {
        return JSON.stringify(result);
    }
    else {
        return ''OK'';
    }
}
catch (error) {
    Zabbix.log(3, ''[ SolarWinds SD Webhook ] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','1','1','{EVENT.TAGS.__zbx_solarwinds_inc_link}','SolarWinds incident ID: {EVENT.TAGS.__zbx_solarwinds_inc_id}','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('24','4','SysAid','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var SysAid = {
    params: {},

    setParams: function (params) {
        var required = [''url'', ''auth_user'', ''auth_password'', ''category_level_1'', ''category_level_2'',
            ''category_level_3'', ''incident_id'', ''template_id'', ''urgency_id'', ''incident_state'',
            ''default_priority_id''
        ];

        required.forEach(function (field) {
            if (typeof params !== ''object'' || typeof params[field] === ''undefined'' || params[field] === '''') {
                throw ''Required param is not set: "'' + field + ''".'';
            }
        });

        SysAid.params = params;
        if (typeof SysAid.params.url === ''string'' && !SysAid.params.url.endsWith(''/'')) {
            SysAid.params.url += ''/'';
        }
    },

    login: function () {
        var result = SysAid.request(''post'', ''api/v1/login'', {
            user_name: SysAid.params.auth_user,
            password: SysAid.params.auth_password
        });

        return result.response.user.id;
    },

    request: function (method, query, data) {
        var response,
            request = SysAid.req || (SysAid.req = new HttpRequest()),
            url = SysAid.params.url + query;

        if (typeof SysAid.HTTPProxy !== ''undefined'' && SysAid.HTTPProxy.trim() !== '''') {
            request.setProxy(SysAid.HTTPProxy);
        }

        if (typeof data !== ''undefined'') {
            data = JSON.stringify(data);
        }

        Zabbix.log(4, ''[ SysAid Webhook ] Sending request: '' +
            url + ((typeof data === ''string'') ? ('' '' + data) : ''''));

        switch (method) {
            case ''get'':
                response = request.get(url, data);
                break;

            case ''post'':
                response = request.post(url, data);
                break;

            case ''put'':
                response = request.put(url, data);
                break;

            default:
                throw ''Unsupported HTTP request method: '' + method;
        }

        Zabbix.log(4, ''[ SysAid Webhook ] Received response with status code '' + request.getStatus() + '': '' + response);

        if (request.getStatus() !== 200) {
            var message = ''Request failed with status code '' + request.getStatus();

            message += '': '' + response;
            throw message + '' Check debug log for more information.'';
        }

        if (response !== null) {
            try {
                response = JSON.parse(response);
            }
            catch (error) {
                Zabbix.log(4, ''[ SysAid Webhook ] Failed to parse response received from SysAid'');
                response = null;
            }
        }

        if (response === null || (typeof response.Error !== ''undefined'' && Object.keys(response.Error).length > 0)) {
            throw ''Request failed: '' + JSON.stringify(response.Error);
        }

        return {
            status: request.getStatus(),
            response: response
        };
    },

    createIncident: function(subject, message, priority) {
        var result = SysAid.request(''post'', ''api/v1/sr/?template='' + encodeURIComponent(SysAid.params.template_id), {
            info: [
                {
                    key: ''problem_type'',
                    value: [
                        SysAid.params.category_level_1,
                        SysAid.params.category_level_2,
                        SysAid.params.category_level_3
                    ].join(''_'')
                },
                {
                    key: ''title'',
                    value: subject
                },
                {
                    key: ''description'',
                    value: message
                },
                {
                    key: ''status'',
                    value: ''1''
                },
                {
                    key: ''urgency'',
                    value: SysAid.params.urgency_id
                },
                {
                    key: ''priority'',
                    value: priority || SysAid.params.default_priority_id,
                }
            ]
        });

        if (result.response.id === ''undefined'') {
            throw ''Cannot create SysAid incident. Check debug log for more information.'';
        }

        return result.response.id;
    },

    updateTicket: function(note) {
        var date = new Date().getTime();

        SysAid.request(''put'', ''api/v1/sr/'' + encodeURIComponent(SysAid.params.incident_id), {
            id: SysAid.params.incident_id,
            info: [
                {
                    key: ''update_time'',
                    value: date
                },
                {
                    key: ''notes'',
                    value: [
                        {
                            userName: ''Zabbix'',
                            createDate: date,
                            text: note
                        }
                    ]
                }
            ]
        });
    }
};

try {
    var params = JSON.parse(value),
        params_sysaid = {},
        params_update = {},
        result = {tags: {}},
        required_params = [''alert_subject'', ''event_source'', ''event_value'',  ''event_update_status''],
        severities = [
            {name: ''not_classified'', color: ''#97AAB3''},
            {name: ''information'', color: ''#7499FF''},
            {name: ''warning'', color: ''#FFC859''},
            {name: ''average'', color: ''#FFA059''},
            {name: ''high'', color: ''#E97659''},
            {name: ''disaster'', color: ''#E45959''},
            {name: ''resolved'', color: ''#009900''},
            {name: null, color: ''#000000''}
        ],
        priority;

    Object.keys(params)
        .forEach(function (key) {
            if (key.startsWith(''sysaid_'')) {
                params_sysaid[key.substring(7)] = params[key];
            }
            else if (key.startsWith(''event_update_'')) {
                params_update[key.substring(13)] = params[key];
            }
            else if (required_params.indexOf(key) !== -1 && params[key].trim() === '''') {
                throw ''Parameter "'' + key + ''" cannot be empty.'';
            }
        });

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: '' + params.event_source + ''\\nMust be 0-3.'';
    }

    // Check {EVENT.VALUE} for trigger-based and internal events.
    if (params.event_value !== ''0'' && params.event_value !== ''1''
        && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
    if (params.event_source === ''0'' && params.event_update_status !== ''0'' && params.event_update_status !== ''1'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }

    if (params.event_source !== ''0'' && params.event_value === ''0'') {
        throw ''Recovery operations are supported only for trigger-based actions.'';
    }

    if (params.event_source === ''0'' && ((params.event_value === ''1'' && params.event_update_status === ''1'')
            || (params.event_value === ''0'' && (params.event_update_status === ''0'' || params.event_update_status === ''1'')))
            && (isNaN(parseInt(params.sysaid_incident_id)) || parseInt(params.sysaid_incident_id) < 1 )) {
        throw ''Incorrect "sysaid_incident_id" parameter given: '' + params.sysaid_incident_id + ''\\nMust be positive integer.'';
    }

    if ([0, 1, 2, 3, 4, 5].indexOf(parseInt(params.event_nseverity)) === -1) {
        params.event_nseverity = ''7'';
    }

    if (params.event_value === ''0'') {
        params.event_nseverity = ''6'';
    }

    priority = params[''severity_'' + severities[params.event_nseverity].name];
    priority = priority && priority.trim() || severities[7].name;

    SysAid.setParams(params_sysaid);
    SysAid.HTTPProxy = params.HTTPProxy;
    SysAid.login();

    if (params.event_source !== ''0'' && params.event_value !== ''0'') {
        // Create ticket for non trigger-based events.
        SysAid.createIncident(params.alert_subject, params.alert_message, priority);
    }
    else if (params.event_value === ''1'' && params_update.status === ''0'') {
        // Create ticket for trigger-based events.
        var incident_id = SysAid.createIncident(params.alert_subject, params.alert_subject + ''\\n'' + params.alert_message +
                ''\\n'' + params.zabbix_url + (params.zabbix_url.endsWith(''/'') ? '''' : ''/'') + ''tr_events.php?triggerid='' +
                params.trigger_id + ''&eventid='' + params.event_id + ''\\n'', priority
        );

        result.tags.__zbx_sysaid_incident_id = incident_id;
        result.tags.__zbx_sysaid_incidentlink = params.sysaid_url +
            (params.sysaid_url.endsWith(''/'') ? '''' : ''/'') + ''SREdit.jsp?id='' + incident_id + ''&fromId=IncidentsList'';
    }
    else {
        // Update created ticket for trigger-based event.
        SysAid.updateTicket(params.alert_subject + ''\\n'' + params.alert_message);
    }

    return JSON.stringify(result);
}
catch (error) {
    Zabbix.log(3, ''[ SysAid Webhook ] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','1','1','{EVENT.TAGS.__zbx_sysaid_incidentlink}','SysAid: incident #{EVENT.TAGS.__zbx_sysaid_incident_id}','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('25','4','TOPdesk','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var Media = {
    params: {},
    name: '''',
    labels: [],
    HTTPProxy: '''',

    setParams: function (params) {
        if (typeof params !== ''object'') {
            return;
        }

        Media.params = params;
        Media.params.api += Media.params.api.endsWith(''/'') ? '''' : ''/'';
    },

    setProxy: function (HTTPProxy) {
        if (typeof HTTPProxy !== ''undefined'' && HTTPProxy.trim() !== '''') {
            Media.HTTPProxy = HTTPProxy;
        }
    },

    request: function (method, query, data) {
        [''api'', ''token''].forEach(function (field) {
            if (typeof Media.params !== ''object'' || typeof Media.params[field] === ''undefined''
                    || Media.params[field] === '''') {
                throw ''Required '' + Media.name + '' param is not set: "'' + field + ''".'';
            }
        });

        var response,
            url = Media.params.api + query,
            request = new HttpRequest();

        request.addHeader(''Content-Type: application/json'');
        request.addHeader(''Accept: application/json'');
        request.addHeader(''Authorization: '' + Media.params.token);
        request.setProxy(Media.HTTPProxy);

        if (typeof data !== ''undefined'') {
            data = JSON.stringify(data);
        }

        Zabbix.log(4, ''[ '' + Media.name + '' Webhook ] Sending request: '' +
            url + ((typeof data === ''string'') ? (''\\n'' + data) : ''''));

        switch (method) {
            case ''get'':
                response = request.get(url, data);
                break;

            case ''post'':
                response = request.post(url, data);
                break;

            case ''put'':
                response = request.put(url, data);
                break;

            default:
                throw ''Unsupported HTTP request method: '' + method;
        }

        Zabbix.log(4, ''[ '' + Media.name + '' Webhook ] Received response with status code '' +
            request.getStatus() + ''\\n'' + response);

        if (response !== null) {
            try {
                response = JSON.parse(response);
            }
            catch (error) {
                Zabbix.log(4, ''[ '' + Media.name + '' Webhook ] Failed to parse response.'');
                response = null;
            }
        }

        if (request.getStatus() < 200 || request.getStatus() >= 300) {
            var message = ''Request failed with status code '' + request.getStatus();

            if (response !== null) {
                if (typeof response.errors === ''object'' && Object.keys(response.errors).length > 0) {
                    message += '': '' + JSON.stringify(response.errors);
                }
                else if (typeof response.errorMessages === ''object'' && Object.keys(response.errorMessages).length > 0) {
                    message += '': '' + JSON.stringify(response.errorMessages);
                }
                else if (typeof response.message === ''string'') {
                    message += '': '' + response.message;
                }
            }

            throw message + '' Check debug log for more information.'';
        }

        return {
            status: request.getStatus(),
            response: response
        };
    }
};

try {
    var result = {tags: {}},
        params = JSON.parse(value),
        media = {},
        fields = {},
        resp = {},
        required_params = [
            ''alert_subject'',
            ''alert_message'',
            ''event_id'',
            ''event_source'',
            ''event_value'',
            ''event_update_status'',
            ''topdesk_api'',
            ''topdesk_user'',
            ''topdesk_password''
        ],
        severities = [
            ''not_classified'',
            ''information'',
            ''warning'',
            ''average'',
            ''high'',
            ''disaster'',
            ''resolved'',
            ''default''
        ],
        priority;

    Object.keys(params)
        .forEach(function (key) {
            if (required_params.indexOf(key) !== -1 && params[key].trim() === '''') {
                throw ''Parameter "'' + key + ''" cannot be empty.'';
            }
            if (key.startsWith(''topdesk_'')) {
                media[key.substring(8)] = params[key];
            }
        });

    // Possible values of event_source:
    // 0 - Trigger, 1 - Discovery, 2 - Autoregistration, 3 - Internal.
    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: "'' + params.event_source + ''".\\nMust be 0-3.'';
    }

    // Check event_value for trigger-based and internal events.
    // Possible values: 1 for problem, 0 for recovering
    if (params.event_value !== ''0'' && params.event_value !== ''1''
        && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    // Check event_update_status only for trigger-based events.
    // Possible values: 0 - Webhook was called because of problem/recovery event, 1 - Update operation.
    if (params.event_source === ''0'' && params.event_update_status !== ''0'' && params.event_update_status !== ''1'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }

    // Check event_id for a numeric value.
    if (isNaN(parseInt(params.event_id)) || params.event_id < 1) {
        throw ''Incorrect "event_id" parameter given: '' + params.event_id + ''\\nMust be a positive number.'';
    }

    if ((params.event_source === ''1'' || params.event_source === ''2'')  && params.event_value === ''0'') {
        throw ''Recovery operations are supported only for Trigger and Internal actions.'';
    }

    if ([0, 1, 2, 3, 4, 5].indexOf(parseInt(params.event_nseverity)) === -1) {
        params.event_nseverity = ''7'';
    }

    if (params.event_value === ''0'') {
        params.event_nseverity = ''6'';
    }

    priority = params[''severity_'' + severities[params.event_nseverity]];
    params.zbxurl = params.zbxurl + (params.zbxurl.endsWith(''/'') ? '''' : ''/'');

    Media.name = ''TOPdesk'';
    Media.setParams(media);
    Media.params.token = ''Basic '' + btoa(Media.params.user + '':'' + Media.params.password);
    Media.setProxy(params.HTTPProxy);

    // Create an issue.
    // Numeric value of the event that triggered an action (1 for problem, 0 for recovering).
    // Numeric value of the problem update status. Possible values:
    // 0 - Webhook was called because of problem/recovery event, 1 - Update operation.
    if ((params.event_source == 0 && params.event_value == 1 && params.event_update_status == 0)
            || (params.event_source == 3 && params.event_value == 1)
            || params.event_source == 1 || params.event_source == 2) {
        Zabbix.log(4, ''[ '' + Media.name + '' Webhook ] Request of the ticket creating.'');
        fields.caller = {dynamicName: ''Zabbix''};
        fields.briefDescription = params.alert_subject;
        fields.request = params.alert_message.replace(/\\n/g, ''<br>'');
        fields.priority = {name: priority};
        fields.processingStatus = {name: Media.params.status};
        fields.externalNumber = params.event_id;
        fields.request += ''<br>'' + params.zbxurl;

        if (params.event_source === ''0'') {
            fields.request += ''tr_events.php?triggerid='' + params.trigger_id + ''&eventid='' + params.event_id;
        }

        resp = Media.request(''post'', ''tas/api/incidents'', fields);
        if (typeof resp.response !== ''object'' || typeof resp.response.id === ''undefined'') {
            throw ''Cannot create '' + Media.name + '' issue. Check debug log for more information.'';
        }

        if (params.event_source == 0 && params.event_value == 1 && params.event_update_status == 0) {
            result.tags.__zbx_tpd_issuekey = resp.response.number;
            result.tags.__zbx_tpd_issuelink = Media.params.api +
                ''tas/secure/incident?action=show&unid='' + resp.response.id;
        }
    }
    // Update a created issue.
    else {
        if (params.event_source == 3 && params.event_value == 0) {
            throw ''Internal event recovery actions are not supported.'';
        }

        Zabbix.log(4, ''[ '' + Media.name + '' Webhook ] Request of the ticket updating.'');
        fields.action = params.alert_message.replace(/\\n/g, ''<br>'');

        resp = Media.request(''put'', ''tas/api/incidents/number/'' + Media.params.issue_key, fields);
        if (typeof resp.response !== ''object'' || typeof resp.response.id === ''undefined''
                || resp.response.number !== Media.params.issue_key) {
            throw ''Cannot update '' + Media.name + '' issue. Check debug log for more information.'';
        }
    }

    return JSON.stringify(result);
}
catch (error) {
    Zabbix.log(3, ''[ '' + Media.name + '' Webhook ] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','1','1','{EVENT.TAGS.__zbx_tpd_issuelink}','TOPdesk: {EVENT.TAGS.__zbx_tpd_issuekey}','Please refer to https://developers.topdesk.com/documentation/index.html and https://www.zabbix.com/documentation/6.0/manual/config/notifications/media/webhook#example_scripts.
  
Set global macro {$ZABBIX.URL} with your Zabbix server URL.
Add a dedicated user with the media type "TOPdesk".
Change the values of the variables topdesk_api (URL), topdesk_password, topdesk_user. The topdesk_status is the default status for creating a new TOPdesk ticket.');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('26','4','iTop','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var Itop = {
    params: {},

    setParams: function (params) {
        if (typeof params !== ''object'') {
            return;
        }

        if (params.log !== ''private_log'' && params.log !== ''public_log'') {
            throw ''Incorrect "itop_log" parameter given: '' + params.log + ''\\nMust be "private_log" or "public_log".'';
        }

        Itop.params = params;
        if (typeof Itop.params.url === ''string'') {
            if (!Itop.params.url.endsWith(''/'')) {
                Itop.params.url += ''/'';
            }

            Itop.params.url += ''webservices/rest.php?version='' + encodeURIComponent(Itop.params.api_version);
        }
    },

    setProxy: function (HTTPProxy) {
        Itop.HTTPProxy = HTTPProxy;
    },

    setCreatePayload: function () {
        json_data.operation = ''core/create'';
        json_data.fields.org_id = Itop.params.organization_id;
        json_data.fields.title = params.alert_subject;
        json_data.fields.description = params.alert_message.replace(''<'', ''&lt;'')
            .replace(''>'', ''&gt;'')
            .replace(/(?:\\r\\n|\\r|\\n)/g, ''<br>'');
    },

    setUpdatePayload: function () {
        json_data.operation = ''core/update'';
        json_data.key = Itop.params.id;
        json_data.fields.title = params.alert_subject;
        json_data.fields[Itop.params.log] = {
            add_item: {
                message: params.alert_subject + ''\\n'' + params.alert_message,
                format: ''text''
            }
        };
    },

    request: function (data) {
        [''url'', ''user'', ''password'', ''organization_id'', ''class'', ''api_version'', ''id''].forEach(function (field) {
            if (typeof Itop.params !== ''object'' || typeof Itop.params[field] === ''undefined''
                    || Itop.params[field] === '''' ) {
                throw ''Required Itop param is not set: "itop_'' + field + ''".'';
            }
        });

        var response,
            url = Itop.params.url,
            request = new HttpRequest(),
            object;

        request.addHeader(''Content-Type: multipart/form-data'');
        request.addHeader(''Authorization: Basic '' + btoa(Itop.params.user + '':'' + Itop.params.password));

        if (Itop.HTTPProxy) {
            request.setProxy(Itop.HTTPProxy);
        }

        if (typeof data !== ''undefined'') {
            data = JSON.stringify(data);
        }

        Zabbix.log(4, ''[ iTop Webhook ] Sending request: '' + url + ''&json_data='' + data);

        response = request.post(url + ''&json_data='' + encodeURIComponent(data));

        Zabbix.log(4, ''[ iTop Webhook ] Received response with status code '' + request.getStatus() + ''\\n'' + response);

        try {
            response = JSON.parse(response);
        }
        catch (error) {
            Zabbix.log(4, ''[ iTop Webhook ] Failed to parse response received from iTop'');
            throw ''Failed to parse response received from iTop.\\nRequest status code '' +
                    request.getStatus() + ''. Check debug log for more information.'';
        }

        if (request.getStatus() < 200 || request.getStatus() >= 300) {
            throw ''Request failed with status code '' + request.getStatus() + ''. Check debug log for more information.'';
        }
        else if (typeof response.code !== ''undefined'' && response.code !== 0) {
            throw ''Request failed with iTop code '' + response.code + '': '' +
                    JSON.stringify(response.message) + ''. Check debug log for more information.'';
        }
        else {
            Object.keys(response.objects)
                .forEach(function (key) {
                    object = response.objects[key];
                });
    
            return {
                status: request.getStatus(),
                response: object.fields
            };
        }
    }
};

try {
    var params = JSON.parse(value),
        json_data = {},
        itop_params = {},
        result = {tags: {}},
        required_params = [
            ''alert_subject'', ''summary'', ''event_recovery_value'',
            ''event_source'', ''event_value'', ''action_name''
        ];

    Object.keys(params)
        .forEach(function (key) {
            if (key.startsWith(''itop_'')) {
                itop_params[key.substring(5)] = params[key];
            }
            else if (required_params.indexOf(key) !== -1 && params[key] === '''') {
                throw ''Parameter "'' + key + ''" can\\''t be empty.'';
            }
        });

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: '' + params.event_source + ''\\nMust be 0-3.'';
    }

    // Check {EVENT.VALUE} for trigger-based and internal events.
    if (params.event_value !== ''0'' && params.event_value !== ''1''
            && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
    if (params.event_update_status !== ''0'' && params.event_update_status !== ''1'' && params.event_source === ''0'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }

    if (params.event_source !== ''0'' && params.event_recovery_value === ''0'') {
        throw ''Recovery operations are supported only for trigger-based actions.'';
    }

    Itop.setParams(itop_params);
    Itop.setProxy(params.HTTPProxy);

    json_data.operation = '''';
    json_data.class = Itop.params.class;
    json_data.comment = Itop.params.comment;
    json_data.output_fields = ''id, friendlyname'';
    json_data.fields = {};

    // Create issue for non trigger-based events.
    if (params.event_source !== ''0'' && params.event_recovery_value !== ''0'') {
        Itop.setCreatePayload();
        Itop.request(json_data);
    }
    // Create issue for trigger-based events.
    else if (params.event_value === ''1'' && params.event_update_status === ''0''
            && Itop.params.id === ''{EVENT.TAGS.__zbx_itop_id}'') {
        Itop.setCreatePayload();

        var response = Itop.request(json_data);

        result.tags.__zbx_itop_id = response.response.id;
        result.tags.__zbx_itop_key = response.response.friendlyname;
        result.tags.__zbx_itop_link = params.itop_url + (params.itop_url.endsWith(''/'') ? '''' : ''/'') +
                ''pages/UI.php?operation=details&class='' + encodeURIComponent(Itop.params.class) + ''&id='' +
                encodeURIComponent(response.response.id);
    }
    // Update created issue for trigger-based event.
    else {
        if (Itop.params.id === ''{EVENT.TAGS.__zbx_itop_id}'') {
            throw ''Incorrect iTop ticket ID given: '' + Itop.params.id;
        }
        Itop.setUpdatePayload();
        Itop.request(json_data);
    }

    return JSON.stringify(result);
}
catch (error) {
    Zabbix.log(3, ''[ iTop Webhook ] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','1','1','{EVENT.TAGS.__zbx_itop_link}','iTop: {EVENT.TAGS.__zbx_itop_key}','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('27','4','Rocket.Chat','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var RocketChat = {
    params: {},

    setParams: function (params) {
        if (typeof params !== ''object'') {
            return;
        }

        RocketChat.params = params;
        if (RocketChat.params.url && RocketChat.params.api_url) {
            if (!RocketChat.params.url.endsWith(''/'')) {
                RocketChat.params.url += ''/'';
            }
            if (!RocketChat.params.api_url.endsWith(''/'')) {
                RocketChat.params.api_url += ''/'';
            }
            if (RocketChat.params.api_url.startsWith(''/'')) {
                RocketChat.params.api_url = RocketChat.params.api_url.substring(1);
            }

            RocketChat.params.url += RocketChat.params.api_url;
        }
    },

    setProxy: function (HTTPProxy) {
        RocketChat.HTTPProxy = HTTPProxy;
    },

    addFields: function (fields) {
        var data = [];

        if (typeof fields === ''object'' && Object.keys(fields).length) {
            Object.keys(fields)
                .forEach(function(field) {
                    if (fields[field] === '''') {
                        Zabbix.log(4, ''[ RocketChat Webhook ] Field "'' + field +
                            ''" can\\''t be empty. The field ignored.'');
                    }
                    else {
                        try {
                            var parts = field.split('':''),
                                prefix = parts[0].split(''_'');

                            if (typeof prefix[2] === ''undefined''
                                    || (prefix[2] === ''p'' && params.event_value === ''1'')
                                    || (prefix[2] === ''r'' && params.event_value === ''0'')) {
                                data.push({
                                    title: field.substring(field.indexOf('':'') + 1),
                                    value: fields[field],
                                    short: prefix[1] === ''short''
                                });
                            }
                        }
                        catch (error) {
                            Zabbix.log(4, ''[ RocketChat Webhook ] Can\\''t parse field "'' + field +
                                ''". The field ignored.'');
                        }
                    }
                });
        }

        return data;
    },

    request: function (method, query, data) {
        [''url'', ''api_url'', ''user_id'', ''user_token'', ''send_to''].forEach(function (field) {
            if (typeof RocketChat.params !== ''object'' || typeof RocketChat.params[field] === ''undefined''
                    || RocketChat.params[field] === '''' ) {
                throw ''Required parameter is not set: "'' + field + ''".'';
            }
        });

        var response,
            url = RocketChat.params.url + query,
            request = new HttpRequest();

        request.addHeader(''Content-Type: application/json'');
        request.addHeader(''X-Auth-Token:'' + RocketChat.params.user_token);
        request.addHeader(''X-User-Id:'' + RocketChat.params.user_id);

        if (typeof RocketChat.HTTPProxy !== ''undefined'' && RocketChat.HTTPProxy !== '''') {
            request.setProxy(RocketChat.HTTPProxy);
        }

        if (typeof data !== ''undefined'') {
            data = JSON.stringify(data);
        }

        Zabbix.log(4, ''[ RocketChat Webhook ] Sending request: '' + url +
            ((typeof data === ''string'') ? (''\\n'' + data) : ''''));

        switch (method) {
            case ''get'':
                response = request.get(url, data);
                break;

            case ''post'':
                response = request.post(url, data);
                break;

            default:
                throw ''Unsupported HTTP request method: '' + method;
        }

        Zabbix.log(4, ''[ RocketChat Webhook ] Received response with status code '' +
            request.getStatus() + ''\\n'' + response);

        if (response !== null) {
            try {
                response = JSON.parse(response);
            }
            catch (error) {
                Zabbix.log(4, ''[ RocketChat Webhook ] Failed to parse response received from RocketChat'');
                response = null;
            }
        }

        if (request.getStatus() < 200 || request.getStatus() >= 300) {
            var message = ''Request failed with status code '' + request.getStatus();

            if (response !== null && typeof response.message !== ''undefined'') {
                message += '': '' + JSON.stringify(response.message);
            }
            else if (response !== null && typeof response.error !== ''undefined'') {
                message += '': '' + JSON.stringify(response.error);
            }

            throw message + ''. Check debug log for more information.'';
        }

        return {
            status: request.getStatus(),
            response: response
        };
    },

    postMessage: function(use_default_message, message, fields) {
        var data = {
            channel: RocketChat.params.send_to,
            attachments: [{
                collapsed: false,
                color: RocketChat.params.color,
                title: params.alert_subject
            }]
        };

        if (RocketChat.params.title_link) {
            data.attachments[0].title_link = RocketChat.params.title_link;
        }

        if (use_default_message) {
            data.attachments[0].text = message;
        }
        else {
            data.attachments[0].fields = RocketChat.addFields(fields);
        }

        var result = RocketChat.request(''post'', ''chat.postMessage'', data);

        if (typeof result.response !== ''object'' || typeof result.response.message._id === ''undefined'') {
            throw ''Cannot send RocketChat message. Check debug log for more information.'';
        }

        return {
            id: result.response.message._id,
            rid: result.response.message.rid,
            channel: result.response.channel
        };
    },

    sendMessage: function(update, fields) {

        var data = {
            message: {
                rid: RocketChat.params.room_id,
                tmid: RocketChat.params.msg_id,
                tshow: true
            }
        };

        if (update.status === ''0'') {
            data.message.attachments = [{
                collapsed: false,
                color: RocketChat.params.color,
                title: params.alert_subject,
                title_link: RocketChat.params.title_link,
                fields: RocketChat.addFields(fields)
            }];
        }
        else {
            data.message.alias = update.user;
            data.message.msg = update.action;
            if (update.message) {
                data.message.attachments = [{
                    color: RocketChat.params.color,
                    text: update.message
                }];
            }
        }

        RocketChat.request(''post'', ''chat.sendMessage'', data);
    },

    getMessageLink: function(rid, id) {
        var room = RocketChat.request(''get'', ''rooms.info?roomId='' + encodeURIComponent(rid)),
            link = params.rc_url +
                (params.rc_url.endsWith(''/'') ? '''' : ''/'');

        switch (room.response.room.t) {
            case ''c'':
                link += ''channel/'' + room.response.room.name + ''?msg='' + id;
                break;

            case ''p'':
                link += ''group/'' + room.response.room.name + ''?msg='' + id;
                break;

            case ''d'':
                link += ''direct/'' + rid + ''?msg='' + id;
                break;

            default:
                Zabbix.log(4, ''[ RocketChat Webhook ] Can\\''t get room type. Link to message will not be added.'');
        }

        return link;
    }
};

try {
    var params = JSON.parse(value),
        response,
        fields = {},
        rc = {},
        update = {},
        result = {tags: {}},
        required_params = [''alert_subject'', ''alert_message'', ''event_source'', ''event_value''],
        severities = [
            {name: ''not_classified'', color: ''#97AAB3''},
            {name: ''information'', color: ''#7499FF''},
            {name: ''warning'', color: ''#FFC859''},
            {name: ''average'', color: ''#FFA059''},
            {name: ''high'', color: ''#E97659''},
            {name: ''disaster'', color: ''#E45959''},
            {name: ''resolved'', color: ''#009900''},
            {name: ''default'', color: ''#000000''}
        ];

    Object.keys(params)
        .forEach(function (key) {
            if (key.startsWith(''rc_'')) {
                rc[key.substring(3)] = params[key];
            }
            else if (key.startsWith(''field_'')) {
                fields[key.substring(6)] = params[key];
            }
            else if (key.startsWith(''event_update_'')) {
                update[key.substring(13)] = params[key];
            }
            else if (required_params.indexOf(key) !== -1 && params[key] === '''') {
                throw ''Parameter "'' + key + ''" can\\''t be empty.'';
            }
        });

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: '' + params.event_source + ''\\nMust be 0-3.'';
    }

    // Forcing parameters for non trigger-based events.
    if (params.event_source !== ''0'') {
        params.use_default_message = ''true'';
        params.event_nseverity = ''0'';
        params.rc_title_link = false;
    }

    // Check {EVENT.VALUE} for trigger-based and internal events.
    if (params.event_value !== ''0'' && params.event_value !== ''1''
            && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
    if (params.event_update_status !== ''0'' && params.event_update_status !== ''1'' && params.event_source === ''0'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }

    if ([0, 1, 2, 3, 4, 5].indexOf(parseInt(params.event_nseverity)) === -1) {
        params.event_nseverity = ''7'';
    }

    if (params.event_value === ''0'') {
        params.event_nseverity = ''6'';
    }

    RocketChat.setParams(rc);
    RocketChat.setProxy(params.HTTPProxy);
    RocketChat.params.color = severities[params.event_nseverity].color;

    // Send default message if use_default_message === true.
    if (params.use_default_message.toLowerCase() === ''true'') {
        response = RocketChat.postMessage(true, params.alert_message);
        result.tags.__zbx_rc_id = response.id;
        result.tags.__zbx_rc_rid = response.rid;
        result.tags.__zbx_rc_msg_url = RocketChat.getMessageLink(response.rid, response.id);
    }
    // Send message for trigger-based events.
    else if (params.event_value === ''1'' && update.status === ''0'') {
        response = RocketChat.postMessage(false, params.alert_message, fields);
        result.tags.__zbx_rc_id = response.id;
        result.tags.__zbx_rc_rid = response.rid;
        result.tags.__zbx_rc_msg_url = RocketChat.getMessageLink(response.rid, response.id);
    }
    // Send thread message for trigger-based event.
    else {
        RocketChat.sendMessage(update, fields);
    }

    return JSON.stringify(result);
}
catch (error) {
    Zabbix.log(3, ''[ RocketChat Webhook ] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','1','1','{EVENT.TAGS.__zbx_rc_msg_url}','Rocket.Chat','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('28','4','VictorOps','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var VictorOps = {
    params: {},

    setParams: function (params) {
        if (typeof params !== ''object'') {
            return;
        }

        VictorOps.params = params;
        if (VictorOps.params.endpoint) {
            if (!VictorOps.params.endpoint.endsWith(''/'')) {
                VictorOps.params.endpoint += ''/'';
            }

            if (typeof VictorOps.params.routing_key !== ''undefined''
                    && VictorOps.params.routing_key !== ''{ALERT.SENDTO}''
                    && VictorOps.params.routing_key !== ''Default'') {
                VictorOps.params.endpoint += VictorOps.params.routing_key;
            }
        }
    },

    setProxy: function (HTTPProxy) {
        VictorOps.HTTPProxy = HTTPProxy;
    },

    addFields: function (fields) {
        var data = {};

        if (typeof fields === ''object'') {
            Object.keys(fields)
                .forEach(function(field) {
                    if (fields[field] === '''') {
                        Zabbix.log(4, ''[ VictorOps Webhook ] Field "'' + field +
                            ''" can\\''t be empty. The field ignored.'');
                    }
                    else {
                        try {
                            var parts = field.split('':''),
                                prefix = parts[0].split(''_'');

                            if (typeof prefix[1] === ''undefined''
                                    || (prefix[1] === ''p'' && params.event_value === ''1''
                                        && (params.event_update_status === ''0''
                                            || params.event_update_status === ''{EVENT.UPDATE.STATUS}''))
                                    || (prefix[1] === ''r'' && params.event_value === ''0''
                                        && (params.event_update_status === ''0''
                                            || params.event_update_status === ''{EVENT.UPDATE.STATUS}''))
                                    || (prefix[1] === ''u'' && params.event_update_status === ''1'')) {
                                data[field.substring(field.indexOf('':'') + 1)] = fields[field];
                            }
                        }
                        catch (error) {
                            Zabbix.log(4, ''[ VictorOps Webhook ] Can\\''t parse field "'' + field +
                                ''". The field ignored.'');
                        }
                    }
                });
        }

        return data;
    },

    request: function (data) {
        if (typeof VictorOps.params !== ''object'' || typeof VictorOps.params.endpoint === ''undefined''
                || VictorOps.params.endpoint === '''' ) {
            throw ''Required parameter is not set: "vops_endpoint".'';
        }

        var response,
            url = VictorOps.params.endpoint,
            request = new HttpRequest();

        request.addHeader(''Content-Type: application/json'');

        if (typeof VictorOps.HTTPProxy !== ''undefined'' && VictorOps.HTTPProxy !== '''') {
            request.setProxy(VictorOps.HTTPProxy);
        }

        if (typeof data !== ''undefined'') {
            data = JSON.stringify(data);
        }

        Zabbix.log(4, ''[ VictorOps Webhook ] Sending request: '' + url +
            ((typeof data === ''string'') ? (''\\n'' + data) : ''''));

        response = request.post(url, data);

        Zabbix.log(4, ''[ VictorOps Webhook ] Received response with status code '' +
            request.getStatus() + ''\\n'' + response);

        if (response !== null) {
            try {
                response = JSON.parse(response);
            }
            catch (error) {
                Zabbix.log(4, ''[ VictorOps Webhook ] Failed to parse response received from VictorOps'');
                response = null;
            }
        }

        if (request.getStatus() < 200 || request.getStatus() >= 300) {
            var message = ''Request failed with status code '' + request.getStatus();

            if (response !== null && typeof response.messages !== ''undefined'') {
                message += '': '' + JSON.stringify(response.messages);
            }

            throw message + ''. Check debug log for more information.'';
        }

        return response;
    }
};

try {
    var params = JSON.parse(value),
        fields = {},
        vops = {},
        required_params = [''event_source'', ''event_value'', ''priority_update''],
        severities = [
            {name: ''not_classified'', color: ''#97AAB3''},
            {name: ''information'', color: ''#7499FF''},
            {name: ''warning'', color: ''#FFC859''},
            {name: ''average'', color: ''#FFA059''},
            {name: ''high'', color: ''#E97659''},
            {name: ''disaster'', color: ''#E45959''},
            {name: ''resolved'', color: ''#009900''},
            {name: ''default'', color: ''#000000''}
        ];

    Object.keys(params)
        .forEach(function (key) {
            if (key.startsWith(''vops_'')) {
                vops[key.substring(5)] = params[key];
            }
            else if (key.startsWith(''field'')) {
                fields[key.substring(5)] = params[key];
            }
            else if (required_params.indexOf(key) !== -1 && params[key] === '''') {
                throw ''Parameter "'' + key + ''" can\\''t be empty.'';
            }
        });

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: '' + params.event_source + ''\\nMust be 0-3.'';
    }

    // Check {EVENT.VALUE} for trigger-based and internal events.
    if (params.event_value !== ''0'' && params.event_value !== ''1''
            && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
    if (params.event_update_status !== ''0'' && params.event_update_status !== ''1'' && params.event_source === ''0'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }

    if ([0, 1, 2, 3, 4, 5].indexOf(parseInt(params.event_nseverity)) === -1) {
        params.event_nseverity = ''7'';
    }

    if (params.event_value === ''0'') {
        params.event_nseverity = ''6'';
    }

    if (params.event_update_status === ''1'') {
        fields['':message_type''] = params.priority_update;
    }
    else {
        fields['':message_type''] = params[''priority_'' + severities[params.event_nseverity].name]
            || ''INFO'';
    }

    if (params.event_info && params.event_source === ''0'') {
        fields['':event_info''] = params.event_info;
    }

    VictorOps.setParams(vops);
    VictorOps.setProxy(params.HTTPProxy);
    VictorOps.request(VictorOps.addFields(fields));

    return ''OK'';
}
catch (error) {
    Zabbix.log(3, ''[ VictorOps Webhook ] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','0','0','','','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('29','4','Brevis.one','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var BrevisOne = {
    params: [],

    addParam: function (name, value) {
        BrevisOne.params.push(name + ''='' + encodeURIComponent(value));
    },

    setProxy: function (HTTPProxy) {
        BrevisOne.HTTPProxy = HTTPProxy;
    },

    setPayload: function (params) {
        var parts = params.send_to.split('':''),
            defaultValues = {
                ring: ''true'',
                flash: ''true'',
                telauto: ''false''
            };

        BrevisOne.addParam(''username'', params.username);
        BrevisOne.addParam(''password'', params.password);
        BrevisOne.addParam(''text'', params.text);

        if (parts.length > 1) {
            BrevisOne.addParam(''mode'', parts[0]);
            BrevisOne.addParam(''to'', parts[1]);
        }
        else {
            BrevisOne.addParam(''to'', parts[0]);
        }

        Object.keys(defaultValues)
            .forEach(function (key) {
                if (params[key] && params[key].trim() && params[key].toLowerCase() === defaultValues[key]) {
                    BrevisOne.addParam(key, defaultValues[key]);
                }
            });
    },

    request: function () {
        var response,
            request = new HttpRequest(),
            data = ''?'' + BrevisOne.params.join(''&'');

        request.addHeader(''Content-Type: multipart/form-data'');

        if (typeof BrevisOne.HTTPProxy !== ''undefined'' && BrevisOne.HTTPProxy !== '''') {
            request.setProxy(BrevisOne.HTTPProxy);
        }

        Zabbix.log(4, ''[ BrevisOne Webhook ] Sending request.'');

        response = request.post(params.endpoint + data);

        Zabbix.log(4, ''[ BrevisOne Webhook ] Received response with status code '' +
            request.getStatus() + ''\\n'' + response);

        if (request.getStatus() < 200 || request.getStatus() >= 300) {
            var message = ''Request failed with status code '' + request.getStatus();

            if (response) {
                message += '': '' + response;
            }

            throw message + ''. Check debug log for more information.'';
        }
    }
};

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

    [''endpoint'', ''password'', ''username'', ''text'', ''send_to''].forEach(function (field) {
        if (typeof params !== ''object'' || typeof params[field] === ''undefined''
                || !params[field].trim()) {
            throw ''Required parameter is not set: "'' + field + ''".'';
        }
    });

    if (params.send_to === ''{ALERT.SENDTO}'') {
        throw ''Required parameter is not set: "send_to".'';
    }

    BrevisOne.setProxy(params.HTTPProxy);
    BrevisOne.setPayload(params);
    BrevisOne.request();

    return ''OK'';
}
catch (error) {
    Zabbix.log(3, ''[ BrevisOne Webhook ] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','0','0','','','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('30','4','Express.ms','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var Express = {
    params: [],

    setParams: function (params) {
        if (typeof params !== ''object'') {
            return;
        }

        Express.params = params;

        if (typeof Express.params.url === ''string'' && !Express.params.url.endsWith(''/'')) {
            Express.params.url += ''/'';
        }
    },

    setProxy: function (HTTPProxy) {
        Express.HTTPProxy = HTTPProxy;
    },

    request: function (query, data) {
        var response,
            url = Express.params.url + query,
            request = new HttpRequest();

        request.addHeader(''Content-Type: application/json'');
        request.addHeader(''Authorization: Bearer '' + Express.params.token);

        if (typeof Express.HTTPProxy !== ''undefined'' && Express.HTTPProxy !== '''') {
            request.setProxy(Express.HTTPProxy);
        }

        if (typeof data !== ''undefined'') {
            data = JSON.stringify(data);
        }

        Zabbix.log(4, ''[ Express Webhook ] Sending request: '' + url +
            ((typeof data === ''string'') ? (''\\n'' + data) : ''''));

        response = request.post(url, data);

        Zabbix.log(4, ''[ Express Webhook ] Received response with status code '' +
            request.getStatus() + ''\\n'' + response);

        if (response !== null) {
            try {
                response = JSON.parse(response);
            }
            catch (error) {
                Zabbix.log(4, ''[ Express Webhook ] Failed to parse response received from Express'');
                response = {};
            }
        }

        if (response.status !== ''ok'') {
            var message = ''Request failed with status code '' + request.getStatus();

            if (typeof response.reason !== ''undefined'') {
                message += '': '' + JSON.stringify(response.reason);
            }

            throw message + ''. Check debug log for more information.'';
        }

        return response.result;
    },

    postMessage: function (is_problem) {
        var data,
            url,
            result = {tags: {}},
            response;

        if (is_problem) {
            data = {
                group_chat_id: Express.params.send_to,
                notification: {
                    status: ''ok'',
                    body: Express.params.message
                }
            };
            url = ''api/v4/botx/notifications/direct'';
        }
        else {
            data = {
                reply: {
                    status: ''ok'',
                    body: Express.params.message
                }
            };
            url = ''api/v3/botx/events/reply_event'';

            try {
                var tags = JSON.parse(Express.params.tags);
            }
            catch (error) {
                throw ''Value of "express_tags" is not JSON. Value: '' + Express.params.tags + ''.'';
            }

            tags.forEach(function(tag) {
                if (tag.tag === ''__zbx_ex_sync_id_'' + Express.params.send_to) {
                    data.source_sync_id = tag.value;
                }
            });

            if (!data.source_sync_id) {
                throw ''Cannot update data. sync_id for the provided sender is unknown.'';
            }
        }

        response = Express.request(url, data);

        if (is_problem && response.sync_id) {
            result.tags[''__zbx_ex_sync_id_'' + Express.params.send_to] = response.sync_id;

            return JSON.stringify(result);
        }
        else {
            return ''OK'';
        }
    }
};

try {
    var params = JSON.parse(value),
        express = {},
        required_params = [
            ''express_url'', ''express_send_to'', ''express_message'', ''express_tags'', ''express_token'',
            ''event_source'', ''event_value'', ''event_update_status''
        ];

    Object.keys(params)
        .forEach(function (key) {
            if (key.startsWith(''express_'')) {
                express[key.substring(8)] = params[key];
            }

            if (required_params.indexOf(key) !== -1
                    && (params[key].trim() === '''' || params[key] === ''{ALERT.SENDTO}'')) {
                throw ''Parameter "'' + key + ''" can\\''t be empty.'';
            }
        });

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: '' + params.event_source + ''\\nMust be 0-3.'';
    }

    // Forcing event_value and event_update_status for non trigger-based events.
    if (params.event_source !== ''0'' ) {
        params.event_value = ''1'';
        params.event_update_status = ''0'';
    }

    if (params.event_value !== ''0'' && params.event_value !== ''1'') {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
    if (params.event_update_status !== ''0'' && params.event_update_status !== ''1'' && params.event_source === ''0'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }

    Express.setParams(express);
    Express.setProxy(params.HTTPProxy);

    return Express.postMessage(params.event_value === ''1'' && params.event_update_status === ''0'');
}
catch (error) {
    Zabbix.log(3, ''[ Express Webhook ] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','1','0','','','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('31','4','ManageEngine ServiceDesk','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var MEngine = {
    params: {},

    setParams: function (params) {
        if (typeof params !== ''object'') {
            return;
        }

        MEngine.params = params;
        if (typeof MEngine.params.url === ''string'') {
            if (!MEngine.params.url.endsWith(''/'')) {
                MEngine.params.url += ''/'';
            }

            MEngine.params.url += ''api/v3/'';
        }

        if (MEngine.params.on_premise.toLowerCase() !== ''true''
                && typeof MEngine.params.on_demand_url_auth === ''string'') {
            if (!MEngine.params.on_demand_url_auth.endsWith(''/'')) {
                MEngine.params.on_demand_url_auth += ''/'';
            }

            MEngine.params.on_demand_url_auth += ''oauth/v2/token?'';
        }
    },

    setProxy: function (HTTPProxy) {
        MEngine.HTTPProxy = HTTPProxy;
    },

    createLink: function (id, url) {
        return url + (url.endsWith(''/'') ? '''' : ''/'') +
            ((MEngine.params.on_premise.toLowerCase() === ''true'')
                ? (''WorkOrder.do?woMode=viewWO&woID='' + id)
                : (''app/itdesk/ui/requests/'' + id + ''/details'')
            );
    },

    refreshAccessToken: function () {
        [
            ''on_demand_url_auth'',
            ''on_demand_refresh_token'',
            ''on_demand_client_id'',
            ''on_demand_client_secret''
        ].forEach(function (field) {
            if (typeof MEngine.params !== ''object'' || typeof MEngine.params[field] === ''undefined''
                    || MEngine.params[field].trim() === '''' ) {
                throw ''Required MEngine param is not set: "sd_'' + field + ''".'';
            }
        });

        var response,
            request = new HttpRequest(),
            url = MEngine.params.on_demand_url_auth +
                ''refresh_token='' + encodeURIComponent(MEngine.params.on_demand_refresh_token) +
                ''&grant_type=refresh_token&client_id='' + encodeURIComponent(MEngine.params.on_demand_client_id) +
                ''&client_secret='' + encodeURIComponent(MEngine.params.on_demand_client_secret) +
                ''&redirect_uri=https://www.zoho.com&scope=SDPOnDemand.requests.ALL'';

        if (MEngine.HTTPProxy) {
            request.setProxy(MEngine.HTTPProxy);
        }

        Zabbix.log(4, ''[ ManageEngine Webhook ] Refreshing access token. Request: '' + url);

        response = request.post(url);

        Zabbix.log(4, ''[ ManageEngine Webhook ] Received response with status code '' +
        request.getStatus() + ''\\n'' + response);

        try {
            response = JSON.parse(response);
        }
        catch (error) {
            Zabbix.log(4, ''[ ManageEngine Webhook ] Failed to parse response received from Zoho Accounts'');
        }

        if ((request.getStatus() < 200 || request.getStatus() >= 300) && !response.access_token) {
            throw ''Access token refresh failed with HTTP status code '' + request.getStatus() +
                ''. Check debug log for more information.'';
        }
        else {
            MEngine.params.on_demand_auth_token = response.access_token;
        }
    },

    request: function (method, query, data) {
        var response,
            url = MEngine.params.url + query,
            input,
            request = new HttpRequest(),
            message;

        if (MEngine.params.on_premise.toLowerCase() === ''true'') {
            request.addHeader(''TECHNICIAN_KEY: '' + MEngine.params.on_premise_auth_token);
        }
        else {
            request.addHeader(''Authorization: Zoho-oauthtoken '' + MEngine.params.on_demand_auth_token);
            request.addHeader(''Accept: application/v3+json'');
        }

        if (MEngine.HTTPProxy) {
            request.setProxy(MEngine.HTTPProxy);
        }

        if (typeof data !== ''undefined'') {
            data = JSON.stringify(data);
        }

        input = ''input_data='' + encodeURIComponent(data);
        Zabbix.log(4, ''[ ManageEngine Webhook ] Sending request: '' + url + ''?'' + input);

        switch (method) {
            case ''post'':
                response = request.post(url, input);
                break;

            case ''put'':
                response = request.put(url, input);
                break;

            default:
                throw ''Unsupported HTTP request method: '' + method;
        }

        Zabbix.log(4, ''[ ManageEngine Webhook ] Received response with status code '' +
            request.getStatus() + ''\\n'' + response);

        try {
            response = JSON.parse(response);
        }
        catch (error) {
            Zabbix.log(4, ''[ ManageEngine Webhook ] Failed to parse response received from ManageEngine'');
        }

        if ((request.getStatus() < 200 || request.getStatus() >= 300)
                && typeof response.response_status !== ''object'') {
            throw ''Request failed with HTTP status code '' + request.getStatus() +
                ''. Check debug log for more information.'';
        }
        else if (typeof response.response_status === ''object'' && response.response_status.status === ''failed'') {
            message = ''Request failed with status_code '';

            if (typeof response.response_status.messages === ''object''
                    && response.response_status.messages[0]
                    && response.response_status.messages[0].message) {
                message += response.response_status.messages[0].status_code +
                    ''. Message: '' + response.response_status.messages[0].message;
            }
            else {
                message += response.response_status.status_code;
            }

            message += ''. Check debug log for more information.'';
            throw message;
        }
        else if (response.request) {
            return response.request.id;
        }
    },

    createPaylaod: function (fields, isNote) {
        var data = {},
            result;

        if (isNote) {
            data.description = fields[''field_string:description''].replace(/(?:\\r\\n|\\r|\\n)/g, ''<br>'');
            result = {request_note: data};
        }
        else {
            Object.keys(fields)
                .forEach(function(field) {
                    if (fields[field].trim() === '''') {
                        Zabbix.log(4, ''[ ManageEngine Webhook ] Field "'' + field +
                            ''" can\\''t be empty. The field ignored.'');
                    }
                    else {
                        try {
                            var prefix = field.split('':'')[0],
                                root;

                            if  (prefix.startsWith(''udf_'') && !data.udf_fields) {
                                data.udf_fields = {};
                                root = data.udf_fields;
                            }
                            else if (prefix.startsWith(''udf_'')) {
                                root = data.udf_fields;
                            }
                            else {
                                root = data;
                            }

                            if (prefix.endsWith(''string'')) {
                                root[field.substring(field.indexOf('':'') + 1)
                                    .toLowerCase()] = fields[field];
                            }
                            else {
                                root[field.substring(field.indexOf('':'') + 1)
                                    .toLowerCase()] = {
                                    name: fields[field]
                                };
                            }
                        }
                        catch (error) {
                            Zabbix.log(4, ''[ ManageEngine Webhook ] Can\\''t parse field "'' + field +
                                ''". The field ignored.'');
                        }
                    }
                });
            if (data.description) {
                data.description = data.description.replace(/(?:\\r\\n|\\r|\\n)/g, ''<br>'');
            }

            result = {request: data};
        }

        return result;
    }
};

try {
    var params = JSON.parse(value),
        fields = {},
        sd = {},
        result = {tags: {}},
        required_params = [
            ''sd_on_premise'', ''field_string:subject'', ''field_string:description'',
            ''event_recovery_value'', ''event_source'', ''event_value'', ''event_update_status''
        ],
        severities = [
            {name: ''not_classified'', color: ''#97AAB3''},
            {name: ''information'', color: ''#7499FF''},
            {name: ''warning'', color: ''#FFC859''},
            {name: ''average'', color: ''#FFA059''},
            {name: ''high'', color: ''#E97659''},
            {name: ''disaster'', color: ''#E45959''},
            {name: ''default'', color: ''#000000''}
        ];

    Object.keys(params)
        .forEach(function (key) {
            if (key.startsWith(''sd_'')) {
                sd[key.substring(3)] = params[key];
            }
            else if (key.startsWith(''field_'') || key.startsWith(''udf_field_'')) {
                fields[key] = params[key];
            }

            if (required_params.indexOf(key) !== -1 && params[key].trim() === '''') {
                throw ''Parameter "'' + key + ''" can\\''t be empty.'';
            }
        });

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: '' + params.event_source + ''\\nMust be 0-3.'';
    }

    // Check {EVENT.VALUE} for trigger-based and internal events.
    if (params.event_value !== ''0'' && params.event_value !== ''1''
        && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
    if (params.event_update_status !== ''0'' && params.event_update_status !== ''1'' && params.event_source === ''0'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }

    if (params.event_source !== ''0'' && params.event_recovery_value === ''0'') {
        throw ''Recovery operations are supported only for trigger-based actions.'';
    }

    if ([0, 1, 2, 3, 4, 5].indexOf(parseInt(params.event_nseverity)) === -1) {
        params.event_nseverity = ''6'';
    }

    if (params.event_update_status === ''1'' && (typeof params.sd_request_id === ''undefined''
            || params.sd_request_id.trim() === ''''
            || params.sd_request_id === ''{EVENT.TAGS.__zbx_sd_request_id}'')) {
        throw ''Parameter "sd_request_id" can\\''t be empty for update operation.'';
    }

    MEngine.setParams(sd);
    MEngine.setProxy(params.HTTPProxy);

    if (MEngine.params.on_premise.toLowerCase() !== ''true'') {
        MEngine.refreshAccessToken();
    }

    // Create issue for non trigger-based events.
    if (params.event_source !== ''0'' && params.event_recovery_value !== ''0'') {
        fields[''field_object:priority''] = params[''priority_'' + severities[params.event_nseverity].name]
        || ''Normal'';

        MEngine.request(''post'', ''requests'', MEngine.createPaylaod(fields));
    }
    // Create issue for trigger-based events.
    else if (params.event_value === ''1'' && params.event_update_status === ''0'') {
        fields[''field_object:priority''] = params[''priority_'' + severities[params.event_nseverity].name]
        || ''Normal'';

        var id = MEngine.request(''post'', ''requests'', MEngine.createPaylaod(fields));

        result.tags.__zbx_sd_request_id = id;
        result.tags.__zbx_sd_request_link = MEngine.createLink(id, params.sd_url);
    }
    // Update created issue for trigger-based event.
    else {
        if (params.event_update_status === ''1'') {
            MEngine.request(''post'', ''requests/'' + params.sd_request_id + ''/notes'',
                MEngine.createPaylaod(fields, true)
            );
        }
        delete fields[''field_string:description''];
        MEngine.request(''put'', ''requests/'' + params.sd_request_id, MEngine.createPaylaod(fields));
    }

    return JSON.stringify(result);
}
catch (error) {
    Zabbix.log(3, ''[ ManageEngine Webhook ] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','1','1','{EVENT.TAGS.__zbx_sd_request_link}','ManageEngine: {EVENT.TAGS.__zbx_sd_request_id}','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('32','4','Github','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var Github = {
    params: {},

    setParams: function (params) {
        if (typeof params !== ''object'') {
            return;
        }
        Github.params = params;
    },

    setProxy: function (HTTPProxy) {
        Github.HTTPProxy = HTTPProxy;
    },

    urlCheckFormat: function (url) {

        if (typeof url === ''string'' && !url.endsWith(''/'')) {
            url += ''/'';
        }

        if (url.indexOf(''http://'') === -1 && url.indexOf(''https://'') === -1) {
            url = ''https://'' + url;
        }

        return url;
    },

    createProblemURL: function (zabbix_url, triggerid, eventid, event_source) {
        var problem_url = zabbix_url;

        if (event_source === ''0'') {
            problem_url += ''tr_events.php?triggerid='' + triggerid + ''&eventid='' + eventid;
        }

        return problem_url;
    },

    request: function (method, url, data) {
        [''token'', ''user_agent''].forEach(function (field) {
            if (typeof Github.params !== ''object'' || typeof Github.params[field] === ''undefined'' || Github.params[field] === '''') {
                throw ''Required Github param is not set: "'' + field + ''".'';
            }
        });

        var response,
            request = new HttpRequest();

        request.addHeader(''User-Agent: '' + Github.params.user_agent);
        request.addHeader(''Accept: application/vnd.github.v3+json'');
        request.addHeader(''Authorization: token '' + Github.params.token);

        if (typeof Github.HTTPProxy !== ''undefined'' && Github.HTTPProxy !== '''') {
            request.setProxy(Github.HTTPProxy);
        }

        if (typeof data !== ''undefined'') {
            data = JSON.stringify(data);
        }

        Zabbix.log(4, ''[ Github Webhook ] Sending request: '' + url + ((typeof data === ''string'')
            ? (''\\n'' + data)
            : ''''));

        switch (method) {
            case ''post'':
                response = request.post(url, data);
                break;

            case ''patch'':
                response = request.patch(url, data);
                break;

            default:
                throw ''Unsupported HTTP request method: '' + method;
        }

        Zabbix.log(4, ''[ Github Webhook ] Received response with status code '' +
            request.getStatus() + ''\\n'' + response);

        if (response !== null) {
            try {
                response = JSON.parse(response);
            }
            catch (error) {
                Zabbix.log(4, ''[ Github Webhook ] Failed to parse response received from Github'');
                response = null;
            }
        }

        if (typeof response !== ''object'') {
            throw ''Failed to process response received from Github. Check debug log for more information.'';
        }

        if (request.getStatus() < 200 || request.getStatus() >= 300) {
            var message = ''Request failed with status code '' + request.getStatus();

            if (response.message) {
                message += '': '' + response.message;
            }

            throw message + '' Check debug log for more information.'';
        }

        return response;
    }
};

try {
    var params = JSON.parse(value),
        github = {},
        url = '''',
        data = {},
        comment_data,
        result = { tags: {} },
        required_params = [
            ''alert_subject'', ''alert_message'', ''event_source'', ''event_value'',
            ''event_update_status'', ''event_recovery_value'', ''event_severity'',
            ''event_id'', ''trigger_id'', ''zabbix_url'',
            ''github_token'', ''github_url'', ''github_user_agent''
        ],
        method = ''post'',
        process_tags = true;

    Object.keys(params)
        .forEach(function (key) {
            if (key.startsWith(''github_'')) {
                github[key.substring(7)] = params[key];
            }
            else if (required_params.indexOf(key) !== -1 && params[key] === '''') {
                throw ''Parameter "'' + key + ''" can\\''t be empty.'';
            }
        });

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: '' + params.event_source + ''\\nMust be 0-3.'';
    }

    // Check {EVENT.VALUE} for trigger-based and internal events.
    if (params.event_value !== ''0'' && params.event_value !== ''1''
        && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
    if (params.event_update_status !== ''0'' && params.event_update_status !== ''1'' && params.event_source === ''0'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }

    if (params.event_source !== ''0'' && params.event_recovery_value === ''0'') {
        throw ''Recovery operations are supported only for trigger-based actions.'';
    }

    if (typeof params.zabbix_url !== ''string'' || params.zabbix_url.trim() === '''' || params.zabbix_url === ''{$ZABBIX.URL}'') {
        throw ''Field "zabbix_url" cannot be empty.'';
    }

    // Check for backslash in the end of url and schema.
    github.url = Github.urlCheckFormat(github.url);
    params.zabbix_url = Github.urlCheckFormat(params.zabbix_url);

    // Default url for creating issue
    url = github.url + ''repos/'' + github.repo + ''/issues'';

    data.title = params.alert_subject;
    data.body = params.alert_message;
    data.labels = [
        { name: "Zabbix" }
    ];

    // Adding label corresponding to trigger severity in Zabbix.
    if (params.event_severity !== ''undefined'' && params.event_source === ''0'') {
        data.labels.push({ name: params.event_severity });
    }

    // In case of update or resolve event.
    if (params.event_source === ''0'' && (params.event_value === ''0'' || params.event_update_status === ''1'')) {
        process_tags = false;
        method = ''patch'';
        url = github.url + ''repos/'' + github.repo + ''/issues/'' + github.issue_number;
        comment_data = Object.assign({}, data);
        delete data.body;
    } else {
        problem_url = Github.createProblemURL(params.zabbix_url, params.trigger_id, params.event_id, params.event_source);
        data.body += ''\\nEvent details in Zabbix: ['' + problem_url + '']('' + problem_url + '')'';
    }

    Github.setParams(github);
    Github.setProxy(params.HTTPProxy);

    var response = Github.request(method, url, data);

    // Leave a comment if comment_data present.
    if (typeof comment_data === ''object'') {
        url = github.url + ''repos/'' + github.repo + ''/issues/'' + github.issue_number + ''/comments'';
        Github.request("post", url, comment_data);
    }

    if (process_tags) {
        result.tags.__zbx_github_issue_number = response.number;
        result.tags.__zbx_github_repo = github.repo;
        result.tags.__zbx_github_link = response.html_url;
    }

    Zabbix.log(4, ''[ Github Webhook ] Result: '' + JSON.stringify(result));
    return JSON.stringify(result);
}
catch (error) {
    Zabbix.log(4, ''[ Github Webhook ] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','1','1','{EVENT.TAGS.__zbx_github_link}','Github: Issue {EVENT.TAGS.__zbx_github_issue_number}','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('33','4','GLPi','','','','','','','','0','25','0','0','0','0','','1','1','10s','1',E'var GLPi = {
    params: {},

    setParams: function (params) {
        if (typeof params !== ''object'') {
            return;
        }
        GLPi.params = params;
    },

    setProxy: function (HTTPProxy) {
        GLPi.HTTPProxy = HTTPProxy;
    },

    urlCheckFormat: function (url) {
        if (typeof url === ''string'' && !url.endsWith(''/'')) {
            url += ''/'';
        }

        if (url.indexOf(''http://'') === -1 && url.indexOf(''https://'') === -1) {
            url = ''https://'' + url;
        }

        return url;
    },

    getAuthToken: function (url, token) {
        var response,
            request = new HttpRequest();

        request.addHeader(''Content-Type: application/json'');
        request.addHeader(''Authorization: user_token '' + token);

        response = request.get(url + "apirest.php/initSession");

        if (response !== null) {
            try {
                response = JSON.parse(response);
            }
            catch (error) {
                Zabbix.log(4, ''[ GLPi Webhook ] Failed to receive authentication token from GLPi.'');
                response = null;
            }
        }

        if (Array.isArray(response)) {
            if (response[1]) {
                throw ''Error received from GLPi: '' + response[1];
            } else {
                throw ''Failed to receive authentication token from GLPi.'';
            }
        }

        if (typeof response !== ''object'' || !response.session_token) {
            throw ''Failed to process response received from getting GLPi authentication token. Check debug log for more information.'';
        }

        return response.session_token;
    },

    getProblemUrl: function (zabbix_url, triggerid, eventid, event_source) {
        var problem_url = zabbix_url;

        if (event_source === ''0'') {
            problem_url += ''tr_events.php?triggerid='' + triggerid + ''&eventid='' + eventid;
        }

        return problem_url;
    },

    request: function (method, url, data) {
        if (typeof GLPi.params !== ''object'' || typeof GLPi.params.authToken === ''undefined'' || GLPi.params.authToken === '''') {
            throw ''Required GLPi param authToken is not set.'';
        }

        var response,
            request = new HttpRequest();

        request.addHeader(''Content-Type: application/json'');
        request.addHeader(''Session-Token:'' + GLPi.params.authToken);

        if (typeof GLPi.HTTPProxy !== ''undefined'' && GLPi.HTTPProxy !== '''') {
            request.setProxy(GLPi.HTTPProxy);
        }

        if (typeof data !== ''undefined'') {
            data = JSON.stringify(data);
        }

        Zabbix.log(4, ''[ GLPi Webhook ] Sending request: '' + url + ((typeof data === ''string'')
            ? (''\\n'' + data)
            : ''''));

        switch (method) {
            case ''post'':
                response = request.post(url, data);
                break;

            case ''put'':
                response = request.put(url, data);
                break;

            default:
                throw ''Unsupported HTTP request method: '' + method;
        }

        Zabbix.log(4, ''[ GLPi Webhook ] Received response with status code '' +
            request.getStatus() + ''\\n'' + response);

        if (response !== null) {
            try {
                response = JSON.parse(response);
            }
            catch (error) {
                Zabbix.log(4, ''[ GLPi Webhook ] Failed to parse response received from GLPi'');
                response = null;
            }
        }

        if (typeof response !== ''object'' || typeof response === ''undefined'' || response === null) {
            throw ''Failed to process response received from GLPi. Check debug log for more information.'';
        }

        if (request.getStatus() < 200 || request.getStatus() >= 300) {
            var message = ''Request failed with status code '' + request.getStatus();

            if (response.message) {
                message += '': '' + response.message;
            }

            throw message + '' Check debug log for more information.'';
        }

        return response;
    }
};

try {
    var params = JSON.parse(value),
        glpi = {},
        url = '''',
        data = {},
        comment_data,
        result = { tags: {} },
        required_params = [
            ''alert_subject'', ''alert_message'', ''event_source'', ''event_value'',
            ''event_update_status'', ''event_recovery_value'',
            ''event_id'', ''trigger_id'', ''zabbix_url'',
            ''glpi_token'', ''glpi_url''
        ],
        method = ''post'',
        process_tags = true,
        response;

    Object.keys(params)
        .forEach(function (key) {
            if (key.startsWith(''glpi_'')) {
                glpi[key.substring(5)] = params[key];
            }
            else if (required_params.indexOf(key) !== -1 && params[key] === '''') {
                throw ''Parameter "'' + key + ''" can\\''t be empty.'';
            }
        });

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: '' + params.event_source + ''\\nMust be 0-3.'';
    }

    // Check {EVENT.VALUE} for trigger-based and internal events.
    if (params.event_value !== ''0'' && params.event_value !== ''1''
        && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
    if (params.event_update_status !== ''0'' && params.event_update_status !== ''1'' && params.event_source === ''0'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }

    if (params.event_source !== ''0'' && params.event_recovery_value === ''0'') {
        throw ''Recovery operations are supported only for trigger-based actions.'';
    }

    if (typeof params.zabbix_url !== ''string'' || params.zabbix_url.trim() === '''' || params.zabbix_url === ''{$ZABBIX.URL}'') {
        throw ''Field "zabbix_url" cannot be empty.'';
    }

    // Check for backslash in the end of url and schema.
    glpi.url = GLPi.urlCheckFormat(glpi.url);
    params.zabbix_url = GLPi.urlCheckFormat(params.zabbix_url);

    glpi.authToken = GLPi.getAuthToken(glpi.url, glpi.token);
    GLPi.setParams(glpi);

    data = {
        ''input'': {
            ''name'': params.alert_subject,
            ''content'': params.alert_message + ''\\n<a href='' + GLPi.getProblemUrl(params.zabbix_url, params.trigger_id, params.event_id, params.event_source) + ''>Link to problem in Zabbix</a>'',
            ''status'': 1,  // Set status "New"
            ''urgency'': params.event_nseverity
        }
    };

    // In case of resolve
    if (params.event_source === ''0'' && params.event_value === ''0'') {
        process_tags = false;
        dataFollowup = {
            ''input'': {
                ''items_id'': glpi.problem_id,
                ''itemtype'': ''Problem'',
                ''content'': params.alert_message + ''\\n<a href='' + GLPi.getProblemUrl(params.zabbix_url, params.trigger_id, params.event_id, params.event_source) + ''>Link to problem in Zabbix</a>''
            }
        };
        dataProblem = {
            ''id'': glpi.problem_id,
            ''input'': {
                ''name'': params.alert_subject,
                ''status'': 5,  // Set status "Solved"
                ''urgency'': params.event_nseverity
            }
        };

        GLPi.request(''put'', glpi.url + ''apirest.php/Problem/'' + glpi.problem_id, dataProblem);
        GLPi.request(''post'', glpi.url + ''apirest.php/Problem/'' + glpi.problem_id + ''/ITILFollowup'', dataFollowup);
    }

    // In case of update
    else if (params.event_source === ''0'' && params.event_update_status === ''1'') {
        process_tags = false;
        dataFollowup = {
            ''input'': {
                ''items_id'': glpi.problem_id,
                ''itemtype'': ''Problem'',
                ''content'': params.alert_message + ''\\n<a href='' + GLPi.getProblemUrl(params.zabbix_url, params.trigger_id, params.event_id, params.event_source) + ''>Link to problem in Zabbix</a>''
            }
        };
        dataProblem = {
            ''id'': glpi.problem_id,
            ''input'': {
                ''name'': params.alert_subject,
                ''urgency'': params.event_nseverity
            }
        };

        GLPi.request(''put'', glpi.url + ''apirest.php/Problem/'' + glpi.problem_id, dataProblem);
        GLPi.request(''post'', glpi.url + ''apirest.php/Problem/'' + glpi.problem_id + ''/ITILFollowup'', dataFollowup);
    }

    // In case of problem
    else {
        response = GLPi.request(''post'', glpi.url + ''apirest.php/Problem/'', data);
    }

    if (process_tags) {
        result.tags.__zbx_glpi_problem_id = response.id;
        result.tags.__zbx_glpi_link = glpi.url + ''front/problem.form.php?id='' + response.id;
    }

    Zabbix.log(4, ''[ GLPi Webhook ] Result: '' + JSON.stringify(result));
    return JSON.stringify(result);
}
catch (error) {
    Zabbix.log(4, ''[ GLPi Webhook ] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','1','1','{EVENT.TAGS.__zbx_glpi_link}','GLPi: Problem {EVENT.TAGS.__zbx_glpi_problem_id}','');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('34','4','Line','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'function sendMessage(to, messages, params) {
    var response,
        request = new HttpRequest();

    if (typeof params.HTTPProxy === ''string'' && params.HTTPProxy.trim() !== '''') {
        request.setProxy(params.HTTPProxy);
    }

    request.addHeader(''Content-Type: application/json'');
    request.addHeader(''Authorization: Bearer '' + params.bot_token);

    response = request.post(''https://api.line.me/v2/bot/message/push'', JSON.stringify({
        "to": to,
        "messages": messages
    }));

    if (request.getStatus() !== 200) {
        throw response;
    }
}

function validateParams(params) {
    if (typeof params.bot_token !== ''string'' || params.bot_token.trim() === '''') {
        throw ''Field "bot_token" cannot be empty'';
    }

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: "'' + params.event_source + ''".\\nMust be 0-3.'';
    }

    if (params.event_source !== ''0'') {
        params.event_nseverity = ''0'';
        params.event_severity = ''Not classified'';
        params.event_update_status = ''0'';
    }

    if (params.event_source === ''1'' || params.event_source === ''2'') {
        params.event_value = ''1'';
    }

    if ([0, 1, 2, 3, 4, 5].indexOf(parseInt(params.event_nseverity)) === -1) {
        throw ''Incorrect "event_nseverity" parameter given: '' + params.event_nseverity + ''\\nMust be 0-5.'';
    }

    if (params.event_update_status !== ''0'' && params.event_update_status !== ''1'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }

    if (params.event_value !== ''0'' && params.event_value !== ''1'') {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    if (isNaN(params.trigger_id) && params.event_source === ''0'') {
        throw ''field "trigger_id" is not a number'';
    }

    if (typeof params.zabbix_url !== ''string'' || params.zabbix_url.trim() === '''') {
        throw ''Field "zabbix_url" cannot be empty'';
    }

    if (!/^(http|https):\\/\\/.+/.test(params.zabbix_url)) {
        throw ''Field "zabbix_url" must contain a schema'';
    }
}

function getZabbixProblemLink(params) {
    return params.zabbix_url + (params.zabbix_url.endsWith(''/'') ? '''' : ''/'') + ''tr_events.php?triggerid='' + params.trigger_id + ''&eventid='' + params.event_id;    
}

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

    validateParams(params);

    severity_emoji = [
        "\\u26AA",
        "\\uD83D\\uDD35",
        "\\uD83D\\uDFE4",
        "\\uD83D\\uDFE1",
        "\\uD83D\\uDFE0",
        "\\uD83D\\uDD34",
    ];

    // If its a trigger and a recovery operation and not an update operation.
    if (params.event_source === ''0'' && params.event_value === ''0'' && params.event_update_status === ''0'') {
        var line_message = [
            {
                "type": "text",
                "text": ''\\u2705 '' + params.alert_subject + ''\\n\\n'' + params.alert_message + ''\\n'' + params.trigger_description + ''\\n\\n'' + getZabbixProblemLink(params)
            }
        ];
    }
    // If its a trigger and its a problem.
    else if (params.event_source === ''0'' && params.event_value === ''1'') {
        var line_message = [
            {
                "type": "text",
                "text": severity_emoji[params.event_nseverity] + '' '' + params.alert_subject + ''\\n\\n'' + params.alert_message + ''\\n'' + params.trigger_description + ''\\n\\n'' + getZabbixProblemLink(params)
            }
        ];
    }
    // If its a trigger and its an update operation.
    else if (params.event_source === ''0'' && params.event_update_status === ''1'') {
        var line_message = [
            {
                "type": "text",
                "text": ''\\u2733 '' + severity_emoji[params.event_nseverity] + '' '' + params.alert_subject + ''\\n\\n'' + params.alert_message + ''\\n'' + params.trigger_description + ''\\n\\n'' + getZabbixProblemLink(params)
            }
        ];
    }
    else {
        var line_message = [
            {
                "type": "text",
                "text": params.alert_subject + ''\\n\\n'' + params.alert_message + ''\\n''
            }
        ];
    }

    sendMessage(params.send_to, line_message, params);

    return ''OK'';
}
catch (err) {
    Zabbix.log(4, ''[ Line Webhook ] Line notification failed : '' + err);
    throw ''Line notification failed : '' + err;
}','30s','0','0','','','Please refer to setup guide here: https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/line

Set bot_token parameter to your Line bot token.
When assigning Line media to the Zabbix user - add the ID of the target recipient. Use a userId, groupId, or roomId value.');
INSERT INTO media_type (mediatypeid,type,name,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem,username,passwd,status,smtp_port,smtp_security,smtp_verify_peer,smtp_verify_host,smtp_authentication,exec_params,maxsessions,maxattempts,attempt_interval,content_type,script,timeout,process_tags,show_event_menu,event_menu_url,event_menu_name,description) values ('35','4','OTRS CE','','','','','','','','0','25','0','0','0','0','','1','3','10s','1',E'var OTRS = {
    params: {},
    entrypoint: ''nph-genericinterface.pl/Webservice/ZabbixTicketConnector/Ticket'',

    setParams: function (params) {
        if (typeof params !== ''object'') {
            return;
        }

        OTRS.params = params;
        if (typeof OTRS.params.url === ''string'') {
            if (!OTRS.params.url.endsWith(''/'')) {
                OTRS.params.url += ''/'';
            }
        }
    },

    addDynamicFields: function (data, fields) {
        if (typeof fields === ''object'' && Object.keys(fields).length) {
            data.DynamicField = [];

            Object.keys(fields)
                .forEach(function(field) {
                    if (field !== undefined) {
                        if (fields[field].match(/^\\d{4}[.-]\\d{2}[.-]\\d{2}$/)) {
                            fields[field] = fields[field].replace(/\\./g, ''-'');
                        }

                        data.DynamicField.push({Name: field, Value: fields[field]});
                    }
                });
        }

        return data;
    },

    request: function (method, query, data) {
        [''url'', ''auth_user'', ''auth_password'', ''queue'',
            ''customer'', ''ticket_state'', ''default_priority_id'', ''time_unit''].forEach(function (field) {
            if (typeof OTRS.params !== ''object'' || typeof OTRS.params[field] === ''undefined''
                || OTRS.params[field] === '''' ) {
                throw ''Required param is not set: "'' + field + ''".'';
            }
        });

        var response,
            request = new HttpRequest(),
            url = OTRS.params.url + query +
                ''?UserLogin='' + encodeURIComponent(OTRS.params.auth_user) +
                ''&Password='' + encodeURIComponent(OTRS.params.auth_password);

        if (typeof OTRS.HTTPProxy !== ''undefined'' && OTRS.HTTPProxy.trim() !== '''') {
            request.setProxy(OTRS.HTTPProxy);
        }

        request.addHeader(''Content-Type: application/json'');

        if (typeof data !== ''undefined'') {
            data = JSON.stringify(data);
        }

        Zabbix.log(4, ''[ OTRS Webhook ] Sending request: '' +
            url + ((typeof data === ''string'') ? ('' '' + data) : ''''));

        switch (method) {
            case ''get'':
                response = request.get(url, data);
                break;

            case ''post'':
                response = request.post(url, data);
                break;

            case ''put'':
                response = request.put(url, data);
                break;

            default:
                throw ''Unsupported HTTP request method: '' + method;
        }

        Zabbix.log(4, ''[ ((OTRS)) CE Webhook ] Received response with status code '' + request.getStatus() + '': '' + response);

        if (request.getStatus() < 200 || request.getStatus() >= 300) {
            var message = ''Request failed with status code '' + request.getStatus();

            message += '': '' + response;
            throw message + '' Check debug log for more information.'';
        }

        if (response !== null) {
            try {
                response = JSON.parse(response);
            }
            catch (error) {
                Zabbix.log(4, ''[ ((OTRS)) CE Webhook ] Failed to parse response received from ((OTRS)) CE'');
                response = null;
            }
        }

        if (typeof response.Error !== ''undefined''
            && Object.keys(response.Error).length > 0) {
            message = ''Request failed: '' + JSON.stringify(response.Error);
        }


        return {
            status: request.getStatus(),
            response: response
        };
    },

    createTicket: function(subject, message, priority, fields) {
        var result,
            data = {
                Ticket: {
                    Title: subject,
                    Queue: OTRS.params.queue,
                    State: OTRS.params.ticket_state,
                    PriorityID: priority || OTRS.params.default_priority_id,
                    CustomerUser: OTRS.params.customer
                },
                Article: {
                    Subject: subject,
                    Body: message,
                    TimeUnit: OTRS.params.time_unit,
                    ContentType: ''text/plain; charset=utf8''
                }
            };

        result = OTRS.request(''post'', OTRS.entrypoint, OTRS.addDynamicFields(data, fields));

        if (typeof result.response !== ''object''
            || typeof result.response.TicketID === ''undefined''
            || result.status != 200) {
            throw ''Cannot create ((OTRS)) CE ticket. Check debug log for more information.'';
        }

        return result.response.TicketID;
    },

    updateTicket: function(subject, message) {
        var result,
            data = {
                Article: {
                    Subject: subject,
                    Body: message || '''',
                    TimeUnit: OTRS.params.time_unit,
                    ContentType: ''text/plain; charset=utf8''
                }
            };

        result = OTRS.request(''put'', OTRS.entrypoint + ''/'' + encodeURIComponent(OTRS.params.ticket_id), data);

        if (typeof result.response !== ''object''
            || typeof result.response.TicketID === ''undefined''
            || result.status != 200) {
            throw ''Cannot update ((OTRS)) CE ticket. Check debug log for more information.'';
        }
    }
};

try {
    var params = JSON.parse(value),
        params_otrs = {},
        params_fields = {},
        params_update = {},
        result = {tags: {}},
        required_params = [
            ''alert_subject'', ''event_source'',
            ''event_value'',  ''event_update_status''
        ],
        severities = [
            {name: ''not_classified'', color: ''#97AAB3''},
            {name: ''information'', color: ''#7499FF''},
            {name: ''warning'', color: ''#FFC859''},
            {name: ''average'', color: ''#FFA059''},
            {name: ''high'', color: ''#E97659''},
            {name: ''disaster'', color: ''#E45959''},
            {name: ''resolved'', color: ''#009900''},
            {name: null, color: ''#000000''}
        ],
        priority;

    Object.keys(params)
        .forEach(function (key) {
            if (key.startsWith(''otrs_'')) {
                params_otrs[key.substring(5)] = params[key];
            }
            else if (key.startsWith(''dynamicfield_'')) {
                params_fields[key.substring(13)] = params[key];
            }
            else if (key.startsWith(''event_update_'')) {
                params_update[key.substring(13)] = params[key];
            }
            else if (required_params.indexOf(key) !== -1 && params[key].trim() === '''') {
                throw ''Parameter "'' + key + ''" cannot be empty.'';
            }
        });

    if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
        throw ''Incorrect "event_source" parameter given: '' + params.event_source + ''\\nMust be 0-3.'';
    }

    // Check {EVENT.VALUE} for trigger-based and internal events.
    if (params.event_value !== ''0'' && params.event_value !== ''1''
        && (params.event_source === ''0'' || params.event_source === ''3'')) {
        throw ''Incorrect "event_value" parameter given: '' + params.event_value + ''\\nMust be 0 or 1.'';
    }

    // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
    if (params.event_source === ''0'' && params.event_update_status !== ''0'' && params.event_update_status !== ''1'') {
        throw ''Incorrect "event_update_status" parameter given: '' + params.event_update_status + ''\\nMust be 0 or 1.'';
    }

    if (params.event_source !== ''0'' && params.event_value === ''0'') {
        throw ''Recovery operations are supported only for trigger-based actions.'';
    }

    if (params.event_source === ''0''
        && ((params.event_value === ''1'' && params.event_update_status === ''1'')
            || (params.event_value === ''0''
                && (params.event_update_status === ''0'' || params.event_update_status === ''1'')))
        && (isNaN(parseInt(params.otrs_ticket_id)) || parseInt(params.otrs_ticket_id) < 1 )) {
        throw ''Incorrect "otrs_ticket_id" parameter given: '' + params.otrs_ticket_id +
            ''\\nMust be positive integer.'';
    }

    if ([0, 1, 2, 3, 4, 5].indexOf(parseInt(params.event_nseverity)) === -1) {
        params.event_nseverity = ''7'';
    }

    if (params.event_value === ''0'') {
        params.event_nseverity = ''6'';
    }

    priority = params[''severity_'' + severities[params.event_nseverity].name];
    priority = priority && priority.trim() || severities[7].name;

    OTRS.setParams(params_otrs);
    OTRS.HTTPProxy = params.HTTPProxy;

    // Create ticket for non trigger-based events.
    if (params.event_source !== ''0''
        && params.event_value !== ''0'') {
        OTRS.createTicket(params.alert_subject, params.alert_message, priority);
    }
    // Create ticket for trigger-based events.
    else if (params.event_value === ''1'' && params_update.status === ''0'') {
        var ticket_id = OTRS.createTicket(params.alert_subject,
            params.alert_subject + ''\\n'' + params.alert_message + ''\\n'' +
            params.zabbix_url + (params.zabbix_url.endsWith(''/'') ? '''' : ''/'') +
            ''tr_events.php?triggerid='' + params.trigger_id + ''&eventid='' + params.event_id + ''\\n'',
            priority,
            params_fields);

        result.tags.__zbx_otrs_ticket_id = ticket_id;
        result.tags.__zbx_otrs_ticketlink = params.otrs_url +
            (params.otrs_url.endsWith(''/'') ? '''' : ''/'') + ''index.pl?Action=AgentTicketZoom;TicketID='' + ticket_id;
    }
    // Update created ticket for trigger-based event.
    else {
        OTRS.updateTicket(params.alert_subject, params.alert_message);
    }

    return JSON.stringify(result);
}
catch (error) {
    Zabbix.log(3, ''[ ((OTRS)) CE Webhook ] ERROR: '' + error);
    throw ''Sending failed: '' + error;
}','30s','1','1','{EVENT.TAGS.__zbx_otrs_ticketlink}','((OTRS)) CE: ticket #{EVENT.TAGS.__zbx_otrs_ticket_id}','');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('1','5','zabbix_url','{$ZABBIX.URL}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('2','5','bot_token','<YOUR BOT TOKEN>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('3','5','mattermost_url','<YOUR MATTERMOST URL>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('4','5','send_mode','alarm');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('5','5','send_to','{ALERT.SENDTO}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('6','5','event_tags','{EVENT.TAGS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('8','5','event_nseverity','{EVENT.NSEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('10','5','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('11','5','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('12','5','event_date','{EVENT.DATE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('13','5','event_time','{EVENT.TIME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('14','5','event_severity','{EVENT.SEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('15','5','event_opdata','{EVENT.OPDATA}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('16','5','event_id','{EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('18','5','trigger_id','{TRIGGER.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('19','5','trigger_description','{TRIGGER.DESCRIPTION}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('20','5','host_name','{HOST.HOST}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('21','5','host_ip','{HOST.IP}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('22','5','event_update_date','{EVENT.UPDATE.DATE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('23','5','event_update_time','{EVENT.UPDATE.TIME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('24','5','event_recovery_date','{EVENT.RECOVERY.DATE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('25','5','event_recovery_time','{EVENT.RECOVERY.TIME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('37','6','zbxurl','{$ZABBIX.URL}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('39','7','token','<put your key>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('40','7','eventid','{EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('41','7','eventname','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('42','7','hostname','{HOST.NAME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('43','7','hostip','{HOST.IP}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('44','7','severity','{EVENT.NSEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('45','7','triggerdesc','{TRIGGER.DESCRIPTION}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('46','7','triggeropdata','{EVENT.OPDATA}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('47','7','eventtags','{EVENT.TAGS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('48','7','triggerid','{TRIGGER.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('49','7','eventdate','{EVENT.DATE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('50','7','eventtime','{EVENT.TIME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('52','7','eventack','{EVENT.ACK.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('53','7','eventupdate','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('54','7','eventvalue','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('55','7','url','{$ZABBIX.URL}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('56','8','token','<PUSHOVER TOKEN HERE>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('57','8','user','{ALERT.SENDTO}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('58','8','message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('59','8','title','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('60','8','url','{$ZABBIX.URL}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('61','8','url_title','Zabbix');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('63','8','eventid','{EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('64','8','triggerid','{TRIGGER.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('65','9','zabbix_url','{$ZABBIX.URL}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('66','9','bot_token','<PLACE YOUR KEY HERE>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('67','9','channel','{ALERT.SENDTO}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('68','9','slack_mode','alarm');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('69','9','slack_as_user','true');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('71','9','event_tags','{EVENT.TAGSJSON}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('73','9','event_nseverity','{EVENT.NSEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('75','9','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('76','9','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('77','9','event_date','{EVENT.DATE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('78','9','event_time','{EVENT.TIME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('79','9','event_severity','{EVENT.SEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('80','9','event_opdata','{EVENT.OPDATA}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('81','9','event_id','{EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('83','9','trigger_id','{TRIGGER.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('84','9','trigger_description','{TRIGGER.DESCRIPTION}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('85','9','host_name','{HOST.NAME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('87','9','event_update_date','{EVENT.UPDATE.DATE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('88','9','event_update_time','{EVENT.UPDATE.TIME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('89','9','event_recovery_date','{EVENT.RECOVERY.DATE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('90','9','event_recovery_time','{EVENT.RECOVERY.TIME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('91','10','zabbix_url','{$ZABBIX.URL}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('92','10','discord_endpoint','{ALERT.SENDTO}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('93','10','use_default_message','false');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('94','10','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('95','10','alert_subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('96','10','event_name','{EVENT.NAME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('97','10','event_id','{EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('98','10','event_severity','{EVENT.SEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('99','10','event_nseverity','{EVENT.NSEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('100','10','event_opdata','{EVENT.OPDATA}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('101','10','event_tags','{EVENT.TAGS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('102','10','event_time','{EVENT.TIME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('103','10','event_date','{EVENT.DATE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('104','10','event_recovery_date','{EVENT.RECOVERY.DATE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('105','10','event_recovery_time','{EVENT.RECOVERY.TIME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('106','10','event_update_date','{EVENT.UPDATE.DATE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('107','10','event_update_time','{EVENT.UPDATE.TIME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('108','10','event_update_action','{EVENT.UPDATE.ACTION}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('109','10','event_update_message','{EVENT.UPDATE.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('110','10','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('111','10','event_update_user','{USER.FULLNAME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('112','10','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('113','10','host_ip','{HOST.IP}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('114','10','host_name','{HOST.NAME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('115','10','trigger_description','{TRIGGER.DESCRIPTION}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('116','10','trigger_id','{TRIGGER.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('117','8','endpoint','https://api.pushover.net/1/messages.json');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('118','8','retry','60');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('119','8','expire','1200');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('120','11','teamsecret','{ALERT.SENDTO}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('121','11','Subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('122','11','Message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('123','11','Severity','{EVENT.SEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('125','11','Hostname','{HOST.NAME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('127','12','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('128','12','alert_subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('129','12','event_recovery_value','{EVENT.RECOVERY.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('130','12','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('131','12','event_tags_json','{EVENT.TAGSJSON}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('132','12','event_update_action','{EVENT.UPDATE.ACTION}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('133','12','event_update_message','{EVENT.UPDATE.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('134','12','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('135','12','event_update_user','{USER.FULLNAME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('136','12','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('137','12','jira_issue_key','{EVENT.TAGS.__zbx_jira_issuekey}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('138','12','jira_issue_type','<PLACE ISSUETYPE NAME>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('139','12','jira_password','<PLACE PASSWORD OR TOKEN>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('140','12','jira_project_key','<PLACE PROJECT KEY>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('141','12','jira_url','<PLACE YOUR JIRA URL>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('142','12','jira_user','<PLACE LOGIN>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('143','12','trigger_description','{TRIGGER.DESCRIPTION}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('144','13','<''DATETIME'' CUSTOMFIELD FOR EVENT RECOVERY TIME>','{EVENT.RECOVERY.DATE}T{EVENT.RECOVERY.TIME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('145','13','<''DATETIME'' CUSTOMFIELD FOR EVENT TIME>','{EVENT.DATE}T{EVENT.TIME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('146','13','<''NUMBER'' CUSTOMFIELD FOR EVENT.ID>','{EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('147','13','<''NUMBER'' CUSTOMFIELD FOR TRIGGER.ID>','{TRIGGER.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('148','13',E'<''STRING'' CUSTOMFIELD FOR HOST\\IP>','{HOST.HOST} [{HOST.IP}]');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('149','13','<''STRING'' CUSTOMFIELD FOR OPERATIONAL DATA>','{EVENT.OPDATA}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('150','13','<''STRING'' CUSTOMFIELD FOR SEVERITY>','{EVENT.SEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('151','13','<''URL'' CUSTOMFIELD FOR EVENT URL>','{$ZABBIX.URL}/tr_events.php?triggerid={TRIGGER.ID}&eventid={EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('152','13','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('153','13','alert_subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('154','13','event_recovery_value','{EVENT.RECOVERY.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('155','13','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('156','13','event_tags_json','{EVENT.TAGSJSON}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('157','13','event_update_action','{EVENT.UPDATE.ACTION}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('158','13','event_update_message','{EVENT.UPDATE.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('159','13','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('160','13','event_update_user','{USER.FULLNAME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('161','13','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('162','13','jira_issue_key','{EVENT.TAGS.__zbx_jira_issuekey}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('163','13','jira_issue_type','<PLACE ISSUETYPE NAME>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('164','13','jira_password','<PLACE PASSWORD OR TOKEN>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('165','13','jira_project_key','<PLACE PROJECT KEY>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('166','13','jira_url','<PLACE YOUR JIRA URL>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('167','13','jira_user','<PLACE LOGIN>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('168','13','trigger_description','{TRIGGER.DESCRIPTION}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('169','14','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('170','14','alert_subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('171','14','event_date','{EVENT.DATE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('172','14','event_id','{EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('173','14','event_nseverity','{EVENT.NSEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('174','14','event_opdata','{EVENT.OPDATA}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('175','14','event_recovery_date','{EVENT.RECOVERY.DATE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('176','14','event_recovery_time','{EVENT.RECOVERY.TIME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('177','14','event_severity','{EVENT.SEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('178','14','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('179','14','event_status','{EVENT.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('180','14','event_tags','{EVENT.TAGS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('181','14','event_time','{EVENT.TIME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('182','14','event_update_action','{EVENT.UPDATE.ACTION}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('183','14','event_update_date','{EVENT.UPDATE.DATE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('184','14','event_update_message','{EVENT.UPDATE.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('185','14','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('186','14','event_update_time','{EVENT.UPDATE.TIME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('187','14','event_update_user','{USER.FULLNAME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('188','14','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('189','14','host_ip','{HOST.IP}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('190','14','host_name','{HOST.NAME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('191','14','teams_endpoint','<PLACE WEBHOOK URL HERE>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('192','14','trigger_description','{TRIGGER.DESCRIPTION}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('193','14','trigger_id','{TRIGGER.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('194','14','use_default_message','false');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('195','14','zabbix_url','{$ZABBIX.URL}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('196','15','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('197','15','alert_subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('198','15','event_id','{EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('199','15','event_nseverity','{EVENT.NSEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('200','15','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('201','15','event_update_message','{EVENT.UPDATE.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('202','15','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('203','15','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('204','15','redmine_access_key','<PUT YOUR ACCESS KEY>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('205','15','redmine_issue_key','{EVENT.TAGS.__zbx_redmine_issue_id}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('206','15','redmine_project','<PUT YOUR PROJECT ID OR NAME>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('207','15','redmine_tracker_id','<PUT YOUR TRACKER ID>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('208','15','redmine_url','<PUT YOUR REDMINE URL>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('209','15','trigger_id','{TRIGGER.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('210','15','zabbix_url','{$ZABBIX.URL}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('211','16','Message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('212','16','ParseMode','');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('213','16','Subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('214','16','To','{ALERT.SENDTO}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('215','16','Token','<PLACE YOUR TOKEN>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('216','17','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('217','17','alert_subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('218','17','event_id','{EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('219','17','event_nseverity','{EVENT.NSEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('220','17','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('221','17','event_tags','{EVENT.TAGS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('222','17','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('223','17','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('224','17','severity_average','normal');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('225','17','severity_default','-');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('226','17','severity_disaster','urgent');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('227','17','severity_high','high');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('228','17','severity_information','low');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('229','17','severity_not_classified','low');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('230','17','severity_warning','normal');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('231','17','trigger_id','{TRIGGER.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('232','17','zbxurl','{$ZABBIX.URL}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('233','17','zendesk_issue_key','{EVENT.TAGS.__zbx_zdk_issuekey}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('234','17','zendesk_token','<put your {enduser_email_address}/token:{api_token}>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('235','17','zendesk_type','incident');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('236','17','zendesk_url','<put your Zendesk URL>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('237','18','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('238','18','alert_subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('239','18','event_nseverity','{EVENT.NSEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('240','18','event_recovery_value','{EVENT.RECOVERY.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('241','18','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('242','18','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('243','18','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('244','18','servicenow_password','<PLACE PASSWORD HERE>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('245','18','servicenow_sys_id','{EVENT.TAGS.__zbx_servicenow_sys_id}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('246','18','servicenow_url','{ALERT.SENDTO}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('247','18','servicenow_user','<PLACE USERNAME HERE>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('248','18','urgency_for_average','2');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('249','18','urgency_for_disaster','1');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('250','18','urgency_for_high','2');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('251','18','urgency_for_information','3');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('252','18','urgency_for_not_classified','3');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('253','18','urgency_for_warning','3');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('254','19','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('255','19','alert_subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('256','19','event_id','{EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('257','19','event_nseverity','{EVENT.NSEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('258','19','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('259','19','event_tags','{EVENT.TAGSJSON}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('260','19','event_update_message','{EVENT.UPDATE.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('261','19','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('262','19','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('263','19','trigger_id','{TRIGGER.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('264','19','zabbix_url','{$ZABBIX.URL}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('265','19','zammad_access_token','<PUT YOUR ACCESS TOKEN>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('266','19','zammad_customer','<PUT YOUR CUSTOMER EMAIL>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('267','19','zammad_enable_tags','true');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('268','19','zammad_ticket_id','{EVENT.TAGS.__zbx_zammad_ticket_id}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('269','19','zammad_url','<PUT YOUR ZAMMAD URL>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('270','20','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('271','20','alert_subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('272','20','event_recovery_value','{EVENT.RECOVERY.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('273','20','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('274','20','event_tags_json','{EVENT.TAGSJSON}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('275','20','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('276','20','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('277','20','jira_password','<PLACE PASSWORD OR TOKEN>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('278','20','jira_request_key','{EVENT.TAGS.__zbx_jira_requestkey}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('279','20','jira_request_type_id','<PLACE REQUEST TYPE ID>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('280','20','jira_servicedesk_id','<PLACE SERVICEDESK ID>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('281','20','jira_url','<PLACE YOUR JIRA URL>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('282','20','jira_user','<PLACE LOGIN>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('283','21','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('284','21','alert_subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('285','21','event_id','{EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('286','21','event_nseverity','{EVENT.NSEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('287','21','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('288','21','event_update_message','{EVENT.UPDATE.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('289','21','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('290','21','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('291','21','otrs_auth_password','<PUT YOUR USER PASSWORD>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('292','21','otrs_auth_user','<PUT YOUR USER NAME>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('293','21','otrs_customer','<PUT YOUR CUSTOMER EMAIL>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('294','21','otrs_default_priority_id','3');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('295','21','otrs_queue','<PUT YOUR QUEUE NAME>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('296','21','otrs_ticket_id','{EVENT.TAGS.__zbx_otrs_ticket_id}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('297','21','otrs_ticket_state','new');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('298','21','otrs_time_unit','0');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('299','21','otrs_url','<PUT YOUR OTRS URL>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('300','21','trigger_id','{TRIGGER.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('301','21','zabbix_url','{$ZABBIX.URL}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('302','11','Event_Ack_Status','{EVENT.ACK.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('303','11','Event_Date_Time','{EVENT.DATE} {EVENT.TIME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('304','11','Event_ID','{EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('305','11','Event_Update_Action','{EVENT.UPDATE.ACTION}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('306','11','Event_Update_Status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('307','11','Host_IP','{HOST.IP}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('308','11','Trigger_ID','{TRIGGER.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('309','11','Trigger_Status','{TRIGGER.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('310','11','User','{USER.FULLNAME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('311','11','Zabbix_URL','{$ZABBIX.URL}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('312','10','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('313','22','.ILERT.ALERT.SOURCE.KEY','{ALERT.SENDTO}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('314','22','.ILERT.INCIDENT.SUMMARY','');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('315','22','ALERT.MESSAGE','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('316','22','ALERT.SUBJECT','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('317','22','EVENT.ACK.STATUS','{EVENT.ACK.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('318','22','EVENT.DATE','{EVENT.DATE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('319','22','EVENT.ID','{EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('320','22','EVENT.NAME','{EVENT.NAME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('321','22','EVENT.NSEVERITY','{EVENT.NSEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('322','22','EVENT.OPDATA','{EVENT.OPDATA}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('323','22','EVENT.RECOVERY.DATE','{EVENT.RECOVERY.DATE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('324','22','EVENT.RECOVERY.TIME','{EVENT.RECOVERY.TIME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('325','22','EVENT.RECOVERY.VALUE','{EVENT.RECOVERY.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('326','22','EVENT.SEVERITY','{EVENT.SEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('327','22','EVENT.TAGS','{EVENT.TAGS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('328','22','EVENT.TIME','{EVENT.TIME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('329','22','EVENT.UPDATE.ACTION','{EVENT.UPDATE.ACTION}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('330','22','EVENT.UPDATE.DATE','{EVENT.UPDATE.DATE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('331','22','EVENT.UPDATE.MESSAGE','{EVENT.UPDATE.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('332','22','EVENT.UPDATE.STATUS','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('333','22','EVENT.UPDATE.TIME','{EVENT.UPDATE.TIME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('334','22','EVENT.VALUE','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('335','22','HOST.HOST','{HOST.HOST}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('336','22','HOST.IP','{HOST.IP}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('337','22','HOST.NAME','{HOST.NAME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('338','22','ITEM.ID1','{ITEM.ID1}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('339','22','ITEM.ID2','{ITEM.ID2}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('340','22','ITEM.ID3','{ITEM.ID3}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('341','22','ITEM.ID4','{ITEM.ID4}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('342','22','ITEM.ID5','{ITEM.ID5}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('343','22','ITEM.NAME1','{ITEM.NAME1}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('344','22','ITEM.NAME2','{ITEM.NAME2}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('345','22','ITEM.NAME3','{ITEM.NAME3}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('346','22','ITEM.NAME4','{ITEM.NAME4}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('347','22','ITEM.NAME5','{ITEM.NAME5}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('348','22','TRIGGER.DESCRIPTION','{TRIGGER.DESCRIPTION}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('349','22','TRIGGER.ID','{TRIGGER.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('350','22','TRIGGER.NAME','{TRIGGER.NAME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('351','22','TRIGGER.SEVERITY','{TRIGGER.SEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('352','22','TRIGGER.STATUS','{TRIGGER.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('353','22','TRIGGER.URL','{TRIGGER.URL}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('354','22','TRIGGER.VALUE','{TRIGGER.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('355','22','USER.FULLNAME','{USER.FULLNAME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('356','22','ZABBIX.URL','{$ZABBIX.URL}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('357','5','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('358','5','alert_subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('359','5','discovery_host_dns','{DISCOVERY.DEVICE.DNS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('360','5','discovery_host_ip','{DISCOVERY.DEVICE.IPADDRESS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('361','5','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('362','6','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('363','6','alert_subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('364','6','event_id','{EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('365','6','event_nseverity','{EVENT.NSEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('366','6','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('367','6','event_tags_json','{EVENT.TAGSJSON}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('368','6','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('369','6','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('370','6','opsgenie_api','<put your opsgenie api>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('371','6','opsgenie_tags','');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('372','6','opsgenie_teams','');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('373','6','opsgenie_token','<put your token>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('374','6','opsgenie_web','<put your opsgenie web>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('375','6','severity_average','P3');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('376','6','severity_default','P5');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('377','6','severity_disaster','P1');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('378','6','severity_high','P2');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('379','6','severity_information','P5');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('380','6','severity_not_classified','P5');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('381','6','severity_warning','P4');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('382','6','trigger_id','{TRIGGER.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('383','6','zbxuser','{USER.FULLNAME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('384','7','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('385','7','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('386','8','event_nseverity','{EVENT.NSEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('387','8','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('388','8','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('389','8','priority_average','0');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('390','8','priority_default','0');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('391','8','priority_disaster','0');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('392','8','priority_high','0');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('393','8','priority_information','0');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('394','8','priority_not_classified','0');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('395','8','priority_warning','0');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('396','9','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('397','9','alert_subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('398','9','discovery_host_dns','{DISCOVERY.DEVICE.DNS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('399','9','discovery_host_ip','{DISCOVERY.DEVICE.IPADDRESS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('400','9','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('401','9','host_conn','{HOST.CONN}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('402','23','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('403','23','alert_subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('404','23','event_nseverity','{EVENT.NSEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('405','23','event_recovery_value','{EVENT.RECOVERY.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('406','23','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('407','23','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('408','23','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('409','23','priority_average','Medium');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('410','23','priority_default','Low');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('411','23','priority_disaster','Critical');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('412','23','priority_high','High');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('413','23','samanage_incident_id','{EVENT.TAGS.__zbx_solarwinds_inc_id}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('414','23','samanage_token','<PUT YOUR TOKEN HERE>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('415','23','samanage_url','<PUT YOUR INSTANCE URL HERE>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('416','24','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('417','24','alert_subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('418','24','event_id','{EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('419','24','event_nseverity','{EVENT.NSEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('420','24','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('421','24','event_update_message','{EVENT.UPDATE.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('422','24','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('423','24','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('424','24','sysaid_auth_password','<PUT YOUR USER PASSWORD>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('425','24','sysaid_auth_user','<PUT YOUR USER NAME>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('426','24','sysaid_category_level_1','<PUT YOUR CATEGORY>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('427','24','sysaid_category_level_2','<PUT YOUR SUB-CATEGORY>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('428','24','sysaid_category_level_3','<PUT YOUR THIRD LEVEL CATEGORY>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('429','24','sysaid_default_priority_id','1');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('430','24','sysaid_incident_id','{EVENT.TAGS.__zbx_sysaid_incident_id}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('431','24','sysaid_incident_state','1');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('432','24','sysaid_template_id','<PUT YOUR TEMPLATE ID>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('433','24','sysaid_urgency_id','<PUT YOUR URGENCY ID>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('434','24','sysaid_url','<PUT YOUR SYSAID URL>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('435','24','trigger_id','{TRIGGER.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('436','24','zabbix_url','{$ZABBIX.URL}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('437','25','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('438','25','alert_subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('439','25','event_id','{EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('440','25','event_nseverity','{EVENT.NSEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('441','25','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('442','25','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('443','25','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('444','25','severity_average','P3');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('445','25','severity_default','P5');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('446','25','severity_disaster','P1');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('447','25','severity_high','P2');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('448','25','severity_information','P5');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('449','25','severity_not_classified','P5');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('450','25','severity_warning','P4');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('451','25','topdesk_api','<put your TOPdesk API URL>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('452','25','topdesk_issue_key','{EVENT.TAGS.__zbx_tpd_issuekey}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('453','25','topdesk_password','<put your TOPdesk application password>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('454','25','topdesk_status','<put default status for new tickets>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('455','25','topdesk_user','<put your TOPdesk username>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('456','25','trigger_id','{TRIGGER.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('457','25','zbxurl','{$ZABBIX.URL}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('458','26','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('459','26','alert_subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('460','26','event_recovery_value','{EVENT.RECOVERY.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('461','26','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('462','26','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('463','26','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('464','26','itop_api_version','1.3');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('465','26','itop_class','UserRequest');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('466','26','itop_comment','Created by Zabbix action {ACTION.NAME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('467','26','itop_id','{EVENT.TAGS.__zbx_itop_id}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('468','26','itop_log','private_log');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('469','26','itop_organization_id','<PLACE ORGANIZATION ID>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('470','26','itop_password','<PLACE PASSWORD OR TOKEN>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('471','26','itop_url','<PLACE YOUR ITOP URL>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('472','26','itop_user','<PLACE LOGIN>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('473','27','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('474','27','alert_subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('475','27','event_nseverity','{EVENT.NSEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('476','27','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('477','27','event_update_action','{EVENT.UPDATE.ACTION}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('478','27','event_update_message','{EVENT.UPDATE.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('479','27','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('480','27','event_update_user','{USER.FULLNAME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('481','27','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('482','27','field_1_full:Host','{HOST.NAME} [{HOST.IP}]');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('483','27','field_2_short:Severity','{EVENT.SEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('484','27','field_3_short:Event time','{EVENT.DATE} {EVENT.TIME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('485','27','field_3_short_r:Recovery time','{EVENT.RECOVERY.DATE} {EVENT.RECOVERY.TIME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('486','27','field_4_short_r:Event duration','{EVENT.DURATION}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('487','27','field_5_short:Operational data','{EVENT.OPDATA}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('488','27','field_999_full_p:Trigger description','{TRIGGER.DESCRIPTION}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('489','27','rc_api_url','api/v1/');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('490','27','rc_msg_id','{EVENT.TAGS.__zbx_rc_id}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('491','27','rc_room_id','{EVENT.TAGS.__zbx_rc_rid}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('492','27','rc_send_to','{ALERT.SENDTO}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('493','27','rc_title_link','{$ZABBIX.URL}/tr_events.php?triggerid={TRIGGER.ID}&eventid={EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('494','27','rc_url','<PLACE YOUR INSTANCE URL HERE>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('495','27','rc_user_id','<PLACE USER ID HERE>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('496','27','rc_user_token','<PLACE TOKEN HERE>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('497','27','use_default_message','false');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('498','28','event_info','{$ZABBIX.URL}/tr_events.php?triggerid={TRIGGER.ID}&eventid={EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('499','28','event_nseverity','{EVENT.NSEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('500','28','event_recovery_value','{EVENT.RECOVERY.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('501','28','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('502','28','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('503','28','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('504','28','field:entity_display_name','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('505','28','field:entity_id','{EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('506','28','field:hostname','{HOST.NAME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('507','28','field:monitoring_tool','Zabbix');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('508','28','field:operational_data','{EVENT.OPDATA}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('509','28','field:severity','{EVENT.SEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('510','28','field:state_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('511','28','field_p:trigger_description','{TRIGGER.DESCRIPTION}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('512','28','field_r:event_duration','{EVENT.DURATION}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('513','28','field_r:recovery time','{EVENT.RECOVERY.DATE} {EVENT.RECOVERY.TIME}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('514','28','priority_average','WARNING');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('515','28','priority_default','INFO');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('516','28','priority_disaster','CRITICAL');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('517','28','priority_high','WARNING');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('518','28','priority_information','INFO');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('519','28','priority_not_classified','INFO');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('520','28','priority_resolved','OK');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('521','28','priority_update','INFO');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('522','28','priority_warning','INFO');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('523','28','vops_endpoint','<PLACE ENDPOINT URL HERE>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('524','28','vops_routing_key','{ALERT.SENDTO}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('525','29','endpoint','<PLACE HTTP API URL>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('526','29','flash','false');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('527','29','password','<PLACE PASSWORD>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('528','29','ring','false');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('529','29','send_to','{ALERT.SENDTO}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('530','29','telauto','true');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('531','29','text','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('532','29','username','<PLACE USERNAME>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('535','30','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('536','30','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('537','30','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('538','30','express_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('539','30','express_send_to','{ALERT.SENDTO}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('540','30','express_tags','{EVENT.TAGSJSON}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('541','30','express_token','<PLACE BOT TOKEN>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('542','30','express_url','<PLACE INSTANCE URL>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('543','31','event_nseverity','{EVENT.NSEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('544','31','event_recovery_value','{EVENT.RECOVERY.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('545','31','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('546','31','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('547','31','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('548','31','field_ref:requester','<PLACE API USER NAME>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('549','31','field_string:description','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('550','31','field_string:subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('551','31','priority_average','Normal');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('552','31','priority_default','Normal');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('553','31','priority_disaster','High');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('554','31','priority_high','High');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('555','31','priority_information','Low');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('556','31','priority_not_classified','Low');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('557','31','priority_warning','Medium');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('558','31','sd_on_demand_client_id','<PLACE ON DEMAND CLIENT ID>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('559','31','sd_on_demand_client_secret','<PLACE ON DEMAND CLIENT SECRET>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('560','31','sd_on_demand_refresh_token','<PLACE ON DEMAND REFRESH TOKEN>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('561','31','sd_on_demand_url_auth','<PLACE AUTHENTICATION URL FOR ON DEMAND>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('562','31','sd_on_premise','true');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('563','31','sd_on_premise_auth_token','<PLACE ON PREMISE TECHNICIAN_KEY>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('564','31','sd_request_id','{EVENT.TAGS.__zbx_sd_request_id}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('565','31','sd_url','<PLACE INSTANCE URL>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('566','31','trigger_description','{TRIGGER.DESCRIPTION}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('567','32','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('568','32','alert_subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('569','32','event_id','{EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('570','32','event_recovery_value','{EVENT.RECOVERY.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('571','32','event_severity','{EVENT.SEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('572','32','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('573','32','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('574','32','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('575','32','github_issue_number','{EVENT.TAGS.__zbx_github_issue_number}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('576','32','github_repo','{ALERT.SENDTO}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('577','32','github_token','<PLACE GITHUB TOKEN>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('578','32','github_url','https://api.github.com');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('579','32','github_user_agent','Zabbix/6.0');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('580','32','trigger_id','{TRIGGER.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('581','32','zabbix_url','{$ZABBIX.URL}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('582','33','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('583','33','alert_subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('584','33','event_id','{EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('585','33','event_nseverity','{EVENT.NSEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('586','33','event_recovery_value','{EVENT.RECOVERY.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('587','33','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('588','33','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('589','33','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('590','33','glpi_problem_id','{EVENT.TAGS.__zbx_glpi_problem_id}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('591','33','glpi_token','<PLACE GLPI TOKEN>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('592','33','glpi_url','<PLACE GLPI URL>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('593','33','trigger_id','{TRIGGER.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('594','33','zabbix_url','{$ZABBIX.URL}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('595','6','event_update_action','{EVENT.UPDATE.ACTION}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('596','6','status_counter','25');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('597','34','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('598','34','alert_subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('599','34','bot_token','<PLACE BOT TOKEN>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('600','34','event_id','{EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('601','34','event_nseverity','{EVENT.NSEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('602','34','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('603','34','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('604','34','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('605','34','send_to','{ALERT.SENDTO}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('606','34','trigger_description','{TRIGGER.DESCRIPTION}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('607','34','trigger_id','{TRIGGER.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('608','34','zabbix_url','{$ZABBIX.URL}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('609','35','alert_message','{ALERT.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('610','35','alert_subject','{ALERT.SUBJECT}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('611','35','event_id','{EVENT.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('612','35','event_nseverity','{EVENT.NSEVERITY}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('613','35','event_source','{EVENT.SOURCE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('614','35','event_update_message','{EVENT.UPDATE.MESSAGE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('615','35','event_update_status','{EVENT.UPDATE.STATUS}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('616','35','event_value','{EVENT.VALUE}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('617','35','otrs_auth_password','<PUT YOUR USER PASSWORD>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('618','35','otrs_auth_user','<PUT YOUR USER NAME>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('619','35','otrs_customer','<PUT YOUR CUSTOMER EMAIL>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('620','35','otrs_default_priority_id','3');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('621','35','otrs_queue','<PUT YOUR QUEUE NAME>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('622','35','otrs_ticket_id','{EVENT.TAGS.__zbx_otrs_ticket_id}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('623','35','otrs_ticket_state','new');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('624','35','otrs_time_unit','0');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('625','35','otrs_url','<PUT YOUR ((OTRS)) CE URL>');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('626','35','trigger_id','{TRIGGER.ID}');
INSERT INTO media_type_param (mediatype_paramid,mediatypeid,name,value) values ('627','35','zabbix_url','{$ZABBIX.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('1','1','0','0','Problem: {EVENT.NAME}','Problem started at {EVENT.TIME} on {EVENT.DATE}
Problem name: {EVENT.NAME}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Operational data: {EVENT.OPDATA}
Original problem ID: {EVENT.ID}
{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('2','1','0','1','Resolved in {EVENT.DURATION}: {EVENT.NAME}','Problem has been resolved at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}
Problem name: {EVENT.NAME}
Problem duration: {EVENT.DURATION}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Original problem ID: {EVENT.ID}
{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('3','1','0','2','Updated problem in {EVENT.AGE}: {EVENT.NAME}','{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.
{EVENT.UPDATE.MESSAGE}

Current problem status is {EVENT.STATUS}, age is {EVENT.AGE}, acknowledged: {EVENT.ACK.STATUS}.');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('4','1','1','0','Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}','Discovery rule: {DISCOVERY.RULE.NAME}

Device IP: {DISCOVERY.DEVICE.IPADDRESS}
Device DNS: {DISCOVERY.DEVICE.DNS}
Device status: {DISCOVERY.DEVICE.STATUS}
Device uptime: {DISCOVERY.DEVICE.UPTIME}

Device service name: {DISCOVERY.SERVICE.NAME}
Device service port: {DISCOVERY.SERVICE.PORT}
Device service status: {DISCOVERY.SERVICE.STATUS}
Device service uptime: {DISCOVERY.SERVICE.UPTIME}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('5','1','2','0','Autoregistration: {HOST.HOST}','Host name: {HOST.HOST}
Host IP: {HOST.IP}
Agent port: {HOST.PORT}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('6','3','0','0','','{EVENT.SEVERITY}: {EVENT.NAME}
Host: {HOST.NAME}
{EVENT.DATE} {EVENT.TIME}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('7','3','0','1','','Resolved in {EVENT.DURATION}: {EVENT.NAME}
Host: {HOST.NAME}
{EVENT.DATE} {EVENT.TIME}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('8','3','0','2','','{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem in {EVENT.AGE} at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('9','3','1','0','','Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('10','3','2','0','','Autoregistration: {HOST.HOST}
Host IP: {HOST.IP}
Agent port: {HOST.PORT}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('11','4','0','0','Problem: {EVENT.NAME}','<b>Problem started</b> at {EVENT.TIME} on {EVENT.DATE}<br><b>Problem name:</b> {EVENT.NAME}<br><b>Host:</b> {HOST.NAME}<br><b>Severity:</b> {EVENT.SEVERITY}<br><b>Operational data:</b> {EVENT.OPDATA}<br><b>Original problem ID:</b> {EVENT.ID}<br>{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('12','4','0','1','Resolved in {EVENT.DURATION}: {EVENT.NAME}','<b>Problem has been resolved</b> at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}<br><b>Problem name:</b> {EVENT.NAME}<br><b>Problem duration:</b> {EVENT.DURATION}<br><b>Host:</b> {HOST.NAME}<br><b>Severity:</b> {EVENT.SEVERITY}<br><b>Original problem ID:</b> {EVENT.ID}<br>{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('13','4','0','2','Updated problem in {EVENT.AGE}: {EVENT.NAME}','<b>{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem</b> at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.<br>{EVENT.UPDATE.MESSAGE}<br><br><b>Current problem status:</b> {EVENT.STATUS}<br><b>Age:</b> {EVENT.AGE}<br><b>Acknowledged:</b> {EVENT.ACK.STATUS}.');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('14','4','1','0','Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}','<b>Discovery rule:</b> {DISCOVERY.RULE.NAME}<br><br><b>Device IP:</b> {DISCOVERY.DEVICE.IPADDRESS}<br><b>Device DNS:</b> {DISCOVERY.DEVICE.DNS}<br><b>Device status:</b> {DISCOVERY.DEVICE.STATUS}<br><b>Device uptime:</b> {DISCOVERY.DEVICE.UPTIME}<br><br><b>Device service name:</b> {DISCOVERY.SERVICE.NAME}<br><b>Device service port:</b> {DISCOVERY.SERVICE.PORT}<br><b>Device service status:</b> {DISCOVERY.SERVICE.STATUS}<br><b>Device service uptime:</b> {DISCOVERY.SERVICE.UPTIME}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('15','4','2','0','Autoregistration: {HOST.HOST}','<b>Host name:</b> {HOST.HOST}<br><b>Host IP:</b> {HOST.IP}<br><b>Agent port:</b> {HOST.PORT}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('16','11','0','0','Problem: {EVENT.NAME}','Problem started at {EVENT.TIME} on {EVENT.DATE}
Problem name: {EVENT.NAME}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Operational data: {EVENT.OPDATA}
Original problem ID: {EVENT.ID}
{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('17','11','0','1','Resolved: {EVENT.NAME}','Problem has been resolved in {EVENT.DURATION} at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}
Problem name: {EVENT.NAME}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Original problem ID: {EVENT.ID}
{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('18','11','0','2','Updated problem: {EVENT.NAME}','{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.
{EVENT.UPDATE.MESSAGE}

Current problem status is {EVENT.STATUS}, acknowledged: {EVENT.ACK.STATUS}.');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('19','11','1','0','Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}','Discovery rule: {DISCOVERY.RULE.NAME}

Device IP: {DISCOVERY.DEVICE.IPADDRESS}
Device DNS: {DISCOVERY.DEVICE.DNS}
Device status: {DISCOVERY.DEVICE.STATUS}
Device uptime: {DISCOVERY.DEVICE.UPTIME}

Device service name: {DISCOVERY.SERVICE.NAME}
Device service port: {DISCOVERY.SERVICE.PORT}
Device service status: {DISCOVERY.SERVICE.STATUS}
Device service uptime: {DISCOVERY.SERVICE.UPTIME}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('20','11','2','0','Autoregistration: {HOST.HOST}','Host name: {HOST.HOST}
Host IP: {HOST.IP}
Agent port: {HOST.PORT}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('21','12','0','0','[{EVENT.STATUS}] {EVENT.NAME}','Problem started at {EVENT.TIME} on {EVENT.DATE}
Problem name: {EVENT.NAME}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Operational data: {EVENT.OPDATA}
Original problem ID: {EVENT.ID}
{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('22','12','0','1','[{EVENT.STATUS}] {EVENT.NAME}','Problem has been resolved in {EVENT.DURATION} at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}
Problem name: {EVENT.NAME}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Original problem ID: {EVENT.ID}
{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('23','12','0','2','[{EVENT.STATUS}] {EVENT.NAME}','{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.
{EVENT.UPDATE.MESSAGE}

Current problem status is {EVENT.STATUS}, acknowledged: {EVENT.ACK.STATUS}.');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('24','12','1','0','Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}','Discovery rule: {DISCOVERY.RULE.NAME}

Device IP: {DISCOVERY.DEVICE.IPADDRESS}
Device DNS: {DISCOVERY.DEVICE.DNS}
Device status: {DISCOVERY.DEVICE.STATUS}
Device uptime: {DISCOVERY.DEVICE.UPTIME}

Device service name: {DISCOVERY.SERVICE.NAME}
Device service port: {DISCOVERY.SERVICE.PORT}
Device service status: {DISCOVERY.SERVICE.STATUS}
Device service uptime: {DISCOVERY.SERVICE.UPTIME}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('25','12','2','0','Autoregistration: {HOST.HOST}','Host name: {HOST.HOST}
Host IP: {HOST.IP}
Agent port: {HOST.PORT}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('26','13','0','0','[{EVENT.STATUS}] {EVENT.NAME}','Problem started at {EVENT.TIME} on {EVENT.DATE}
Problem name: {EVENT.NAME}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Operational data: {EVENT.OPDATA}
Original problem ID: {EVENT.ID}
{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('27','13','0','1','[{EVENT.STATUS}] {EVENT.NAME}','Problem has been resolved in {EVENT.DURATION} at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}
Problem name: {EVENT.NAME}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Original problem ID: {EVENT.ID}
{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('28','13','0','2','[{EVENT.STATUS}] {EVENT.NAME}','{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.
{EVENT.UPDATE.MESSAGE}

Current problem status is {EVENT.STATUS}, acknowledged: {EVENT.ACK.STATUS}.');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('29','13','1','0','Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}','Discovery rule: {DISCOVERY.RULE.NAME}

Device IP: {DISCOVERY.DEVICE.IPADDRESS}
Device DNS: {DISCOVERY.DEVICE.DNS}
Device status: {DISCOVERY.DEVICE.STATUS}
Device uptime: {DISCOVERY.DEVICE.UPTIME}

Device service name: {DISCOVERY.SERVICE.NAME}
Device service port: {DISCOVERY.SERVICE.PORT}
Device service status: {DISCOVERY.SERVICE.STATUS}
Device service uptime: {DISCOVERY.SERVICE.UPTIME}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('30','13','2','0','Autoregistration: {HOST.HOST}','Host name: {HOST.HOST}
Host IP: {HOST.IP}
Agent port: {HOST.PORT}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('31','14','1','0','Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}','Discovery rule: {DISCOVERY.RULE.NAME}

Device IP: {DISCOVERY.DEVICE.IPADDRESS}
Device DNS: {DISCOVERY.DEVICE.DNS}
Device status: {DISCOVERY.DEVICE.STATUS}
Device uptime: {DISCOVERY.DEVICE.UPTIME}

Device service name: {DISCOVERY.SERVICE.NAME}
Device service port: {DISCOVERY.SERVICE.PORT}
Device service status: {DISCOVERY.SERVICE.STATUS}
Device service uptime: {DISCOVERY.SERVICE.UPTIME}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('32','14','2','0','Autoregistration: {HOST.HOST}','Host name: {HOST.HOST}
Host IP: {HOST.IP}
Agent port: {HOST.PORT}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('33','14','0','0','Problem: {EVENT.NAME}','Problem started at {EVENT.TIME} on {EVENT.DATE}
Problem name: {EVENT.NAME}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Operational data: {EVENT.OPDATA}
Original problem ID: {EVENT.ID}
{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('34','14','0','1','Resolved: {EVENT.NAME}','Problem has been resolved in {EVENT.DURATION} at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}
Problem name: {EVENT.NAME}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Original problem ID: {EVENT.ID}
{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('35','14','0','2','Updated problem: {EVENT.NAME}','{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.
{EVENT.UPDATE.MESSAGE}

Current problem status is {EVENT.STATUS}, acknowledged: {EVENT.ACK.STATUS}.');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('36','15','0','0','Problem: {EVENT.NAME}','Problem started at {EVENT.TIME} on {EVENT.DATE}
Problem name: {EVENT.NAME}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Operational data: {EVENT.OPDATA}
Original problem ID: {EVENT.ID}
{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('37','15','0','1','Resolved: {EVENT.NAME}','Problem has been resolved in {EVENT.DURATION} at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}
Problem name: {EVENT.NAME}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Original problem ID: {EVENT.ID}
{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('38','15','0','2','Updated problem: {EVENT.NAME}','{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.
{EVENT.UPDATE.MESSAGE}

Current problem status is {EVENT.STATUS}, acknowledged: {EVENT.ACK.STATUS}.');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('39','15','1','0','Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}','Discovery rule: {DISCOVERY.RULE.NAME}

Device IP: {DISCOVERY.DEVICE.IPADDRESS}
Device DNS: {DISCOVERY.DEVICE.DNS}
Device status: {DISCOVERY.DEVICE.STATUS}
Device uptime: {DISCOVERY.DEVICE.UPTIME}

Device service name: {DISCOVERY.SERVICE.NAME}
Device service port: {DISCOVERY.SERVICE.PORT}
Device service status: {DISCOVERY.SERVICE.STATUS}
Device service uptime: {DISCOVERY.SERVICE.UPTIME}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('40','15','2','0','Autoregistration: {HOST.HOST}','Host name: {HOST.HOST}
Host IP: {HOST.IP}
Agent port: {HOST.PORT}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('41','16','0','0','Problem: {EVENT.NAME}','Problem started at {EVENT.TIME} on {EVENT.DATE}
Problem name: {EVENT.NAME}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Operational data: {EVENT.OPDATA}
Original problem ID: {EVENT.ID}
{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('42','16','0','1','Resolved in {EVENT.DURATION}: {EVENT.NAME}','Problem has been resolved in {EVENT.DURATION} at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}
Problem name: {EVENT.NAME}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Original problem ID: {EVENT.ID}
{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('43','16','0','2','Updated problem: {EVENT.NAME}','{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.
{EVENT.UPDATE.MESSAGE}

Current problem status is {EVENT.STATUS}, acknowledged: {EVENT.ACK.STATUS}.');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('44','16','1','0','Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}','Discovery rule: {DISCOVERY.RULE.NAME}

Device IP: {DISCOVERY.DEVICE.IPADDRESS}
Device DNS: {DISCOVERY.DEVICE.DNS}
Device status: {DISCOVERY.DEVICE.STATUS}
Device uptime: {DISCOVERY.DEVICE.UPTIME}

Device service name: {DISCOVERY.SERVICE.NAME}
Device service port: {DISCOVERY.SERVICE.PORT}
Device service status: {DISCOVERY.SERVICE.STATUS}
Device service uptime: {DISCOVERY.SERVICE.UPTIME}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('45','16','2','0','Autoregistration: {HOST.HOST}','Host name: {HOST.HOST}
Host IP: {HOST.IP}
Agent port: {HOST.PORT}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('46','17','0','0','{EVENT.NAME}','Problem started at {EVENT.TIME} on {EVENT.DATE}
Problem name: {EVENT.NAME}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Operational data: {EVENT.OPDATA}
Original problem ID: {EVENT.ID}
{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('47','17','0','1','{EVENT.NAME}','Problem has been resolved in {EVENT.DURATION} at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}
Problem name: {EVENT.NAME}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Operational data: {EVENT.OPDATA}
Original problem ID: {EVENT.ID}
{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('48','17','0','2','{EVENT.NAME}','{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.
{EVENT.UPDATE.MESSAGE}

Current problem status is {EVENT.STATUS}, acknowledged: {EVENT.ACK.STATUS}.');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('49','17','1','0','Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}','Discovery rule: {DISCOVERY.RULE.NAME}

Device IP: {DISCOVERY.DEVICE.IPADDRESS}
Device DNS: {DISCOVERY.DEVICE.DNS}
Device status: {DISCOVERY.DEVICE.STATUS}
Device uptime: {DISCOVERY.DEVICE.UPTIME}

Device service name: {DISCOVERY.SERVICE.NAME}
Device service port: {DISCOVERY.SERVICE.PORT}
Device service status: {DISCOVERY.SERVICE.STATUS}
Device service uptime: {DISCOVERY.SERVICE.UPTIME}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('50','17','2','0','Autoregistration: {HOST.HOST}','Host name: {HOST.HOST}
Host IP: {HOST.IP}
Agent port: {HOST.PORT}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('51','17','3','0','Internal problem: {EVENT.NAME}','Internal problem started at {EVENT.TIME} on {EVENT.DATE}
Problem name: {EVENT.NAME}
Host: {HOST.NAME}
Operational data: {EVENT.OPDATA}
Original problem ID: {EVENT.ID}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('52','18','0','0','[{EVENT.STATUS}] {EVENT.NAME}','Problem started at {EVENT.TIME} on {EVENT.DATE}
Problem name: {EVENT.NAME}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Operational data: {EVENT.OPDATA}
Original problem ID: {EVENT.ID}
{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('53','18','0','1','[{EVENT.STATUS}] {EVENT.NAME}','Problem has been resolved in {EVENT.DURATION} at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}
Problem name: {EVENT.NAME}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Original problem ID: {EVENT.ID}
{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('54','18','0','2','[{EVENT.STATUS}] {EVENT.NAME}','{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.
{EVENT.UPDATE.MESSAGE}

Current problem status is {EVENT.STATUS}, acknowledged: {EVENT.ACK.STATUS}.');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('55','18','1','0','Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}','Discovery rule: {DISCOVERY.RULE.NAME}

Device IP: {DISCOVERY.DEVICE.IPADDRESS}
Device DNS: {DISCOVERY.DEVICE.DNS}
Device status: {DISCOVERY.DEVICE.STATUS}
Device uptime: {DISCOVERY.DEVICE.UPTIME}

Device service name: {DISCOVERY.SERVICE.NAME}
Device service port: {DISCOVERY.SERVICE.PORT}
Device service status: {DISCOVERY.SERVICE.STATUS}
Device service uptime: {DISCOVERY.SERVICE.UPTIME}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('56','18','2','0','Autoregistration: {HOST.HOST}','Host name: {HOST.HOST}
Host IP: {HOST.IP}
Agent port: {HOST.PORT}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('57','19','0','0','Problem: {EVENT.NAME}','Problem started at {EVENT.TIME} on {EVENT.DATE}
Problem name: {EVENT.NAME}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Operational data: {EVENT.OPDATA}
Original problem ID: {EVENT.ID}
{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('58','19','0','1','Resolved: {EVENT.RECOVERY.NAME}','Problem has been resolved in {EVENT.DURATION} at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}
Problem name: {EVENT.RECOVERY.NAME}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Original problem ID: {EVENT.ID}
{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('59','19','0','2','Updated problem: {EVENT.NAME}','{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.
{EVENT.UPDATE.MESSAGE}

Current problem status is {EVENT.STATUS}, acknowledged: {EVENT.ACK.STATUS}.');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('60','19','1','0','Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}','Discovery rule: {DISCOVERY.RULE.NAME}

Device IP: {DISCOVERY.DEVICE.IPADDRESS}
Device DNS: {DISCOVERY.DEVICE.DNS}
Device status: {DISCOVERY.DEVICE.STATUS}
Device uptime: {DISCOVERY.DEVICE.UPTIME}

Device service name: {DISCOVERY.SERVICE.NAME}
Device service port: {DISCOVERY.SERVICE.PORT}
Device service status: {DISCOVERY.SERVICE.STATUS}
Device service uptime: {DISCOVERY.SERVICE.UPTIME}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('61','19','2','0','Autoregistration: {HOST.HOST}','Host name: {HOST.HOST}
Host IP: {HOST.IP}
Agent port: {HOST.PORT}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('62','20','0','0','{EVENT.NAME}','Problem started at {EVENT.TIME} on {EVENT.DATE}
Problem name: {EVENT.NAME}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Operational data: {EVENT.OPDATA}
Original problem ID: {EVENT.ID}
{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('63','20','0','1','{EVENT.NAME}','Problem has been resolved in {EVENT.DURATION} at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}
Problem name: {EVENT.NAME}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Original problem ID: {EVENT.ID}
{TRIGGER.URL}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('64','20','0','2','{EVENT.NAME}','{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.
{EVENT.UPDATE.MESSAGE}

Current problem status is {EVENT.STATUS}, acknowledged: {EVENT.ACK.STATUS}.');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('65','20','1','0','Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}','Discovery rule: {DISCOVERY.RULE.NAME}

Device IP: {DISCOVERY.DEVICE.IPADDRESS}
Device DNS: {DISCOVERY.DEVICE.DNS}
Device status: {DISCOVERY.DEVICE.STATUS}
Device uptime: {DISCOVERY.DEVICE.UPTIME}

Device service name: {DISCOVERY.SERVICE.NAME}
Device service port: {DISCOVERY.SERVICE.PORT}
Device service status: {DISCOVERY.SERVICE.STATUS}
Device service uptime: {DISCOVERY.SERVICE.UPTIME}');
INSERT INTO media_type_message (mediatype_messageid,mediatypeid,eventsource,recovery,subject,message) values ('66','20','2','0','Autoregistration: {HOST.HOST}','Host name: {HOST.HOST}
Host IP: {HOST.IP}
Agent port: {HOST.PORT}');
