zabbix报警信息提取在日常的监控中,我们除了日常的zabbix操作外,我们有的时候还涉及到与其他公司
进行数据对接。由于别的公司的数据对接很多时候并不是按照zabbix的数据结构
(尤其是大型厂家,或是专业监控厂家,并不会直接使用zabbix,多数是自己开发
或是对其他监控软件进行二次开发之类),在这种需求基础上,我们就需要整理下
zabbix的数据库,将需要的数据提取出来,并转化成我们需要的格式。对接格式:
1.创建对接库: 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.创建触发器,实时同步zabbix库的报警信息 DROP TRIGGER IF EXISTS Ysten_afterinsert_on_event;CREATE TRIGGER Ysten_afterinsert_on_eventAFTER INSERT ON zabbix.`events`FOR EACH ROWBEGIN 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;这样我们就能在alarmreport这个库里面实时存储报警信息了 原创:graysky
|