# -*- coding: utf-8 -*-
# @File : utils.py
# 需要知悉聚合图形的id,以及确认行号列号
from pyzabbix import ZabbixAPI, ZabbixAPIException
import sys,time,datetime
class Zabbix(object):
def __init__(self):
ZABBIX_SERVER = 'http://abc.com/zabbix'
zapi = ZabbixAPI(ZABBIX_SERVER)
zapi.login('abc', 'xx')
self.zapi = zapi
def logout_2(self):
self.zapi.logout()
def get_scrrenitems(self, host):
# 获取主机
screenitems = self.zapi.screenitem.get(
screenids='137'
)
return screenitems
def create_scrrenitem(self, x,y,resourceid):
# 获取主机
print(x,y,resourceid)
screenitems = self.zapi.screenitem.create(
screenid=141, ##聚合图形的id
resourcetype=0,
resourceid=resourceid,
x=x, #第几行 不得超过聚合图形设定的行数
y=y, #第几列 不得超过聚合图形设定的列数
rowspan=1,
colspan=1,
width=300,
)
return screenitems
test=Zabbix()
screenitems=test.get_scrrenitems('')
print(screenitems)
for k in screenitems:
print(k)
sql="""SELECT graphid FROM zabbix.graphs_items where itemid in (
select itemid from zabbix.items where hostid in(
select hostid from zabbix.hosts where (name like '%MBX%' or name like '%mbx%' )
and status=0
and name like '%IIS Web Service(_Total) Current Connections%')""" ##获取MBX的current connections的图形id
#IIS connections
resourceid=['12682','12716','12801','12835','12869','13379','14540','14557','14574','14591','14608','14625','14642','14659','14676','14693','14710','14727','14744','14761','14778','14795','14812','14829','14846','14863','14880','14897','14914','20571','20786','20803','20877','20894','20911','20928','20945','20962','22353','22371','22388','22407','22424','22441','23074','23115','23557','23589']
#CPU Utilization
resourceid=['12692','12726','12811','12845','12879','13389','14550','14567','14584','14601','14618','14635','14652','14669','14686','14703','14720','14737','14754','14771','14788','14805','14822','14839','14856','14873','14890','14907','14924','20581','20796','20813','20887','20904','20921','20938','20955','20972','22363','22381','22398','22417','22434','22451','23084','23125','23567','23599']
#Delay Queue Length
resourceid=['25365','25368','25370','25372','25373','25374','25376','25377','25378','25380','25381','25382','25383','25384','25386','25390','25393','25395','25396','25397','25398','25399','25401','25402','25403','25404','25405','25406','25407','25410','25411','25415','25416','25417','25418','25419','25420','25421','25422','25423','25424','25425','25426','25427','25428','25429','25430','25506']
#Messages Queued For Delivery
resourceid=['25436','25439','25441','25443','25444','25445','25447','25448','25449','25451','25452','25453','25454','25455','25457','25461','25464','25466','25467','25468','25469','25470','25472','25473','25474','25475','25476','25477','25478','25481','25482','25486','25487','25488','25489','25490','25491','25492','25493','25494','25495','25496','25497','25498','25499','25500','25501','25507']
row_num=0
col_num=0
for i in range(len(resourceid)):
if i<3:
row_num = i%3
print(row_num,"行:",end=',')
print("第"+str(col_num)+"列:"+str(resourceid[i]))
test.create_scrrenitem(row_num,col_num,resourceid[i])
elif i%3==0:
col_num+=1
row_num = i%3
print(row_num, "行:", end=',')
print("第" + str(col_num) + "列:" + str(resourceid[i]))
test.create_scrrenitem(row_num, col_num, resourceid[i])
else:
row_num = i % 3
print(row_num, "行:", end=',')
print("第" + str(col_num) + "列:" + str(resourceid[i]))
test.create_scrrenitem(row_num, col_num, resourceid[i])
07-04
6891
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-17
765
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-05
775
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-07
679
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)