Skip to content

How to set up Zabbix notifications on WhatsApp for free#

October 11, 2024

Zabbix Notifications in WhatsApp for Free

This article will look at the integration of the Zabbix monitoring system with WhatsApp messenger using GREEN-API service.

For users who already use Zabbix and GREEN-API, the basic information is provided in the sixth point.

  1. General info
  2. Setting up GREEN-API
  3. Creating a WhatsApp Group
  4. Webhook Endpoint Technology
  5. Zabbix installation and configuration
  6. Zabbix and WhatsApp integration
  7. Conclusion

1. General info#

For any IT infrastructure, it is important to be able to monitor the condition and performance of computers, servers, networks, applications, etc. Continuous monitoring will increase the reliability of the entire system, and correctly selected parameters for monitoring will help in predicting problems that may lead to failures in the infrastructure. This is why there are special monitoring systems - sets of tools and processes that help administrators timely detect and correct problems that arise in the system.

Zabbix is one of the most popular monitoring systems that can monitor the state of the network, virtual machines, servers, applications and devices, databases, and receive data on the state of the device: memory size, processor speed, machine temperature, logs, etc. Zabbix functionality also allows you to monitor business metrics, such as the speed of product sales.

Instant notification of any failures from Zabbix is an important factor for quickly responding to emerging problems. The standard functionality of the system offers various options for sending notifications: SMS, Email, Telegram, Jira, etc. However, Zabbix does not provide direct integration of messages into the popular WhatsApp messenger, which many users always use.

In this article, we show you a simple and free way to set up Zabbix notifications in WhatsApp using our service. GREEN-API service provides a convenient tool for working with WhatsApp and supports more scenarios than those provided in the official channel. The main advantage of using the service is the complete removal of all restrictions. For example, it is possible to write any message first without using templates.

We also have a free plan for developers, which makes it possible to use all the functionality of the service. Plan limits are only 3 chats and 100 WhatsApp availability checks per month.

2. Setting up GREEN-API#

You can read the step-by-step instructions for registration here. For free use create instance at the “Developer” plan.

The instance is a unique gateway number that is required to send and receive messages via WhatsApp. It is created on console and allows you to send and receive messages via the API. The instance allows you to scale communication with clients via WhatsApp and automate processes.

3. Creating a WhatsApp Group#

Let's use a group in WhatsApp to receive notifications for all responsible employees.

You can create a group on your mobile device or using the CreateGroup method. We recommend creating a group using this method, because response body contain chatId of new group, which will be required later when your creating the integration.

4. Webhook Endpoint Technology#

Receiving notifications will be done using Webhook Endpoint technology. To debug incoming notifications, you will need a test site to receive them. As an example, we will use the free service webhook.site.

Set up the receiving of incoming notifications in console. Select the required instance. In instance settings, we will specify the received URL notification sending address (webhookUrl), and also enable the switches by notification types as shown below.

Create a group in WhatsApp

Detailed instructions on working with webhooks are available in the documentation.

To receive messages to a WhatsApp group, you need to know the ID of this group. If the group was created using the CreateGroup method in console, then the response body contains a string with the group ID of the type "chatId": "120XXXXXXXXXX66561@g.us".

If the group was created manually at the previous stage, or you need to use one of the existing groups for notifications, you can find out the ID of the required group by calling the GetContacts method, which is designed to get a list of contacts for the current account. More details about the method are written in our documentation.

In addition, you can find out the group ID using the same webhook.site by writing a message to the group. How to do this is described in one of the videos on GREEN-API channel.

5. Zabbix installation and configuration#

Usually, Zabbix is installed on a Linux server. To demonstrate how our script works, we will install Zabbix on a VirtualBox, although you can easily run it on your server, or run Zabbix in a docker container. The image of the monitoring system of version 5 is installed on AlmaLinux 8 and contains a fully configured Zabbix.

First, a virtualization program is installed to install the image on a local machine. As an example, we will use the free Oracle VM VirtualBox.

Download VirtualBox from the official website of the project. Select your OS, and after downloading the installer run it as an administrator.

On the first step, click Next. On the next tab we will leave everything unchanged.

Installing a Oracle VM VirtualBox 1

After that, a warning will appear - Warning: Network Interfaces, which will notify you that the Internet connection will be restarted during the installation process. Agree by clicking Yes.

If the next step shows the following Error about missing Python Core/win32api dependencies, then first abort the installation and fix the error.

Installing a Oracle VM VirtualBox 3

