Restore previous version

Zabbix

OVERVIEW

In this section, you will learn how to set up Zabbix and Jira integration using Alert Catcher for incident handling.

Communication between Zabbix and Jira is carried out using an http-request, on the basis of which Alert Catcher forms an Issue in Jira; to set up a connection between Alert Catcher and Zabbix, follow the link.

CREATING A HOST

Information about configured hosts in Zabbix is available in Configuration → Hosts

To add a new host, click on Create host.

This will present you with a host configuration form.

All mandatory input fields are marked with a red asterisk.

The bare minimum to enter here is:

Host name

  • Enter a unique host name. Alphanumeric, spaces, dots, dashes and underscores are allowed. 

Groups

  • Select one or several existing groups by clicking Select button or enter a non-existing group name to create a new group.

All access permissions are assigned to host groups, not individual hosts. That is why a host must belong to at least one group.

IP address

  • Enter the IP address of the host. Note that if  it is the Zabbix server IP address, it must be specified in the Zabbix agent configuration file 'Server' directive.

You can learn more about configuring a host at the link.

 

CONFIGURING A WEB SCENARIO

To configure a web scenario:

  • Go to: Configuration → Hosts (or Templates)

  • Click on Web in the row of the host/template

To add a new web scenario, you need to go to the "Web scenarios" tab in order to create a monitoring of a web resource. To do it you need to click on the "Create web scenario" where you need to specify the name of the scenario and the monitoring interval after which you need to go to the "Steps" tab:

In the form that appears, you need to specify the name and URL of the resource that you want to monitor (in our case, I chose the google site for which I will restrict  an access in the future, that will simulate non-performance; in your cases it can be any resource, performance of which you can influence) to save the results, click "Add".

 

All mandatory input fields are marked with a red asterisk.

You can learn more about creating a web scenario at a link.

ADDING TRIGGER

To configure a trigger, do the following:

  • Go to: Configuration → Hosts

  • Click on Triggers in the row of the host

  • Click on Create trigger in the up right corner (or on the trigger name to edit an existing trigger)

  • Enter parameters of the trigger in the form

In the form, you should specify the name of the trigger severity and set the condition (Expression). To do so click "Add" button in the "Element" field, select "Failed to execute the step script" in "Result" also specify "<>":

Afterwards you need to save the result by clicking on the "Add" button.

You can learn more about creating a trigger at link.

At this stage, monitoring of the specified resource is configured and in case of its inoperability, a problem will be created in zabbix where its status will be displayed. For the task to be integrated into Jira, you need to configure "Action".

ADDING ACTIONS

Go to the Configuration → Actions section to configure the action.

Clicking on "Create action" will open the form where you need to specify the name of the action, you also need to add the newly created trigger and go to the "Operations" tab:

In the "Operations" tab, you need to specify the step what frequency the action will be triggered with, as well as add an operation for this. You need to click on "Add", in the appeared "Operation type" window, you need to specify "Remote command", in the "Target list" you need to specify the host which this operation will concern, in the "Type" tab you should select the type of script (by selecting "Global script" you will need to specify the name of the script written inside zabbix), specify "Castopm script" and this script will be run from the "zabbix server". 

In the "commands" tab, you need to write a command that consists of a directory to the script, the name of the script and the parameters that need to be passed to the script.

ADDING SCRIPTS

More details on how to work with scripts can be found here.

The directory where the Custom script should be saved: "/ usr/lib/zabbix/alertscripts" 
The script itself contains "curl" with "post" and "put" requests, the script looks like this:

 

#!/bin/bash a=$8 b=$9 b=${b// / } a=${a// / } if [ "$2" == "OK" ];then curl --request PUT \ --url https://<my-jira.com>/rest/catcher/1.0/alerts/zabbix/$1 \ --header 'content-type: application/json' \ --header 'x-api-key: <your api-key>' \ --data '{ "id": '$1', "rule": "'$4'", "status" : "Completed", "priority": "'$5'", "params" : { "summary": "'$a' '$4'", "Hosts": "'$6'", "IP address": "'$7'", "Problem": "'$a'", "Disc": "'$b'", "stat" : "'$2'", "URL" : "[Details of scenario|'$3']" } }' else curl --request POST \ --url https://<my-jira.com>/rest/catcher/1.0/alerts/zabbix \ --header 'content-type: application/json' \ --header 'x-api-key: <your api-key>' \ --data '{ "id": '$1', "rule": "'$4'", "priority": "'$5'", "params" : { "summary": "'$a' '$4'", "Hosts": "'$6'", "IP address": "'$7'", "Problem": "'$a'", "Disc": "'$b'", "stat" : "'$2'", "URL" : "[Details of scenario|'$3']" } }' fi

 Guidance to create a request can be found here.

A complete list of macros that can be passed to parameters using Zabbix can be found at  link.

* when writing a bash script, there was a problem when passing a string with spaces through parameters to the body of json code, a solution to this problem was found using a regular expression by replacing all spaces with the larger ones:

 

#!/bin/bash a=$8 b=$9 b=${b// / } a=${a// / }

After filling in all the fields to save the result, you need to click "Add" and go to the "Recovery Operation" field, here you need to specify the action when our resource is resumed, since the script contains a PUT request via IF, the same parameters are indicated as above.

The result of the work when the resource is disabled will be Issue creation in Jira:

When the resource is restored, the status in Jira changes:

It is also worth attention that if there is no "custom fields" on the task screen, then all the parameters will be written in the "Description":

If the screen contains "custom fields" but the values ​​are passed to "Description", you need to check the spelling of the "custom fields" names and pay attention to the case.