[pmg-devel] [PATCH pmg-api] add logging to disclaimer action

Stoiko Ivanov s.ivanov at proxmox.com
Thu Jun 18 13:33:17 CEST 2020


the disclaimer action currently does not log, if a disclaimer got added or not.
given that there are a few not directly obvious cases where a disclaimer does
not get added (e.g. it depends on the mail's encoding) - logging success or
failure should help in debugging

Tested by sending mails, where adding the disclaimer works, and where it fails.
verified that the log-tracker also adds those lines to its output.

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
reported via Enterprise support - and it took me quite a while until I found
the culprit (non-ascii characters in the disclaimer text).
 src/PMG/RuleDB/Disclaimer.pm | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/PMG/RuleDB/Disclaimer.pm b/src/PMG/RuleDB/Disclaimer.pm
index 3d2120b..104be72 100644
--- a/src/PMG/RuleDB/Disclaimer.pm
+++ b/src/PMG/RuleDB/Disclaimer.pm
@@ -10,6 +10,8 @@ use MIME::Body;
 use IO::File;
 use Encode qw(decode encode);
 
+use PVE::SafeSyslog;
+
 use PMG::Utils;
 use PMG::ModGroup;
 use PMG::RuleDB::Object;;
@@ -143,17 +145,17 @@ sub add_data {
 }
 
 sub sign {
-    my ($self, $entity, $html, $text) = @_;
+    my ($self, $entity, $html, $text, $logid, $rulename) = @_;
 
     my $found = 0;
 
     if ($entity->head->mime_type =~ m{multipart/alternative}) {
 	foreach my $p ($entity->parts) {
-	    $found = 1 if $self->sign ($p, $html, $text);
+	    $found = 1 if $self->sign ($p, $html, $text, $logid, $rulename);
 	}
     } elsif ($entity->head->mime_type =~ m{multipart/}) {
 	foreach my $p ($entity->parts) {
-	    if ($self->sign ($p, $html, $text)) {
+	    if ($self->sign ($p, $html, $text, $logid, $rulename)) {
 		$found = 1;
 		last;
 	    }
@@ -168,6 +170,11 @@ sub sign {
 	    };
 	    # simply ignore if we can't represent the disclainer
 	    # with that encoding
+	    if ($@) {
+		syslog('info', "%s: adding disclaimer failed (rule: %s)", $logid, $rulename);
+	    } else {
+		syslog('info', "%s: added disclaimer (rule: %s)", $logid, $rulename);
+	    }
 	    $found = 1;
 	} else {
 	    # do nothing - unknown format
@@ -181,6 +188,8 @@ sub execute {
     my ($self, $queue, $ruledb, $mod_group, $targets, 
 	$msginfo, $vars, $marks) = @_;
 
+    my $rulename = $vars->{RULE} // 'unknown';
+
     my $subgroups = $mod_group->subgroups($targets);
 
     foreach my $ta (@$subgroups) {
@@ -199,7 +208,7 @@ sub execute {
 	$parser->parse($tmp);
 	$parser->eof;
 	    
-	$self->sign($entity, "$html\n", "$text\n");
+	$self->sign($entity, "$html\n", "$text\n", $queue->{logid}, $rulename);
 
 	return;
     }
-- 
2.20.1




More information about the pmg-devel mailing list