Fixing Python win32api error
  1. Download Python from official site
  2. Open PowerShell and execute the command python -m pip install pywin32
  3. If necessary, update pip manager execute the command python -m pip install --upgrade pip
  4. Start VirtualBox installation again, Python win32api error is fixed.

After fixing, we will restart the installation process and make sure that the error window no longer appears at the corresponding step.

At the next stage, either leave all the settings unchanged or select them in accordance with the requirements, then click Next and then Install.

Installing a Oracle VM VirtualBox 4

Once the installation is complete, you can click Finish with the Start Oracle VirtualBox after installation checkbox selected and immediately access the program, but it is recommended to first reboot the computer.

Now that VirtualBox is installed, let's download the Zabbix image configured by the developers. Let's go to the download page for the ready-made solution on the official website

To install in VirtualBox, you need an image with the .ovf extension.

Installing a Zabbix 1

Let's download the archive with the image and unpack it to a convenient location.

In this example, we show the installation of Zabbix version Zabbix 5.0 LTS, since it is currently the most stable and widespread. The installation and configuration of other versions may be different.

After that, launch VirtualBox, if this has not been done before, and click the Import button in the interface.

Installing a Zabbix 1

In the opened window Import configurations, next to the field File, click the button to select the location.

Installing a Zabbix 1

Now let's find the Zabbix file in .ovf format in the unpacked folder with the image. Also make sure that the Zabbix file in .vmdk format is in the same folder.

On the next screen, select the import parameters. Here, change the value in MAC Address Policy to Include MAC addresses of all network adapters. After that, click Done.

Now in VirtualBox there is a virtual machine with Zabbix 5.0. Before starting it, let's change some settings. To do this, first select Zabbix 5.0, then click the Configure button.

When opening the configuration window, a message appeared stating that Invalid settings detected. To fix this error, go to the Screen tab and, as written in the error message, increase the video memory of the virtual machine, and also change the type of graphics controller to the recommended VMSVGA. However, this error will not affect the operation of Zabbix in any way and can therefore be ignored. Also, in the latest versions of VirtualBox, you must first switch the settings to Advanced.

In this case, it is necessary to configure the network parameters. Let's go to the Network tab, where we change the value in Connection type to Network bridge. Here we should leave a small note: if an error related to IPv4 occurs later when trying to access the Zabbix web interface, then to solve it, you should change the value in Connection type to Virtual host adapter.

Installing a Zabbix 1

Now apply the settings you made by clicking on OK. After that, let's start Zabbix. To do this, click on the Start button on the machine page.

We will not take any part in loading until the console displays:

appliance login:

Here, according to the official documentation, enter root and press enter.

Next, in the line that appears:

Password:

Enter zabbix and press enter again.

After this, the terminal will display the data for accessing Zabbix web interface:

Username: Admin

Password: zabbix

Now we get the address for working with the web interface. To do this, type the command ip a in the command line and press enter. The location of the required address in the response is shown in the screenshot.

Installing a Zabbix 1

To continue working with the web interface, go to the browser and enter the received address in the address bar (in the example, it is 192.168.31.194) and press enter.

On the opened authorization page, enter the previously obtained UsernameAdmin and Passwordzabbix.

Thus, we will get access to the Zabbix web interface. We will perform further configuration of the integration inside it.

6. Zabbix and WhatsApp integration#

Now that all the preparatory steps have been completed and we have access to the web interface, let’s configure the integration of notifications from Zabbix to WhatsApp when triggers are fired.

In the Zabbix web interface, go to AdministrationMedia types.

In the upper right corner, click on Create media type. Create a notification method called WhatsApp, containing the following parameters, as in the screenshot.

Media type WhatsApp in Zabbix UI

The values for API host linkApiURL, Instance access keyapiTokenInstance и Unique instance numberIdInstance are taken from console. In chatId, insert the ID of the chat to which notifications will be sent, or WhatsApp client ID.
According to the WhatsApp identifier system, the identifier for a Personal chat is formed according to the template 00000000000@c.us, where the zeros 00000000000 are replaced by the recipient's phone number. The phone number is specified in full, with the country code and without spaces. The identifier for a Group chat is a string of the form XXXXXXXXXX-XXXXXXXXXX@g.us or XXXXXXXXXXXXXXXXX@g.us, where the received chat ID is replaced by the symbols XXXXXXXXXXXXXXXXX.

In Script field you need to insert the following script:

