[syslog-ng]Sending Email via syslog-ng

Allan Wind syslog-ng@lists.balabit.hu
Tue, 10 Feb 2004 11:13:43 -0500


--mxv5cy4qt+RJ9ypb
Content-Type: multipart/mixed; boundary="wRRV7LY7NUeQGEoC"
Content-Disposition: inline


--wRRV7LY7NUeQGEoC
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On 2004-02-10T14:37:53+0100, Wilhelm.Greiner@vaps.de wrote:
> destination ruf_mich_an { program("/usr/local/sbin/log_to_mail.pl"); };
> filter ruf_mich_an2 { facility(cron); };
> log { source(net); filter(ruf_mich_an2); destination(ruf_mich_an); };

After restarting syslog-ng with this config, verify that your program is
running with ps.  It looks like you assumed an exec/fork per event,
however the protocol appears to be one event per line.  That is, you
need logic to decide when you send a chunk of data.

I attached the program that I currently use, it is more complicated as I
try to both minimize the number of emails sent and the latency in
getting them.  It dies once in a while, probably because of a unhandled
signal, but I need to rewrite it in C++ one of these days.  That said,
it works quite well.


/Allan
--=20
Allan Wind
P.O. Box 2022
Woburn, MA 01888-0022
USA

--wRRV7LY7NUeQGEoC
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=mailline
Content-Transfer-Encoding: quoted-printable

#!/usr/bin/python


import Queue
import re
import smtplib
import sys
import time
import thread


q =3D Queue.Queue(0)


def producer():
	tag =3D re.compile('<.{1,2}>(.*)')
	while True:
		line =3D sys.stdin.readline()
		untagged =3D tag.match(line)
		if untagged:
			q.put(untagged.group(1) + '\n')
		else:
			pass


def consumer(timeout, mail_from, rcpt_to, subject):
	client =3D smtplib.SMTP()
	body =3D 'From: %s\nTo: %s\nSubject: %s\n\n' % (mail_from, rcpt_to, subjec=
t)
	while True:
		lines =3D q.get()
		time.sleep(timeout)
		while not q.empty():
			lines +=3D q.get()

		client.connect('localhost')
		client.sendmail(mail_from, rcpt_to, body+lines)
		client.quit()
	=09

thread.start_new_thread(producer, ())
consumer(60, 'root', 'root', 'syslog-ng: alert')

--wRRV7LY7NUeQGEoC--

--mxv5cy4qt+RJ9ypb
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAKQM3uDtNyOwreTYRAnz/AKDkJBkJg6O7MkueKBGmo/jL9VlF1wCg7UoX
Uo8fN9QbbzMqDKJzah8ihNo=
=a8T9
-----END PGP SIGNATURE-----

--mxv5cy4qt+RJ9ypb--