html += '<img src="https://%s/%s/%s/%s.%s.png">'%(zabbix_host,save_graph_path.split("/")[len(save_graph_path.split("/"))-2],save_graph_path.split("/")[len(save_graph_path.split("/"))-1],screenid,graphid)
f = open(filename,"wb")
f.write(data)
f.close()
def send_mail(username,password,smtp_server,to_list,sub,content):
print to_list
me = "运维"+"<"+username+"@"+domain +">"
msg = MIMEText(content,_subtype="html",_charset="utf8")
msg["Subject"] = sub
msg["From"] = me
msg["To"] = ";".join(to_list)
try:
server = smtplib.SMTP()
server.connect(smtp_server)
server.login(username,password)
server.sendmail(me,to_list,msg.as_string())
server.close()
print "send mail Ok!"
except Exception, e:
print e
if __name__ == '__main__':
for screen in screens:
get_graph(zabbix_host,username,password,screen,width,height,period,save_graph_path)
send_mail(mail_user,mail_pass,smtp_server,to_list,"test email",html)
设置crontab 每天早上上班前执行一次
crontab -e
45 08 * * * python /root/zabbix_send_report.py
上效果图
《Python核心编程 第二版》.(Wesley J. Chun ).[高清PDF中文版]
《Python开发技术详解》.( 周伟,宗杰).[高清PDF扫描版+随书视频+代码]
在Ubuntu下用Python搭建桌面算法交易研究环境