| Log-Agent documentation | Contained in the Log-Agent distribution. |
Log::Agent::Driver::Mail - email driver for Log::Agent
use Log::Agent;
require Log::Agent::Driver::Mail;
my $driver = Log::Agent::Driver::Mail->make(
-to => 'oncall@example.org',
-cc => [ qw( noc@example.org admin@example,net ) ],
-subject => "ALERT! ALERT!",
-mailer => [ 'smtp', Server => 'mail.example.net' ]
);
logconfig(-driver => $driver);
This driver maps the logxxx() calls to email messages. Each call generates a separate email message. The Mail::Mailer module is required.
The OPTIONS argument is a hash with the following keys:
An optional prefix for the message body.
The destination addresses, may be a scalar containing a valid email address or a reference to an array of addresses.
The reply-to addresses, may be a scalar containing a valid email address or a reference to an array of addresses.
The source address, must be a scalar containing a valid email address.
The subject line of the email message.
The carbon copy addresses, may be a scalar containing a valid email address or a reference to an array of addresses.
The blind carbon copy addresses, may be a scalar containing a valid email address or a reference to an array of addresses.
The priority level for the email message. This is NOT related to the logging priority.
A reference to an array containing the optional arguments to Mail::Mailer->new(). Generally, this can be omitted.
Thanks to Shirley Wang for the idea for this module.
Mark Rogaski <mrogaski@pobox.com>
Copyright (C) 2002 Mark Rogaski; all rights reserved.
See Log::Agent(3) or the README file included with the distribution for license information.
Mail::Mailer, Log::Agent::Driver(3), Log::Agent(3).
| Log-Agent documentation | Contained in the Log-Agent distribution. |
########################################################################### # $Id: Mail.pm,v 1.2 2002/05/12 09:04:09 wendigo Exp $ ########################################################################### # # Log::Agent::Driver::Mail # # RCS Revision: $Revision: 1.2 $ # Date: $Date: 2002/05/12 09:04:09 $ # # Copyright (C) 2002 Mark Rogaski, mrogaski@cpan.org; all rights reserved. # # See the README file included with the # distribution for license information. # # $Log: Mail.pm,v $ # Revision 1.2 2002/05/12 09:04:09 wendigo # added optional arguments to Mail::Mailer->new() # changed format of make() arguments # # Revision 1.1 2002/04/25 05:38:47 wendigo # Initial revision # # ########################################################################### package Log::Agent::Driver::Mail; use strict; use Mail::Mailer; require Log::Agent::Driver; use vars qw(@ISA); @ISA = qw(Log::Agent::Driver); ########################################################################### # # Public Methods # ########################################################################### # # make -- driver constructor # sub make { my $self = bless { prefix => '', to => (getpwuid $<)[0], cc => '', bcc => '', subject => '', from => '', priority => '', reply_to => '', mailer => [] }, shift; my (%args) = @_; foreach my $key (keys %args) { if ($key =~ /^-(to|cc|bcc|prefix|subject|from|priority|reply_to| mailer)$/x) { $self->{$1} = $args{$key}; } else { use Carp; croak "invalid argument: $key"; } } $self->_init($self->{prefix}, 0); return $self; } # # chan_eq -- not much of anything at the moment # sub chan_eq { my($self, $chan0, $chan1) = @_; return $chan0 eq $chan1; } # # write -- send a message to the channel # sub write { my($self, $chan, $prio, $mesg) = @_; my(%headers); foreach my $hdr (qw( to cc bcc subject from priority reply_to )) { my $fhdr = ucfirst($hdr); $fhdr =~ s/_/-/g; $headers{$fhdr} = $self->{$hdr} unless $self->{$hdr} eq ''; } my $mailer = Mail::Mailer->new(@{$self->{mailer}}); $mailer->open(\%headers); print $mailer $mesg, "\n"; $mailer->close; } # # prefix_msg -- add prefix # sub prefix_msg { my($self, $str) = @_; return ($self->{prefix} ? $self->{prefix} . ' ' : '') . $str; } __END__