]> git.proxmox.com Git - pmg-api.git/commitdiff
Add rule name to RuleAction logging
authorStoiko Ivanov <s.ivanov@proxmox.com>
Thu, 18 Apr 2019 15:04:32 +0000 (17:04 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 24 Apr 2019 12:12:36 +0000 (14:12 +0200)
With complicated rulesets knowing which rule is responsible for the action
applied to a mail can become complex. Since relevant actions [0] do log a line
when being executed adding the rule's name to this logline should simplify
understanding and debugging complex rules.

Additionally the mix of string interpolation and formatstrings in Quarantine.pm
got unified to formatstrings.

[0] Attach is covered via Notify, Disclaimer and ModField could result in too
verbose logging (i.e. users adding many headers to a mail) without any gain

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
PMG/RuleDB/Accept.pm
PMG/RuleDB/BCC.pm
PMG/RuleDB/Block.pm
PMG/RuleDB/Notify.pm
PMG/RuleDB/Quarantine.pm
PMG/RuleDB/Remove.pm
PMG/RuleDB/ReportSpam.pm

index 295692799b1e31f8c736f59febc2d15f7b68bea0..1387e2428453650d4a1d505ce77581ac3ae3d7a6 100644 (file)
@@ -91,6 +91,8 @@ sub execute {
 
     my $subgroups = $mod_group->subgroups($targets, 1);
 
+    my $rulename = $vars->{RULE};
+
     foreach my $ta (@$subgroups) {
        my ($tg, $entity) = (@$ta[0], @$ta[1]);
 
@@ -111,12 +113,12 @@ sub execute {
                $msginfo->{xforward}, $msginfo->{fqdn});
            if ($qid) {
                foreach (@$tg) {
-                   syslog('info', "%s: accept mail to <%s> (%s)", $queue->{logid}, encode('UTF-8', $_), $qid);
+                   syslog('info', "%s: accept mail to <%s> (rule: %s, %s)", $queue->{logid}, encode('UTF-8', $_), $rulename, $qid);
                }
                $queue->set_status ($tg, 'delivered', $qid);
            } else {
                foreach (@$tg) {
-                   syslog('err', "%s: reinject mail to <%s> failed", $queue->{logid}, encode('UTF-8', $_));
+                   syslog('err', "%s: reinject mail to <%s> (rule: %s) failed", $queue->{logid}, encode('UTF-8', $_), $rulename);
                }
                if ($code) {
                    my $resp = substr($code, 0, 1);
index 1ee55610be588f9fac55677ad95563410d0560f0..cbe28105b030ace0cb9e016039129200a674b292 100644 (file)
@@ -114,12 +114,14 @@ sub execute {
 
     my $subgroups = $mod_group->subgroups($targets, 1);
 
+    my $rulename = $vars->{RULE};
+
     my $bcc_to = PMG::Utils::subst_values($self->{target}, $vars);
 
     if ($bcc_to =~ m/^\s*$/) {
        # this happens if a notification is triggered by bounce mails
        # which notifies the sender <> - we just log and then ignore it
-       syslog('info', "%s: bcc to <> (ignored)", $queue->{logid});
+       syslog('info', "%s: bcc to <> (rule: %s, ignored)", $queue->{logid}, $rulename);
        return;
     }
 
@@ -148,9 +150,9 @@ sub execute {
                $msginfo->{xforward}, $msginfo->{fqdn}, 1);
            foreach (@bcc_targets) {
                if ($qid) {
-                   syslog('info', "%s: bcc to <%s> (%s)", $queue->{logid}, $_, $qid);
+                   syslog('info', "%s: bcc to <%s> (rule: %s, %s)", $queue->{logid}, $_, $rulename, $qid);
                } else {
-                   syslog('err', "%s: bcc to <%s> failed", $queue->{logid}, $_);
+                   syslog('err', "%s: bcc to <%s> (rule: %s) failed", $queue->{logid}, $_, $rulename);
                }
            }
        }
index 81f00b9f7019df416eb8c2cdf10ad696d12127ba..c7c640efe3253f3ee5e6e5c33f8fc21371d60583 100644 (file)
@@ -89,6 +89,8 @@ sub execute {
     my ($self, $queue, $ruledb, $mod_group, $targets, 
        $msginfo, $vars, $marks) = @_;
 
+    my $rulename = $vars->{RULE};
+
     if ($msginfo->{testmode}) {
        my $fh = $msginfo->{test_fh};
        print $fh "block from: $msginfo->{sender}\n";
@@ -96,7 +98,7 @@ sub execute {
     }
 
     foreach my $to (@$targets) {
-       syslog('info', "%s: block mail to <%s>", $queue->{logid}, encode('UTF-8', $to));
+       syslog('info', "%s: block mail to <%s> (rule: %s)", $queue->{logid}, encode('UTF-8', $to), $rulename);
     }
 
     $queue->set_status($targets, 'blocked');
index 22b8bd268d956223c2c946afb0fca918a6ddaf56..20d87afae2607f886b1249717a834c451c71a87f 100644 (file)
@@ -207,6 +207,8 @@ sub execute {
 
     my $from = 'postmaster';
 
+    my $rulename = $vars->{RULE};
+
     my $body = PMG::Utils::subst_values($self->{body}, $vars);
     my $subject = PMG::Utils::subst_values($self->{subject}, $vars);
     my $to = PMG::Utils::subst_values($self->{to}, $vars);
@@ -214,7 +216,7 @@ sub execute {
     if ($to =~ m/^\s*$/) {
        # this happens if a notification is triggered by bounce mails
        # which notifies the sender <> - we just log and then ignore it
-       syslog('info', "%s: notify <> (ignored)", $queue->{logid});
+       syslog('info', "%s: notify <> (rule: %s, ignored)", $queue->{logid}, $rulename);
        return;
     }
 
@@ -255,9 +257,9 @@ sub execute {
            $top, $from, \@targets, undef, $msginfo->{fqdn});
        foreach (@targets) {
            if ($qid) {
-               syslog('info', "%s: notify <%s> (%s)", $queue->{logid}, $_, $qid);
+               syslog('info', "%s: notify <%s> (rule: %s, %s)", $queue->{logid}, $_, $rulename, $qid);
            } else {
-               syslog ('err', "%s: notify <%s> failed", $queue->{logid}, $_);
+               syslog ('err', "%s: notify <%s> (rule: %s) failed", $queue->{logid}, $_, $rulename);
            }
        }
     }
index eb423a750e2f77bf6a3c082f86a330f49111d96a..487fa6ef71b7f7c39a25a05f8df21d1934d2dc0f 100644 (file)
@@ -89,6 +89,8 @@ sub execute {
     
     my $subgroups = $mod_group->subgroups($targets, 1);
 
+    my $rulename = $vars->{RULE};
+
     foreach my $ta (@$subgroups) {
        my ($tg, $entity) = (@$ta[0], @$ta[1]);
 
@@ -98,7 +100,7 @@ sub execute {
            if (my $qid = $queue->quarantine_mail($ruledb, 'V', $entity, $tg, $msginfo, $vars, $ldap)) {
 
                foreach (@$tg) {
-                   syslog ('info', "$queue->{logid}: moved mail for <%s> to virus quarantine - $qid", $_);
+                   syslog ('info', "$queue->{logid}: moved mail for <%s> to virus quarantine (rule: %s, %s)", $_, $rulename, $qid);
                }
 
                $queue->set_status ($tg, 'delivered');
@@ -108,7 +110,7 @@ sub execute {
            if (my $qid = $queue->quarantine_mail($ruledb, 'S', $entity, $tg, $msginfo, $vars, $ldap)) {
 
                foreach (@$tg) {
-                   syslog ('info', "$queue->{logid}: moved mail for <%s> to spam quarantine - $qid", $_);
+                   syslog ('info', "$queue->{logid}: moved mail for <%s> to spam quarantine (rule: %s, %s)", $_, $rulename, $qid);
                }
 
                $queue->set_status($tg, 'delivered');
index 1bb7a859c339743fde5c3f1cb6dd8b4a62ae0dce..551fb97227ccf4d50ace24feb6505508bfef6a62 100644 (file)
@@ -111,7 +111,7 @@ sub save {
 }
 
 sub delete_marked_parts {
-    my ($self, $queue, $entity, $html, $rtype, $marks) = @_;
+    my ($self, $queue, $entity, $html, $rtype, $marks, $rulename) = @_;
 
     my $nparts = [];
 
@@ -155,8 +155,8 @@ sub delete_marked_parts {
 
            push (@$nparts, $ent);
 
-           syslog ('info', "%s: removed attachment $id ('%s')",
-                   $queue->{logid}, $on);
+           syslog ('info', "%s: removed attachment $id ('%s', rule: %s)",
+                   $queue->{logid}, $on, $rulename);
 
        } else {
            $self->delete_marked_parts($queue, $part, $html, $rtype, $marks);
@@ -171,6 +171,8 @@ sub execute {
     my ($self, $queue, $ruledb, $mod_group, $targets,
        $msginfo, $vars, $marks) = @_;
 
+    my $rulename = $vars->{RULE};
+
     if (!$self->{all} && ($#$marks == -1)) {
        # no marks
        return;
@@ -200,7 +202,7 @@ sub execute {
            $entity->head->delete('x-proxmox-tmp-aid');
        }
 
-       $self->delete_marked_parts($queue, $entity, $html, $rtype, $marks);
+       $self->delete_marked_parts($queue, $entity, $html, $rtype, $marks, $rulename);
 
        if ($msginfo->{testmode}) {
            $entity->head->mime_attr('Content-type.boundary' => '------=_TEST123456') if $entity->is_multipart;
index 105a67f8265288ce0ab95b82e115bb084277c825..a3e06eea5746dadafadba21f663bb4096034597c 100644 (file)
@@ -85,6 +85,8 @@ sub execute {
     my ($self, $queue, $ruledb, $mod_group, $targets, 
        $msginfo, $vars, $marks) = @_;
 
+    my $rulename = $vars->{RULE};
+
     my $subgroups = $mod_group->subgroups($targets);
 
     foreach my $ta (@$subgroups) {
@@ -105,6 +107,7 @@ sub execute {
            
            $mail->finish();    
        }
+       syslog('info', "%s: report mail as spam (rule: %s)", $queue->{logid}, $rulename);
        $queue->set_status ($tg, 'delivered');
     }
 }