使用phpmail下载CACTI图片并以邮件方式每天发送报表

使用phpmail下载CACTI图片并以邮件方式每天发送报表

1.下载到对应的CACTI图片来
2.使用mail功能发送邮件并包含下载下来的图片

一、下载图片,我们使用python来下载图片,在下载前要打开CACTI的来宾账户查看图片不用输入密码这个功能
具体设置在Console -> User Management设置guest的属性为enable并且可以查看图片的权限,并在Console -> Cacti Settings ->Authentication->Special Users选择刚才的guest
下载图片代码如下

/usr/bin/python

import requests,sys
def DownImage(url,filename):
r = requests.get(url)
try:
ImageFile = open(filename,'w')
ImageFile.write(r.content)
ImageFile.close()
return (0,"Success")
except:
return (1,"Write imagefile Error!")
joyful = "/home/sh/mail/png/joyful.png"
DownImage("http://192.168.99.23/graph_image.php?action=view&local_graph_id=115&rra_id=1",joyful)
water = "/home/sh/mail/png/water.png"
DownImage("http://192.168.99.23/graph_image.php?action=view&local_graph_id=130&rra_id=1",water)
club = "/home/sh/mail/png/club.png"
DownImage("http://192.168.99.23/graph_image.php?action=view&local_graph_id=933&rra_id=1",club)
admin = "/home/sh/mail/png/admin.png"
DownImage("http://192.168.99.23/graph_image.php?action=view&local_graph_id=222&rra_id=1",admin)
joyfultem = "/home/sh/mail/png/joyfultem.png"
DownImage("http://192.168.99.23/graph_image.php?action=view&local_graph_id=111&rra_id=1",joyfultem)
admintem = "/home/sh/mail/png/admintem.png"
DownImage("http://192.168.99.23/graph_image.php?action=view&local_graph_id=2322&rra_id=1",admintem)
watertem = "/home/sh/mail/png/watertem.png"
DownImage("http://192.168.99.23/graph_image.php?action=view&local_graph_id=134&rra_id=1",watertem)
clubtem = "/home/sh/mail/png/clubtem.png"
DownImage("http://192.168.99.23/graph_image.php?action=view&local_graph_id=908&rra_id=1",clubtem)
二、下载好图片后 就是要做的就是把图片发送出来

你可能感兴趣的:(使用phpmail下载CACTI图片并以邮件方式每天发送报表)