Zoneminder Alarm Custom Logging (& Notification)

Zoneminder already provide alarm notification by email, but you can’t send the image in it’s email notification (yes, you can see tags below). Instead, you can use custom script to send notification via messaging such as telegram

1. create new filter, put this in its fields:
– Alarm Frames >= 10
– (and) Start Date/Time >= -1 hour
– (and) Monitor Id = 1
– Message details of all matches: checked (you need to set OPT_MESSAGE in email options) otherwise you’ll only get notification after an event finished, not immediately
– Execute command on all matches:
/home/zmuser/logalarm.sh "%EI%" "%EN%" "%ET%" "%EL%" "%EFA%" "%EST%" "%ESA%" "%EP%" "%EFMOD%" "%EPI%" "%EPI1%" "%MN%" "%MP%"
– Run filter in background: checked
* For other tags you can use see below

2. create file logalarm.sh (this script only do logging, you can change this script to do notification via telegram using telegram-cli https://github.com/vysheng/tg):
#!/bin/sh
LOGF=/home/zmuser/alarm.log
echo "--- $(date '+%F %T')" >> ${LOGF}
echo "$1" >> ${LOGF}
echo "$2" >> ${LOGF}
echo "$3" >> ${LOGF}
echo "$4" >> ${LOGF}
echo "$5" >> ${LOGF}
echo "$6" >> ${LOGF}
echo "$7" >> ${LOGF}
echo "$8" >> ${LOGF}
echo "$9" >> ${LOGF}
echo "$10" >> ${LOGF}
echo "$11" >> ${LOGF}
echo "$12" >> ${LOGF}
echo "$13" >> ${LOGF}
echo "$14" >> ${LOGF}
echo "LOGGED OK"
exit 0

3. create alarm.log and make sure it’s accessible:
touch /home/zmuser/alarm.log
chmod 666 /home/zmuser/alarm.log

Here is tags you can use in the field:
%EI% Id of the event - eg 703507
%EN% Name of the event - eg Event- 703507
%EC% Cause of the event
%ED% Event description
%ET% Time of the event - eg 2020-04-15 12:10:00
%EL% Length of the event - eg 600.00
%EF% Number of frames in the event - eg 600
%EFA% Number of alarm frames in the event - eg 618
%EST% Total score of the event - eg 2597
%ESA% Average score of the event - eg 4
%ESM% Maximum score of the event - eg 69
%EP% Path to the event - eg ?view=event&mid=2&eid=703507
%EFMOD% Path to image containing object detection, in frame view (need 3rd party object detection event server)
%EIMOD% Path to image containing object detection, in frame view (need 3rd party object detection event server)
%EPS% Path to the event stream
%EPI% Path to the event images - eg ?view=event&mode=still&mid=2&eid=703507
%EPI1% Path to the first alarmed event image - eg ?view=frame&mid=2&eid=703507&fid=3326
%EPIM% Path to the (first) event image with the highest score
%MN% Name of the monitor - eg 12_LV2_BRH
%MET% Total number of events for the monitor
%MEH% Number of events for the monitor in the last hour
%MED% Number of events for the monitor in the last day
%MEW% Number of events for the monitor in the last week
%MEM% Number of events for the monitor in the last month
%MEA% Number of archived events for the monitor
%MP% Path to the monitor window - eg ?view=watch&mid=2
%MPS% Path to the monitor stream
%MPI% Path to the monitor recent image
%FN% Name of the current filter that matched
%FP% Path to the current filter that matched
%ZP% Path to your ZoneMinder console
LAST_PARAM path to the event folder - eg /var/cache/zoneminder/events/2/2020-04-15/703507

Below are tags for email only (can’t use with execute):
%EI1% Attach first alarmed event image
%EI1A% Attach first alarmed event image (analyse)
%EIM% Attach (first) event image with the highest score
%EIMA% Attach (fist) event image with the highest score (analyse)
%EV% Attach event mpeg video
%EVM% Attach event 3gp video for mobile

Source:
– https://github.com/vysheng/tg
– https://forums.zoneminder.com/viewtopic.php?t=22053

Leave a Reply

Your email address will not be published. Required fields are marked *