-
Notifications
You must be signed in to change notification settings - Fork 2
/
infinibox_zabbix.py
155 lines (133 loc) · 5.53 KB
/
infinibox_zabbix.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env python
__author__ = "Igor Sidorenko"
__email__ = "[email protected]"
__status__ = "Production"
import json
import sys, requests, time, os, urllib3
from datetime import datetime
from requests.auth import HTTPBasicAuth
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
login = ''
password = ''
# lld for Zabbix
if len(sys.argv) == 3:
ip = str(sys.argv[1])
item = str(sys.argv[2])
r = requests.get('https://'+ip+'/api/rest/'+item+'/', auth=HTTPBasicAuth(login,password), verify=False)
data = r.json()
jdata = []
# Get all Service Status
if item == "services":
for id in data['result']:
jdata.append({"{#NAME}":id['name']})
print(json.dumps({"data":jdata}))
# Else
else:
for id in data['result']:
jdata.append({"{#NAME}":id['name'], "{#ID}": id['id']})
print(json.dumps({"data":jdata}))
# System performance metrics
elif len(sys.argv) == 4:
ip = str(sys.argv[1])
item = str(sys.argv[2])
key = str(sys.argv[3])
if item == "system":
r = requests.get('https://'+ip+'/api/rest/counters/'+item+'/total/', auth=HTTPBasicAuth(login,password), verify=False)
data = r.json()
print (data['result'][key])
# State, space, capacityy, enclosures
elif len(sys.argv) == 5:
ip = str(sys.argv[1])
item = str(sys.argv[2])
itemid = str(sys.argv[3])
key = str(sys.argv[4])
if item == "pools" or item == "volumes" or item == "filesystems":
r = requests.get('https://'+ip+'/api/rest/'+item+'/'+itemid+'/', auth=HTTPBasicAuth(login,password), verify=False)
data = r.json()
print (data['result'][key])
# Get enclosures ID
elif item == "racks" and key == "enclosures":
r = requests.get('https://'+ip+'/api/rest/components/'+item+'/'+itemid+'/'+key+'/', auth=HTTPBasicAuth(login,password), verify=False)
data = r.json()
jdata = []
for id in data['result']:
jdata.append({"{#ID}": id['id']})
print(json.dumps({"data":jdata}))
# Get the Rack Nodes
elif item == "racks" and key == "nodes":
r = requests.get('https://'+ip+'/api/rest/components/'+item+'/'+itemid+'/'+key+'/', auth=HTTPBasicAuth(login,password), verify=False)
data = r.json()
jdata = []
for id in data['result']:
jdata.append({"{#ID}": id['id']})
print(json.dumps({"data":jdata}))
# Get all Upss
elif item == "racks" and key == "ups":
r = requests.get('https://'+ip+'/api/rest/components/'+item+'/'+itemid+'/'+key+'/', auth=HTTPBasicAuth(login,password), verify=False)
data = r.json()
jdata = []
for id in data['result']:
jdata.append({"{#ID}": id['id']})
print(json.dumps({"data":jdata}))
# Get Service Status
elif item == "services":
r = requests.get('https://'+ip+'/api/rest/'+item+'/'+itemid+'/', auth=HTTPBasicAuth(login,password), verify=False)
data = r.json()
print (data['result'][key])
# Perfomance metrics
elif len(sys.argv) == 6:
ip = str(sys.argv[1])
counter = str(sys.argv[2])
item = str(sys.argv[3])
itemid = str(sys.argv[4])
key = str(sys.argv[5])
# Get Host Counters Total
if counter == "counters" and item == "hosts":
r = requests.get('https://'+ip+'/api/rest/counters/'+item+'/'+itemid+'/total/', auth=HTTPBasicAuth(login,password), verify=False)
data = r.json()
print (data['result'][key])
# Get Total IO Counters for a Volume
if counter == "counters" and item == "volumes":
r = requests.get('https://'+ip+'/api/rest/counters/'+item+'/'+itemid+'/total/', auth=HTTPBasicAuth(login,password), verify=False)
data = r.json()
print (data['result'][key])
elif len(sys.argv) == 7:
ip = str(sys.argv[1])
component = str(sys.argv[2])
rack= str(sys.argv[3])
item = str(sys.argv[4])
itemid = str(sys.argv[5])
key = str(sys.argv[6])
# Get Enclosure by ID
if component == "racks" and item == "enclosures":
r = requests.get('https://'+ip+'/api/rest/components/'+component+'/'+rack+'/'+item+'/'+itemid+'', auth=HTTPBasicAuth(login,password), verify=False)
data = r.json()
if key == "power_supplies1":
for id in data['result']['power_supplies']:
if id['id'] == 1:
print (id['state'])
elif key == "power_supplies2":
for id in data['result']['power_supplies']:
if id['id'] == 2:
print (id['state'])
elif key != "power_supplies2" and key != "power_supplies2":
print (data['result'][key])
# Get Rack Node by ID
if component == "racks" and item == "nodes":
r = requests.get('https://'+ip+'/api/rest/components/'+component+'/'+rack+'/'+item+'/'+itemid+'', auth=HTTPBasicAuth(login,password), verify=False)
data = r.json()
if key == "power_supplies1":
for id in data['result']['power_supplies']:
if id['id'] == 1:
print (id['state'])
elif key == "power_supplies2":
for id in data['result']['power_supplies']:
if id['id'] == 2:
print (id['state'])
elif key != "power_supplies2" and key != "power_supplies2":
print (data['result'][key])
# Get Ups by ID
if component == "racks" and item == "ups":
r = requests.get('https://'+ip+'/api/rest/components/'+component+'/'+rack+'/'+item+'/'+itemid+'', auth=HTTPBasicAuth(login,password), verify=False)
data = r.json()
print (data['result'][key])