利用python3 调用zabbix接口完成批量加聚合图形(screens)
在上一篇博客中,我們完成的利用python3 調用zabbix接口批量增加主機,增加主機的item,增加主機的圖形!
接下來我們完成批量增加主機的screen
首先我們要增加screen需要哪些參數呢?官方的解釋如下:
{"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
} ? 這里面的參數大致意思如下:
hsize:水平尺寸 ?可以簡單的理解為 這個聚合圖形最多可以有多少行
vsize:垂直尺寸 ? 同理,這個聚合圖形最多可以有多少列
resourcetye :圖形的類型 ?0 代表graph ?1 簡單graph 2 文本 。。。。
resourceid :ID of the screen that the item belongs to. 也就是說需要加入的圖形它的ID是說少
rowspan:屏幕項目將跨越的行數。
colspan:屏幕項目將跨越的列數。 ?意思就是圖形占多少行多少列 ?這里 默認為0就行 ?不需要太大
x:
y: ?這里的x y代表的是圖形的坐標 0 0 就是第一行第一列 ?0 1 第一行第二列 依次類推(這里需要依靠前面設置的hsize,vsize不能超過了),我在測試的時候這里面體比較大,想要把多個監控放在一行:解決辦法是x相同y不同
auth : 認證信息
id : 識別方法
了解了方法之后我們發現想要添加聚合圖形,我們得 auth ?以及 ?resourceid ?這兩個重要參數!所以我們第一步就是去找到這兩個參數!!
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", ###驗證"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的獲取方法在上一章里面已經提到了,這里直接用就行了。
然后我們:
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的圖形加上了!
?
?
?
?
?
轉載于:https://www.cnblogs.com/ZFBG/p/9225312.html
總結
以上是生活随笔為你收集整理的利用python3 调用zabbix接口完成批量加聚合图形(screens)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 黄山风景区的松树如什么
- 下一篇: vuex+vue-router拦截