What is the best way to get the ID of newly closed events in real time?

Current Development version likely to have breaking changes
Post Reply
fontiano
Posts: 68
Joined: Wed Dec 25, 2019 10:29 am

What is the best way to get the ID of newly closed events in real time?

Post by fontiano »

In version 1.34 I use this script to monitor the end of new events in real time and subsequently launch a script for image analysis.

It works in 1.36 too.

##########################################################################################################

#!/bin/bash
PARSER=`pgrep -f zm_parser.sh | wc -l`
#echo $PARSER
if [ $PARSER -eq "2" ]; then
echo "Lancio processo zm_parser"
source /scripts/zoneminder2/variabili.sh
sudo -u www-data tsp -S $CODA
tail -F -n 1 /var/log/eventizoneminder.log | egrep --line-buffered -e "Closing event" |
while read line; do
EVENTO=`echo $line | awk -F'event ' '{print $2}' | awk -F',' '{print $1}'`
echo "Estraggo i frame dall'evento "$EVENTO
sudo -u www-data tsp -n bash /scripts/zoneminder2/estrai_frames.sh $EVENTO
done &
else
echo "Processo zm_parser già in esecuzione"
fi

##########################################################################################################

in version 1.37 the logs are different and there is no specific entry that tells me the id of the last closed event. Furthermore they are not reliable because they do not report the opening of all events

tail -f /var/log/syslog | grep event
2024-01-09T22:15:17.846652+01:00 zoneminder136 zmc_m2[2048]: INF [zmc_m2] [PiazzaleGiardino: 58354 - Opened new event 1055, continuous section start]
2024-01-09T22:15:47.661028+01:00 zoneminder136 zmc_m2[2048]: INF [zmc_m2] [PiazzaleGiardino: 58802 - Opened new event 1057, continuous section start]
2024-01-09T22:16:17.660101+01:00 zoneminder136 zmc_m2[2048]: INF [zmc_m2] [PiazzaleGiardino: 59252 - Opened new event 1059, continuous section start]
2024-01-09T22:16:47.726155+01:00 zoneminder136 zmc_m2[2048]: INF [zmc_m2] [PiazzaleGiardino: 59702 - Opened new event 1061, continuous section start]

If I try to use the "Event End Command" option I always get errors even on simple commands such as "echo > /dev/shm/test" furthermore I can't find the syntax anywhere to define the variable relating to the id event (I tried with $1 but I'm not sure if it's correct).

What is the best way to get the ID of newly closed events in real time? (I would like to avoid installing zmeventnotification server)
Production: zm 1.34.26 - Debian 11 | Test: zm 1.36.33 - Debian 12
User avatar
iconnor
Posts: 2919
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: What is the best way to get the ID of newly closed events in real time?

Post by iconnor »

Logs should be the same, we can look into that and fix it.

The Event End Command method takes EventId as $1 and MonitorId as $2. Remember, it runs as www-data so permissions may be an issue.
fontiano
Posts: 68
Joined: Wed Dec 25, 2019 10:29 am

Re: What is the best way to get the ID of newly closed events in real time?

Post by fontiano »

the logs are not the same

I added this line on /etc/rsyslog.conf

if $syslogfacility-text == 'local1' and $msg contains 'Closing event' then -/var/log/eventizoneminder.log

and this is the result on 1.34 (mocord) if I do cat /var/log/eventizoneminder.log (the same in 1.36.33)


