Using Esendex API to send SMS with Zabbix (Webhook)

Zabbix is a very powerful and free monitoring & alerting solution.

If you want to extend the possibilities for alerting with custom actions, it is possible to use customized webhooks.

I am using ESENDEX, as a SMS provider, which overs a various set of API – for which Zabbix does not have a predefined webhook.

Here are the steps to use the REST api to send SMS alerts.

Administration > Media Types

Then select “create media type” in the upper right corner.

The API requires several parameters, and instead of hardcoding in the JavaScript snippet we will write the values, we can make them dynamic:

The URL used for the Esendex API is https://api.esendex.com/v1.0/messagedispatcher.

In the Script section, you must define a custom script to call the REST API. The language used is Javascript.

Here is the script details to be used:

try {
    var params = JSON.parse(value)

    Zabbix.Log(4, '[ Esendex webhook ] Started with params: ' + params) 
    
    var req = new CurlHttpRequest()

    req.AddHeader('Content-Type: application/json');
    req.AddHeader('Authorization: Basic ' + btoa(params.User + ':' + params.API_KEY));

    var fields = {}
    fields.accountreference = params.Account
    fields.messages = [ { to: params.To, body: params.Message } ]
    
    resp = req.Post(params.URL,
        JSON.stringify(fields)
    );
 
    if (req.Status() != 200) {
        throw 'Response code: ' + req.Status();
    }

    return 'OK';
}
catch (error) {
     throw 'Failed with error: ' + error;
}

You can then use this a new media type, to provide phone numbers to profiles, and receive alerts:

#Zabbix #esendex #REST #webhook #API

2 Replies to “Using Esendex API to send SMS with Zabbix (Webhook)”

  1. Thank you for the script, is this still valid? I have entered all as shown in your screenshots but Zabbix say “401” so no authorized. Question: which kind of information have you entered in field “User”, is this the email address of the account?
    Note: my API key does definitely work, tested it via C#

Leave a Reply

Your email address will not be published. Required fields are marked *