# Create the root message and fill in the from, to, and subject headers
def main(str_from,list_to,image_dir):
pictures = _get_pictures(image_dir)
for screen_name in list(set([x.split('.')[0] for x in pictures ])):
screens = [x for x in pictures if x.startswith(str(screen_name) + '.') ]
msgRoot = _create_msg(screen_name,screens,image_dir,str_from,list_to)
_sendmail('smtp.example.com',25,'username','password',str_from,list_to,msgRoot.as_string())
if __name__ == '__main__':
str_from = 'username@example.com'
list_to = [
"jack@example.com", "tom@example.com", "jim@example.com"
]
image_dir = '/data/graph'
main(str_from,list_to,image_dir)
接着,将这两个脚本加入到crontab中定时执行。
$ sudo crontab -e
30 23 * * * /data/script/save-graph.pl
55 23 * * * /data/script/email-pic.py
这样,就可以收到对应的Zabbix图形邮件报表了,如下图所示:
-------------------------------分割线-------------------------------
1、按周显示:
my $period = 86400; 这里就是用来定义时间的,以秒为单位。
2、执行python时出错,麻烦帮助看一下。python2.6\2.7版本都试过
Traceback (most recent call last):
File "./email-pic.py", line 80, in
main(str_from,list_to,image_dir)
File "./email-pic.py", line 71, in main
msgRoot = _create_msg(screen_name,screens,image_dir,str_from,list_to)
File "./email-pic.py", line 41, in _create_msg
_,hsize,vsize,_,_,_,_,= tuple(screens[0].split('.'))
IndexError: list index out of range
必须和上面的脚本和步骤配合使用,完成的任务其实就是,创建目录,利用Zabbix接口生成好好图片,然后通过邮件发送。