Jan 10 21:24:03 videosorveglianza zma_m2[6198]: INF [zma_m2] [CancelloFabbrica: 33921665 - Closing event 18768288, section end forced 1704918243 - 1704918213 = 30 >= 30]
Jan 10 21:24:06 videosorveglianza zma_m11[3944776]: INF [zma_m11] [Campi: 20969513 - Closing event 18768289, section end forced 1704918246 - 1704918216 = 30 >= 30]
Jan 10 21:24:07 videosorveglianza zma_m3[5661]: INF [zma_m3] [Capanna: 34016061 - Closing event 18768291, section end forced 1704918247 - 1704918217 = 30 >= 30]
Jan 10 21:24:07 videosorveglianza zma_m1[5372]: INF [zma_m1] [PiazzaleGiardino: 33908836 - Closing event 18768290, section end forced 1704918247 - 1704918217 = 30 >= 30]
Jan 10 21:24:07 videosorveglianza zma_m4[2349251]: INF [zma_m4] [GarageMacchina: 15626036 - Closing event 18768293, section end forced 1704918247 - 1704918217 = 30 >= 30]
Jan 10 21:24:08 videosorveglianza zma_m5[5660]: INF [zma_m5] [GarageStanza: 32571753 - Closing event 18768292, section end forced 1704918248 - 1704918218 = 30 >= 30]
Jan 10 21:24:18 videosorveglianza zma_m12[4122664]: INF [zma_m12] [CasaMiaVeranda: 20777423 - Closing event 18768294, section end forced 1704918258 - 1704918228 = 30 >= 30]
Jan 10 21:24:25 videosorveglianza zma_m6[5242]: INF [zma_m6] [InternoFabbrica: 34009826 - Closing event 18768296, section end forced 1704918265 - 1704918235 = 30 >= 30]
Jan 10 21:24:25 videosorveglianza zma_m7[5803]: INF [zma_m7] [PiazzaleFabbrica: 33921939 - Closing event 18768295, section end forced 1704918265 - 1704918235 = 30 >= 30]
Jan 10 21:24:25 videosorveglianza zma_m4[2349251]: INF [zma_m4] [GarageMacchina: 15626216 - Closing event 18768303, section end forced 1704918265 - 1704918235 = 30 >= 30]
Jan 10 21:24:27 videosorveglianza zma_m9[1615208]: INF [zma_m9] [StradaSilvia: 1914268 - Closing event 18768298, section end forced 1704918267 - 1704918237 = 30 >= 30]
Jan 10 21:24:27 videosorveglianza zma_m10[2207024]: INF [zma_m10] [CasaMiaCancello: 10393561 - Closing event 18768297, section end forced 1704918267 - 1704918237 = 30 >= 30]
Jan 10 21:24:30 videosorveglianza zma_m2[6198]: INF [zma_m2] [CancelloFabbrica: 33922070 - Closing event 18768299, section end forced 1704918270 - 1704918240 = 30 >= 30]
Jan 10 21:24:34 videosorveglianza zma_m1[5372]: INF [zma_m1] [PiazzaleGiardino: 33909241 - Closing event 18768302, section end forced 1704918274 - 1704918244 = 30 >= 30]
Jan 10 21:24:35 videosorveglianza zma_m11[3944776]: INF [zma_m11] [Campi: 20969947 - Closing event 18768300, section end forced 1704918275 - 1704918245 = 30 >= 30]
Jan 10 21:24:36 videosorveglianza zma_m3[5661]: INF [zma_m3] [Capanna: 34016497 - Closing event 18768301, section end forced 1704918276 - 1704918246 = 30 >= 30]
Jan 10 21:24:37 videosorveglianza zma_m5[5660]: INF [zma_m5] [GarageStanza: 32572171 - Closing event 18768304, section end forced 1704918277 - 1704918247 = 30 >= 30]
Jan 10 21:24:43 videosorveglianza zma_m4[2349251]: INF [zma_m4] [GarageMacchina: 15626395 - Closing event 18768308, section end forced 1704918283 - 1704918253 = 30 >= 30]
Jan 10 21:24:45 videosorveglianza zma_m12[4122664]: INF [zma_m12] [CasaMiaVeranda: 20777827 - Closing event 18768305, section end forced 1704918285 - 1704918255 = 30 >= 30]
Jan 10 21:24:51 videosorveglianza zma_m6[5242]: INF [zma_m6] [InternoFabbrica: 34010217 - Closing event 18768306, section end forced 1704918291 - 1704918261 = 30 >= 30]
Jan 10 21:24:52 videosorveglianza zma_m7[5803]: INF [zma_m7] [PiazzaleFabbrica: 33922344 - Closing event 18768307, section end forced 1704918292 - 1704918262 = 30 >= 30]
Jan 10 21:24:53 videosorveglianza zma_m9[1615208]: INF [zma_m9] [StradaSilvia: 1914528 - Closing event 18768309, section end forced 1704918293 - 1704918263 = 30 >= 30]
Jan 10 21:24:54 videosorveglianza zma_m10[2207024]: INF [zma_m10] [CasaMiaCancello: 10393965 - Closing event 18768310, section end forced 1704918294 - 1704918264 = 30 >= 30]
Jan 10 21:24:57 videosorveglianza zma_m2[6198]: INF [zma_m2] [CancelloFabbrica: 33922475 - Closing event 18768311, section end forced 1704918297 - 1704918267 = 30 >= 30]
Jan 10 21:25:01 videosorveglianza zma_m4[2349251]: INF [zma_m4] [GarageMacchina: 15626575 - Closing event 18768316, section end forced 1704918301 - 1704918271 = 30 >= 30]
Jan 10 21:25:01 videosorveglianza zma_m1[5372]: INF [zma_m1] [PiazzaleGiardino: 33909646 - Closing event 18768312, section end forced 1704918301 - 1704918271 = 30 >= 30]
Jan 10 21:25:02 videosorveglianza zma_m11[3944776]: INF [zma_m11] [Campi: 20970352 - Closing event 18768313, section end forced 1704918302 - 1704918272 = 30 >= 30]
Jan 10 21:25:03 videosorveglianza zma_m3[5661]: INF [zma_m3] [Capanna: 34016903 - Closing event 18768314, section end forced 1704918303 - 1704918273 = 30 >= 30]
Jan 10 21:25:04 videosorveglianza zma_m5[5660]: INF [zma_m5] [GarageStanza: 32572560 - Closing event 18768315, section end forced 1704918304 - 1704918274 = 30 >= 30]
Jan 10 21:25:12 videosorveglianza zma_m12[4122664]: INF [zma_m12] [CasaMiaVeranda: 20778231 - Closing event 18768317, section end forced 1704918312 - 1704918282 = 30 >= 30]
Jan 10 21:25:19 videosorveglianza zma_m4[2349251]: INF [zma_m4] [GarageMacchina: 15626749 - Closing event 18768323, section end forced 1704918319 - 1704918289 = 30 >= 30]
Jan 10 21:25:19 videosorveglianza zma_m6[5242]: INF [zma_m6] [InternoFabbrica: 34010631 - Closing event 18768318, section end forced 1704918319 - 1704918289 = 30 >= 30]
Jan 10 21:25:19 videosorveglianza zma_m7[5803]: INF [zma_m7] [PiazzaleFabbrica: 33922749 - Closing event 18768319, section end forced 1704918319 - 1704918289 = 30 >= 30]
Jan 10 21:25:21 videosorveglianza zma_m10[2207024]: INF [zma_m10] [CasaMiaCancello: 10394368 - Closing event 18768321, section end forced 1704918321 - 1704918291 = 30 >= 30]
Jan 10 21:25:22 videosorveglianza zma_m9[1615208]: INF [zma_m9] [StradaSilvia: 1914818 - Closing event 18768320, section end forced 1704918322 - 1704918292 = 30 >= 30]
Jan 10 21:25:26 videosorveglianza zma_m2[6198]: INF [zma_m2] [CancelloFabbrica: 33922910 - Closing event 18768322, section end forced 1704918326 - 1704918296 = 30 >= 30]
Jan 10 21:25:28 videosorveglianza zma_m1[5372]: INF [zma_m1] [PiazzaleGiardino: 33910051 - Closing event 18768324, section end forced 1704918328 - 1704918298 = 30 >= 30]
Jan 10 21:25:29 videosorveglianza zma_m11[3944776]: INF [zma_m11] [Campi: 20970755 - Closing event 18768325, section end forced 1704918329 - 1704918299 = 30 >= 30]
Jan 10 21:25:30 videosorveglianza zma_m3[5661]: INF [zma_m3] [Capanna: 34017301 - Closing event 18768326, section end forced 1704918330 - 1704918300 = 30 >= 30]
Jan 10 21:25:33 videosorveglianza zma_m5[5660]: INF [zma_m5] [GarageStanza: 32572973 - Closing event 18768327, section end forced 1704918333 - 1704918303 = 30 >= 30]
Jan 10 21:25:39 videosorveglianza zma_m12[4122664]: INF [zma_m12] [CasaMiaVeranda: 20778636 - Closing event 18768328, section end forced 1704918339 - 1704918309 = 30 >= 30]
Jan 10 21:25:40 videosorveglianza zma_m8[1615278]: INF [zma_m8] [VialeSilvia: 1914805 - Closing event 18768336, alarm end]
Jan 10 21:25:43 videosorveglianza zma_m4[2349251]: INF [zma_m4] [GarageMacchina: 15626995 - Closing event 18768329, section end forced 1704918343 - 1704918313 = 30 >= 30]
Jan 10 21:25:45 videosorveglianza zma_m6[5242]: INF [zma_m6] [InternoFabbrica: 34011022 - Closing event 18768330, section end forced 1704918345 - 1704918315 = 30 >= 30]

