Zabbixpython email script code

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

#! /Usr/bin/env python #-*-coding: UTF-8-*-# author: heyic.m@gmail.com # date: 2017-03-10 # zabbix alert script, set multiple senders to randomly send the import sysimport smtplibfrom email. mime. text import MIMETextfrom email. utils import formataddrimport random # sender dictionary sender = {'sender _ 000000': {'smtp ': 'smtp .139.com', 'user': '136xxxxxx @ 139.com ', 'pass ': 'pass'}, 'sender _ 000000': {'smtp ': 'smtp .163.com', 'user': 'xxxxxxxxxxxx @ 163.com ', 'pass': 'pass '}, 'sender _ comp ': {'smtp': '2017. 168.193.27 ', 'user': 'xxxxxxxxxxx @ local.com', 'pass': 'pass'}, 'sender _ QQ': {'smtp ': 'smtp .qq.com ', 'user': 'xxxxxxxxxxx @ qq.com ', 'pass': 'pass' }}# obtain the sender's email address def get_sender (): send_server_list = [] for each in sender: send_server_list.append (each) index = random. randrange (len (sender) return sender [send_server_list [index] # recipient, Mail title, mail body, sender def send_mail (to_list, subject, msg_content, sender ): # third-party email server and authentication mail_host = sender ['smtp '] mail_user = sender ['user'] mail_pass = sender ['pass'] # Mail content msg = MIMEText (msg_content, 'Plain ', 'utf-8') msg ['from'] = formataddr (['alert mail', mail_user]) # sender display msg ['to'] = formataddr (['me', to_list]) # recipient display msg ['subobject'] = Subject # send try: server = smtplib. SMTP (mail_host, 25) server. login (mail_user, mail_pass) server. sendmail (mail_user, [to_list], msg. as_string () server. quit () counter t smtplib. SMTPException as e: print (e) if _ name _ = '_ main _': sender = get_sender () # Three parameters are required for zabbix alarms, the order is recipient, Mail title, mail body # send_mail ('yic. he@szpcg.com ', 'Random sender test', 'Random sender test', haha Laha', sender) send_mail (sys. argv [1], sys. argv [2], sys. argv [3], sender)

The above is the details of the zabbix python email 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.