lib/App/MadEye/Plugin/Notify/Email.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran n/a Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 55 CC 1 SCAR 6.9
CC
1
Cov
0%
notify
2.0
_format
2.0
BEGIN
2.0
CRAP 2.0
1 package App::MadEye::Plugin::Notify::Email;
2 use strict;
3 use warnings;
4 use base qw/App::MadEye::Plugin::Base/;
5 use Params::Validate;
6 use MIME::Lite;
7 use DateTime;
8  
9 sub notify : Hook {
10 my ($self, $context, $args) = @_;
11  
12 my $conf = $self->{config}->{config};
13 my $subject = $conf->{subject} || '%s alert !!!';
14 my $from_addr = $conf->{from_addr} or die "missing from_addr";
15 my $to_addr = $conf->{to_addr} or die "missing to_addr";
16  
17 while (my ($plugin, $results) = each %$args) {
18 $plugin =~ s/.+::Agent:://;
19  
20 my $mail = MIME::Lite->new(
21 'To' => $to_addr,
22 'From' => $from_addr,
23 'Subject' => sprintf($subject, $plugin),
24 'Data' => $self->_format( $plugin, $results ),
25 );
26 # warn $mail->as_string;
27 $mail->send;
28 }
29 }
30  
31 sub _format {
32 my ($self, $plugin, $results) = @_;
33  
34 my $res = $plugin . "\n\n";
35 for my $result (@$results) {
36 $res .= "- $result->{target}\n";
37 $res .= "$result->{message}\n";
38 $res .= "\n\n";
39 }
40 $res;
41 }
42  
43 1;
44 __END__