MMM::Report::Mail - MMM::Report::Mail documentation


mmm documentation Contained in the mmm distribution.

Index


Code Index:

NAME

Top

MMM::Report::Console

SYNOPSIS

Top

    use MMM::Report::Console;
    my $mmm = MMM::Report::Console->new( configfile => $file );
    $mmm->run();

DESCRIPTION

Top

Produce textual report of MMM work done.

SEE ALSO

Top

MMM MMM::Report MMM::Html

AUTHOR

Top

Olivier Thauvin <nanardon@nanardon.zarb.org>

COPYRIGHT AND LICENSE

Top


mmm documentation Contained in the mmm distribution.
package MMM::Report::Mail;

use strict;
use base qw(MMM::Report);
use Mail::Send;

sub body_queue {
    my ($self, $queue, %info) = @_;
    my $fh = $self->_get_mail_send() or return;
    %info = $queue->state_info() if (!keys %info);
    print $fh sprintf("%s (%s)\n", $queue->name, $queue->dest);
    print $fh sprintf("  last %s end %s\n",
        $info{job}{success} ? 'mirror' : 'try',
        $info{job}{end} ? scalar (gmtime($info{job}{end})) : '(N/A)',
    );
    if (!$info{job}{success} && $info{success}{end}) {
        print $fh sprintf("  last mirror succefully done %s\n", scalar (gmtime($info{success}{end})));
    }
    print $fh "\n";
}

sub run {
    my ($self) = @_;
    MMM::Report::run($self);
    $self->_send_mail();
}

sub _get_mail_send {
    my ($self) = @_;
    $self->{mailsend} ||= Mail::Send->new(
        To => $self->configval( 'default', 'mailto' ) || $ENV{USER},
        Subject => 'MMM Report from ' . $self->hostname
    );
    $self->{fh} ||= $self->{mailsend}->open;
}

sub _send_mail {
    my ($self) = @_;
    my $fh = $self->{fh} or return;
    print $fh sprintf("\n-- \nMMM :: %s\n", $MMM::VERSION);
    $fh->close;
}

1;