zabbix screen 图片以邮件形式发送
zabbix screen 图片以邮件形式发送
#! /usr/bin/env python
#coding=utf-8
# Andy_f
import time,os
import urllib
import urllib2
import cookielib
import MySQLdb
import smtplib
from email.mime.text import MIMEText screen = "Servers"
#
save_graph_path = "/usr/share/zabbix/reports/%s"%time.strftime("%Y-%m-%d")
if not os.path.exists(save_graph_path):
os.makedirs(save_graph_path)
# zabbix host
zabbix_host = "10.10.10.1/zabbix"
# zabbix login username
username = "****"
# zabbix login password
password = "****"
# graph width
width = 500
# graph height
height = 100
# graph Time period, s
period = 604800
# zabbix DB
dbhost = "localhost"
dbport = 3306
dbuser = "zabbix"
dbpasswd = "******"
dbname = "zabbix"
to_list = ["ygw@163.com"]
smtp_server = "10.10.10.8"
mail_user = "zabbix"
mail_pass = "xxxxx"
domain = "163.com"
subj = 'Servers Status ' + time.strftime('%Y-%m-%d',time.localtime(time.time())) def mysql_query(sql):
try:
conn = MySQLdb.connect(host=dbhost,user=dbuser,passwd=dbpasswd,port=dbport,connect_timeout=20)
conn.select_db(dbname)
cur = conn.cursor()
count = cur.execute(sql)
if count == 0:
result = 0
else:
result = cur.fetchall()
return result
cur.close()
conn.close()
except MySQLdb.Error,e:
print "mysql error:" ,e def get_graph(zabbix_host,username,password,screen,width,height,period,save_graph_path):
global screenid
screenid = '27'
global html
html = ''
graphid_list = [8895,8901,8903,8905,8897,8899,8926,8907,8909]
for graphid in graphid_list:
login_opt = urllib.urlencode({
"name": username,
"password": password,
"autologin": 1,
"enter": "Sign in"})
get_graph_opt = urllib.urlencode({
"graphid": graphid,
"screenid": screenid,
"width": width,
"height": height,
"period": period})
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
login_url = r"http://%s/index.php"%zabbix_host
save_graph_url = r"http://%s/chart2.php"%zabbix_host
opener.open(login_url,login_opt).read()
data = opener.open(save_graph_url,get_graph_opt).read()
filename = "%s/%s.%s.png"%(save_graph_path,screenid,graphid)
html += '<img width="600" height="250" src="http://%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) + '<p><br></p>'
f = open(filename,"wb")
f.write(data)
f.close() def send_mail(username,password,smtp_server,to_list,sub,content):
print to_list
me = "Monitoring"+"<"+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,subj,html)
zabbix screen 图片以邮件形式发送的更多相关文章
- 【ABAP系列】SAP ABAP模块-任意report作为附件以邮件形式发送
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP模块-任意rep ...
- 在zabbix中实现发送带有图片的邮件和微信告警
1 python实现在4.2版本zabbix发送带有图片的报警邮件 我们通常收到的报警,都是文字,是把动作中的消息内容当成了正文参数传给脚本,然后邮件或者微信进行接收,往往只能看到当前值,无法直观的获 ...
- PHP 错误与异常 笔记与总结(7)将错误日志以邮件方式发送
当系统发生了很严重的问题,需要立刻发送给管理员.可以通过 error_log() 将错误以邮件形式发送到邮箱. 在 php.ini 中设置: sendmail_from = 472323087@qq. ...
- java带图片的邮件发送方法实现
package sendEmail; import java.util.Properties; import javax.activation.DataHandler; import javax.ac ...
- 使用JavaMail发送邮件-从FTP读取图片并添加到邮件正文发送
业务分析: 最近工作需要,需要从FTP读取图片内容,添加到邮件正文发送.发送邮件正文,添加附件采用Spring的MimeMessageHelper对象来完成,添加图片也将采用MimeMessageHe ...
- zabbix监控系列(4)之zabbix报警邮件无法发送
情况介绍 首先确保邮箱规则没有把报警邮件作为垃圾邮件拉黑了. 服务器断电重启后,发现zabbix报警邮件无法发送,断电之前是好好的,但是重启后不行了,于是查看maillog日志,发现这个错误: Hos ...
- Spring 发送内嵌图片的邮件 遇到的问题
问题1:spring 发送带图片的html格式的邮件? 解决方法1:直接在发送内容里面添加 <img src="http://www.rgagnon.com/images/jht.gi ...
- 接口测试基础——第3篇smtplib发送带图片的邮件
smtplib发送邮件最后一篇,发送带图片的邮件: 大家可以去廖雪峰的网站看一下,下面的代码就是我跟着博客写的,哈哈,大家即使不明白为什么,也要多写两遍,记在心里,如果有不明白的地方可以留言,船长会第 ...
- 使用Zabbix服务端本地邮箱账号发送报警邮件及指定报警邮件操作记录
邮件报警有两种情况:1)Zabbix服务端只是单纯的发送报警邮件到指定邮箱,发送报警邮件的这个邮箱账号是Zabbix服务端的本地邮箱账号(例如:root@localhost.localdomain), ...
随机推荐
- 【秒懂音视频开发】14_AAC编码
AAC(Advanced Audio Coding,译为:高级音频编码),是由Fraunhofer IIS.杜比实验室.AT&T.Sony.Nokia等公司共同开发的有损音频编码和文件格式. ...
- [Fundamental of Power Electronics]-PART I-5.不连续导电模式-5.4 总结与重点
5.4 总结与重点 基本的buck,boost以及buck-boost电路的特点总结在表5.2中.其中给出了\(K_{crit}(D)\)的表达式,CCM和DCM下的变换比,以及DCM下二极管导通占空 ...
- java io系列
java io系列01之 "目录" java io系列02之 ByteArrayInputStream的简介,源码分析和示例(包括InputStream) java io系列03之 ...
- 一键生成dotnet5项目解决方案
> 作为一名从2002年.Net 1.0一路走来的老码农,也持续跟进了dotnet core 1.0~3.1的变革,并不离不弃的玩起了dotnet 5. 每次接到新项目,都要从头搭建项目解决方案 ...
- JAVAEE_Servlet_13_HttpServlet
HttpServlet 因为每次执行前端请求,都需要获取前端的请求方式,都需判断前端的请求方式和后端是否一致,随意这段代码就可以封装起来. 写一个HttpServlet类去继承GenericServl ...
- 使用docker快速安装软件
安装mysql mkdir /opt/mysql /opt/mysql/etc /opt/mysql/data docker run -itd --name mariadb -e MYSQL_ROOT ...
- 案例分析——Who is the king of handwriting notes?
案例分析--Who is the king of handwriting notes? 项目 内容 这个作业属于那个课程 2021春季学期软件工程(罗杰.任健) 这个作业的要求在哪里 案例分析 我在这 ...
- 关于CSS3背景渐变色无效问题
无效的css[linear-gradient]写法 .loginbox{ background-color: linear-gradient(#D0D0D0, #E0E0E0, white); wid ...
- pwn 好的联系网站
https://pwnable.kr/ https://w3challs.com/challenges/wargame http://overthewire.org/wargames/ http:// ...
- 逆向工程第005篇:跨越CM4验证机制的鸿沟(下)
一.前言 本文是逆向分析CM4系列的最后一篇,我会将该游戏的序列号验证机制分析完毕,进而编写出注册码生成器. 二.分析第二个验证循环 延续上一篇文章的内容,来到如下代码处: 图1 上述代码并没有特别需 ...