Skip to content

Instantly share code, notes, and snippets.

@bassdread
Created November 8, 2012 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bassdread/4039007 to your computer and use it in GitHub Desktop.
Save bassdread/4039007 to your computer and use it in GitHub Desktop.
Raid
import subprocess
import signal
import platform
class RaidMonitor:
def __init__(self, agentConfig, checksLogger, rawConfig):
self.agentConfig = agentConfig
self.checksLogger = checksLogger
self.rawConfig = rawConfig
# removes any Filesystem with Filesystem of none in df
self.dmraid = True
self.version = platform.python_version_tuple()
def run(self):
data = {}
if self.dmraid:
output = self.fetchStatus(['sudo', '/sbin/dmraid', '-r'])
volumes = output.split('\n')
for volume in volumes:
if volume:
volume = volume.split(',')
disk = volume[0].split(':')[0]
if volume[3].lstrip() == 'ok':
data[disk] = 0
else:
data[disk] = 1
# assume /proc/mdstat is being used
else:
output = self.fetchStatus(['cat', '/proc/mdstat'])
volumes = output.split('\n')
device = None
for volume in volumes:
if volume.startwiths('md'):
device = volume.split(':')[0].rstrip()
if device and volume.find('blocks') > 0:
status = volume.lstrip().split(' ')[3]
if status.find('_'):
data[device] = 0
else:
data[device] = 1
device = None
return data
def fetchStatus(self, command):
def handler(signum, frame):
raise IOError("Unable to to output from dmraid -r")
proc = subprocess.Popen(command, stdout=subprocess.PIPE, close_fds=True)
signal.signal(signal.SIGALRM, handler)
# wait 10 seconds for df to return
signal.alarm(10)
output = proc.communicate()[0]
if int(self.version[1]) >= 6:
try:
proc.kill()
except Exception, e:
pass
return output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment