Skip to content

Zabbix Integration

To fully understand the integration process, it is necessary to understand the following terms:

  • Item - defines what data or metric Zabbix should collect (e.g. CPU usage, text objects, numeric objects).
  • Trigger - logical condition, that evaluates item values and determines if some action should be taken based on this values (e.g. if code value is greater than 400).
  • Alert - defines action, which will be taken, when trigger detects defined value (e.g. send an email, send an SMS).

To integrate Cluster Manager, to send messages to the Zabbix server, we need to execute 6 configuration operations in it’s frontend:

  1. Create a Zabbix trapper item – define item, which will store the cluster manager messages. Example message object:
    {
        “source”: 127.0.0.1-PrimaryClusterManager”,
        “message”: “example cluster manager message”,
        “code”: 200
    }
    
  2. Create dependent items for the Zabbix trapper created in step 1 – define subobjects of the cluster manager message. Each message consists of three variables: source (where does the message come from), message (actual message), code (message code).
  3. Create a trigger, based on the message code – trigger, when message code indicates an error.
  4. Configure SMTP – configure SMTP server, for sending emails if error occurs.
  5. Configure user’s email address – for the logged in user, define theirs email address.
  6. Create a trigger action (alert) – when trigger created in step 3 indicates an error, then send an email to chosen user(s).

Create Zabbix trapper item

  1. Click Monitoring in the navigation bar.
  2. Click Hosts in the monitoring navigation.
  3. Click on your Zabbix server.
  4. From the Zabbix server menu, choose Items. Create Zabbix trapper item - steps 1-4
  5. Click Create item button in the top right corner. Create Zabbix trapper item - step 5
  6. Set Name (for example Cluster Manager Message).
  7. Set Type to be Zabbix trapper.
  8. Set Key (for example clusterManagerMsg.json).
  9. Set Type of information to Text.
  10. Click Add button at the bottom of the form. Create Zabbix trapper item - steps 6-10

Create dependent items

The following steps, should be executed for code, message and source fields.

  1. Click Create item button in the top right corner (as in step 5 of Create Zabbix trapper item).
  2. Set Name (for example Cluster Manager Message Code).
  3. Set Type to be Dependent item.
  4. Set Key (for example clusterManagerMsg.code).
  5. Set Type of information to Numeric (unsigned) for code and Text for message and source.
  6. Set Master item to clusterManagerMsg.json (select correct Zabbix trapper).
  7. Click on Preprocessing tab. Create dependent items - steps 1-7
  8. Click Add.
  9. Add code/message/source field with JSONPath step (for example $.code).
  10. Click Add button at the bottom of the form. Create dependent items - steps 8-10

Create trigger

Problems Severity by Message Codes

Severity Codes
Information 100-399
Warning 508, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 605, 609
Average 502, 503, 505, 506, 509, 608, 610
High 400, 401, 402, 403, 404, 405, 406, 501, 507, 510, 511, 512, 513, 515, 517, 519, 520, 604, 606
Disaster 500, 514, 516, 518, 521, 600, 601, 602, 603, 607, 611

Expressions by Severity

Information
(jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")>=100) and (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")<=399)
Warning
((jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 508) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 522) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 523) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 524) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 525) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 526) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 527) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 528) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 529) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 530) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 531) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 532) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 533) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 534) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 535) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 605) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 609))
Average
((jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 502) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 503) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 505) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 506) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 509) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 608) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 610))
High
((jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 400) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 401) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 402) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 403) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 404) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 405) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 406) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 501) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 507) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 510) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 511) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 512) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 513) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 515) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 517) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 519) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 520) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 604) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 606))
Disaster
((jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 500) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 514) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 516) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 518) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 521) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 600) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 601) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 602) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 603) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 607) or
 (jsonpath(last(/Zabbix server/clusterManagerMsg.json),"$.code")
 = 611))

Create trigger

  1. Click Monitoring in the navigation bar.
  2. Click Hosts in the monitoring navigation.
  3. Click on your Zabbix server.
  4. From the Zabbix server menu, choose Triggers. Create trigger - steps 1-4
  5. Click Create trigger button in the top right corner. Create trigger - step 5
  6. Set Name (for example Cluster Message Information)
  7. Set proper Severity based on the severities table.
  8. Set PROBLEM event generation mode to Multiple.
  9. In the Expression text field, paste correct expression based on the trigger severity.
  10. Click Add at the bottom of the form. Create trigger - steps 6-10

Configure SMTP

  1. Click Alerts in the navigation bar.
  2. Click Media types in the alerts navigation.
  3. Click on Email media type.
  4. Configure SMTP server.
  5. Check the Enabled box.
  6. Click Update button. Configure SMTP - steps 1-6

Configure user’s email address

  1. Click User settings at the bottom of the navigation bar.
  2. Click Profile in the user settings navigation.
  3. Click on Media tab.
  4. Click Add. Configure user's email address - steps 1-4
  5. Add email to Send to section.
  6. Click Add at the bottom of the form. Configure user's email address - steps 5-6

