-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_h700_status_plus.py
126 lines (115 loc) · 4.64 KB
/
check_h700_status_plus.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
#######################################################################################
# H700 Raid卡磁盘监控扩展版(包括对多个Virtual Drive进行检查) FOR Zabbix
#
# 用法:
# UserParameter=raid.h700[*],/usr/local/etc/scripts/check_h700_status_plus.py $1
#######################################################################################
#! /usr/bin/python
# -*- coding: utf-8 -*-
import os, sys
def formatList(list):
info = {}
arrayInfo = list.split('\n')
del arrayInfo[len(arrayInfo) - 1]
info['Virtual Drive'] = arrayInfo[0].split(' ')[0]
info['State'] = arrayInfo[1].split(':')[1].replace(' ', '')
info['Current Cache Policy'] = arrayInfo[2].split(':')[1].split(',')[0].replace(' ', '')
i = 3
disk = []
while(i < len(arrayInfo)):
tempDisk = {}
for x in arrayInfo[i:i+5]:
tempDisk[x.split(':')[0]] = x.split(':')[1].split(',')[0].replace(' ', '')
disk.append(tempDisk)
i = i + 5
info['Disk'] = disk
# 返回一个dict
return info
def getH700Status():
infos = []
popShell = os.popen("sudo MegaCli -LDPDInfo -aall | egrep 'Virtual Drive|State|Current Cache Policy|Firmware state|Slot Number|Count:' | egrep -v 'Foreign State|Media Type'")
popShellResult = popShell.read()
popShell.close()
tempFormat = popShellResult.split('Virtual Drive: ')
del tempFormat[0]
for i in range(len(tempFormat)):
infos.append(formatList(tempFormat[i]))
# 返回一个list
return infos
def printMediaError(obj):
eMediaStr = []
for i in obj['Disk']:
if int(i['Media Error Count']) <> 0:
eMediaStr.append(i['Media Error Count'])
if len(eMediaStr) > 1:
return 'Code:1 Info:有%d块磁盘同时存在Media Error'%(len(eMediaStr))
else:
return 'Code:0 Info:没有同时存在Media Error的磁盘'
def printOtherError(obj):
eOtherStr = []
for i in obj['Disk']:
if int(i['Other Error Count']) <> 0:
eOtherStr.append(i['Other Error Count'])
if len(eOtherStr) > 1:
return 'Code:1 Info:有%d块磁盘存在Other Error'%(len(eOtherStr))
else:
return 'Code:0 Info:没有同时存在Other Error的磁盘'
def printPredictiveFailure(obj):
pStr = []
for i in obj['Disk']:
if int(i['Predictive Failure Count']) <> 0:
tempObj2 = {}
tempObj2[i['Slot Number']] = i['Predictive Failure Count']
pStr.append(tempObj2)
if len(pStr) > 0:
return 'Code:1 Info:有%d块磁盘存在Predictive Failure %s'%(len(pStr), pStr)
else:
return 'Code:0 Info:没有磁盘存在Predictive Failure'
def printState(obj):
if obj['State'] != 'Optimal':
oStr = []
for i in obj['Disk']:
if i['Firmware state'] != 'Online':
tempObj1 = {}
tempObj1[i['Slot Number']] = i['Firmware state']
oStr.append(tempObj1)
return 'Code:1 Info:%s %s'%(obj['State'], oStr)
else:
return 'Code:0 Info:%s'%(obj['State'])
def printSumError(obj):
errSum = 0
for i in obj['Disk']:
if int(i['Media Error Count']) <> 0:
errSum += int(i['Media Error Count'])
if int(i['Other Error Count']) <> 0:
errSum += int(i['Other Error Count'])
return errSum
def printCache(obj):
if obj['Current Cache Policy'] != 'WriteBack':
return 'Code:1 Info:%s'%(obj['Current Cache Policy'])
else:
return 'Code:0 Info:%s'%(obj['Current Cache Policy'])
if __name__ == '__main__':
obj = getH700Status()
if sys.argv[1] == 'Media Error':
for i in range(len(obj)):
print 'Virtual Drive:%s %s'%(obj[i]['Virtual Drive'], printMediaError(obj[i]))
elif sys.argv[1] == 'Other Error':
for i in range(len(obj)):
print 'Virtual Drive:%s %s'%(obj[i]['Virtual Drive'], printOtherError(obj[i]))
elif sys.argv[1] == 'Predictive Failure':
for i in range(len(obj)):
print 'Virtual Drive:%s %s'%(obj[i]['Virtual Drive'], printPredictiveFailure(obj[i]))
elif sys.argv[1] == 'State':
for i in range(len(obj)):
print 'Virtual Drive:%s %s'%(obj[i]['Virtual Drive'], printState(obj[i]))
elif sys.argv[1] == 'Sum Error':
sumErr = 0
for i in range(len(obj)):
sumErr += printSumError(obj[i])
print sumErr
elif sys.argv[1] == 'Cache':
for i in range(len(obj)):
print 'Virtual Drive:%s %s'%(obj[i]['Virtual Drive'], printCache(obj[i]))
else:
print "Usage: check_h700_status.py 'Media Error'|'Other Error'|'Predictive Failure'|'State'|'Sum Error'|'Cache'"