OpenNMS, check email status (MailTransport)

 

Carrying on talking about OpenNMS features, this time I’d like to introduce the service called Mail Transport Monitor, normally abbreviated to MTM. The aim of this service is to monitor the complete functioning of your mail system: sending and receiving e-mails. For this purpose we need an “external” email which should rapidly answer to our request with a so called “echo-reply”, to let us know that everything’s working. Instead of putting an automatic reply rule to your ”free” Gmail/Hotmail/Yahoo (etc..) account, it would be nice to have an automatic service that does this job automatically, without any configuration. These services exists and they’re public (anyone can use them) but unfortunately they’re not so reliable as expected (if you only think at how many emails per seconds they receive, maybe this delay is understandable)

Here you can look at the most famous Echo-Mailer (just a German page on Wikipedia, Google helps you). After many tries, here’s my suggestion: echo@tu-berlin.de and echo@univie.ac.at are the best choices. If you send an email no more frequently than every 2 minutes, you will never have problems with them (since 6-7 months). Now we can have a look on how it’s the configured OpenNMS and this tricky MTM service.

This “mail loop check” on OpenNMS will be configured in this way: from one of our “test” e-mail account via (POP3 or IMAP protocol), it tries to send and email to an Echo-Mailer and then after few minutes it checks again if there’s the expected answer on the “test” e-mail account. If this checks goes well, OpenNMS knows that the service is working and no alerts are sent. Otherwise it will checks many times as it is configured on the service and after that number of tries, it will alert the system that the service is down.

1st configuration on the poller-config.xml. The email address it’s hosted on a “internal” mail server at the address testmailIPaddress. The email address it’s testmail@address and the account credentials are username and passwordtest. Protocol used IMAP (to be more specific Microsoft Exchange Server), Mailer-Echo used echo@tu-berlin.de

<service name="MailTransportCompanyName" interval="300000"
		user-defined="false" status="on">
		<parameter key="retry" value="6"/>
		<parameter key="mail-transport-test">
		<mail-transport-test>
			<mail-test>
				<sendmail-test attempt-interval="30000"
					debug="true" use-authentication="false" use-jmta="false">
					<sendmail-host host="testmailIPaddress" port="25"/>
							<sendmail-protocol char-set="us-ascii"
							mailer="smtpsend"
							message-content-type="text/plain"
							message-encoding="7-bit"
							quit-wait="true" ssl-enable="false"
							start-tls="false" transport="smtp"/>
					<sendmail-message to="echo@tu-berlin.de"
							from="testmail@address"
							subject="OpenNMS Test Message" body="This is an OpenNMS test message."/>
							<user-auth user-name="username" password="passwordtest"/>
				</sendmail-test>
				<readmail-test attempt-interval="50000"
					debug="true" mail-folder="INBOX"
					subject-match="OpenNMS Test Message" delete-all-mail="true">
					<readmail-host host="testmailIPaddress" port="143">
							<readmail-protocol ssl-enable="false"
							start-tls="false" transport="imap"/>
					</readmail-host>
					<user-auth user-name="username" password="passwordtest"/>
				</readmail-test>
			</mail-test>
		</mail-transport-test>
		</parameter>
</service>

2nd configuration on the poller-config.xml. The email address it’s managed via postfix and resides on the same machine which runs OpenNMS, so the mail server address is 127.0.0.1. The email address it’s testmail2@address and the account credentials are the same used from the linux user account “associated” to the mail used for the loop usernamelinux and passwordtestlinux. Protocol used POP3 (Postfix server on localhost running), Mailer-Echo used echo@univie.ac.at

<service name="MailTransportCompanyName2" interval="300000"
	user-defined="false" status="on">
	<parameter key="retry" value="6"/>
	<parameter key="mail-transport-test">
	<mail-transport-test>
		<mail-test>
			<sendmail-test attempt-interval="30000"
				debug="true" use-authentication="false" use-jmta="false">
				<sendmail-host host="127.0.0.1" port="25"/>
				<sendmail-protocol char-set="us-ascii"
				mailer="smtpsend"
				message-content-type="text/plain"
				message-encoding="7-bit"
				quit-wait="true" ssl-enable="false"
				start-tls="false" transport="smtp"/>
				<sendmail-message to="echo@univie.ac.at"
					from="testmail2@address"
					subject="Automatic Response from echo@univie.ac.at" body="This is an OpenNMS test message. The Univie"/>
					<user-auth user-name="usernamelinux" password="passwordtestlinux"/>
				</sendmail-test>
				<readmail-test attempt-interval="50000"
					debug="true" mail-folder="INBOX"
					subject-match="Automatic Response from echo@univie.ac.at" delete-all-mail="true">
					<readmail-host host="127.0.0.1" port="110">
						<readmail-protocol ssl-enable="false"
						start-tls="false" transport="pop3"/>
					</readmail-host>
					<user-auth user-name="usernamelinux" password="passwordtestlinux"/>
				</readmail-test>
		</mail-test>
	</mail-transport-test>
	</parameter>
</service>

After months of experience and false positives alerts, from this service, I can say:

  • find the right amount of timeouts/retries. Don’t poll too much, the minimum requested;
  • every time you change poll-config.xml you need to restart OpenNMS. Otherwise your changes will not be applied;
  • with Postfix works pretty good and if you have a dedicated server for it, you only need to change the Ipaddress 127.0.0.1 at the configuration above;
  • with Exchange also works good but from my experience I received more false positive alarm (resolved usually in less than 30 minutes). For this reason notifications should be delayed just a bit more than 30 minutes;