Page 1 of 1

Purging events older than x

Posted: Sun Apr 08, 2012 10:40 pm
by _saiko
I would like to filter events older then x days so I can create an automatic purge filter instead of relaying on disk usage.
So far i can tell, only values "now" and "%Y-%m-%d %H:%M" are allowed as DateTime value.

In order to filter events older than x minutes/hours/days.. one would have to use something like a dynamic "now-x" as DateTime filter input.

I wasn't able to find where the "now" value is interpreted as the current time, if anyone knows, devs?
The idea would be to translate the "now-x" value to the current time reduced by the x amount of minutes, days or whatever.

If somebody could point me to the right files/locations I could do it myself.

Thanks in advance.

Regards

Re: Purging events older than x

Posted: Tue Apr 10, 2012 5:59 pm
by knight-of-ni
Don't know if Zoneminder can do this on its own, but you could try something like this from the command line (or cron):

Code: Select all

find /path/to/your/zoneminder/events -type f -mtime +30 -delete
This will delete files that were modified more than 30 days ago. My events folder is under /var/lib/zoneminder/events, but yours is likely different.

This assumes the zm_audit daemon will clean up all the orphaned database records this would create. Since zoneminder itself does this internally, I am assuming this is safe.

Re: Purging events older than x

Posted: Tue Apr 10, 2012 7:12 pm
by _saiko
Hm, well a one-liner such as this or a simple script to do it the linux way is something I didn't think about precisely because there's the db to consider...
I could try that for a while and see how it behaves.

Also i DID try and mess a bit with the "now+/-" approach on the filters page.
Apparently it does SOMETHING. Entering random text gives a default "1970-01-01..." date.

I enabled the general_log in mysql to monitor what queries are actually being run.

This is the outcome (lets say now = 2012-04-10 01:00:00):
with "now" the query is as expected

Code: Select all

select E.Id,E.MonitorId,M.Name As MonitorName,M.Width,M.Height,M.DefaultScale,E.Name,E.Cause,E.Notes,E.StartTime,E.Length,E.Frames,E.AlarmFrames,E.TotScore,E.AvgScore,E.MaxScore,E.Archived from Monitors as M inner join Events as E on (M.Id = E.MonitorId) where 1 and ( E.StartTime < '2012-04-10 01:00:00' ) order by E.StartTime asc
with "now+1"

Code: Select all

...( E.StartTime < '2012-04-10 02:00:00' )
with "now+2"
...( E.StartTime < '2012-04-10 01:00:00' )
with "now+3"

Code: Select all

...( E.StartTime < '2012-04-10 00:00:00' )
with "now+30"

Code: Select all

...( E.StartTime < '2012-04-08 21:00:00' )
with "now-1"

Code: Select all

...( E.StartTime < '2012-04-08 04:00:00' )
Anyhow I can't really figure out the formula :D
Nor where/how that "now" value is converted to the current time.

The furthest I went into the past was with "now+99" which brings me back about 5 days. With "now+100" i get the same result as with "now+1"....

Re: Purging events older than x

Posted: Tue Apr 10, 2012 8:09 pm
by knight-of-ni
Out of curiosity I went looking in the Zoneminder documentation, which referred me to this:
http://www.php.net/manual/en/function.strtotime.php

Scrolling down to the examples, it looks like you should be able to use expressions like "+1 week" or "last Thursday", etc.
Try it and let me know.

Re: Purging events older than x

Posted: Tue Apr 10, 2012 8:28 pm
by _saiko
That's it!

"-1 week" was what I was searching for :)
"+/-1 day" etc. works too, just like in the examples.

There should definitely be an article in the ZM wiki for this.

Edit: ok it actually IS in the wiki and I was to lazy to read.
Which brings me to the fact, there should at least be more examples for filters :)