forked from alt-dima/zabbix-glusterfs
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gstatus_discovery.py
executable file
·42 lines (34 loc) · 1.1 KB
/
gstatus_discovery.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
#!/usr/bin/python3
import json
import subprocess
import sys
gluster_volume_names = []
gstatus_output = subprocess.check_output('gstatus -a -o json ', shell=True).decode()
gluster_info = json.loads(gstatus_output)
volume_list = gluster_info["data"]["volume_summary"]
nargs = len(sys.argv)
if nargs == 1:
for volume in volume_list:
gluster_volume_names.append({"{#VOLUME_NAME}": volume["name"]})
print(json.dumps({'data': gluster_volume_names}))
elif nargs == 2:
print(gluster_info["data"][sys.argv[1]])
elif nargs == 3:
for volume in volume_list:
if volume.get('name') and sys.argv[2] == volume["name"]:
if sys.argv[1] == "nr_entries":
healinfo_list=volume["healinfo"]
nrents = 0
for heal in healinfo_list:
nrents += int(heal["nr_entries"])
print(nrents)
else:
print(json.dumps(volume[sys.argv[1]]))
break
else:
if sys.argv[1] == "health":
print('down')
else:
print()
else:
print('Wrong arguments')