Open ptroms opened 2 years ago
Thanks for opening your first issue here! Just a reminder, this forum is for Bug Reports only. Be sure to follow the issue template!
Those logs are for ZMES the event server add-on. What version of ZM are you running and how do you have things set up?
That s right. It is the only place in logs where mail is mention.
system:
5.10.0-11-amd64
ZM:
v1.36.12
The 'notificatiom' that zmeventnotofication is talking about is push messages via FCM, a completely different thing. I don't use the mail utility in zm, there must be some logs for it somewhere though. You could try grepping the zm log directory for 'mail' or your email username or something.
I am afraid i couldn't find anything related to email. Alarm section form log below:
02/16/22 00:59:04.420829 zmc_m1[43990].INF-zm_monitor.cpp/2123 [F: 19728 - Opening new event 221, alarm start]
02/16/22 00:59:07.156219 zmc_m1[43951].INF-zm_monitor.cpp/1674 [F: 19800 - Capturing at 22.17 fps, capturing bandwidth 143067bytes/sec]
02/16/22 00:59:07.188146 zmc_m1[43990].INF-zm_monitor.cpp/1715 [F: 19800 - Analysing at 22.13 fps from 19799 - 19699=100 / 1644973147.188143 - 1644973142.668811 = 4.519332]
02/16/22 00:59:11.251843 zmc_m1[43990].INF-zm_monitor.cpp/2157 [F: 19888 - Gone into alert state]
02/16/22 00:59:11.718536 zmc_m1[43951].INF-zm_monitor.cpp/1674 [F: 19900 - Capturing at 21.92 fps, capturing bandwidth 135202bytes/sec]
02/16/22 00:59:11.751270 zmc_m1[43990].INF-zm_monitor.cpp/1715 [F: 19900 - Analysing at 21.91 fps from 19899 - 19799=100 / 1644973151.751267 - 1644973147.188143 = 4.563124]
02/16/22 00:59:16.283858 zmc_m1[43951].INF-zm_monitor.cpp/1674 [F: 20000 - Capturing at 21.90 fps, capturing bandwidth 135029bytes/sec]
02/16/22 00:59:16.317840 zmc_m1[43990].INF-zm_monitor.cpp/1715 [F: 20000 - Analysing at 21.90 fps from 19999 - 19899=100 / 1644973156.317837 - 1644973151.751267 = 4.566570]
02/16/22 00:59:18.379835 zmc_m1[43990].INF-zm_monitor.cpp/2165 [F: 20045 - Left alarm state (221) - 370(162) images]
02/16/22 00:59:18.379907 zmc_m1[43990].INF-zm_monitor.cpp/2170 [F: 20045 - Closing event 221, alarm end]
Ill setup the email functionality quickly and see if I can help out
In the ZM filters I do not see an option to 'Send email', from what I understand that's what is needed in order to receive an email. A ZM filter needs to match and the command to send emails needs to be set up.
Testing if it works To be safe, restart ZM (Frankly I never needed to - but what the heck, in some odd case if it does not pick up these changes, why bang your head. ZM has many other things you are going to fret over :-) )
Is there a reason you want to email instead of zmninja/pushover/gotify notifications using the Event Server? You can not run object detection and instead be notified on every single event on specified monitors.
If is hard to disagree with you regarding accessing ZM form mobile. The only one disadvantage of zmNinja is consuming data. It is a problem when I am far away form civilization. Email would be more convenient in that scenario. Regarding debug in syslog produce tons of data but I am afraid beside does ones that I was sending/testing manually no signs of mails from ZM.
The reason ZM is not sending emails from what I can tell is that that functionality was controlled by using 'filters'. I am running 1.37.11 and I do not see a filter command to send emails so I am assuming that functionality was removed or deprecated, I cant say for sure though. Here is a screenshot of the filters section.
There is an option to run a command there though that you could set up with a custom shell script to send an email, I just don't know how you would extract event info. The other option is to use Event Server push API option and create a script that sends an email instead of using a push notification service, you would get the event #, monitor name and the 'notes' to send in an email.
You have to turn it on Options->Email OPT_EMAIL
Ah, I hadnt turned all that on yet. @ptroms - here is a screenshot of the filters page one OPT_EMAIL is enabled.
You just need to setup a filter to match for emails to be sent.
Let me show what I have here:
Email conf:
Filters conf:
Syslog debug mode shows no sings of mail. When I entering the filter configuration over http the only thing that comes up by command:
tail -n 30000 /var/log/syslog | grep mail
is:
Feb 17 09:09:24 zm web_php[74417]: [AutoEmail] => 0
Feb 17 09:09:24 zm web_php[74417]: [EmailTo] =>
Feb 17 09:09:24 zm web_php[74417]: [EmailSubject] =>
Feb 17 09:09:24 zm web_php[74417]: [EmailBody] =>
Feb 17 09:09:24 zm web_php[74417]: [AutoEmail] => 0
Feb 17 09:09:24 zm web_php[74417]: [EmailTo] =>
Feb 17 09:09:24 zm web_php[74417]: [EmailSubject] =>
Feb 17 09:09:24 zm web_php[74417]: [EmailBody] =>
Feb 17 09:09:40 zm web_php[77921]: [AutoEmail] => 0
Feb 17 09:09:40 zm web_php[77921]: [EmailTo] =>
Feb 17 09:09:40 zm web_php[77921]: [EmailSubject] =>
Feb 17 09:09:40 zm web_php[77921]: [EmailBody] =>
Feb 17 09:09:40 zm web_php[77921]: [AutoEmail] => 1
Feb 17 09:09:40 zm web_php[77921]: [EmailTo] =>
Feb 17 09:09:40 zm web_php[77921]: [EmailSubject] =>
Feb 17 09:09:40 zm web_php[77921]: [EmailBody] =>
Feb 17 09:09:40 zm web_php[77921]: [AutoEmail] => 0
Feb 17 09:09:40 zm web_php[77921]: [EmailTo] =>
Feb 17 09:09:40 zm web_php[77921]: [EmailSubject] =>
Feb 17 09:09:40 zm web_php[77921]: [EmailBody] =>
Feb 17 09:09:40 zm web_php[77921]: [AutoEmail] => 1
Feb 17 09:09:40 zm web_php[77921]: [EmailTo] =>
Feb 17 09:09:40 zm web_php[77921]: [EmailSubject] =>
Feb 17 09:09:40 zm web_php[77921]: [EmailBody] =>
Set the filter to Id equal to sudo zmu -m[MONITOR ID] -a -U [USERNAME] -P [PASSWORD]
and to cancel the alarm use sudo zmu -m[MONITOR ID] -ac -U [USERNAME] -P [PASSWORD]
Or try executing the filter from the filter page.
I don't use filters so I can't really help on that part, I am assuming having 'StartDate' 'equals to' and then the editable field set to nothing is invalid or may not trigger. IDK for sure though.
So to reiterate, set the filter condition to Id
equals to
3
and then go and force an alarm on monitor 3 (or change the Id to a monitor that is able to create events)
Edit: Also try re-entering all the info on the filter page (email address, message, body, etc.)
Right. I have sliced and diced baudneo's suggestion's commands, but as he mentioned it triggers on-off the alarms. I am sure there is a simple catch.
These are my settings, but I'm probably going to switch to zmeventnotification to get notifications in real time ratner than delayed 1 minute in the worst case. It may be possible to change "end date/time" to "start date/time" to receive the event even sooner, "end date/time" means it won't send the mail until the event has already finished.
You also need to set "run filter in background", "run filter concurrently" and set your filter run interval in system settings to 1 minute (the value set in the filter -1min) or you'll miss some events or send duplicate mails.
Here we go: syslog:
Feb 17 15:48:05 zm zmfilter_3[81736]: DB1 [Checking filter message-send email returned 0 events ]
Feb 17 15:49:05 zm zmfilter_3[81736]: DB1 [Filter::Execute SQL (SELECT E.*, unix_timestamp(E.StartDateTime) as Time#012 FROM Events as E WHERE ( E.EndDateTime >= '2022-02-17 15:48:05' #012 and E.AlarmFrames >= 5 #012 and E.Cause = 'Motion' #012 and ( extract( hour_second from E.EndDateTime ) > extract( hour_second from '2022-02-17 00:00:00' ) #012 or extract( hour_second from E.EndDateTime ) < extract( hour_second from '2022-02-17 23:59:59' ) )#012 ) AND ( E.Emailed = 0 ) ORDER BY E.Name ASC LIMIT 0,100)]
Feb 17 15:49:05 zm zmfilter_3[81736]: DB1 [Loaded 0 events for filter message-send using query (SELECT E.*, unix_timestamp(E.StartDateTime) as Time#012 FROM Events as E WHERE ( E.EndDateTime >= '2022-02-17 15:48:05' #012 and E.AlarmFrames >= 5 #012 and E.Cause = 'Motion' #012 and ( extract( hour_second from E.EndDateTime ) > extract( hour_second from '2022-02-17 00:00:00' ) #012 or extract( hour_second from E.EndDateTime ) < extract( hour_second from '2022-02-17 23:59:59' ) )#012 ) AND ( E.Emailed = 0 ) ORDER BY E.Name ASC LIMIT 0,100)"]
Feb 17 15:49:05 zm zmfilter_3[81736]: DB1 [Checking filter message-send email returned 0 events ]
For sure filter works.
So those End Time clauses are pretty superfluous. Also you likely want Cause CONTAINS, not equal to.
Oh and DON'T use the concurrent option. It was ill-conceived and not needed.
So those End Time clauses are pretty superfluous. Also you likely want Cause CONTAINS, not equal to.
Yep, you can omit the last 2 "End Time" clauses, I have them because I want to ignore events during work hours. Good to know about Cause contains, thanks.
Great point. The filter works for sure, however no alert emails (so far),
Finally works. As usual it was a tiny bit. In options "email to", "email subject" and "email body" needs to be filled . And then "voila" here we are. Also I have a two additional questions regarding this functionality.
I would use an email filtering rule to automatically forward a copy of the email to the 2nd address. If you are using outlook or Gmail you need to login to your account on desktop and find where the email filtering/forwarding rules are.
There is many, many ways of doing it. As baudneo pointed out I think is one of the most popular one. Good stuff.
<>
are not mandatory, they are only if you want to include a human-readable name in front of the e-mail address (e.g. "John Doe" <johndoe@foo.bar>
).P.S.: If you also want to filter out events from a particular time range, you probably want a range like I did in my example above, e.g. and (Start Time greater than 8:50)
for 8:50-23:59; or and (Start Time greater than 8:50 and Start Time less than 20:00)
for 8:50-20:00. My example above has an "or" between the two conditions because I want to include midnight, which means I need 2 conditions for one time range, because 00:00 is less than 23:59, so it needs a separate condition.
I have got a small problem regarding sending emails form ZM via ssmtp, or msmtp so far. According to the documentation and pretty straightforward guide all emails are send by command via ssmtp, or msmtp passed in flying colours, as a root, www-data user and so on. Syslog and mail-log do indicate the right action. When it comes to receiving emails form ZM daemon - no luck. The only indication of some action taken by ZM daemon is below:
Syslog, and mail.log - no record at all. ZM daemon (Options -> Email) is configured as guided. I tried msmtp and ssmtp as well. Is a way around it?