Zabbix email warning python script code

Source: Internet
Author: User
This article introduces zabbix email warning python script code

#! /Usr/bin/python #-*-coding: UTF-8-*-"Zabbix SMTP Alert script from qq. auth: json "" import sysimport emailimport smtplibimport osfrom email. mime. text import MIMETextfrom email. mime. multipart import MIMEMultipart # Mail sending list to whom # mailto_list = ["winson. zhou @ gmail "," zhoufr@youqudao.com "] # set the server, username, password mail_host = "smtp.exmail.qq.com" mail_user = "123456789@qq.com" mail_pass = "123456789" mail_postfix = "qq.com" # define the send_mail function def send_mail (to_list, sub, content ): '''to_list: to whom sub: topic content: 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 ['subobject'] = 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 expect T Exception, e: print str (e) return Falseif _ name _ = '_ main _': send_mail (sys. argv [1], sys. argv [2], sys. argv [3])

Test method:

Run the following command in the current script Directory:

Python script name sender email Mail title email content

Python sendemail. py test@qq.com zabbix zabbixcontent

The above is the details of the zabbix email warning python script code. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.