you can see that all events are recorded although not in ascending order

this is what I have in 1.37.48 (recording: always + motion detection: always)

2024-01-10T21:29:43.810241+01:00 zoneminder136 zmc_m1[2361]: INF [zmc_m1] [CasaMiaVeranda: 255 - Closing event 1272, alarm end, section truncated]
2024-01-10T21:30:13.712389+01:00 zoneminder136 zmc_m2[2366]: INF [zmc_m2] [PiazzaleGiardino: 705 - Closing event 1275, alarm end, section truncated]
2024-01-10T21:30:34.790496+01:00 zoneminder136 zmc_m1[2361]: INF [zmc_m1] [CasaMiaVeranda: 1020 - Closing event 1277, alarm end, section truncated]
2024-01-10T21:32:03.056820+01:00 zoneminder136 zmc_m1[2361]: INF [zmc_m1] [CasaMiaVeranda: 2340 - Closing event 1282, alarm end, section truncated]
2024-01-10T21:32:19.091409+01:00 zoneminder136 zmc_m1[2361]: INF [zmc_m1] [CasaMiaVeranda: 2580 - Closing event 1284, alarm end, section truncated]
2024-01-10T21:32:43.118599+01:00 zoneminder136 zmc_m1[2361]: INF [zmc_m1] [CasaMiaVeranda: 2940 - Closing event 1286, alarm end, section truncated]
2024-01-10T21:32:59.173932+01:00 zoneminder136 zmc_m1[2361]: INF [zmc_m1] [CasaMiaVeranda: 3180 - Closing event 1287, alarm end, section truncated]

