How to configure mail alerts on zabbix server
Posted By : Prakhar Budholiya | 09-Dec-2015
Your zabbix server must have any mail server configured on it. Like SMTP or Postfix etc, then configure your Zabbix for mail alerts.
1. Here we will setup a Postfix (send only) mail server on it-
i) Install Mailutils, it will automatically install postfix and other dependency packages needed for it.
# apt-get install mailutils
Now at the end of installation a window will pop up, just as below ‘Image- 1’. Select Internet-Site and tab for ok.
Image- 1
After this you will see another popped up window as shown below to give your domain name. Here give your (FQDN) fully qualified domain name. If not then give your Hostname only. I have shown an example of FQDN in below ‘Image- 2’.
Image- 2
After this installation of postfix is complete and now we will configure postfix.
ii) Open /etc/postfix/main.cf file in any editor, and make following changes
# vim /etc/postfix/main.cf
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
// Change the line inet_interfaces = all to loopback-only //
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
// Exit and save //
Now restart the service
# sudo service postfix restart
iii) Now test your mail server,
# echo “Content of the mail” | mail -s “Subject of the mail” user@example.com
Replace user@example.com with a proper mail id, and now check your inbox. If you don’t have a FQDN then check spam folder and mark it as important, So you will get these mail in inbox from next time.
So our mail server is configured and tested successfully.
2. Now configure mail alerts for zabbix triggers.
i) First we will create a script,
Use your favorite editor to create send-mail script, and write
# vim /usr/lib/zabbix/alertscripts/zabbix-sendmail
#!/bin/bash
echo “$3” | /usr/bin/mail -s “$2” “$1”
// make this script executable //
# chmod +x /usr/lib/zabbix/alertscripts/zabbix-sendmail
Again test script’s functionality by sending an email to gmail account as-
# /usr/lib/zabbix/alertscripts/zabbix-sendmail username@mail.com "Subject Here" "Body of the mail"
Afterwards, Verify mail inbox and check the mail.
ii) Configure Zabbix to send alerts to mail id
Go to web page of your Zabbix Server and then
Administration > Media Types > Create media types
Here give a unique name to identify your script, select Script from types, give Script name zabbix-sendmail, as in below Image- 3,
Image- 3
Check mark enable option and add.
iii) Now let's add a Email address to which alerts will be send-
Go to Profile > Media > add, it will pop up with a new window
Select your script from types and give user mail address in “Send to”, Status- Enabled, and Add. as shown in below Image- 4 & 5,
Image- 4
Image- 5
iv) Now enable the default zabbix alerts by navigating to Configuration > Actions > select Triggers (from Event Source)
And enable it, Repeat the same for Internal/Discovery/Auto Registration (from Event Source). As shown in below Images 6, 7 & 8.
Image- 6
Image- 7
Image- 8
Wait for zabbix to gather information and generate some reports, then verify your configured gmail account. and you will see mails as in below Image- 9.
Image- 9
Note- For now the zabbix will generate mails only for default triggers in your group, you can also create your own triggers to generate mails.
THANKS
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Prakhar Budholiya
Prakhar is a linux administrator and well versed with linux and networking. he loves horse riding and is an athlete.