Allow me to describe a bit of my thought process. Knowing that all events and alarm frames have a database record with a column for StartTime, I realized that I could easily write a query to return the number of events within a specified time period. In turn, that makes it pretty easy to limit the events that are returned by a filter query that sends emails.
For starters, it should be somewhat obvious to anyone who knows SQL that the query immediately below will return the count of events that have alarmed and have been emailed within the past 10 minutes (MySQL’s “INTERVAL” keyword makes this quite easy and readable):
Code: Select all
SELECT count(*) FROM Events as E2
WHERE E2.StartTime >= DATE_SUB(NOW(), INTERVAL 10 MINUTE)
and E2.AlarmFrames >= 1 and E2.Emailed = 1
Code: Select all
select E.Id,E.MonitorId, …
from Events as E inner join Monitors as M on M.Id = E.MonitorId
where not isnull(E.EndTime)
and ( E.Archived = 0
and E.StartTime >= '2007-12-07 20:48:53'
and E.AlarmFrames >= 1 ) and ( E.Emailed = 1 )
and 5 >= (SELECT count(*) FROM Events as E2
WHERE E2.StartTime >= DATE_SUB(NOW(), INTERVAL 10 MINUTE)
and E2.AlarmFrames >= 1 and E2.Emailed = 1 )
order by E.StartTime asc
To add this solution/approach as a core feature of the product, I believe ZoneMinder only needs to ask the user for two additional configuration options. The first is the number of events (5 in my example) and the second is the time interval (10 minutes in my example). We could assume the interval is only specified in minutes, such that both options could be simple numeric values (rather than letting the user specify the interval is seconds or hours).
For now, anyone can hard-code this restriction into zm_filter.pl just before the sort column is appended to the query with a line such as:
Code: Select all
If ($filter_data->{AutoEmail})
{
sql .= “and 5 <= (SELECT count(*) … )”
}
The count(*) query can be expanded to join to the Frames table if people want more precision, but I haven’t thought through how that would exactly work since emails are generated and flagged at the level of the Events table.
So as I said, this isn’t perfect, but it’s easy and seems to handle a large number of the situations that users probably wish to cover.