I created a small shell script with no dependencies other than basic Linux tools (like find and wc) which counts the number of mails in the queue and let you thereby monitor them with Nagios/Icinga. For my example I'll use check_nrpe to execute the plugin remote on the application server.
First, here is the script. You need to save it executeable in your plugin directory on the remote machine, which in my case is
/usr/lib/nagios/plugins. I saved it as check_spool:
Next you need to configure the plugin on your remote machine, adding the command to the nrpe commands in your
command[check_spool]=/usr/lib/nagios/plugins/check_spool "/path/to/swiftmailer/spool" -w 5 -c 50
/path/to/swiftmailer/spoolwhich should be replaced by the directory you keep your spooled files in. The -w and -c options are the Nagios/Icinga standard parameters for warning and critical threshhold. With this command registered, you can restart your nrpe server and add the check to the monitoring server:
service_description Swiftmailer Spooling Queue
You can place this anywhere in your icinga/objects folder. Change the hostname for your defined hostname and restart Icinga. Maybe you need to change the
check_nrpe, depending on your Nagios/Icinga version.
Now, looking in your Nagios/Icinga frontend, you should see the service running without issues. To troubleshoot, you can execute the script on the remote server manually and see if any errors are thrown. Doublecheck the command in your
nrpe.cfgif parameters are correct. If NRPE is working, this command should be no exception.