nagios_client: make check_raid python 2/3 compatible
Signed-off-by: Francois Andrieu <naolwen@gmail.com>
This commit is contained in:
parent
e071a55d7e
commit
30d704f486
1 changed files with 8 additions and 10 deletions
|
@ -1,16 +1,15 @@
|
||||||
#!/usr/bin/python2
|
#!/usr/bin/python
|
||||||
#
|
#
|
||||||
# very simple python script to parse out /proc/mdstat
|
# very simple python script to parse out /proc/mdstat
|
||||||
# and give results for nagios to monitor
|
# and give results for nagios to monitor
|
||||||
#
|
#
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import string
|
|
||||||
|
|
||||||
devices = []
|
devices = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mdstat = string.split(open('/proc/mdstat').read(), '\n')
|
mdstat = open('/proc/mdstat').read().split('\n')
|
||||||
except IOError:
|
except IOError:
|
||||||
# seems we have no software raid on this machines
|
# seems we have no software raid on this machines
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
@ -19,12 +18,12 @@ error = ""
|
||||||
i = 0
|
i = 0
|
||||||
for line in mdstat:
|
for line in mdstat:
|
||||||
if line[0:2] == 'md':
|
if line[0:2] == 'md':
|
||||||
device = string.split(line)[0]
|
device = line.split()[0]
|
||||||
devices.append(device)
|
devices.append(device)
|
||||||
status = string.split(mdstat[i+1])[-1]
|
status = mdstat[i+1].split()[-1]
|
||||||
if string.count(status, "_"):
|
if status.count("_"):
|
||||||
# see if we can figure out what's going on
|
# see if we can figure out what's going on
|
||||||
err = string.split(mdstat[i+2])
|
err = mdstat[i+2].split()
|
||||||
msg = "device=%s status=%s" % (device, status)
|
msg = "device=%s status=%s" % (device, status)
|
||||||
if len(err) > 0:
|
if len(err) > 0:
|
||||||
msg = msg + " rebuild=%s" % err[0]
|
msg = msg + " rebuild=%s" % err[0]
|
||||||
|
@ -36,10 +35,9 @@ for line in mdstat:
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
|
||||||
if not error:
|
if not error:
|
||||||
print "DEVICES %s OK" % " ".join(devices)
|
print("DEVICES %s OK" % " ".join(devices))
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print error
|
print(error)
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue