Integrating with Zabbix

You can use the generic webhook integration to integrate Zabbix with IBM Cloud Pak for AIOps.

To do so, use the instructions in the following sections:

Creating a Generic Webhook integration for Zabbix

To create a Generic Webhook integration, complete the following steps:

  1. Log in to IBM Cloud Pak for AIOps console.

  2. Expand the navigation menu (four horizontal bars), then click Define > Integrations.

  3. On the Integrations page, click Add integration.

  4. From the list of available integrations, find and click the Generic Webhook tile.

  5. Click Get started.

  6. On the Add integration page, define the general integration details:

    • Name: The display name of your integration. For example zabbix-demo

    • Authentication type: Select None.

  7. Click Next.

  8. Configure the event mapping.

    Use JSONATA to map the incoming JSON payload to the IBM Cloud Pak for AIOps event data schema.

    Copy the following Zabbix JSONATA expression into the text area:

    (
       {
          "severity": severity="5"?6:severity="4"?5:severity="3"?4:severity="2"?3:severity="1"?2:1, "summary": message,
          "resource": {
             "name": deviceName,
             "hostname": hostname,
             "ipAddress": ipaddress,
             "sourceId": hostid,
             "port": hostport
       },
       "type": {
          "classification": triggerdesc,
          "eventType": recoveryValue = "0" ? "resolution" : "problem"
       },
       "sender": {
          "name": "Zabbix",
          "sourceId": $exists(actionName) ? $length(actionName) > 0 ? "Trigger action: " & actionName,
          "type": "Webhook Connector"
          }
       }
    )
    
  9. Click Done.

  10. You should see the newly created zabbix-demo webhook integration. Copy the webhook route. You will need to paste this route into the Zabbix configuration later.

Creating a new webhook media type for CP4WAIOPs

Before creating a new webhook media type for CP4WAIOPs, you must a create a cp4waiops-webhook.yaml file that you will import into your Zabbix server.

To create the YAML file, you can use the example YAML that follows. This example supports both basic authentication and no authentication types as defined in the CP4WAIOPs Generic webhook connection.

If you want to use authentication, set req_username and req_password for basic authentication.

If you do not want to use authentication, remove the req_username and req_password variables from the YAML.

Sample CP4WAIOPS Connector Media type YAML

zabbix_export:
  version: '6.4'
  media_types:
    - name: 'CP4WAIOPS connector demo'
      type: WEBHOOK
      parameters:
        - name: actionName
          value: '{ACTION.NAME}'
        - name: deviceName
          value: '{HOST.NAME}'
        - name: hostid
          value: '{HOST.ID}'
        - name: hostname
          value: '{HOST.HOST}'
        - name: hostport
          value: '{HOST.PORT}'
        - name: HTTPProxy
        - name: ipaddress
          value: '{HOST.IP}'
        - name: message
          value: '{ALERT.MESSAGE}'
        - name: recoveryValue
          value: '{EVENT.RECOVERY.VALUE}'
        - name: req_password
          value: password
        - name: req_username
          value: admin
        - name: sendTo
          value: '{ALERT.SENDTO}'
        - name: severity
          value: '{EVENT.NSEVERITY}'
        - name: subject
          value: '{ALERT.SUBJECT}'
        - name: triggerdesc
          value: '{TRIGGER.DESCRIPTION}'
        - name: zabbixServer
          value: '{$ZABBIX.URL}'
      script: |
        try {

            var params = JSON.parse(value),
                req = new HttpRequest(),
                response;

            if (typeof params.HTTPProxy === 'string' && params.HTTPProxy.trim() !== '') {
                req.setProxy(params.HTTPProxy);
            }
            var data = {};
            data.message = params.message;
            data.severity = params.severity;
            data.deviceName = params.deviceName;
            data.hostname = params.hostname;
            data.hostid = params.hostid;
            data.hostport = params.hostport;
            data.ipaddress = params.ipaddress;
            data.subject = params.subject;
            data.recoveryValue = params.recoveryValue;
            data.triggerdesc = params.triggerdesc;
            data.actionName = params.actionName;
            data.sendTo = params.sendTo;
            data.zabbixServer = params.zabbixServer;
            data = JSON.stringify(data);

            req.addHeader('Content-Type: application/json');
            if (params.req_username !== '' && params.req_password !== '') {
               req.addHeader('Authorization: Basic ' + btoa(params.req_username + ':' + params.req_password));
            }

            Zabbix.log(4, '[ CP4WAIOPS webhook ] URL: ' + params.sendTo + ' data: ' + data);
            response = req.post(params.sendTo, data);
            Zabbix.log(4, '[ CP4WAIOPS webhook ] Responded with code: ' + req.getStatus() + '. Response: ' + response);

            if (response !== null) {
                try {
                    response = JSON.parse(response);
                    if (response.Status < 200 || response.Status >= 300) {
                        throw 'Request failed with status code ' + response.Status + ' error: ' + response.ErrorMessage;
                    }
                }
                catch (error) {
                    if (req.getStatus() < 200 || req.getStatus() >= 300) {
                        throw 'Request failed with status code ' + req.getStatus() + ' error: ' + response.ErrorMessage;
                    }
                    else {
                        throw 'Request success, but response parsing failed.';
                    }
                }
            }
            return 'OK';
        }
        catch (error) {
            Zabbix.log(3, '[ CP4WAIOPS webhook ] Sending failed. Error: ' + error);
            throw 'Failed with error: ' + error;
        }
      description: 'webhook media type for Cloud Pak Watson AIOPS - Webhook connector'
      message_templates:
        - event_source: TRIGGERS
          operation_mode: PROBLEM
          subject: 'Problem: {EVENT.NAME}'
          message: |
            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}
        - event_source: TRIGGERS
          operation_mode: RECOVERY
          subject: 'Resolved in {EVENT.DURATION}: {EVENT.NAME}'
          message: |
            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}
        - event_source: TRIGGERS
          operation_mode: UPDATE
          subject: 'Updated problem in {EVENT.AGE}: {EVENT.NAME}'
          message: |
            {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}.