Create trigger action (alert)

  1. Click Alerts in the navigation bar.
  2. Click Actions in the alerts navigation.
  3. Click Trigger actions in the actions navigation.
  4. Click Create action button in the top right corner. Create trigger action (alert) - steps 1-4
  5. Set Name (for example Send Alert for Cluster Manager Error Code).
  6. Click Add in the Conditions section. Create trigger action (alert) - steps 5-6
  7. Set Type to Trigger.
  8. Click Select on Triggers and choose the trigger created in previous steps.
  9. Click Add. Create trigger action (alert) - steps 7-9
  10. Click Operations tab and the Add button in Operations section.
  11. Choose users and/or user groups.
  12. Enable Custom Message.
  13. Set Subject (for example Cluster Manager Error).
  14. Set Message, with the following content as part of the message, to receive a JSON object of the message: {ITEM.LASTVALUE}.
  15. Click Add.
  16. Click Add. Create trigger action (alert) - steps 10-15

Send message to Zabbix

Send message via zabbix_sender

zabbix_sender is a command-line utility, a binary file used to send data to a Zabbix server, that comes with Zabbix.

To send a message via zabbix_sender use the following schema:

zabbix_sender \
    -z 127.0.0.1 \
    -s "Zabbix server" \
    -k clusterManagerMsg.json \
    -o '{"source": "127.0.0.1", "message": "Hello, Zabbix!", "code": 200}'

Where:

  • zabbix_sender is the executable command,
  • -z 127.0.0.1 specifies the target Zabbix server’s IP address,
  • -s "Zabbix server" specifies the monitored host name in Zabbix,
  • -k clusterManagerMsg.json is the item (Zabbix trapper) key,
  • -o '{"source": "127.0.0.1", "message": "Hello, Zabbix!", "code": 200}' is a JSON-formatted message.

Send message via API

Generate API Token

  1. Click Users in the navigation bar.
  2. Click API tokens in the users navigation.
  3. Click Create API token button. Generate API token - steps 1-3
  4. Set Name.
  5. Either disable the expiration date or remember to update the token, when expired.
  6. Click Add.
  7. Copy the API Token. Generate API token - steps 4-6

Get Host ID

Before executing the next step – getting the item ID, we need to get the host’s ID. To do so, execute the following cURL command and replace:

  • $auth_token – actual API token (from previous step),
  • $zabbix_ip – actual Zabbix server IP.
curl -X POST -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
      "output": ["hostid", "name"],
      "search": {
        "name": "Zabbix server"
      }
    },
    "auth": "$auth_token",
    "id": 1
  }' \
  http://$zabbix_ip/zabbix/api_jsonrpc.php | jq -r '.result[0].hostid'

Get Item ID

Before actually sending a message, we need to get the Zabbix trappers item ID. To do so, execute the following cURL command and replace:

  • $auth_token – actual API token (from previous step),
  • $host_id – host ID (from previous step),
  • $zabbix_ip – actual Zabbix server IP.
curl -X POST -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "item.get",
    "params": {
      "output": "extend",
      "hostids": "$host_id",
      "search": {
        "key_": "clusterManagerMsg"
      }
    },
    "auth": "$auth_token",
    "id": 1
  }' \
  http://$zabbix_ip/zabbix/api_jsonrpc.php | jq -r '.result[0].itemid'

Send Message

To send a message to the Zabbix server, execute the following cURL command and replace:

  • $auth_token – actual API token (from previous step),
  • $item_id – item ID (from previous step),
  • $zabbix_ip – actual Zabbix server IP.
curl -X POST -H "Content-Type: application/json" -d '{
    "jsonrpc": "2.0",
    "method": "history.push",
    "params": {
      "itemid": "$item_id",
      "value": "{\"source\": \"127.0.0.1-Primary-Cluster-Manager\", \"message\": \"Hello, Zabbix!\", \"code\": 200}"
    },
    "auth": "$auth_token",
    "id": 1
  }' http://$zabbix_ip/zabbix/api_jsonrpc.php

Cluster Manager Message Scripts

Cluster Manager message scripts (both standard and error), should contain the following content, where:

  • $auth_token – API token,
  • $item_id – item ID,
  • $zabbix_ip – actual Zabbix server IP.
  • $cluster_manager_ip – ip of the Cluster Manager.
#!/bin/bash

set -e -o errexit

curl -X POST \
    --header "Content-Type: application/json"
    --data {
        "jsonrpc": "2.0",
            "method": "history.push",
            "params": {
            "itemid": "$item_id",
            "value": "{\"source\": \"$cluster_manager_ip-Primary-Cluster-Manager\", \"message\": \"${message}\", \"code\": ${code}}"
        },
        "auth": "$auth_token",
        "id": 1
    } http://$zabbix_ip/zabbix/api_jsonrpc.php

Messages Dashboard

Dashboard

In the Dashboard screen, problems are displayed in the Current problems section. They are categorized by severity (corresponding colors are visible in the Problems by severity section).

Dashboard View

Latest values

Latest Values View

  1. Click Monitoring in the navigation bar.
  2. Click Latest data in the monitoring navigation.
  3. Select your host in the Hosts section.
  4. Click the Apply button. Latest Values - steps 1-4
  5. Click the Cluster Manager Message item.
  6. Click 500 latest values from the menu. Latest Values - steps 5-6