#!/usr/bin/python import Queue import re import smtplib import sys import time import thread q = Queue.Queue(0) def producer(): tag = re.compile('<.{1,2}>(.*)') while True: line = sys.stdin.readline() untagged = tag.match(line) if untagged: q.put(untagged.group(1) + '\n') else: pass def consumer(timeout, mail_from, rcpt_to, subject): client = smtplib.SMTP() body = 'From: %s\nTo: %s\nSubject: %s\n\n' % (mail_from, rcpt_to, subject) while True: lines = q.get() time.sleep(timeout) while not q.empty(): lines += q.get() client.connect('localhost') client.sendmail(mail_from, rcpt_to, body+lines) client.quit() thread.start_new_thread(producer, ()) consumer(60, 'root', 'root', 'syslog-ng: alert')