1) Create a host, create item and trigger for it. Demonstrated here is a direct link to the template
2) Add alarm media type to the user
3) Configure /etc/mail.rc
, add the following lines at the end
set sendcharsets=iso-8859-1,utf-8
set from=MAIL [email protected]
set smtp=smtp.163.com
set smtp-auth-user=MAIL [email protected]
set smtp-auth-password=PASSWORD
set smtp-auth=login
4) Test sending email
echo "hello world" | mail -s "zabbix" MAIL [email protected]
5) Define the action for the trigger
6) Test if the httpd of the agent port is stopped, and whether it will send an email
7) Email alarm information
If the sent email is an attachment, you can
install the dos2unix
conversion tool as follows: 1) Install the conversion tool (to solve the problem that the sent email is in the attachment format)
yum install -y dos2unix
2) Create a script to send mail
[root@zabbix ~]# cat sendmail.sh
#!/bin/bash
#export.UTF-8 ###解决发送的中文变成了乱码的问题
FILE=/tmp/mailtmp.txt
echo "$3" >$FILE
dos2unix -k $FILE ###解决了发送的邮件内容变成附件的问题。
/bin/mail -s "$2" $1 < $FILE
mv sendmail.sh /usr/lib/zabbix/alertscripts/ # 此处为zabbix-server.conf中定义的目录。
3) Modify the above alarm media type
4) The rest of the definitions are the same as the above, stop httpd on the agent port, and test email sending