Home > Backend Development > Python Tutorial > zabbix email alert python script code

zabbix email alert python script code

高洛峰
Release: 2017-03-10 19:03:18
Original
1317 people have browsed it

This article introduces the zabbix email alarm python script code

#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Zabbix SMTP Alert script from qq.
auth:json
"""
import sys
import email
import smtplib
import os
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
#邮件发送列表,发给哪些人
#mailto_list=["winson.zhou@gmail","zhoufr@youqudao.com"]
#设置服务器,用户名、密码
mail_host="smtp.exmail.qq.com"
mail_user="123456789@qq.com"
mail_pass="123456789"
mail_postfix="qq.com"
#定义send_mail函数
def send_mail(to_list,sub,content):
    '''
    to_list:发给谁
    sub:主题
    content:内容
    send_mail("123456789@qq.com","sub","content")
    '''
    #if not isinstance(sub,unicode):
    #sub = unicode(sub)
    address=mail_user
    msg = MIMEText(content,format,'utf-8')
    msg["Accept-Language"]="zh-CN"
    msg["Accept-Charset"]="ISO-8859-1,utf-8"
    msg['Subject'] = sub
    msg['From'] = address
    msg['To'] =to_list
    try:
        s = smtplib.SMTP_SSL(mail_host,port=465)
        #s.connect(mail_host)
        s.login(mail_user,mail_pass)
        s.sendmail(address, to_list, msg.as_string())
        s.close()
        return True
    except Exception, e:
        print str(e)
        return False
if __name__ == '__main__':
        send_mail(sys.argv[1], sys.argv[2], sys.argv[3])
Copy after login

Test method:

Execute in the current script directory

python script name sender email address email title email Content

python sendemail.py test@qq.com zabbix zabbixcontent


The above is the detailed content of zabbix email alert python script code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template