To create a new webhook media type for CP4WAIOPs

  1. Log in to your Zabbix server web GUI. Click Alerts > Media types.

  2. Click Import in the top right corner. Click Choose file from the pop-out windows, select the cp4waiops-webhook.yaml file you created previously, make sure the Create new box is checked, and click Import.

Note: If you already had imported the cp4waiops webhook media type and want to update the existing one, check the Update existing box.

  1. A new media should now be showing up in the media type list. This new media type has not yet been assigned to a trigger action, and so the Used in action field will be blank.

  2. To test the new webhook media type, click Test in the Action column and fill in the required fields. In the sendTo field, paste in the details of the CPWAIOPs webhook connection route from Creating a Generic Webhook integration for Zabbix.

  3. Click Test.

  4. If the test is successful, you should receive the response OK and the message: Media type test successful. In CP4WAIOPs, you should receive the test POST message from Zabbix.

Assigning the CP4WAIOPs webhook media type into Admin user

After you have created and tested the new media type, you must assign the media type into the Admin user.

  1. At the Zabbix web GUI side bar, click Users > Users to access the Users page. Click Admin.

  2. Click the Media tab.

  3. On the Media tab, click Add.

  4. On the Media windows, select the integration that you created in Creating a Generic Webhook integration for Zabbix from the Type filed. Fill in the Send to field with the webhook connector route. Ensure the Enabled box is checked. Click Add.

  5. You should see the new entry in media type now. Click Update to save it. You have now assigned the CP4WAIOPs media type to the Admin user.

Creating a Zabbix Trigger Action to send notification to CP4WAIOPs

After assigning the media type to the Admin user, you need to create a trigger action in Zabbix.

  1. At the Zabbix web GUI side bar, click Alerts > Actions > Trigger actions. Click Create action in the top right corner. You need to create a trigger action that will send notifications to CP4WAIOPs using the integration that you created in Creating a Generic Webhook integration for Zabbix.

  2. Complete the Name field, for example enter Send CP4WAIOPs notification.

  3. Click Add under the Conditions section. A New condition window will pop-out. Define the condition where you want to send notification for this group of resource types. For example, select the Host as resource type.

  4. Click Select from the Hosts section.

  5. A Hosts window will pop-out. Click Select in the Host Group section. A Host groups window will pop-out to show you all available host groups that you can select from.

  6. Select the host groups or hosts that you want to send notification to CP4WAIOPs. Click Select.

  7. Click Add to add them into your trigger condition.

  8. Now you should have set your trigger condition. Make sure check the Enabled box.

  9. Click on the Operations tab. Click Add under the Operations section.

  10. The Operation details window should pop-out. In the Send to users section, click Select and select Admin. In the Send only to section, click Select and select the integration that you created in Creating a Generic Webhook integration for Zabbix. Click Add to add the operation details.

  11. Repeat Step 10. for the Recovery operations and Update operations sections. Click Add.

  12. You should see an Action Added message. You have now created a trigger action with the name Send CP4WAIOPs notification that will trigger CP4WAIOPs notifications through the Admin user.