Skip to content

Instantly share code, notes, and snippets.

@eliotk
Last active December 15, 2015 23:19
Show Gist options
  • Save eliotk/5339281 to your computer and use it in GitHub Desktop.
Save eliotk/5339281 to your computer and use it in GitHub Desktop.
A simple script for triggering an email alert to an administrator when the exim mail queue count exceeds a certain threshold
import subprocess
import string
# import smtplib for sending email
import smtplib
# execute exim queue count command
proc = subprocess.Popen(['/usr/sbin/exim','-bpc'], stdout=subprocess.PIPE)
mail_count = int(proc.stdout.read())
# min number of emails in queue that should trigger an alert
threshold = 50
if mail_count > threshold:
msg = {}
msg['Body'] = 'Current email count in queue: %s' % mail_count
msg['Subject'] = 'High Email Count in Exim Queue'
msg['From'] = '[sender address]'
msg['To'] = '[recipient address]'
sendmail_body = string.join(('From: %s' % msg['From'], 'To: %s' % msg['To'], 'Subject: %s' % msg['Subject'], '', msg['Body']), "\r\n")
s = smtplib.SMTP('localhost')
s.sendmail(msg['From'], msg['To'], sendmail_body)
s.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment