Zabbix sets QQ mailbox alarm

zabbix environment construction

zabbix set 163 mailbox alarm

Zabbix sets QQ mailbox alarm

  • background
    • Set QQ mailbox alarm
  • Implementation (refer to 163 mailbox settings alarm)
  1. First, in the QQ mailbox, open the POP3/SMTP service to obtain the authorization code, QQ mailbox -> Settings -> Account -> Enable POP3/SMTP service
  2. Go to the web interface of zabbix --> Management --> Alarm Media Type --> Create Media Type

Enter image description

  • 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} 表示邮件内容
  1. 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 目标邮箱 "邮件主题" "邮件内容"
  1. 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 ~]# 
  1. 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]# 
  1. Check QQ mailbox, you will see the sent mail

Enter image description

  1. 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

Enter image description

  1. Then set the mailbox for the user just now, Manage --> User --> Alarm Media

Enter image description

  1. To change the user's permissions (the default user is none), you need to modify the group, give permissions, manage --> user group

Enter image description

  1. Set the action, configure-->action-->create action

Enter image description

  • 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)

Enter image description

  • 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)

Enter image description

  • Finally add
  1. The test alarm is the same as the 163 mailbox, and the 163 mailbox test alarm

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325482245&siteId=291194637