Zoneminder API and Filters

Forum for questions and support relating to the 1.29.x releases only.
Locked
gert
Posts: 14
Joined: Fri Jul 01, 2016 12:43 am

Zoneminder API and Filters

Post by gert »

I am working my way through an automated setup of a zoneminder server. It looks like there is no API for setting up Filters. Is this correct, and are there any plans to add this in the future?

Thanks!
gert
Posts: 14
Joined: Fri Jul 01, 2016 12:43 am

Re: Zoneminder API and Filters

Post by gert »

As a somewhat horrible workaround, I guess I can use mysql to insert filters, using /usr/share/zoneminder/db/zm_create.sql as a guide.

Since I'm using Ansible, I might even just fix the version at 1.29 and include a modified zm_create.sql for use in install.

(And this would also work for adding additional users)
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Zoneminder API and Filters

Post by asker »

correct, no APIs for filters. I don't have any current plans to add APIs for filters, but anyone who can do a PR can.
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
gert
Posts: 14
Joined: Fri Jul 01, 2016 12:43 am

Re: Zoneminder API and Filters

Post by gert »

I was able to set up filters like by creating a pared down version of zm_create.sql, and loading it as an additional step (and FYI: it overwrites all existing filters, too).

The file I created has the default filter plus a delete unarchived 7day old footage filter.

Code: Select all

-- MySQL dump 10.13 Distrib 5.6.13, for Linux (i686)
-- 
-- Host: localhost Database: zm
-- ------------------------------------------------------
-- Server version 5.6.13
-- 
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
-- 
-- Current Database: `zm`
-- 
USE `zm`;
-- 
-- Table structure for table `Filters`
-- 
DROP TABLE IF EXISTS `Filters`;
CREATE TABLE `Filters` (
`Name` varchar(64) NOT NULL default '',
`Query` text NOT NULL,
`AutoArchive` tinyint(3) unsigned NOT NULL default '0',
`AutoVideo` tinyint(3) unsigned NOT NULL default '0',
`AutoUpload` tinyint(3) unsigned NOT NULL default '0',
`AutoEmail` tinyint(3) unsigned NOT NULL default '0',
`AutoMessage` tinyint(3) unsigned NOT NULL default '0',
`AutoExecute` tinyint(3) unsigned NOT NULL default '0',
`AutoExecuteCmd` tinytext,
`AutoDelete` tinyint(3) unsigned NOT NULL default '0',
`Background` tinyint(1) unsigned NOT NULL default '0',
PRIMARY KEY (`Name`)
) ENGINE=InnoDB;
-- 
-- Add a sample filter to purge the oldest 100 events when the disk is 95% full
-- 
insert into Filters values ('PurgeWhenFull','{"sort_field":"Id","terms":[{"val":0,"attr":"Archived","op":"="},{"cnj":"and","val":95,"attr":"DiskPercent","op":">="}],"limit":100,"sort_asc":1}',0,0,0,0,0,0,'',1,1);
insert into Filters values ('Purge1WeekOld','{"terms":[{"attr":"Archived","op":"=","val":"0"},{"cnj":"and","attr":"DateTime","op":"<","val":"7 day ago"}],"sort_field":"DateTime","sort_asc":"1","limit":"100"}',0,0,0,0,0,0,'',1,1);
And then use this with:

Code: Select all

mysql -uYOURUSER -pYOURPASS < /usr/share/zoneminder/db/zm_reset_filters.sql
Or in the case of using ansible:

Code: Select all

# Always overwrite the filters
- name: Copy mysql code for filters to host
  copy:
    src=files/zm_reset_filters.sql
    dest=/usr/share/zoneminder/db/zm_reset_filters.sql
    owner=root
    group=root
    mode=0644
    force=yes
- name: Reset the Zoneminder filters in the database
  shell: mysql -u{{ mysqlusr }} -p{{ mysqlpwd }} < /usr/share/zoneminder/db/zm_reset_filters.sql
Locked