Alerting in Zabbix

The Importance of Alerting
Alerting is a crucial aspect of monitoring; we can't spend 24/7 looking at a monitoring dashboard. With alerting, we receive notifications from platforms like Telegram, Discord, Opsgenie, or Jira. This provides an immediate indicator that a host or item we are monitoring is down or has reached a critical severity. In Zabbix, alerts are defined in Trigger actions, meaning alerts are generated by triggers.

What is a Zabbix Trigger?
Triggers are logical rules that evaluate data collected from monitored items and flag issues. For example, if I monitor a host's disk usage percentage, Zabbix collects this data every minute and stores it as item values. I can then create trigger rules based on this data:

- Warning Severity Trigger: Activates if disk usage value is greater than or equal to 80%.
- High Severity Trigger: Activates if disk usage value is greater than or equal to 90%.
After Zabbix creates these triggers, we need to configure their actions. For instance, I might want to send 'Warning' severity triggers to a Telegram chat and 'High' severity triggers to a Discord channel. Beyond just notifications, you can also configure actions to run scripts or perform other automated tasks.

Configuration Guide: Step-by-Step
This guide will walk through the entire process based on a practical setup.
Summary of Steps:
- Create an Item to monitor disk usage.
- Create Triggers with 'Warning' and 'High' severity levels.
- Create Trigger Actions to send notifications to Telegram and Discord.
Step 1: Create the Monitoring Item
First, we need to create a new item because the default Zabbix Agent template for Linux does not include disk usage monitoring.
- Navigate to your Host's configuration and click Items.
- Select Create Item.
- Fill in the item details as follows:
- Name:
Disk Usage /
- Type:
Zabbix agent
- Key:
vfs.fs.size[/,pused]
- Type of information:
Numeric (float)
- Host interface:
10.8.13.2:10050
(or your specific host) - Units:
%
- Update interval:
1m
- Name:


Key Explanation: The keyvfs.fs.size[/,pused]
is used based on Zabbix documentation, wherepused
stands for "used, percentage." The information type isfloat
to handle percentage values.

Test the Item
Before saving, click the Test button at the bottom of the form and then Get value to ensure Zabbix can retrieve data. A successful test should return a numeric value (e.g., 42.92...
).

Step 2: Create Triggers with Severity Levels
With the item collecting data, we can now create triggers that react to that data.
- Navigate to your Host's configuration and select Triggers.
- Click Create trigger.

Create the 'Warning' Trigger
- Name:
Disk Usage / Warning
- Severity:
Warning
- In the Expression field, click Add.
- Define the condition:
- Item: Select the
Disk Usage /
item we created earlier. - Function:
last()
- This gets the most recent value. - Result:
>= 80
- Item: Select the
- Check the box for Allow manual close. This allows an administrator to manually resolve the trigger from the Zabbix dashboard.




To make this trigger fire only between 80% and 90%, we add a second condition. The final expression should be:
last(/blog.pramudika.my.id/vfs.fs.size[/,pused])>=80 and last(/blog.pramudika.my.id/vfs.fs.size[/,pused])<90

Create the 'High' Severity Trigger
Follow the same process to create a trigger for high severity.
- Name:
Disk Usage / High
- Severity:
High
- Check Allow manual close.
Expression:
last(/blog.pramudika.my.id/vfs.fs.size[/,pused])>=90

You should now have two new triggers associated with your host.

Step 3: Create Trigger Actions to Send Notifications
Now we'll configure Zabbix to send alerts to Telegram and Discord when the triggers fire.
Prerequisites
- Prepare a Telegram Bot: Follow instructions to create a bot using BotFather.
- Prepare a Discord Webhook: Create a webhook for the desired channel in your Discord server.
- Enable Media Types: In Zabbix, go to Alerts -> Media types and ensure both Telegram and Discord are enabled.

Configure Media Types in Zabbix
- Telegram:
- Select the Telegram media type.
- Input your bot's API token in the
api_token
field and click Update. - Go to Users -> Your User -> Media.
- Add a new media of type Telegram and enter your personal or group chat ID in the Send to field.


- Discord:
- Select the Discord media type and paste your webhook URL.
- To use the Discord media type, you must configure the
{$ZABBIX.URL}
macro. Go to Administration -> Macros, add a new macro{$ZABBIX.URL}
with the value of your Zabbix frontend URL, and click Update.



Create the 'Warning' Trigger Action
- Navigate to Alerts -> Actions -> Trigger Actions and click Create action.
- Name:
blog.pramudika.my.id Warning
- Under the Conditions tab, set the following:
Host
equals
blog.pramudika.my.id
Trigger severity
equals
Warning



- Switch to the Operations tab. Here you define what happens when the conditions are met.
- Steps:
1-1
(This means the action runs only once). - Step duration:
0
(No delay). - Operations: Click Add to define the operation.
- Steps:
- Send to users:
Admin
(or your desired user). - Send only to:
Telegram
.



- Switch to the Recovery operations tab. This defines what happens when the issue is resolved.
- To notify everyone involved that the problem is solved, simply check Notify all involved.
- Click Add to save the action.



Create the 'High' Severity Trigger Action
Repeat the process above to create an action for high-severity alerts, but with these changes:
- Name:
blog.pramudika.my.id High
- Condition:
Trigger severity
equals
High
- Operation: Send only to
Discord
.

Step 4: Testing the Alerts
To test the setup, we'll manually increase the disk usage on the monitored server.
Test the 'Warning' Alert (>=80%)
Create a large file to push usage over 80%.
root@blog:~# fallocate -l 6G file.iso
root@blog:~# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 15G 13G 2.2G 85% /
Check current disk usage.
root@blog:~# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 15G 6.2G 8.2G 44% /
After the next check (within 1 minute), a notification should be sent to Telegram, and the trigger will appear on the Zabbix Dashboard.


Test the 'High' Alert (>=90%)
Create another file to push usage over 90%.
root@blog:~# fallocate -l 1G file2.iso
root@blog:~# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 15G 14G 1.2G 92% /
This will trigger the 'High' severity action, and a notification should be sent to Discord. The Zabbix dashboard will update to show the new, more critical problem.

Conclusion
This guide demonstrated how to set up Zabbix alerting from creating custom items and defining triggers with different severities to configuring notification actions for platforms like Telegram and Discord. By following these steps, you can effectively monitor your systems and receive timely alerts for critical events.