What is Postfix?
Postfix is an Open Source mail transfer agent (MTA) that routes and delivers electronic mail.
It was released under an IBM Public License 1.0 and was later distributed under and Eclipse Public License 2.0.
Postfix monitoring
ServicePilot monitors Postfix by reporting Postfix queue indicators.
This package will be sent Postfix statistics with scripts on the Linux machine.
For each of the active, hold, incoming, maildrop, and deferred queues (http://www.postfix.org/QSHAPE_README.html#queues), here are the statistics gathered:
- Queue length: Number of items in the queue
- Size: Size in bytes of all the items in the queue
- Age: Age in seconds of the oldest item in the queue
Requirements
Network Flows - It is necessary to ensure network connectivity between ServicePilot and the monitored device.
- TCP/80 (Default) (HTTP): Between Postfix server and ServicePilot for web access
Third Party Configuration
- Postfix monitoring backend must be enabled
- The Postfix host needs a scheduled script to run to obtain and send data to ServicePilot. See below for script and scheduling.
- The Postfix host needs wget or curl to send data to ServicePilot.
Installation
Before adding a resource to monitor, make certain that all pre-requisites are in place.
Follow the documentation to add a resource to ServicePilot.
Key field notes
In the Policies tab, specify the policy or policies to apply to the resource.
The No-response timeout value has been set to 60 minutes in the class definition. A monitoring policy will be required if, for example, the script is called every 30 minutes.
Notes
Note 1:
Add the given script below in a directory such as /opt/bin on the KVM host and save the file as sp_postfix_queues_report.sh
.
chmod +x sp_postfix_queues_report.sh
Note 2:
Replace the values of IP_PORT, RESOURCE_NAME with the name of the resource provisioned in ServicePilot and API_KEY in the script. Set USE_HTTPS to 1 if your connection to ServicePilot is encrypted over HTTPS. Otherwise, set it to 0. Set WGET_OR_CURL to wget
or curl
depending on which web client is installed. Make sure that the Postfix queue path POSTFIX_PATH is set correctly for your system.
#!/usr/bin/bashshopt -s xpg_echoIP_PORT=sphost1.company.com:443USE_HTTPS=1RESOURCE_NAME="Postfix"API_KEY=00000000-0000-0000-0000-000000000000WGET_OR_CURL=wgetPOSTFIX_PATH=/var/spool/postfixCLASS_NAME=Postfixpost_data="type,resname,object,class,parentview,view,i1,i2,i3\r\n"# Reset counter variablesreset_variables(){ items_number=0 size_sum=0 oldest=0}file_specification() { file_date=$(stat -c %Y "${entry}") now=$(date +"%s") FILE_NAME="$(basename "${entry}")" DIR="$(dirname "${entry}")" NAME="${FILE_NAME%.*}" EXT="${FILE_NAME##*.}" SIZE="$(du -sb "${entry}" | cut -f1)" FILE_AGE=$((now - file_date)) items_number=$((items_number+1)) size_sum=$((size_sum+SIZE)) if [ "$oldest" -lt "$FILE_AGE" ]; then oldest=$FILE_AGE fi}walk() { local indent="${2:-0}" # If the entry is a file do only for entry in "$1"/*; do [[ -f "$entry" ]] && file_specification; done}send_values(){ if [ $USE_HTTPS -eq 1 ];then protocol=https; else protocol=http; fi if [ "$WGET_OR_CURL" = "wget" ];then wget --quiet --no-check-certificate --header 'content-type: text/csv' --header "x-api-key:$API_KEY" --post-data "$( echo $post_data |sed 's/%20/ /g' )" $( echo "$protocol://$IP_PORT/api/send") -t 1 -O/dev/null> /dev/null else curl -s -k -d "$( echo $post_data |sed 's/%20/ /g' )" -H "Content-Type: text/csv" -H "x-api-key:$API_KEY" -X POST $( echo "$protocol://$IP_PORT/api/send") > /dev/null fi}cd $POSTFIX_PATHreset_variablesif [ -d "active" ]; then walk "${POSTFIX_PATH}/active"; fipost_data="${post_data}$( echo "\"data\",\"$RESOURCE_NAME\",\"$RESOURCE_NAME - ACTIVE\",\"$CLASS_NAME\",\"\",\"$RESOURCE_NAME\",\"$items_number\",\"$size_sum\",\"$oldest\"" | sed 's/ /%20/g' )\r\n"reset_variablesif [ -d "hold" ]; then walk "${POSTFIX_PATH}/hold"; fipost_data="${post_data}$( echo "\"data\",\"$RESOURCE_NAME\",\"$RESOURCE_NAME - HOLD\",\"$CLASS_NAME\",\"\",\"$RESOURCE_NAME\",\"$items_number\",\"$size_sum\",\"$oldest\"" | sed 's/ /%20/g' )\r\n"reset_variablesif [ -d "maildrop" ]; then walk "${POSTFIX_PATH}/maildrop"; fipost_data="${post_data}$( echo "\"data\",\"$RESOURCE_NAME\",\"$RESOURCE_NAME - MAILDROP\",\"$CLASS_NAME\",\"\",\"$RESOURCE_NAME\",\"$items_number\",\"$size_sum\",\"$oldest\"" | sed 's/ /%20/g' )\r\n"reset_variablesif [ -d "incoming" ]; then walk "${POSTFIX_PATH}/incoming"; fipost_data="${post_data}$( echo "\"data\",\"$RESOURCE_NAME\",\"$RESOURCE_NAME - INCOMING\",\"$CLASS_NAME\",\"\",\"$RESOURCE_NAME\",\"$items_number\",\"$size_sum\",\"$oldest\"" | sed 's/ /%20/g' )\r\n"reset_variablesif [ -d "deferred" ]; then walk "${POSTFIX_PATH}/deferred"; fipost_data="${post_data}$( echo "\"data\",\"$RESOURCE_NAME\",\"$RESOURCE_NAME - DEFERRED\",\"$CLASS_NAME\",\"\",\"$RESOURCE_NAME\",\"$items_number\",\"$size_sum\",\"$oldest\"" | sed 's/ /%20/g' )\r\n"send_values
Note 3:
To run the job every minute, execute crontab -e
and add the following line
* * * * * /opt/bin/sp_postfix_queues_report.sh
License
Object Type | License object Consumed | Condition |
---|---|---|
Postfix | 5 |
How to install a postfix resource?
- Use your ServicePilot OnPremise installation or a SaaS account.
- Add a new postfix resource via the web interface (
/prmviews
or/prmresources
) or via API (/prmpackages
page), the default ServicePilot agent or another agent will be provisioned automatically.
Details of the postfix package are located in the
/prmpackages
page of the software.
Benefits
ServicePilot enables you to deliver IT services faster and more securely with automated discovery and advanced monitoring features.
By correlating the technology POSTFIX with APM and infrastructure monitoring, ServicePilot is able to provide a more comprehensive view of an organization's IT environment.
This allows IT teams to quickly identify and diagnose issues that may be impacting application performance, and take corrective action before end-users are affected.
Start with a free trial of our SaaS solution. Explore ourplans or contact us to find what works best for you.