# HG changeset patch # User Sean E. Millichamp # 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 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. +BI + +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" ) +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 root@hostname) + + B I 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{USER}\@$hostname"); $smtp->to($to_addr); $smtp->data(); - $smtp->datasend("From: $ENV{USER}\@$hostname\n"); + if($EMAILALERTFROM) { + $smtp->datasend("From: $EMAILALERTFROM\n"); + } else { + $smtp->datasend("From: $ENV{USER}\@$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; }