Last active
September 6, 2016 18:29
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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