Patch 3/4 This patch adds an "emailalertfrom" option, allowing the From address of emails to be set.
This allows the From address used in emails to be set using either the local system mail facilities or SMTP. Since this may result in the source hostname no longer being available in the From, it also adds a line to the email body indicating the hostname of the system running ldirectord for identification purposes. This patch is useful for us as we are forced us as we are forced into using a corporate mail system with rather limited email filtering capabilities. Being able to set the From to a consistent value across servers helps considerably in being able to filter ldirectord emails appropriately. Thanks, Sean
# HG changeset patch # User Sean E. Millichamp <[email protected]> # Date 1242074594 14400 # Node ID c5f037878efa07946d2b8772db41901ea62c3442 # Parent 6081ec3a7a9c6556827b21ce5eb7bcfbec303d80 Add "emailalertfrom" option, allowing the From address of emails to be set. This allows the From address used in emails to be set. Since this may result in the source hostname no longer being available in the From, it also adds a line to the email body indicating the hostname of the system running ldirectord for identification purposes. Signed-Off-By: Sean E. Millichamp <[email protected]> diff -r 6081ec3a7a9c -r c5f037878efa ldirectord/ldirectord.in --- a/ldirectord/ldirectord.in Mon May 11 16:15:17 2009 -0400 +++ b/ldirectord/ldirectord.in Mon May 11 16:43:14 2009 -0400 @@ -233,6 +233,17 @@ If defined in a virtual server section then the global value is overridden. +B<emailalertfrom = >I<emailaddress> + +A valid email address to use as the from address of the email alerts. You +can use a plain email address or any RFC-compliant string for the From header +in the body of an email message (such as: "ldirectord Alerts" <[email protected]>) +Do not quote this string unless you want the quotes passed in as part of the +From header. + +Default: unset, take system generated default (probably r...@hostname) + + B<emailalertfreq => I<n> Delay in seconds between repeating email alerts while any given real server @@ -682,6 +693,7 @@ $EMAILALERT $EMAILALERTFREQ $EMAILALERTSTATUS + $EMAILALERTFROM $SMTP $CLEANSTOP @@ -1169,6 +1181,7 @@ $DEFAULT_NEGOTIATETIMEOUT = 30; $EMAILALERT = ""; $EMAILALERTFREQ = 0; + $EMAILALERTFROM = undef; $EMAILALERTSTATUS = $DAEMON_STATUS_ALL; $FAILURECOUNT = 1; $FALLBACK = undef; @@ -1581,6 +1594,10 @@ $EMAILALERTFREQ = $1; } elsif ($linedata =~ /^emailalertstatus\s*=\s*(.*)/) { $EMAILALERTSTATUS = &parse_emailalertstatus($line, $1); + } elsif ($linedata =~ /^emailalertfrom\s*=\s*(.*)/) { + $1 =~ /(.+)/ or &config_error($line, + "no email from address specified"); + $EMAILALERTFROM = $1; } elsif ($linedata =~ /^cleanstop\s*=\s*(.*)/) { ($1 eq "yes" || $1 eq "no") or &config_error($line, "cleanstop must be 'yes' or 'no'"); @@ -4256,10 +4273,15 @@ $smtp->mail("$env{use...@$hostname"); $smtp->to($to_addr); $smtp->data(); - $smtp->datasend("From: $env{use...@$hostname\n"); + if($EMAILALERTFROM) { + $smtp->datasend("From: $EMAILALERTFROM\n"); + } else { + $smtp->datasend("From: $env{use...@$hostname\n"); + } $smtp->datasend("To: $to_addr\n"); $smtp->datasend("Subject: $subject\n\n"); - $smtp->datasend("Log-Message: $subject\n" . + $smtp->datasend("ldirectord host: $hostname\n" . + "Log-Message: $subject\n" . "Daemon-Status: " . &daemon_status_str() . "\n"); $smtp->dataend(); @@ -4288,12 +4310,13 @@ use Mail::Send; - unless ($emailmsg = new Mail::Send Subject=>$subject, To=>$to_addr - and $emailfh = $emailmsg->open - and print $emailfh "Log-Message: $subject\n" . - "Daemon-Status: " . - &daemon_status_str() . "\n" - and $emailfh->close) { + $emailmsg = new Mail::Send Subject=>$subject, To=>$to_addr; + $emailmsg->set('From', $EMAILALERTFROM) if ($EMAILALERTFROM); + $emailfh = $emailmsg->open; + print $emailfh "ldirectord host: " . hostname() . "\n" . + "Log-Message: $subject\n" . + "Daemon-Status: " . &daemon_status_str() . "\n"; + unless ($emailfh->close) { &ld_log("failed to send email message\n"); $status = 1; }
_______________________________________________ Please read the documentation before posting - it's available at: http://www.linuxvirtualserver.org/ LinuxVirtualServer.org mailing list - [email protected] Send requests to [email protected] or go to http://lists.graemef.net/mailman/listinfo/lvs-users
