Python 实现Zabbix自动发送报表(2)

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 实现Zabbix自动发送报表

《Python核心编程 第二版》.(Wesley J. Chun ).[高清PDF中文版]

《Python开发技术详解》.( 周伟,宗杰).[高清PDF扫描版+随书视频+代码]

Python脚本获取Linux系统信息

Ubuntu下用Python搭建桌面算法交易研究环境

Python 的详细介绍请点这里
Python 的下载地址请点这里

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/403bcf2834ab0fe28b9adc82d169ea67.html