Custom Monitor Example (windows) – Monitor Email Queue Folder

by Oct 16, 2006

We run a simple mail server package on one of our systems. Sometimes we find a problem by where the email gets locked and therefore lots of others then start to queue up behind it until the offending email is deleted and resent. We decided to use an Uptime Monitor to alert when this condition happened.

Here is an example of the script we use;


cut here

' Uptime Custom Service Monitor
' *****************************

' Written by Greg Noonan 2/10/2006
'
'



' EMAIL QUEUE CHECK
'



'
' This check looks at the mail queue folder and checks the last modified time of the files in
' the mail queue to see if they have been waiting for more than 5 minutes. A wait of more than
' 5 minutes would signal a problem with the mail server not sending email.
'
' A CRITICAL alarm is sent to Uptime should these waiting email files be older than 5 minutes
' A INFO alarm is sent when the files are under 5 minutes or there is no files in the folder
'
' **********************************************************************************
'
on error resume next
delayed_mail_alert = “”
Mail_queue_location = “C:Program FilesmailOUT” ' location of folder to monitor
time_delay = 300 ' time delay in milliseconds

Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objMailFolder = objFSO.GetFolder(Mail_queue_location)
delayed_mail_alert = “nothing”
For Each waiting_mail In objMailFolder.Files
IF delayed_mail_alert <> “true” THEN
Set objMail = waiting_mail
mail_in_queue_name = objMail.Name
mail_in_queue_path = objMailFolder
mail_in_queue_modified_time = objMail.DateLastModified
mail_in_queue_timer = DateDiff(“s”, mail_in_queue_modified_time, Now())
If mail_in_queue_timer > time_delay Then
delayed_mail_alert = “true”
ELSE
delayed_mail_alert = “false”
End IF
End IF
Next

IF delayed_mail_alert = “false” THEN output_message = “INFO There is currently no mail older than 5 minutes waiting to be sent”
IF delayed_mail_alert = “true” THEN output_message = “CRIT There is currently mail older than 5 minutes stuck in the mail queue”
IF delayed_mail_alert = “nothing” THEN output_message = “INFO The mail queue is currently empty”

wscript.echo output_message ' output the message to the uptime console


cut here

You need to also create a batch file on the main console/monitoring server that is called from within the Uptime Console/Service monitor setup in order to call the rexec command that is stored on the target server's registry.

The batch file is as follows;


cut here

@echo off
echo rexec password mail_queue_check “%*” | “C:uptimebinnetcat.exe” %1 9998


cut here

The mail_queue_check must be the same as what is listed in the target servers registry under the rexec_commands branch.

In the service monitor custom settings setup on the main console you then look for a part that “contains” the string “CRIT” in the output. Assuming you have the batch script being called in the right place on the console server, the same name given for the rexec process in the batch file that matches what is in the registry on the target server you should have no problems. Remember to set the password too on the target server's uptime registry that matches what is sent in the batch file. If you have done this already beware of my registry patch.

Don't forget to restart the agent too if you make any changes in the target server's registry

Good luck!

Cheers,
Greg