Count of all active events or only new events

Count events for last hour:
select count(*) from events where clock >= unix_timestamp(NOW() - INTERVAL 1 DAY);
Including severity:
select t.priority, count(triggerid) as count from triggers as t left join events as e on t.triggerid = e.objectid where e.clock >= unix_timestamp(NOW() - INTERVAL 1 HOUR) group by t.priority;
Count events for last day:
select count(*) from events where clock >= unix_timestamp(NOW() - INTERVAL 1 HOUR);
Including severity:
select t.priority, count(triggerid) as count from triggers as t left join events as e on t.triggerid = e.objectid where e.clock >= unix_timestamp(NOW() - INTERVAL 1 DAY) group by t.priority;
priority explanation:
0, TRIGGER_SEVERITY_NOT_CLASSIFIED - Not classified
1, TRIGGER_SEVERITY_INFORMATION - Information
2, TRIGGER_SEVERITY_WARNING - Warning
3, TRIGGER_SEVERITY_AVERAGE - Average
4, TRIGGER_SEVERITY_HIGH - High
5, TRIGGER_SEVERITY_DISASTER - Disaster
Another:
select
   t.priority,
   count(triggerid) as count 
from
   triggers as t 
   left join
      events as e 
      on t.triggerid = e.objectid 
where
   e.source = 0 
   AND e.object = 0
   AND e.value = 1
   AND e.clock >= unix_timestamp(NOW() - INTERVAL 1 DAY) 
group by
   t.priority;

No comments: