Zabbix sets QQ mailbox alarm
- background
- Implementation (refer to 163 mailbox settings alarm)
- First, in the QQ mailbox, open the POP3/SMTP service to obtain the authorization code, QQ mailbox -> Settings -> Account -> Enable POP3/SMTP service
- Go to the web interface of zabbix --> Management --> Alarm Media Type --> Create Media Type
- Under the py script parameters, the three parameters are distributed in the py script
- The order of parameters cannot be disordered
{ALERT.SENDTO} 表示收件人
{ALERT.SUBJECT} 表示邮件主题
{ALERT.MESSAGE} 表示邮件内容
- Create a script email.py on the server side, QQ mailbox alarm points
[root@hf-01 alertscripts]# cat /usr/lib/zabbix/alertscripts/qqmail.py
#!/usr/bin/env python
#-*- coding: UTF-8 -*-
import os,sys
reload(sys)
sys.setdefaultencoding('utf8')
import getopt
import smtplib
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
from subprocess import *
def sendqqmail(username,password,mailfrom,mailto,subject,content):
gserver = 'smtp.qq.com'
##定义发邮件类型
gport = 465
try:
msg = MIMEText(unicode(content).encode('utf-8'))
msg['from'] = mailfrom
msg['to'] = mailto
msg['Reply-To'] = mailfrom
msg['Subject'] = subject
#ssl连接,把下面改为smtp = smtplib.SMTP_SSL(gserver, gport)
smtp = smtplib.SMTP_SSL(gserver, gport)
smtp.set_debuglevel(0)
smtp.ehlo()
smtp.login(username,password)
smtp.sendmail(mailfrom, mailto, msg.as_string())
smtp.close()
except Exception,err:
print "Send mail failed. Error: %s" % err
def main():
to=sys.argv[1]
subject=sys.argv[2]
content=sys.argv[3]
##定义QQ邮箱的账号和密码,你需要修改成你自己的账号和密码(请不要把真实的用户名和密码放到网上公开,否则你会死的很惨)
sendqqmail('[email protected]','mjjqsasaqxfwbcdj','[email protected]',to,subject,content)
if __name__ == "__main__":
main()
#####脚本使用说明######
#1. 首先定义好脚本中的邮箱账号和密码
#2. 脚本执行命令为:python mail.py 目标邮箱 "邮件主题" "邮件内容"
- Change the permissions of the mail.py script (important!!!), otherwise the alert will not work
[root@hf-01 ~]# chmod 755 /usr/lib/zabbix/alertscripts/qqmail.py
[root@hf-01 ~]#
- After changing the port number, send the email again, you will find that there is no error, indicating that the sending is successful
[root@hf-01 ~]# cd /usr/lib/zabbix/alertscripts/
[root@hf-01 alertscripts]# python qqmail.py [email protected] "ssss" "dddd"
[root@hf-01 alertscripts]#
- Check QQ mailbox, you will see the sent mail
- Create a user to receive alarm emails (the user is used to receive emails). The premise of creating a user is to create a user group. The user group can use the existing one, so create a user directly here, Manage --> User --> create user
- Then set the mailbox for the user just now, Manage --> User --> Alarm Media
- To change the user's permissions (the default user is none), you need to modify the group, give permissions, manage --> user group
- Set the action, configure-->action-->create action
- Configuration --> Actions --> Actions
- Default information: directly delete the original (more messy), paste the following content
- Suspend the operation during maintenance: select a check (if you don't check it, it is also possible, because it is defined in the conditions of the action)
- Configuration-->Actions-->Restore Actions
- Default information: directly delete the original (more messy), paste the following content (the pasted content and the copied information in the operation are the same)
- The test alarm is the same as the 163 mailbox, and the 163 mailbox test alarm