as you can see only some events are logged, others are ignored. The same goes if I go to monitor the "Opened new event" string, not all events are logged.
Production: zm 1.34.26 - Debian 11 | Test: zm 1.36.33 - Debian 12
fontiano
Posts: 68
Joined: Wed Dec 25, 2019 10:29 am

Re: What is the best way to get the ID of newly closed events in real time?

Post by fontiano »

trying with integrated option:

root@zoneminder137:~# cat /etc/sudoers | grep www-data
www-data ALL=NOPASSWD: /bin/bash /scripts/zoneminder2/estrai_frames.sh *

root@zoneminder137:~# sudo -u www-data bash

www-data@zoneminder137:/root$ whoami
www-data

www-data@zoneminder137:/root$ sudo /bin/bash /scripts/zoneminder2/estrai_frames.sh 700
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 68637 100 68637 0 0 840k 0 --:--:-- --:--:-- --:--:-- 837k
Il file video è presente e non sono presenti immagini di analisi, procedo ad estrarre i frames.
Provo ad estrarre i frames:
Estraggo il frame al secondo 0.0
Estraggo il frame al secondo 4.01
Estraggo il frame al secondo 5.01
Estraggo il frame al secondo 5.99
Estraggo il frame al secondo 6.99
Estraggo il frame al secondo 7.98
Estraggo il frame al secondo 9.01
Estraggo il frame al secondo 10.03
Estraggo il frame al secondo 11.02
Estraggo il frame al secondo 12.02
Estraggo il frame al secondo 13.02
Estraggo il frame al secondo 14.02
Estraggo il frame al secondo 15.04
Estraggo il frame al secondo 16.02
Estraggo il frame al secondo 17.04
Estraggo il frame al secondo 18.03
Estraggo il frame al secondo 20.02
Estraggo il frame al secondo 24.05
Estraggo il frame al secondo 25.18
Estraggo il frame al secondo 26.13
Estraggo il frame al secondo 27.12
Estraggo il frame al secondo 28.15
Estraggo il frame al secondo 29.12

but from zoneminder he is unable to launch the command

root@zoneminder137:~# tail -f /var/log/syslog | grep Error
2024-01-10T22:05:29.621080+01:00 zoneminder137 zmc_m1[1990]: ERR [zmc_m1] [Error execing sudo /bin/bash /scripts/zoneminder2/estrai_frames.sh $1]
2024-01-10T22:05:43.602057+01:00 zoneminder137 zmc_m2[2016]: ERR [zmc_m2] [Error execing sudo /bin/bash /scripts/zoneminder2/estrai_frames.sh $1]
2024-01-10T22:05:45.623861+01:00 zoneminder137 zmc_m1[2027]: ERR [zmc_m1] [Error execing sudo /bin/bash /scripts/zoneminder2/estrai_frames.sh $1]
Production: zm 1.34.26 - Debian 11 | Test: zm 1.36.33 - Debian 12
Post Reply