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
- Creating a new webhook media type for CP4WAIOPs
- Assigning the CP4WAIOPs webhook media type into Admin user
- Creating a Zabbix Trigger Action to send notification to CP4WAIOPs
Creating a Generic Webhook integration for Zabbix
To create a Generic Webhook integration, complete the following steps:
-
Log in to IBM Cloud Pak for AIOps console.
-
Expand the navigation menu (four horizontal bars), then click Define > Integrations.
-
On the Integrations page, click Add integration.
-
From the list of available integrations, find and click the Generic Webhook tile.
-
Click Get started.
-
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.
-
-
Click Next.
-
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" } } )
-
Click Done.
-
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
-
Log in to your Zabbix server web GUI. Click Alerts > Media types.
-
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.
-
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.
-
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.
-
Click Test.
-
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.
-
At the Zabbix web GUI side bar, click Users > Users to access the Users page. Click Admin.
-
Click the Media tab.
-
On the Media tab, click Add.
-
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.
-
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.
-
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.
-
Complete the Name field, for example enter
Send CP4WAIOPs notification
. -
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.
-
Click Select from the Hosts section.
-
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.
-
Select the host groups or hosts that you want to send notification to CP4WAIOPs. Click Select.
-
Click Add to add them into your trigger condition.
-
Now you should have set your trigger condition. Make sure check the Enabled box.
-
Click on the Operations tab. Click Add under the Operations section.
-
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.
-
Repeat Step 10. for the Recovery operations and Update operations sections. Click Add.
-
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.