-
Notifications
You must be signed in to change notification settings - Fork 9
/
check_lsimpt.py
91 lines (82 loc) · 3.17 KB
/
check_lsimpt.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
#!/usr/bin/python
#
# check_mptsas - A Nagios check for MPT RAID controllers with more than one volume.
#
import pexpect
import re
import sys
EXIT_OK = 0
EXIT_CRIT = 1
EXIT_WARN = 2
EXIT_UNKNOWN = 3
# Set logfile to sys.stdout if you want to see the output of the child program
logfile = None
# The path to the lsiutil binary
binary = '/usr/sbin/lsiutil'
def getNumVols():
child = pexpect.spawn (binary,logfile=logfile)
# Get to the RAID menu and get the number of configured volumes
child.expect ('Select a device: \[[^-]+-[^-]+ or 0 to quit\]')
child.sendline('1')
child.expect ('Main menu, select an option: \[[^-]+-[^-]+ or e/p/w or 0 to quit\]')
child.sendline('21')
child.expect ('RAID actions menu, select an option: \[[^-]+-[^-]+ or e/p/w or 0 to quit\]')
child.sendline('1')
child.expect ('(\d+) volume(s are| is) active, (\d+) physical disks are active')
numVols,ignore,numPhys = child.match.groups()
child.kill
return int(numVols),int(numPhys)
def getVolStatusMulti(volID):
child = pexpect.spawn (binary,logfile=logfile)
# Get to the RAID menu to get the volume status
child.expect('Select a device: \[[^-]+-[^-]+ or 0 to quit\]')
child.sendline('1')
child.expect ('Main menu, select an option: \[[^-]+-[^-]+ or e/p/w or 0 to quit\]')
child.sendline('21')
child.expect ('RAID actions menu, select an option: \[[^-]+-[^-]+ or e/p/w or 0 to quit\]')
child.sendline('3')
child.expect ('Volume: \[[^-]+-[^-]+ or RETURN to quit\]')
child.sendline(str(volID))
child.expect ('Volume %d State: ([^,]+), ([^\W]+)' % (volID))
state,enablestate = child.match.groups()
child.kill
return [state,enablestate]
def getVolStatusSingle():
child = pexpect.spawn (binary,logfile=logfile)
# Get to the RAID menu to get the volume status
child.expect('Select a device: \[[^-]+-[^-]+ or 0 to quit\]')
child.sendline('1')
child.expect ('Main menu, select an option: \[[^-]+-[^-]+ or e/p/w or 0 to quit\]')
child.sendline('21')
child.expect ('RAID actions menu, select an option: \[[^-]+-[^-]+ or e/p/w or 0 to quit\]')
child.sendline('3')
child.expect ('Volume 0 State: ([^,]+), ([^\W]+)')
state,enablestate = child.match.groups()
child.kill
return [state,enablestate]
# Set some variables we can re-assign when checking the disk states
enabledVols = 0
pre_exit = EXIT_OK
exit_msg = 'OK:'
msg = ''
numVols,numPhys = getNumVols()
if numVols == 1:
enabledVols = 1
volState = getVolStatusSingle()
msg = msg + ' Volume 0: %s.' % (volState[0])
if volState[0] != 'optimal':
pre_exit = EXIT_CRIT
exit_msg = 'CRITICAL:'
else:
for x in range(numVols):
volState = getVolStatusMulti(x)
if volState[1] != 'enabled':
# The volume is not enabled, so we do not care about the state.
continue
enabledVols += 1
msg = msg + ' Volume %d: %s.' % (x,volState[0])
if volState[0] != 'optimal':
pre_exit = EXIT_CRIT
exit_msg = 'CRITICAL:'
print exit_msg + ' %d Volumes configured, %d Volumes enabled. %d Physical Disks used.' % (numVols, enabledVols, numPhys) + msg
sys.exit(pre_exit)