technology and zen of life

“A heisenbug (named after the Heisenberg Uncertainty Principle) is a computer bug that disappears or alters its characteristics when an attempt is made to study it.”

Exchange Back Pressure external SMTP test and warning

Your Exchange server will stop receiving email messages when the disk utilization is high. This is called Back Pressure. There are various ways to prevent such a dreadful situation, such as enabling circular logging and monitoring for lack of server resources, but you might want a warning message when this happens.

Below you find a Python script. Run it periodically, e.g. using cron on Linux, and you are set. Don’t forget to change the variables for your own email address and servers.

#!/usr/bin/python

# Tests an Exchange transport server for Back Pressure
# using SMTP probe connections.
# Run (periodically) from another server.
# This script will also send a warning email message,
# using another mailserver.
# I suggest you set an Outlook rule for automatic deletion
# of the test messages when you run this script periodically.

# Evert Mouw 
# 2014-01-04

# variables used for the target that will be tested
SERVER="exchange.example.net"
PORT=25
TO="evert@exchange.example.net"
FROM="i-am-so-fake@somerealdomain.net" # should be from AN EXTERNAL DOMAIN to the Exchange server
SUBJECT="test: back pressure"
BODY="This is a test message. Please ignore."
DEBUG=0 # either 0 (no SMTP debugging) or 1

# variables used to send yourself a warning message
WARNSERVER="smtp.somerealdomain.net"
WARNPORT=25
WARNTO="admin@somerealdomain.net"
WARNFROM=WARNTO
WARNSUBJECT="Back Pressure on Exchange server " + SERVER
WARNBODY="Exchange server " + SERVER + " is experiencing Back Pressure and cannot receive (external) emails any longer."

import smtplib

if (SERVER==WARNSERVER):
	print ("You are a moron.")

MSG="""To: %s
From: %s
Subject: %s

%s
""" % ( TO, FROM, SUBJECT, BODY )

WARNMSG="""To: %s
From: %s
Subject: %s

%s
""" % ( WARNTO, WARNFROM, WARNSUBJECT, WARNBODY )

if (PORT==465):
	smtp = smtplib.SMTP_SSL(SERVER, PORT)
else:
	smtp = smtplib.SMTP(SERVER)

smtp.set_debuglevel(DEBUG)
try:
	smtp.ehlo_or_helo_if_needed()
	smtp.sendmail (FROM, TO, MSG)
except smtplib.SMTPException, error:
	if "Insufficient system resources" in str(error):
		print (WARNBODY)
		if (WARNPORT==465):
			warnsmtp = smtplib.SMTP_SSL(WARNSERVER, WARNPORT)
		else:
			warnsmtp = smtplib.SMTP(WARNSERVER)
		warnsmtp.ehlo_or_helo_if_needed()
		warnsmtp.sendmail (WARNFROM, WARNTO, WARNMSG)
		warnsmtp.quit()
	print (error)
	#print (repr(error))
finally:
	smtp.quit()

About Evert Mouw

Interested in kinda everything, studied political science, now studying medical informatics. MCSE, Linux enthousiast, and believing that technology is the path to enlightenment ;-) Best RTS game ever is Warhammer Soulstorm (IMHO). Other hobbies include hiking, kayaking, reading and when I have time, trying to have an ant colony in an artificial nest (formicarium).

Leave a Reply

Email Subscription

Disclaimer

The views expressed on this blog are personal. We do not claim to be a representative voice of the views of any organisation whatsoever. We are not responsible for the content present on the blogs to which we have linked.Views expressed are solely that of the author and does not reflect a collective opinion of contributors.
%d bloggers like this: