1,报警媒介
2,用户报警媒介
3,用户动作
4,zabbix server脚本
/usr/lib/zabbix/alertscripts
[root@localhost alertscripts]# cat mail_cs.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import argparse
import smtplib
from email.header import Header
from email.mime.text import MIMEText
def send_mail(msg, to_addr):
from_addr = 'xxxx@xxx.xx' #发送邮箱的地址
password = 'pwd' #发送邮箱的客户端登陆密码,可能和网页登陆密码不同需要单独设置
smtp_server = 'mail.teleinfo.cn'
# to_addr = 'wangjiahui@teleinfo.cn' #接收邮箱地址
subject = u'邮件报警'
msg = MIMEText(msg, 'plain', 'utf-8')
msg['From'] = from_addr #发送邮箱地址
msg['Subject'] = Header(subject, 'utf8').encode() #邮件主题
server = smtplib.SMTP(smtp_server, 25) #连接SMTP服务器
server.login(from_addr, password) #登陆
server.sendmail(from_addr, [to_addr], msg.as_string()) #发送
server.quit()
if __name__ == '__main__':
#parser = argparse.ArgumentParser(description='Python send mail script.')
#parser.add_argument('-t', '--text', required=True)
#args = parser.parse_args()
send_mail(sys.argv[1], sys.argv[2])