[syslog-ng] [PATCH]: Experimental SMTP destination
Balazs Scheidler
bazsi at balabit.hu
Sun Feb 20 19:29:38 CET 2011
Hi,
Thanks for your contribution, some comments below.
On Sat, 2011-02-12 at 17:12 +0100, Gergely Nagy wrote:
> Hi!
>
> I've had a little free time, and started toying with the idea of
> implementing an SMTP destination for syslog-ng. So far, it's progressing
> nicely, but there are a few shortcomings, as I will explain later.
>
> For anyone interested, it can be found on the 'work/modules/afsmtp'
> branch of my syslog-ng-3.3 tree:
>
> git://git.balabit.hu/algernon/syslog-ng-3.3.git
>
> Or, one can browse the branch on the web:
>
> http://git.balabit.hu/?p=algernon/syslog-ng-3.3.git;a=shortlog;h=work/modules/afsmtp
>
> One will need the libesmtp library installed for the module to work. It
> should be available in most distributions, but if one doesn't have it,
> it can be downloaded from http://www.stafford.uklinux.net/libesmtp/
> (although, as of this writing, the site seems to be down).
>
> The usage is something like this:
>
> destination d_smtp {
> smtp(
> host("localhost")
> port(25)
> mail_from("syslog-ng alert service <noreply at example.com>")
> rcpt_to("Admin #1 <admin at example.com>")
> rcpt_to("Admin #2 <admin2 at example.com>")
> subject("[ALERT] $LEVEL condition in $PROGRAM!")
> header("X-Program" "$PROGRAM")
> header("X-Facility" "$FACILITY")
> body("Hi!\nThe syslog-ng alerting service thinks you might be interested in the following message:\n $MSG\n-- \nsyslog-ng\n")
> );
> };
I'd love to get away a little bit from SMTP logic, and use option names
that reflect more closely what the user sees in a MUA.
We might give a chance to specify all the rest of the details, but they
should be the exception and not the rule.
smtp(
host("localhost")
port(25)
from("syslog-ng alert service <noreply at example.com>")
to("Admin #1 <admin at example.com>", "Admin #2 <admin2 at example.com>")
cc("Admin BOSS <admin.boss at example.com>")
bcc("Blind CC <blindcc at example.com>")
subject("[ALERT] $LEVEL condition in $PROGRAM!")
body("Hi!\nThe syslog-ng alerting service thinks you might be interested in the following message:\n $MSG\n-- \nsyslog-ng\n")
extra-header("X-Program", "$PROGRAM")
);
I doubt it'd be useful to use templates within To/Cc/Bcc, but the rest should be templates,
with support for embedded newline characters. (headers can also contain embedded
newlines, by embedding NL and adding whitespace in the front of the upcoming line,
although I'm not sure how much MUAs like it).
The same syntax could perhaps be used by a possible "sendmail()" destination, which
could spawn the local sendmail binary, instead of directly using SMTP.
Otherwise I really like the functionality, great stuff.
>
>
> One can specify any number of recipients, and the mail will be sent to
> all of them. Custom headers can also be specified, but at this time, a
> selected few headers do not work as one would expect, due to libesmtp
> handling them specially.
>
> These are: Date, From, To, Cc, Bcc, Reply-To - trying to set either of
> these will result in unspecified behaviour (ranging from mangled headers
> to crashes, in case of Date). I will fix these at a later point. They
> will probably be need to set via their own statements (header_date,
> header_from, etc, or something along those lines).
>
> Specifying mail_from or subject multiple times will override any
> previous values. Adding the same custom header multiple times will only
> add the first (though, plans include changing that, so that one can
> include the same header multiple times, with different values - if I can
> find a use-case for that).
>
> There are also a few other minor issues here and there, but nothing
> major, as far as I could check.
>
> Further plans include authentication & starttls support. libesmtp
> supports both, I just didn't have time to write the neccessary glue code
> yet.
Great. Just let me know when I can pull it :)
--
Bazsi
More information about the syslog-ng
mailing list