-
Notifications
You must be signed in to change notification settings - Fork 2
/
check_minio.py
61 lines (50 loc) · 2.21 KB
/
check_minio.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
#!/usr/bin/env python3
import subprocess
import json
from pprint import pprint
status_strings = ['OK','WARNING','CRITICAL','UNKNOWN']
#/opt/mc/mc admin info --json minio
#out=subprocess.run(['/opt/mc/mc','admin','info','--json','minio'])
# need --insecure with recent mc clients and self-signed certs
out=subprocess.check_output(['/opt/mc/mc','admin','info','--insecure','--json','minio'])
# default to OK
status = 0
#print(out)
minioInfo = json.loads(out)
#pprint(minioInfo)
# global mode
# alert if not "online"
clusterModeString = 'cluster: ' + minioInfo['info']['mode']
if (minioInfo['info']['mode'] != 'online'):
# not sure what other states are possible, some might be warning only
status = 2
serverStateString = ''
driveStateString = ''
for server in (minioInfo['info']['servers']):
# server state; alert if not "ok"
serverStateString += ' ' + server['endpoint'] + ' : ' + server['state']
if (server['state'] != 'ok'):
# not sure what other states are possible, some might be warning only
status = 2
for drive in (server['drives']):
# if there's an unformatted drive on a remote, it has only these keys
# if there's a healthy drive on a remote, or an unformatted drive on the
# serving instance, there is a path key as well
# so...construct an endpoint from server['endpoint']+drive['path']
# and if drive['path'] doesn't exist, use drive['endpoint']
try:
driveEndpoint = server['endpoint'] + ':' + drive['path']
except:
# try to strip leading "https:" from this to be consistent with above
driveEndpoint = drive['endpoint'].replace('https://','')
# drive state; alert if not "ok"
if (drive['state'] != 'ok' or 'healing' in drive):
# assume a missing drive is not critical
status = 1
driveExtraInfo = ''
if ('healing' in drive):
driveExtraInfo = '(healing)'
# since there are so many drives, only add unhealthy ones to output
driveStateString += ' ' + driveEndpoint + ' : ' + drive['state'] + ' ' + driveExtraInfo
print ("%d Minio_status - %s - %s %s %s" % (status, status_strings[status], clusterModeString, serverStateString, driveStateString) )
exit (status)