Customizing triggers in Zabbix

Zabbix monitoring customize triggers
After the initial article on how to install Zabbix, this article delves deeper into customizing Zabbix. We start small and want to adjust the threshold of the number of running processes as we have a host running many LXC containers. Next up is the threshold of the free disk space. Again, some LXC containers don't store a lot of data and as such, they don't need a lot of free space. Your milleage may vary off course so feel free to adjust where you see fit.

1. Change threshhold for the number of running processes

1.1. Add a macro to the existing Template OS Linux

Go to Configuration > Templates. Click on the Template OS Linux line. Go to the Macros tab and add a macro.

Macro name: {$TRIGGER_THRESHOLD_PROCESSES_RUNNING} Value: 300

The 300 is the standard value as given in the Template OS Linux.

Zabbix template

Now we need to change the trigger to compare to this macro instead of the value 300. Click on the triggers line just above the tabs. Click on the "Too many processes on..." line.

Zabbix template

Change the expression to the following:

Zabbix template

By defining a macro here, you can override this setting in a linked template.

1.2. Create a custom template

Create a new template Groups: Templates

Zabbix template

Linked template: Template OS Linux

You could not link a template and only use the item and trigger from the main template.

Zabbix template

Define a Template macro (tab Macros in the Template view)

{$TRIGGER_THRESHOLD_PROCESSES_RUNNING}

1000

Now we have overriden the standard 300 from the base template.

Zabbix template

As we have linked the template to an existing template, items and triggers will already be present.

2. Change % of free disk space

Since I'm using LXC containers, their free space is often less than 20% which is the default free space % threshold in Zabbix. For those machines, I would want to override this. To do this, we are going to create a new template, and copy the item (what's being measured) and triggers to a new non-linked template.

The disks are created via a "Discovery rules". When a filesystem is discovered, it used item and trigger prototypes to build an item and trigger for the filesystem found. For this we choose to clone the existing template "Template OS Linux".

2.1. Clone a template

Go to Configuration > Templates. In the list click on the template "Template OS Linux". At the bottom choose "Full clone". Give a new name to the template and save.

Zabbix template

2.2. Customize template

To customize the template, go back to Configuration > Templates and click on the name. Go to the macros tab and you should notice the {$TRIGGER_THRESHOLD_PROCESSES_RUNNING} macro is already defined. Create a new macro {$TRIGGER_THRESHOLD_FREE_SPACE}, value 10 and click update.

Go to Discovery rules, Triggers prototypes on "Mounted filesystem discovery" of this template.

Zabbix template

Click on the "Free disk space..." trigger.

Zabbix template

Change the expression. Use {$TRIGGER_THRESHOLD_FREE_SPACE} instead of the value "20".

Zabbix template

2.3. Add template

Add the newly created template to the host where you want to have a free space compared to the macro. Since this is a clone, you can't use the original template.

Zabbix template

Note

We have now used 2 methods to change the trigger values. The first method was by making a new linked template, where we create a new macro to change the threshold value. The 2nd way is to create a new cloned template, and us that one instead of the standard template. In that new template we have also overridden the default threshold value.

In my particular case, I needed to delete the old the old trigger prototype rule. See the screenshot at the bottom right. Number of Trigger prototypes is 3 instead of the expected 2. Click on the trigger prototype line.

3 Trigger prototypes

Delete the line that doesn't have our newly created template in front. This will remove the old free space check without the macro.

Delete old discovery rule