Zabbix4.2邮件告警python脚本

环境 :
Ubunutu 16.04 LTS
Zabbix 4.2.6
psotgresql 9.6.6

脚本如下:

root@ubuntu:/usr/lib/zabbix/alertscripts# vi send.py 
#!/usr/bin/env python
# _*_ coding:utf-8 _*_

import smtplib
from email.mime.text import MIMEText
import sys

# configure your own parameters here
#下面邮件地址的smtp地址
mail_host = 'smtp.163.com'
#用来发邮件的邮箱,在发件人抬头显示(不然你的邮件会被当成是垃圾邮件)
mail_user = '[email protected]'
# 客户端授权码
mail_auth = 'xxxxxx'
# 发送方显示的名称
send_name = mail_user
# 接收方显示的名称
recv_name = mail_user

def excute(to, title, content):
    msg = MIMEText(content, 'plain', 'utf-8')
    msg['From'] = send_name
    msg['To'] = recv_name
    msg['Subject'] = title
    server = smtplib.SMTP(mail_host, 25)
    server.login(mail_user,mail_auth)
    server.sendmail(mail_user,to,msg.as_string())
    server.quit()

if __name__ == '__main__':
    excute(sys.argv[1]

你可能感兴趣的:(监控)