Operations 4 min read

Extract Zabbix Alarm Data into a Custom Reporting Database

This guide explains how to create a dedicated MySQL database and trigger to continuously pull Zabbix alarm information, transform it, and store it in a format suitable for integration with external systems.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Extract Zabbix Alarm Data into a Custom Reporting Database

Zabbix Alarm Data Extraction

In routine monitoring, besides regular Zabbix operations, we often need to exchange data with other companies. Since many partners do not follow Zabbix's data schema, we must extract relevant alarm data from Zabbix's database and convert it to the required format.

Integration format:

1. Create Integration Database

DROP DATABASE IF EXISTS `alarmreport`;
CREATE DATABASE alarmreport;
USE alarmreport;
DROP TABLE IF EXISTS `report`;
CREATE TABLE `report` (
  `reportid` int(11) NOT NULL AUTO_INCREMENT,
  `reportip` varchar(64) NOT NULL,
  `reporttype` varchar(64) NOT NULL,
  `alarmid` int(11) NOT NULL,
  `alarmname` varchar(64) NOT NULL,
  `alarmlevel` varchar(64) NOT NULL,
  `alarmstat` varchar(64) NOT NULL,
  `alarmtime` varchar(64) NOT NULL,
  `alarmcause` varchar(64) NOT NULL,
  `sendstatus` varchar(64) NOT NULL,
  PRIMARY KEY(reportid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `dictionary`;
CREATE TABLE `dictionary` (
  `alarmid` int(11) NOT NULL,
  `alarmname` varchar(64) NOT NULL,
  `alarmcause` varchar(64) NOT NULL,
  PRIMARY KEY(alarmid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

2. Create Trigger to Sync Zabbix Alarm Information in Real Time

DROP TRIGGER IF EXISTS Ysten_afterinsert_on_event;
CREATE TRIGGER Ysten_afterinsert_on_event
AFTER INSERT ON zabbix.`events`
FOR EACH ROW
BEGIN
        INSERT INTO alarmreport.report (
            alarmreport.report.reportip,
            alarmreport.report.reporttype,
            alarmreport.report.alarmid,
            alarmreport.report.alarmname,
            alarmreport.report.alarmlevel,
            alarmreport.report.alarmstat,
            alarmreport.report.alarmtime
        )
        SELECT
            zabbix.`hosts`.`host`,
            CONCAT('服务器'),
            zabbix.`triggers`.triggerid,
            zabbix.`triggers`.description,
            zabbix.`triggers`.priority,
            zabbix.`events`.`value`,
            FROM_UNIXTIME(zabbix.`events`.clock)
        FROM
            zabbix.`hosts`,
            zabbix.`triggers`,
            zabbix.`events`,
            zabbix.items,
            zabbix.functions,
            zabbix.groups,
            zabbix.hosts_groups
        WHERE
            zabbix.`hosts`.hostid = zabbix.hosts_groups.hostid
            AND zabbix.hosts_groups.groupid = zabbix.groups.groupid
            AND zabbix.`triggers`.triggerid = zabbix.`events`.objectid
            AND zabbix.`hosts`.hostid = zabbix.items.hostid
            AND zabbix.items.itemid = zabbix.functions.itemid
            AND zabbix.functions.triggerid = zabbix.`triggers`.triggerid
            AND zabbix.`events`.eventid = new.eventid;
END;
Now the alarm information is stored in real time within the alarmreport database.
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

SQLZabbixAlert ExtractionDatabase Trigger
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.