]> git.proxmox.com Git - pmg-api.git/commitdiff
bin/pmgpolicy - count PREGREET rejects (postscreen)
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 7 Dec 2017 06:43:08 +0000 (07:43 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 7 Dec 2017 06:43:08 +0000 (07:43 +0100)
PMG/Utils.pm
bin/pmgpolicy

index 271f8814e0f4508f0264b23673fd4288845a73b9..1f773190ff58c4923fdff5b0a1b6f01b4d3bc860 100644 (file)
@@ -1091,9 +1091,13 @@ sub scan_journal_for_rbl_rejects {
     # example postscreen log entry for RBL rejects
     # Aug 29 08:00:36 proxmox postfix/postscreen[11266]: NOQUEUE: reject: RCPT from [x.x.x.x]:1234: 550 5.7.1 Service unavailable; client [x.x.x.x] blocked using zen.spamhaus.org; from=<xxxx>, to=<yyyy>, proto=ESMTP, helo=<zzz>
 
+    # example for PREGREET reject
+    # Dec  7 06:57:11 proxmox postfix/postscreen[32084]: PREGREET 14 after 0.23 from [x.x.x.x]:63492: EHLO yyyyy\r\n
+
     my $identifier = 'postfix/postscreen';
 
-    my $count = 0;
+    my $rbl_count = 0;
+    my $pregreet_count = 0;
 
     my $parser = sub {
        my $line = shift;
@@ -1103,8 +1107,11 @@ sub scan_journal_for_rbl_rejects {
            return;
        }
 
-       return if $line !~ m/\s$identifier\[\d+\]:\sNOQUEUE:\sreject:.*550 5.7.1 Service unavailable;/;
-       $count++;
+       if ($line =~ m/\s$identifier\[\d+\]:\sNOQUEUE:\sreject:.*550 5.7.1 Service unavailable;/) {
+           $rbl_count++;
+       } elsif ($line =~ m/\s$identifier\[\d+\]:\sPREGREET\s\d+\safter\s/) {
+           $pregreet_count++;
+       }
     };
 
     # limit to last 5000 lines to avoid long delays
@@ -1119,7 +1126,7 @@ sub scan_journal_for_rbl_rejects {
 
     PVE::Tools::run_command($cmd, outfunc => $parser);
 
-    return $count;
+    return ($rbl_count, $pregreet_count);
 }
 
 my $hwaddress;
index c017e6e23c57993855d4670eeb860f083ce02339..69f29fd2cd6f8cb7212b3e57afae05cbd2038a7b 100755 (executable)
@@ -103,20 +103,21 @@ $SIG{'__WARN__'} = sub {
 sub update_rbl_stats {
     my ($dbh, $lcid) = @_;
 
-    my $rblcount = PMG::Utils::scan_journal_for_rbl_rejects();
-    return if !$rblcount;
+    my ($rbl_count, $pregreet_count) = PMG::Utils::scan_journal_for_rbl_rejects();
+    return if !$rbl_count && !$pregreet_count;
 
     my $timezone = tz_local_offset();;
     my $hour = int((time() + $timezone)/3600) * 3600;
 
     my $sth = $dbh->prepare(
-       'INSERT INTO LocalStat (Time, RBLCount, CID, MTime) ' .
-       'VALUES (?, ?, ?, EXTRACT(EPOCH FROM now())) ' .
+       'INSERT INTO LocalStat (Time, RBLCount, PregreetCount, CID, MTime) ' .
+       'VALUES (?, ?, ?, ?, EXTRACT(EPOCH FROM now())) ' .
        'ON CONFLICT (Time, CID) DO UPDATE SET ' .
        'RBLCount = LocalStat.RBLCount + excluded.RBLCount, ' .
+       'PregreetCount = LocalStat.PregreetCount + excluded.PregreetCount, ' .
        'MTime = excluded.MTime');
 
-    $sth->execute($hour, $rblcount, $lcid);
+    $sth->execute($hour, $rbl_count, $pregreet_count, $lcid);
     $sth->finish();
 };