root/lang/perl/App-MadEye/trunk/lib/App/MadEye/Plugin/Notify/Email.pm @ 7565

Revision 7565, 1.0 kB (checked in by tokuhirom, 5 years ago)

added Notify::Email

Line 
1package App::MadEye::Plugin::Notify::Email;
2use strict;
3use warnings;
4use base qw/Class::Component::Plugin/;
5use Params::Validate;
6use MIME::Lite;
7use DateTime;
8
9sub notify : Hook('notify') {
10    my ($self, $context, $args) = @_;
11
12    my $conf = $self->{config}->{config};
13    my $from_addr = $conf->{from_addr} or die "missing from_addr";
14    my $to_addr   = $conf->{to_addr} or die "missing to_addr";
15
16    while (my ($plugin, $results) = each %$args) {
17        $plugin =~ s/.+::Agent:://;
18
19        my $mail = MIME::Lite->new(
20            'To'        => $from_addr,
21            'From'      => $to_addr,
22            'Subject'   => "$plugin alert !!!",
23            'Data'      => $self->_format( $plugin, $results ),
24        );
25        # warn $mail->as_string;
26        $mail->send;
27    }
28}
29
30sub _format {
31    my ($self, $plugin, $results) = @_;
32
33    my $res = $plugin . "\n\n";
34    for my $result (@$results) {
35        $res .= "- $result->{target}\n";
36        $res .= "$result->{message}\n";
37        $res .= "\n\n";
38    }
39    $res;
40}
41
421;
Note: See TracBrowser for help on using the browser.