Ad Widget

Collapse

SQL script to reset Triggers automatically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mgibson
    Junior Member
    • Jun 2012
    • 14

    #1

    SQL script to reset Triggers automatically

    I'm not sure if something like this has been posted before, but I was looking for a way to automatically clear triggers (specifically Window Event logs - but this will work for anything) after they reached a certain age.

    Change the '0:30:00' to whatever age you want Triggers reset after, and change the "%event log%" to filter on other trigger names.

    NOTE: This script creates a scheduled event in MySQL that will run every 10 minutes. Get rid of everything before and including BEGIN, and after and including END if you want to use it as a standalone script.

    Code:
    use zabbix;
    delimiter |
    CREATE EVENT `Zabbix_EventLog_Trigger_Reset` 
    ON SCHEDULE EVERY 10 MINUTE 
    DO 
    BEGIN
    	UPDATE `hosts`
    	INNER JOIN `items` ON `hosts`.hostid = `items`.hostid
    	INNER JOIN `functions` ON `items`.itemid = `functions`.itemid
    	INNER JOIN `triggers` ON `functions`.triggerid = `triggers`.triggerid SET `triggers`.value = 0
    	WHERE `items`.name LIKE "%event log%" AND `items`.templateid IS NOT NULL AND triggers.value = 1 AND (TIMEDIFF(NOW(), FROM_UNIXTIME(`items`.lastclock)) > CAST('0:30:00' AS TIME) OR `items`.lastclock IS NULL); 
    END |
    delimiter ;
    Last edited by mgibson; 14-12-2012, 20:38. Reason: Forgot to mention...
Working...