Expand script
var WhatsApp= {
    ApiURL: null,
    IdInstance: null,
    apiTokenInstance: null,
    chatId: null,
    message: null,
    parse_mode: null, 
    // Function for escaping special characters depending on the selected markup format
    escapeMarkup: function (str, mode) {
        switch (mode) {
            case 'markdown':
                return str.replace(/([_*\[`])/g, '\\$&');
            case 'markdownv2':
                return str.replace(/([_*\[\]()~`>#+\-=|{}.!])/g, '\\$&');
            case 'html':
                return str.replace(/<(\s|[^a-z\/])/g, '&lt;$1');
            default:
                return str;
        }
    },
    // Function for sending a message to WhatsApp
    sendMessage: function () {
        var params = {
            chatId: WhatsApp.chatId,
            message: WhatsApp.message,
            linkPreview: false
        },
        data,
        response,
        request = new CurlHttpRequest(),
        url = WhatsApp.ApiURL + '/waInstance' + WhatsApp.IdInstance + '/sendMessage/' + WhatsApp.apiTokenInstance;
        Zabbix.Log(4, url);
        if (WhatsApp.parse_mode !== null) {
            params['parse_mode'] = WhatsApp.parse_mode;
        }
        if (WhatsApp.proxy) {
            request.SetProxy(WhatsApp.proxy);
        }
        request.AddHeader('Content-Type: application/json');
        data = JSON.stringify(params);
        Zabbix.Log(4, '[WhatsApp Webhook] params: ' + data);
        response = request.Post(url, data);
        Zabbix.Log(4, '[WhatsApp Webhook] HTTP code: ' + request.Status());
        try {
            response = JSON.parse(response);
        }
        catch (error) {
            response = null;
        }
        // Check if the message was sent successfully
        if (request.Status() !== 200) {
            if (typeof response.description === 'string') {
                throw response.description;
            }
            else {
                throw 'Unknown error. Check debug log for more information.';
            }
        }
    }
};  
try {
    var params = JSON.parse(value);
// Check for required parameters
    if (typeof params.ApiURL === 'undefined') {
        throw 'Incorrect value is given for parameter "ApiURL": parameter is missing';
    }
    WhatsApp.ApiURL = params.ApiURL;

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

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

    if (params.HTTPProxy) {
        WhatsApp.proxy = params.HTTPProxy;
    } 
    params.ParseMode = params.ParseMode.toLowerCase();

    if (['markdown', 'html', 'markdownv2'].indexOf(params.ParseMode) !== -1) {
        WhatsApp.parse_mode = params.ParseMode;
    }
// Checking the correctness of the chat ID
    if (params.To.includes('@c.us') || params.chatId.includes('@g.us')) {
        WhatsApp.chatId = params.chatId;
    } else {
        throw 'Incorrect value is given for parameter "chatId": parameter is not ended with "@c.us" or "@g.us"';
    }

    WhatsApp.message = '';
    if (params.Subject.length > 0) {
        WhatsApp.message += (params.Subject + '\n');
    }
    WhatsApp.message += params.Message;
    if (['markdown', 'html', 'markdownv2'].indexOf(params.ParseMode) !== -1) {
        WhatsApp.message = WhatsApp.escapeMarkup(WhatsApp.message, params.ParseMode);
    }
    WhatsApp.sendMessage();
    return 'OK';
}
catch (error) {
    Zabbix.Log(4, '[WhatsApp Webhook] notification failed: ' + error);
    throw 'Sending failed: ' + error + '.';
}

Or take this script from the GREEN-API repository on GitHub.

Next, you need to go to the Message templates tab and add the following standard message templates, which you can change to suit your taste if you wish.

Message templates in Zabbix UI

A message template is a pre-prepared message text that will be used when sending. Dynamic variables selected in templates are changed to the current ones at the time of sending.

The Options tab is left unchanged. This tab contains notification processing settings. These parameters will be identical for all message types. More details can be found in the Zabbix documentation.

Now you need to test the created notification method. When you return to Media types, you can see the previously added WhatsApp method. On the right side of the screen, on the line with the selected method, you need to click Test.

Test WA media type in Zabbix UI

As an example, let's put Trigger message in the Message value, and Trigger fired in the Subject value.

Message from Zabbix to WhatsApp

If everything is done correctly, then after clicking on Test, the value OK will be displayed in Response.

Next, we will check whether the notification was delivered to the chat WhatsApp.

Message from Zabbix in WhatsApp

The trigger message has been delivered.

Using this method, you can set up any notifications from Zabbix to WhatsApp for free using GREEN-API, within the framework of the "Developer" plan.

7. Conclusion#

So, this article describes how to integrate Zabbix with WhatsApp using GREEN-API service. This method is free and, with these instructions, simple. We hope that this will make it available to a wide range of users.

Now you can quickly receive notifications from Zabbix directly to your WhatsApp work chat and promptly respond to any problems that arise.