The problem seems to appear when sending an alert email, at least for
me. By inserting a slew of syslog debug messages I found out that the
"smtpsend" function turns out to be the last one called from NfAlert.pm
before the PANIC. 

I am not sure what exactly goes wrong -- it seems to be some XS code
that isn't reentrant, though I don't see where that is -- but replacing
the Mail::* modules with Email::*, which locally uses "sendmail" by
default, seems to do the trick. A patch for this against nfsen-1.3.8 is
provided below.

-- 
Peter Rathlev

--- nfsen-1.3.8/libexec/NfAlert.pm      2014-06-23 21:27:50.000000000 +0200
+++ nfsen-1.3.8-rmnet-20190114/libexec/NfAlert.pm       2019-01-14 
15:21:02.475224196 +0100
@@ -41,8 +41,9 @@
 use Storable qw(lock_store lock_retrieve);
 use POSIX ":sys_wait_h";
 use POSIX 'strftime';
-use Mail::Header;
-use Mail::Internet;
+use Email::Sender::Simple qw( sendmail );
+use Email::Simple;
+use Email::Simple::Creator;
 
 use NfSen;
 use NfSenRRD;
@@ -842,53 +843,31 @@
        if ( ($$alertref{'action_type'} & 1) > 0 ) {
                syslog('debug', "alert '$alert' Send email to: 
$$alertref{'action_email'}");
 
-               my @header = (  
-                       "From: $NfConf::MAIL_FROM",
-                       "To: $$alertref{'action_email'}",
-                       "Subject: $$alertref{'action_subject'}" 
-               );
-
-               my $mail_header = new Mail::Header( \@header ) ;
-
                my $mail_body_string = $NfConf::MAIL_BODY;
                # substitute all vars
-               my %replace = ( 
-                       'alert'         =>      $alert, 
-                       'timeslot'      =>      $timeslot,
+               my %replace = (
+                       'alert'    => $alert,
+                       'timeslot' => $timeslot,
                );
                foreach my $key ( keys %replace ) {
                        $mail_body_string =~ s/\@$key\@/$replace{$key}/g;
                }
 
-               my @mail_body = split /\n/, $mail_body_string;
-
-               my $mail = new Mail::Internet( 
-                       Header => $mail_header, 
-                       Body   => \@mail_body,
-               );
-
-               my @sent_to = $mail->smtpsend( 
-                       Host     => $NfConf::SMTP_SERVER , 
-                       Hello    => $NfConf::SMTP_SERVER, 
-                       MailFrom => $NfConf::MAIL_FROM 
+               my $mail = Email::Simple->create(
+                       'header' => [
+                               "From"    => $NfConf::MAIL_FROM,
+                               "To"      => $$alertref{'action_email'},
+                               "Subject" => $$alertref{'action_subject'},
+                       ],
+                       'body' => $mail_body_string,
                );
 
-               # Do we have failed receipients?
-               my %_tmp;
-               my @_recv = split /\s*,\s*/, $$alertref{'action_email'};
-               @_tmp{@_recv} = 1;
-               delete @_tmp{@sent_to};
-               my @Failed = keys %_tmp;
-
-               foreach my $rcpt ( @sent_to ) {
-                       syslog('info', "alert '$alert' : Successful sent mail 
to: '$rcpt'");
-               }
-               if ( scalar @Failed > 0 ) {
-                       foreach my $rcpt ( @Failed ) {
-                               syslog('err', "alert '$alert' : Failed to send 
alert email to: $rcpt");
-                       }
-               } 
-
+               eval { sendmail($mail); };
+               if ($@) {
+                       syslog('err', "alert '$alert' : Failed to send alert 
email: $@");
+               } else {
+                       syslog('info', "alert '$alert' : Successfully sent 
alert mail");
+               }
        }
 
        # execute system command




_______________________________________________
Nfsen-discuss mailing list
Nfsen-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfsen-discuss

Reply via email to