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
Purging events older than x
- knight-of-ni
- Posts: 2406
- Joined: Thu Oct 18, 2007 1:55 pm
- Location: Shiloh, IL
Re: Purging events older than x
Don't know if Zoneminder can do this on its own, but you could try something like this from the command line (or cron):
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.
Code: Select all
find /path/to/your/zoneminder/events -type f -mtime +30 -delete
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.
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/
All of these can be found at https://zoneminder.blogspot.com/
Re: Purging events older than x
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
with "now+1"
with "now+2"
with "now+30"
with "now-1"
Anyhow I can't really figure out the formula
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"....
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
Code: Select all
...( E.StartTime < '2012-04-10 02:00:00' )
with "now+3"...( E.StartTime < '2012-04-10 01:00:00' )
Code: Select all
...( E.StartTime < '2012-04-10 00:00:00' )
Code: Select all
...( E.StartTime < '2012-04-08 21:00:00' )
Code: Select all
...( E.StartTime < '2012-04-08 04:00:00' )
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"....
- knight-of-ni
- Posts: 2406
- Joined: Thu Oct 18, 2007 1:55 pm
- Location: Shiloh, IL
Re: Purging events older than x
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.
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.
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/
All of these can be found at https://zoneminder.blogspot.com/
Re: Purging events older than x
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
"-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