Saturday, 18 July 2015

Monitoring an external SMTP relay service with Synagios

I use an outbound email relay service,, and it stopped working last week without me knowing. Emails I had sent sat around for four days before I found out, which caused me a few problems.

The problem was with SSL - Dns Exit fixed it within 24 hours and I was able to switch to their backup server until it was fixed, but I should have known earlier. I'm pretty happy with DNS Exit though as they were pretty quick to fix it, had a backup server to connect to, and emailed me when the problem was fixed.

I'm going to add a new check to Synagios to check my email relay service so I know more quickly next time.

Finding a Plugin

I need a plugin to check STMP. First I'll log into my diskstation and see what plugins are available.

I'll Log into my diskstation using Putty or ssh then use the 'chroot' command to enter into the nagios chroot as shown: 
chroot /volume1/@appstore/Synagios/nagios-chroot/ /bin/bash
I'm in the nagios chroot now so I'll look at the plugins. They are in two locations, /usr/lib/nagios/plugins and /usr/local/nagios/plugins.

Looking in /usr/lib/nagios/plugins: 
ls /usr/lib/nagios/plugins
Shows a list of the default nagios plugins. The one I need is right there, 'check_smtp'.

Testing the Plugin

I'll test it from the command line first.

Check the plugin's options:
/usr/lib/nagios/plugins/check_smtp -h
The next command tests the host, STARTTLS(-S), verbosely(-v):
/usr/lib/nagios/plugins/check_smtp  -S -H -v
Next I'll add authentication(-A) and my user name(-U) and password(-P):
/usr/lib/nagios/plugins/check_smtp  -S -H -v \
-A LOGIN -U theusername -P thepassword
Note that '\' is a continuation character. This allows the command to span multiple lines and I only do it here so the line fits in the blog.

I think this is enough to test for. It checks SSL, STARTTLS, and authentication.

A Note About Plugin Locations

In the synagios chroot, in the file '/etc/nagios3/resource.cfg', there are two nagios macros, $USER1$ and $USER5$, which hold the locations of the nagios plugins and are used in the 'Commands' tab in the Nagrestconf GUI.

The two Nagios macros are defined in resource.cfg as:
$USER1$ is where the official nagios plugins are and $USER5$ is where extra plugins are kept.

I found 'check_smtp' in '/usr/lib/nagios/plugins', so this is '$USER1$'.

Open Nagrestconf and Nagios3

Using a Web Browser, preferably Firefox, Safari, or Chrome, I'll open the following links. Change 'diskstation' for the name or IP address of your diskstation.
I'll refer to this as the Nagrestconf GUI from now on, and,
,which I will refer to as the Nagios GUI.

Adding the Check 

Looking in the Nagrestconf GUI, the 'check_smtp' plugin is already listed there as:
$USER1$/check_smtp -H $HOSTADDRESS$ $ARG1$
I can just add it then, great. To do this I will first add a new host, then add a service to that host.

Refer to the Nagios Documentation to find out more about Nagios configuration. It will explain the format of the Command that is entered next and what the '!' sign is for (it's a delimiter between arguments).

Adding the host:
  • Click on the Hosts tab
  • Click on the Add New Host icon at the top right of the table
  • For the three fields Host Name, Alias, and IP Address enter:
    Of course, change to your email relay provider.
  • Click Create Host
Adding the service:
  • Click on the new '' entry, expanding it
  • Click on the Add New Service icon at the top right of the inner table
  • For the Service Template choose: svctmpl-lin
  • For the Command field enter:
    check_smtp!-S -U theusername -P thepassword -A LOGINOf course, change 'theusername' and 'thepassword' to your username and password.
  • For the Description field enter: Outbound Mail Relay
  • Click the Additional tab
  • For the Check Interval field enter: 30.
    This checks the relay service every 30 minutes
Click Create Service.

Click Apply Changes at the top left of the screen, the Apply Configuration.

Switching to the Nagios GUI, the new host and check will appear in a couple of minutes and hopefully both turn green, as shown in the screen shot at the top of this page.

Now I'm going to do the same for the backup relay so if there's a problem I'll know it's good to switch to it.

No comments:

Post a Comment