-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_h700_status.py
109 lines (98 loc) · 3.71 KB
/
check_h700_status.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
####################################################################################
# H700 Raid卡磁盘监控 FOR Zabbix
#
# 用法:
# UserParameter=raid.h700[*],/usr/local/etc/scripts/check_h700_status.py $1
####################################################################################
#! /usr/bin/python
# -*- coding: utf-8 -*-
import os, sys
def getH700Status():
infos = {}
popShell = os.popen("sudo MegaCli -LDPDInfo -aall | egrep 'State|Current Cache Policy|Firmware state|Slot Number|Count:' | grep -v 'Foreign State'")
popShellResult = popShell.read()
popShell.close()
arrayInfo = popShellResult.split('\n')
del arrayInfo[len(arrayInfo) - 1]
infos['State'] = arrayInfo[0].split(':')[1].replace(' ', '')
infos['Current Cache Policy'] = arrayInfo[1].split(':')[1].split(',')[0].replace(' ', '')
i = 2
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
infos['Disk'] = disk
# 返回一个dict
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:
print 'Code:1 Info:有%d块磁盘同时存在Media Error'%(len(eMediaStr))
else:
print '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:
print 'Code:1 Info:有%d块磁盘存在Other Error'%(len(eOtherStr))
else:
print '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:
print 'Code:1 Info:有%d块磁盘存在Predictive Failure %s'%(len(pStr), pStr)
else:
print '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)
print 'Code:1 Info:%s %s'%(obj['State'], oStr)
else:
print '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'])
print errSum
def printCache(obj):
if obj['Current Cache Policy'] != 'WriteBack':
print 'Code:1 Info:%s'%(obj['Current Cache Policy'])
else:
print 'Code:0 Info:%s'%(obj['Current Cache Policy'])
if __name__ == '__main__':
obj = getH700Status()
if sys.argv[1] == 'Media Error':
printMediaError(obj)
elif sys.argv[1] == 'Other Error':
printOtherError(obj)
elif sys.argv[1] == 'Predictive Failure':
printPredictiveFailure(obj)
elif sys.argv[1] == 'State':
printState(obj)
elif sys.argv[1] == 'Sum Error':
printSumError(obj)
elif sys.argv[1] == 'Cache':
printCache(obj)
else:
print "Usage: check_h700_status.py 'Media Error'|'Other Error'|'Predictive Failure'|'State'|'Sum Error'|'Cache'"