[pmg-devel] [PATCH pmg-api 1/2] add rule's score to pmg-smtp-filter logline

Stoiko Ivanov s.ivanov at proxmox.com
Fri Feb 8 11:11:49 CET 2019


We already log which Spamassassin rules apply to a mail. Given that the scores
depend on configuration and setup (e.g. AWL) writing them in the log provides
a quick overview of Spamassassin performance, and spares admins and support from
having to gather the complete mail just for assessing Spamassessin.

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 PMG/RuleDB/Spam.pm | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/PMG/RuleDB/Spam.pm b/PMG/RuleDB/Spam.pm
index 8545b62..987b85d 100644
--- a/PMG/RuleDB/Spam.pm
+++ b/PMG/RuleDB/Spam.pm
@@ -329,8 +329,9 @@ sub analyze_spam {
 
     $maxspamsize = 200*1024 if !$maxspamsize;
 
-    my ($sa_score, $sa_max, $sa_scores, $sa_sumary, $list, $autolearn, $bayes);
+    my ($sa_score, $sa_max, $sa_scores, $sa_sumary, $list, $autolearn, $bayes, $loglist);
     $list = '';
+    $loglist = '';
     $bayes = 'undefined';
     $autolearn = 'no';
     $sa_score = 0;
@@ -354,6 +355,7 @@ sub analyze_spam {
 	my $rule = 'ClamAVHeuristics';
 	$sa_score += $score;
 	$list .= $list ? ",$rule" : $rule;
+	$loglist .= $loglist ? ",$rule($score)" : "$rule($score)";
 	push @$sa_scores, { score => $score, rule => $rule, desc => $descr };
     }
 
@@ -416,6 +418,7 @@ sub analyze_spam {
 	    foreach my $rule (split (/,/, $salist)) {
 		$list .= $list ? ",$rule" : $rule;
 		my $score = $status->{conf}->{scores}->{$rule};
+		$loglist .= $loglist ? ",$rule($score)" : "$rule($score)";
 		my $desc = $status->{conf}->get_description_for_rule($rule);
 		push @$sa_scores, { score => $score, rule => $rule, desc => $desc };
 	    }
@@ -450,7 +453,7 @@ sub analyze_spam {
 
     syslog ('info', "%s: SA score=%s/%s time=%0.3f bayes=%s autolearn=%s hits=%s", 
 	    $queue->{logid}, $sa_score, $sa_max, $queue->{ptime_spam}/1000.0, 
-	    $bayes, $autolearn, $list);
+	    $bayes, $autolearn, $loglist);
 
     $queue->{sa_score} = $sa_score;
     $queue->{sa_max} = $sa_max;
-- 
2.11.0




More information about the pmg-devel mailing list