From ad32fcdf29c1b009c4ad4188ab74abd6a3a1c329 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Mon, 3 Jul 2023 11:44:21 +0200 Subject: [PATCH] enh(plugin): update email notification mode (#4520) --- src/notification/email/mode/alert.pm | 84 +++++++++++++++------------- 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/src/notification/email/mode/alert.pm b/src/notification/email/mode/alert.pm index b57829a94..bc5e20447 100644 --- a/src/notification/email/mode/alert.pm +++ b/src/notification/email/mode/alert.pm @@ -263,6 +263,7 @@ sub host_message { padding: 0 !important; height: 100% !important; width: 100% !important; + background-color: #F2F2F2; } * { @@ -360,9 +361,6 @@ sub host_message { } - - -
@@ -581,7 +579,7 @@ sub service_message { my $img; if ($self->{http}->get_code() !~ /200/ || $content =~ /^OK/) { - $img = '

No graph

'; + $img = '

No graph

'; } else { $self->{payload_attachment}->{png} = $content; $img = '\n"; @@ -641,6 +639,7 @@ sub service_message { padding: 0 !important; height: 100% !important; width: 100% !important; + background-color: #F2F2F2; } * { @@ -738,9 +737,6 @@ sub service_message { } - - -
@@ -863,10 +859,6 @@ sub service_message {

Service Graph:

- - - - '. $img . ' @@ -937,22 +929,6 @@ sub run { my ($self, %options) = @_; $self->set_payload(); - my $attachement = ''; - if (defined($self->{payload_attachment}->{png}) && $self->{payload_attachment}->{png} ne '' && $self->{payload_attachment}->{png} ne 'Resource not found' ) { - my $img_cid = $self->{option_results}->{host_name} . '_' . $self->{option_results}->{service_description}; - $attachement = Email::MIME->create( - header_str => [ - 'Content-ID' => "<$img_cid>" - ], - attributes => { - content_type => 'image/png', - disposition => 'inline', - encoding => 'base64', - name => $self->{option_results}->{host_name} . ' - ' . $self->{option_results}->{service_description} . '.png' - }, - body => $self->{payload_attachment}->{png} - ); - } my $html_part = Email::MIME->create( attributes => { @@ -970,23 +946,53 @@ sub run { body => $self->{payload_attachment}->{alt_message} ); - my $email = Email::MIME->create( - header_str => [ - From => $self->{option_results}->{from_address}, - To => $self->{option_results}->{to_address}, - Subject => $self->{payload_attachment}->{subject} - ], - parts => [ - Email::MIME->create( + my $email; + + if (defined($self->{payload_attachment}->{png}) && $self->{payload_attachment}->{png} ne '' && $self->{payload_attachment}->{png} ne 'Resource not found' ) { + my $img_cid = $self->{option_results}->{host_name} . '_' . $self->{option_results}->{service_description}; + + $email = Email::MIME->create( + header_str => [ + From => $self->{option_results}->{from_address}, + To => $self->{option_results}->{to_address}, + Subject => $self->{payload_attachment}->{subject} + ], + parts => [ + Email::MIME->create( + attributes => { + content_type => 'multipart/alternative', + charset => 'UTF-8', + }, + parts => [$text_part, $html_part], + ), + Email::MIME->create( + header_str => [ + 'Content-ID' => "<$img_cid>" + ], + attributes => { + content_type => 'image/png', + disposition => 'inline', + encoding => 'base64', + name => $self->{option_results}->{host_name} . ' - ' . $self->{option_results}->{service_description} . '.png' + }, + body => $self->{payload_attachment}->{png} + ) + ] + ); + } else { + $email = Email::MIME->create( + header_str => [ + From => $self->{option_results}->{from_address}, + To => $self->{option_results}->{to_address}, + Subject => $self->{payload_attachment}->{subject} + ], attributes => { content_type => 'multipart/alternative', charset => 'UTF-8', }, parts => [$text_part, $html_part], - ), - $attachement - ] - ); + ); + } my $smtp = Email::Sender::Transport::SMTP->new({ host => $self->{option_results}->{smtp_address},