Skip to content

Instantly share code, notes, and snippets.

@troeger
Last active September 6, 2016 18:29
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 troeger/b12d13d8a4c8c0892e3556548b02dd41 to your computer and use it in GitHub Desktop.
Save troeger/b12d13d8a4c8c0892e3556548b02dd41 to your computer and use it in GitHub Desktop.
Draft for a Python script that checks an Adaptec HW RAID controller through the arcconf utility
#!/usr/bin/python
'''
Check status of an Adaptec HW RAID controller and sends an email
if something looks bad.
Intended for being used as cron job, so no screen output is generated.
'''
# Configuration section
notify_email="root"
# Code starts here
from subprocess import check_output
import smtplib
from email.message import Message
def find_problem(cmdline, key, expected):
''' Check if the key has the expected value, otherwise return the different one. '''
output=check_output(cmdline, shell=True).splitlines()
data=[line.split(':',1) for line in output if ' : ' in line]
data={k.strip():v.strip() for (k,v) in data}
if data[key] != expected:
msg=Message()
msg.set_payload('%s == %s, not "%s"'%(key, data[key], expected))
msg['Subject'] = '[RAID Warning] Bad news from arcconf'
msg['From'] = notify_email
msg['To'] = notify_email
s = smtplib.SMTP('localhost')
s.sendmail(notify_email, notify_email, msg.as_string())
s.quit()
return data[key]
else:
return None
find_problem('arcconf GETCONFIG 1 AD', 'Controller Status', 'Optimal')
find_problem('arcconf GETCONFIG 1 LD', 'Status of Logical Device', 'Optimal')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment