Can't initiate email notifications

Forum for questions and support relating to the 1.30.x releases only.
SkippyDo
Posts: 98
Joined: Mon Nov 20, 2017 6:49 pm

Can't initiate email notifications

Post by SkippyDo » Mon Nov 20, 2017 8:56 pm

ZM: 1.30.4
OS: Debian 9
Network: WiFi interface directly on the WAN (IP dynamically assigned from ISP- DMZ of router/modem); using dns mapping via NoIP.com (all is good, though I sometimes have to update the IP when my ISP mucks with their gear); camera feeds are on a separate, local switch (all hardwired).

Background

I am new to ZM. I'd first played/tested it by doing a ground-up-build, getting everything working that I required to work in for my eventual "production" (home) environment. I then put together my own production hardware pieces and installed the 1.30.4 binary package from the repository, along with all the same bits that I was able to make work with my original testing environment.

I had been able to generate alarms which invoked ssmtp. At one point I'd managed to receive e-mail notifications in my hotmail account/inbox. Since installing all my cameras and then setting up filtering on a couple of them I am no longer able to get ZM to trigger email (Force Alarm won't work either).

Problem

ZM does not attempt to call email/ssmtp, nothing in ZM's log or in syslog. Forcing an alarm will create an event but will not attempt to send any notification.

I can call ssmtp from the system's command line, in which case I can see that the pieces are functioning. HOWEVER, I have another, separate issue in that the hotmail servers are rejecting my mail now: "Authorization failed (451 4.7.0 Temporary server error. Please try again later. PRX4...)" I have no idea how I'm going to rectify this (it had worked), but for now I need to focus on getting ZM to do what it's supposed to do. If someone can direct me toward a viable solution on this hotmail connection/authorization issue then that also would be welcomed.

ZM Conig->Email I have OPT_EMAIL, NEW_MAIL_MODULES and SSMTP_MAIL all checked. SSMTP_PATH has not been changed (as has worked in the past- executable has not moved).

I created a filter that would email on all events, with "Email details of all matches" checked. Set limit to "1" (first) result. This has had no impact. I created this after I'd already been having these issues.

I've waded through may postings and none seem to match up exactly or shed any light for my situation.

kennbr34
Posts: 36
Joined: Sat Jan 14, 2017 6:43 pm

Re: Can't initiate email notifications

Post by kennbr34 » Wed Nov 22, 2017 5:20 pm

You set your filter to run in the background right?

Open up the Log and force an alarm, then copy and past so we can see what ZM is doing.

If you set the "Filter Log - Copmonet" drop-down to zmfilter.py, you should see entries like this...

Code: Select all

Date/Time
Component	Server	PID	Level	Message	File	Line
2017-11-22 08:57:50.668550	zmfilter		27233	INF	Notification email sent	zmfilter.pl	
2017-11-22 08:57:45.493150	zmfilter		27233	INF	Attaching '/usr/share/zoneminder/www/events/4/17/11/22/08/56/19/Event-37172-r1-s1.avi	zmfilter.pl	
2017-11-22 08:57:45.425320	zmfilter		27233	INF	Attaching '/usr/share/zoneminder/www/events/4/17/11/22/08/56/19/00038-capture.jpg	zmfilter.pl	
2017-11-22 08:57:45.380980	zmfilter		27233	INF	Attaching '/usr/share/zoneminder/www/events/4/17/11/22/08/56/19/00026-capture.jpg	zmfilter.pl	
2017-11-22 08:57:45.335820	zmfilter		27233	INF	Sending notification email 'ZoneMinder: Alarm'	zmfilter.pl	
2017-11-22 08:57:44.870260	zmfilter		27233	INF	Creating notification email	zmfilter.pl	
2017-11-22 08:57:42.506220	zmfilter		27233	INF	Notification email sent	zmfilter.pl	

SkippyDo
Posts: 98
Joined: Mon Nov 20, 2017 6:49 pm

Re: Can't initiate email notifications

Post by SkippyDo » Wed Nov 22, 2017 7:57 pm

Thank you for the tip/advice to filter logs to zmfilter events! So... here's what I see (and just after forcing an alarm):

2017-11-22 11:08:14.201110 zmfilter 29852 INF Scanning for events zmfilter.pl
2017-11-21 12:35:14.424170 zmfilter 13712 INF Scanning for events zmfilter.pl
2017-11-20 11:45:32.040630 zmfilter 22307 INF Scanning for events zmfilter.pl
2017-11-19 20:31:48.089360 zmfilter 25259 INF Scanning for events zmfilter.pl
2017-11-17 10:00:00.072450 zmfilter 25234 ERR Can't send email: error closing /usr/lib/sendmail: (exit 256) zmfilter.pl
2017-11-17 09:59:58.394220 zmfilter 25234 INF Sending notification email 'ZoneMinder: Alarm - Camera1-1 (255 - 255 12)' zmfilter.pl
2017-11-17 09:59:58.392770 zmfilter 25234 INF Creating notification email zmfilter.pl
2017-11-17 09:59:58.358870 zmfilter 25234 INF Scanning for events using filter '_TempFilter1510941598' zmfilter.pl

As one can see, there were notification attempts on the 17th. And yesterday (21st) while trying to get a new filter to work (see next paragraph) I decided to delete that "_TempFilter1510941598" filter thinking that it somehow was some sort of artifact and was partly responsible for my problem. No affect.

Today I created this filter:

(cause matches "Motion" or cause matches "Forced Web") + Date/Time greater than or equal to "10 minutes ago"
"Email details of all matches" is selected

When I force an alarm the filter is matching the event, BUT, no hint in the logs of even trying to perform any notification (no attempts, so not even an "ERR" showing up!). Change of alarm state shows up in syslog, but nothing else (related to any attempts to perform notification function).

montagdude
Posts: 62
Joined: Fri Nov 10, 2017 6:05 pm

Re: Can't initiate email notifications

Post by montagdude » Wed Nov 22, 2017 8:08 pm

Not exactly a solution for your filter problem, but you could try this motion alert notification script I created. It doesn't depend on filters, so you can see if that works. Be sure to edit the inputs as described in the first post.

viewtopic.php?f=9&t=26758

Feel free to edit the script to add more logging output or send a single test email without checking for motion if you want.

Edit: I should mention, this script doesn't use ssmtp to send notifications, so I think you will need sendmail/postfix running for it to actually send emails.

SkippyDo
Posts: 98
Joined: Mon Nov 20, 2017 6:49 pm

Re: Can't initiate email notifications

Post by SkippyDo » Wed Nov 22, 2017 9:16 pm

montagdude, thanks for the pointer. I'll keep it in mind if I cannot resolve the standard stuff (which, since I'd had working, I figure SHOULD be resolvable).

I've turned on all sorts of logging and absolutely no call is even being attempted. Looking at zmfilter.pl I see the following code segment as being relative:

if ( $Config{ZM_OPT_EMAIL} && $filter->{AutoEmail} )
{
if ( !$event->{Emailed} )
{
$delete_ok = undef if ( !sendEmail( $filter, $event ) );
}
}

ZM_OPT_EMAIL is set, so that really only leaves AutoEmail as being the candidate for obstruction. Where is the "AutoEMail" coming from?

I'm not happy with my ssmtp settings (totally external to ZM), but, regardless, ZM should still be making an attempt to call ssmtp.

montagdude
Posts: 62
Joined: Fri Nov 10, 2017 6:05 pm

Re: Can't initiate email notifications

Post by montagdude » Thu Nov 23, 2017 12:12 am

I believe AutoEmail is the flag that gets set for an event matching your filter conditions when you have "Email details of all matches" checked. Just curious, have you tried it without ssmtp? I suppose another thing you could is to add more Info() calls in zmfilter.pl. That way you could see if the sendEmail function is actually being executed or not.

kennbr34
Posts: 36
Joined: Sat Jan 14, 2017 6:43 pm

Re: Can't initiate email notifications

Post by kennbr34 » Thu Nov 23, 2017 8:11 am

SkippyDo wrote:
Wed Nov 22, 2017 7:57 pm
Thank you for the tip/advice to filter logs to zmfilter events! So... here's what I see (and just after forcing an alarm):

2017-11-22 11:08:14.201110 zmfilter 29852 INF Scanning for events zmfilter.pl
2017-11-21 12:35:14.424170 zmfilter 13712 INF Scanning for events zmfilter.pl
2017-11-20 11:45:32.040630 zmfilter 22307 INF Scanning for events zmfilter.pl
2017-11-19 20:31:48.089360 zmfilter 25259 INF Scanning for events zmfilter.pl
2017-11-17 10:00:00.072450 zmfilter 25234 ERR Can't send email: error closing /usr/lib/sendmail: (exit 256) zmfilter.pl
2017-11-17 09:59:58.394220 zmfilter 25234 INF Sending notification email 'ZoneMinder: Alarm - Camera1-1 (255 - 255 12)' zmfilter.pl
2017-11-17 09:59:58.392770 zmfilter 25234 INF Creating notification email zmfilter.pl
2017-11-17 09:59:58.358870 zmfilter 25234 INF Scanning for events using filter '_TempFilter1510941598' zmfilter.pl

As one can see, there were notification attempts on the 17th. And yesterday (21st) while trying to get a new filter to work (see next paragraph) I decided to delete that "_TempFilter1510941598" filter thinking that it somehow was some sort of artifact and was partly responsible for my problem. No affect.

Today I created this filter:

(cause matches "Motion" or cause matches "Forced Web") + Date/Time greater than or equal to "10 minutes ago"
"Email details of all matches" is selected

When I force an alarm the filter is matching the event, BUT, no hint in the logs of even trying to perform any notification (no attempts, so not even an "ERR" showing up!). Change of alarm state shows up in syslog, but nothing else (related to any attempts to perform notification function).
Looks like it could be a permissions issue.

viewtopic.php?t=25346

Which is funky because exist 256 MIGHT not give you a clue that it's a permissions issue since sysexit.h exit codes only go up to 255 but I found this...

https://stackoverflow.com/questions/373 ... -that-mean

According to this, perl system errors are multiples of 256, so an exit code of 256 would equal 1, or "Operation not permitted."

charles_fr
Posts: 4
Joined: Sun Nov 19, 2017 7:52 pm

Re: Can't initiate email notifications

Post by charles_fr » Thu Nov 23, 2017 12:44 pm

sendmail is not present on the system or unexecutable by apache user (if apache2 runs with apache user)

SkippyDo
Posts: 98
Joined: Mon Nov 20, 2017 6:49 pm

Re: Can't initiate email notifications

Post by SkippyDo » Thu Nov 23, 2017 3:32 pm

I probably should have excluded the error. That output contained all records returned from filtering for fmfilter from the logs; I didn't omit it because it shows that mail was being called at one point in time (17th). The file permissions on the config files are fine: 0644; ssmtp executable is set to owner and group root with permissions set to 0755.

Currently ZM makes no attempt to invoke the notification function. I get NO errors. And as mentioned, I do have an authentication issue of some sort with the external mail server (hotmail), but that was an issue even before this ZM issue.

It's like the database has a corrupted value.

SkippyDo
Posts: 98
Joined: Mon Nov 20, 2017 6:49 pm

Re: Can't initiate email notifications

Post by SkippyDo » Thu Nov 23, 2017 5:06 pm

One interesting thing I see in the log output is that when notifications last worked the filter that was active at that time -"'_TempFilter1510941598"- is shown to be called, whereas now when an event is triggered there is no mention of the name of the filter that I currently am using (after deleting "_TempFilter1510941598"): I named it "DetectionEmail" That is, it appears that the filter isn't even being called. I suspect that this is the crux of my problem.

SkippyDo
Posts: 98
Joined: Mon Nov 20, 2017 6:49 pm

Re: Can't initiate email notifications

Post by SkippyDo » Thu Nov 23, 2017 6:11 pm

More investigation... The ONLY way that I can see for the filter to not be called is if the event's Emailed bit is being set to True/1 by default. Again, looking at the code segment that I posted above:

if ( $Config{ZM_OPT_EMAIL} && $filter->{AutoEmail} )

Both of those should readily evaluate to true/1, as the configuration of OPT_EMAIL is enabled and the filter I have created has its "Email details of all matches" is also enabled. So... the following code is then executed:

if ( !$event->{Emailed} )

^^^ This is the last check before the instructions contained in the filter are actually called/executed. It is here that if the value of Emailed is already set to True/i that the call "sendEmail( $filter, $event )" is NOT performed.

What's the best way of testing this hypothesis? Alter the database record (how?) or temporarily change that code segment to something like "if (1)"?

montagdude
Posts: 62
Joined: Fri Nov 10, 2017 6:05 pm

Re: Can't initiate email notifications

Post by montagdude » Thu Nov 23, 2017 6:13 pm

This may have been asked before, but do you have your filter set to run in the background? What if you create a new filter that is not set to run in the background, set it to email you, and then hit Execute? Make sure it is something that will return a match. You can use Submit to check.

SkippyDo
Posts: 98
Joined: Mon Nov 20, 2017 6:49 pm

Re: Can't initiate email notifications

Post by SkippyDo » Thu Nov 23, 2017 6:53 pm

I have two filters: 1) My DetectionEmail; and, 2) The standard PurgeWhenFull* filter. My DetectionEmail filter is not set to run in the background (PurgeWhenFull" IS set to run in the background).

SkippyDo
Posts: 98
Joined: Mon Nov 20, 2017 6:49 pm

Re: Can't initiate email notifications

Post by SkippyDo » Thu Nov 23, 2017 7:27 pm

Under the Troubleshooting tips (http://zoneminder.readthedocs.io/en/sta ... vents.html):

In the event that you see your new filter is working great when you try it out from the Web Console (using the Submit or Execute button) but does not seem to work when its running in background mode, you might have just chanced upon a compatibility issue between how Perl and PHP translate free form text to dates/times. When you test it via the “Submit” or “Execute” button, you are invoking a PHP function for time conversion. When the filter runs in background mode, zmfilter.pl calls a perl equivalent function. In some cases, depending on the version of Perl and PHP you have, the results may vary. If you face this situation, the best thing to do is to run sudo zmfilter.pl -f <yourfiltername> from a terminal to make sure the filter actually works in Perl as well.

If I invoke the filter from the commandline I now get "Scanning for events using filter 'DetectionEmail'" showing up in the zmfilter log. I had no matching events when I ran that, so no candidates for notifications (and, at this time that is not a concern). It seems, then, that there MAY be an issue with Perl and PHP vis a vis handling date/time. To test I've disabled my DetectionEmail filter and created a temporary filter that is not doing any date/time checking. However, is there a way to probe the database records to see events' state of "Emailed"?

da7
Posts: 4
Joined: Sun Nov 26, 2017 3:07 pm

Re: Can't initiate email notifications

Post by da7 » Sun Nov 26, 2017 3:26 pm

I can send emails from command line using ssmtp and Zoneminder is configured with this wiki.

Zoneminder does not even try to send email according to logs.

Code: Select all

$ uname -rv
4.4.0-101-generic #124-Ubuntu SMP Fri Nov 10 18:29:59 UTC 2017
Is sending email broken or am I missing something?

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests