-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
53 lines (50 loc) · 1.16 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import requests
from pprint import pprint
import json
ZABIX_ROOT = '**********'
url = ZABIX_ROOT + '/api_jsonrpc.php'
########################################
# user.login
########################################
payload = {
"jsonrpc" : "2.0",
"method" : "user.login",
"params": {
'user': '*******',
'password': '******',
},
"auth" : None,
"id" : 0,
}
headers = {
'content-type': 'application/json',
}
res = requests.post(url, data=json.dumps(payload), headers=headers)
res = res.json()
print ('user.login response')
pprint(res)
########################################
# host.get
########################################
payload = {
"jsonrpc": "2.0",
"method": "item.get",
"params": {
"output": "extend",
"hostids": "10105",
"search": {
"key_": "StatusBE1"
},
"sortfield": "name"
},
"auth" : res['result'],
"id" : 2,
}
res2 = requests.post(url, data=json.dumps(payload), headers=headers)
res2 = res2.json()
print ('host.get response')
pprint(res2['result'])
print(type(res2['result'][0]))
for i, v in res2['result'][0].items():
if 'snmp' in i:
print(i, v)