利用python3 调用zabbix接口完成批量加聚合图形(screens)
在上一篇博客中,我們完成的利用python3 調(diào)用zabbix接口批量增加主機(jī),增加主機(jī)的item,增加主機(jī)的圖形!
接下來我們完成批量增加主機(jī)的screen
首先我們要增加screen需要哪些參數(shù)呢?官方的解釋如下:
{"jsonrpc": "2.0","method": "screen.create","params": {"name": "Graphs","hsize": 3,"vsize": 2,"screenitems": [{"resourcetype": 0,"resourceid": "612","rowspan": 0,"colspan": 0,}]},"auth": "038e1d7b1735c6a5436ee9eae095879e","id": 1
} ? 這里面的參數(shù)大致意思如下:
hsize:水平尺寸 ?可以簡單的理解為 這個(gè)聚合圖形最多可以有多少行
vsize:垂直尺寸 ? 同理,這個(gè)聚合圖形最多可以有多少列
resourcetye :圖形的類型 ?0 代表graph ?1 簡單graph 2 文本 。。。。
resourceid :ID of the screen that the item belongs to. 也就是說需要加入的圖形它的ID是說少
rowspan:屏幕項(xiàng)目將跨越的行數(shù)。
colspan:屏幕項(xiàng)目將跨越的列數(shù)。 ?意思就是圖形占多少行多少列 ?這里 默認(rèn)為0就行 ?不需要太大
x:
y: ?這里的x y代表的是圖形的坐標(biāo) 0 0 就是第一行第一列 ?0 1 第一行第二列 依次類推(這里需要依靠前面設(shè)置的hsize,vsize不能超過了),我在測試的時(shí)候這里面體比較大,想要把多個(gè)監(jiān)控放在一行:解決辦法是x相同y不同
auth : 認(rèn)證信息
id : 識(shí)別方法
了解了方法之后我們發(fā)現(xiàn)想要添加聚合圖形,我們得 auth ?以及 ?resourceid ?這兩個(gè)重要參數(shù)!所以我們第一步就是去找到這兩個(gè)參數(shù)!!
def __init__(self):self.url = 'http://192.168.230.164/zabbix/api_jsonrpc.php'self.headers = {'Content-Type': 'application/json'}auth = {"jsonrpc": "2.0","method": "user.login","params": {"user": "Admin", ###驗(yàn)證"password":"zfno11"},"id": 1,"auth":None,}response = requests.post(self.url, data=json.dumps(auth), headers=self.headers)print(response.text)authid = json.loads(response.text)['result'] ### auth的idprint(authid)
上面的方法得到了authid
然后獲取resourceid ?也就是圖形的ID
def get_graid(self,authid):neirong={"jsonrpc": "2.0","method": "graph.get","params": {"output": "extend","hostids": 10255,"sortfield": "name"},"auth": authid,"id": 1}response1 = requests.post(self.url, data=json.dumps(neirong), headers=self.headers)print(response1.text)
這里面需要填寫我們的hostid ?hostid的獲取方法在上一章里面已經(jīng)提到了,這里直接用就行了。
然后我們:
def create_screen(self,authid):neirong={"jsonrpc": "2.0","method": "screen.create","params": {"name": "Graphs12","hsize": 2,"vsize": 2,"screenitems": [{"resourcetype": 0,"resourceid": "790","rowspan": 2,"colspan": 2,"x" : 0,"y" : 0},{"resourcetype": 0,"resourceid": "793","x" :1,"y" :0}]},"auth": authid,"id": 1}response1 = requests.post(self.url, data=json.dumps(neirong), headers=self.headers)print(response1)print(response1.text)print("OK")
通過這樣就可以把screen的圖形加上了!
?
?
?
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/ZFBG/p/9225312.html
總結(jié)
以上是生活随笔為你收集整理的利用python3 调用zabbix接口完成批量加聚合图形(screens)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 黄山风景区的松树如什么
- 下一篇: vuex+vue-router拦截