Knowledgebase: Tools
Script for SMTP Queue Monitoring (Version 1.0 and Version 2.0)
Posted by Dayan D. Jeremiah, Last modified by Dayan D. Jeremiah on 16 April 2015 11:56 AM

IMPORTANT INFORMATION : This script can only be used on IceWarp Server Version 11.1.x and earlier. If you are using or upgrading to IceWarp Server Version 11.2 which supports Priority SMTP Queues please use the SMTP Queue Monitoring Version 2.0 .

This simple PHP script which you can run on a custom schedule from System > Tools > Tasks & Events will monitor the SMTP Temp (no subfolders), SMTP Outgoing (no subfolders) and the SMTP Retry queues (recursive including subfolders). If the number of messages in queue exceeds the preset threshold, it sends an email and/or text message to a defined number. 

The configuration is within config.ini with self-explanatory parameters, including server ID allowing to distinguish multiple installations, custom message content, and paths to where the queues are located. The parameter notify_always=true means a notification will be sent each time the queue is checked on the configured schedule, and can be disabled after initial setup. The number of items reported is counted from all *.imap or *.tmp files within the queue folders (and subfolders in case of SMTP Retry) and can be customized in the script.

The files should be extracted and placed in a folder within \IceWarp\html, eg. \IceWarp\html\monitoring\.

SETUP GUIDE - STEP 1, PHP.INI

  1. Using a text editor edit your \IceWarp\php\php.ini file and change the following directives
    • SMTP, change this to SMTP=localhost, or SMTP=127.0.0.1 or to SMTP=the hostname or IP to which you have bound your SMTP service to in System > Services > General > SMTP
    • sendmail_from, change this to for example; sendmail_from=alias@yourdomain.com
  2. Save your php.ini
  3. Restart your IceWarp CONTROL Service

SETUP GUIDE - STEP 2, CONFIG.INI

  1. Unpack the contents of the queue monitor downloaded ZIP file to \IceWarp\html\monitoring\
  2. Using a text editor edit the config.ini file and set the following parameters
    • [GENERAL]
      • Serverid , a server id number you assign to help you identify the server when you receive a notification
      • hostname , the servers hostname. For example mail.yourdomain.com
      • ip , the servers IP address
    • [NOTIFY_EMAIL]
      • from_name , a generic from name that will appear in the from header of the notification email
      • from_email , the from email address that will appear in the from header of the notification email. For example, noreply@yourdomain.com
      • to_email , the email address to which the email notification will be sent to. You can specify multiple email addresses by seperating them with commas
      • subject , the subject that will appear in the subject header of the notification email. For example Queue Alert For mail.yourdomain.com
      • notify_always , if set to false an email notification is only sent if either one of the thresholds is exceeded. If set to true an email notification is sent each time the script is executed
    • [NOTIFY_SMS]
      • notifyby_sms , a global switch that turns SMS notifications on if set to true of off if set to false
      • to_sms , the sms gateway and phone number to which SMS notifications will be sent to. You can specify multiple recipients by seperating them with commas
      • notify_always, if set to false an SMS notification is only sent if either one of the thresholds is exceeded. If set to true an SMS notification is sent each time the script is executed
    • [SMTP_TEMP]
      • path , the full path to your servers SMTP temp path as defined in System > Storage > Directories > Temp path
      • name , a descriptive name for the SMTP temp path. This will appear in the email and SMS notifications
      • threshold , the number of files allowed in the SMTP temp path. If the threshold is exceeded an email and or SMS notification is triggered
    • [SMTP_OUTGOING]
      • path , the full path to your servers SMTP outgoing path as defined in System > Storage > Directories > Mail path
      • name , a descriptive name for the SMTP outgoing path. This will appear in the email and SMS notifications
      • threshold , the number of files allowed in the SMTP outgoing path. If the threshold is exceeded an email and or SMS notification is triggered
    • [SMTP_RETRY]
      • path , the full path to your servers SMTP outgoing path as defined in System > Storage > Directories > Mail path
      • name , a descriptive name for the SMTP retry path. This will appear in the email and SMS notifications
      • threshold , the number of files allowed in the SMTP retry path and all it's sub-folders. If the threshold is exceeded an email and or SMS notification is triggered
  3. Save your config.ini file

SETUP GUIDE - STEP 3, TASK SCHEDULER

  1. Start your IceWarp management console and go to System > Tools > Tasks & Events
  2. Click [Add...]
  3. In the Description: box enter Queue Monitoring Status Report
  4. Tick the Scheduled Task radio button
  5. Click on [Schedule...]
    • Click [Add...] to add a new schedule
    • Tick ALL Days in week
    • Under Schedule Time click Every, 3 Hours
    • Click [OK] to save the schedule

     

  6. In the Executable: box enter the absolute path to your IceWarp servers php.exe file. For example; C:\Program Files (x86)\IceWarp\php\php.exe
  7. In the Type: drop down, select Executable
  8. In the Parameters: box enter the relative path to the script. For example; ..\html\monitoring\queuemonitor.php
  9. Click [OK] to save your task

TESTING THE SCRIPT

The simplest way to test the script and to ensure that the email and or SMS notifications are sent correctly is to simple set the notify_always to true and then execute the script from System > Tools > Tasks & Events using the [Run Now] button



Attachments 
 
 queuemonitor_v1.0.zip (2.23 KB)
 queuemonitor_v2.0.zip (2.29 KB)
(1 vote(s))
Helpful
Not helpful