[Zabbix Alert] Configure msmtp to work with gmail on linux

Zabbix integrated Email media facility is restricted to basic SMTP protocol. It does not support advanced SMTP capabilities such as authentication or encrypted communication with TLS
Zabbix notification system can be extended with external programs. This solution is based on msmtp command line utility that integrates advanced SMTP capabilities.

Email content customization

Zabbix integrated Email media facility can only send simple text emails.
With an external script, it is possible to add custom email headers. It allows to use HTML formatted messages or change message priority.

Installation

Prerequisites

msmtp must be installed.
  • On CentOS:
    yum install msmtp

msmtp media script

zext_msmtp.sh script (latest version) should be installed in alert scripts directory on Zabbix server.
This directory is defined in zabbix_server.conf by AlertScriptsPath parameter.
Default value is:
# vi /etc/zabbix/zabbix_server.conf
AlertScriptsPath=/etc/zabbix/alert.d/
# /etc/init.d/zabbix_server restart
# chmod +x /etc/zabbix/alert.d/zext_msmtp.sh 
# chgrp zabbix /etc/zabbix/alert.d/zext_msmtp.sh 
By default, zext_msmtp.sh uses zabbix account as defined in msmtp configuration file (/etc/msmtprc by default).
See configuration examples below.

Configuration

Simple SMTP configuration

This configuration is equivalent to Zabbix internal email media. It does not use any advanced SMTP capability but is useful for email content customization.
/etc/msmtprc
account zabbix
host smtp.example.org
domain example.org
from zabbix@example.org

Advanced SMTP configuration

This example illustrate how to configure msmtp to use a Gmail account to send messages as described in Gmail help. It sets authentication and uses TLS/STARTTLS (port 587).

/etc/msmtprc
account default
tls on
tls_starttls on
tls_trust_file /etc/pki/tls/certs/ca-bundle.crt
host smtp.gmail.com
port 587
auth on
from zabbixaccount@gmail.com
user zabbixaccount@gmail.com
password ***********
logfile /var/log/msmtp.log 

Your msmtp configuration is ready. Lets send a test email to yourself to see if everything’s working properly: 
echo -e "Subject: Test Mail\r\n\r\nThis is a test mail" |msmtp --debug --from=default -t username@gmail.com

Media definition

In Zabbix Web interface, Administration/Media Types page, create a new media type:

and save it.

User media configuration

In Zabbix Web interface, Administration/Users page; select user and add a new media:

and save it.

 Config Zabbix Action



Nhận xét

Bài đăng phổ biến từ blog này

CLEANING UP THE ZABBIX DATABASE

Configuring DHCP Relay service on the FortiGate unit

WAN link load balancing