#__coding:utf-8__
import sys
import datetime
import cookielib, urllib2,urllib
class ZabbixGraph(object):
def __init__(self,url,name,password):
self.url=url
self.name=name
self.password=password
#初始化的时候生成cookies
cookiejar = cookielib.CookieJar()
urlOpener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
values = {"name":self.name,'password':self.password,'autologin':1,"enter":'Sign in'}
data = urllib.urlencode(values)
request = urllib2.Request(url, data)
try:
urlOpener.open(request,timeout=10)
self.urlOpener=urlOpener
except urllib2.HTTPError, e:
print e
def GetGraph(self,url,values,p_w_picpath_dir):
key=values.keys()
if "graphid" not in key:
print u"请确认是否输入graphid"
sys.exit(1)
#以下if 是给定默认值
if "period" not in key :
#默认获取一天的数据,单位为秒
values["period"]=86400
if "stime" not in key:
#默认为当前时间开始
values["stime"]=datetime.datetime.now().strftime('%Y%m%d%H%M%S')
if "width" not in key:
values["width"]=800
if "height" not in key:
values["height"]=200