添加了 监控 mdadm 软阵列 的监控脚本

import os,re import smtplib '''config ini''' SMTP_address = 'smtp.gmail.com' SMTP_port = 587 smtp_username = '[email protected]' smtp_passwd = 'sdfsdf' alerts_mail_address = '[email protected]' server_alerts_ip = "192.168.1.243" def _get_disk_message(): diskinfo_parser = re.compile(r"(?P<Use>(/d)+)%") #diskinfo_parser = re.compile(r"(.+?)/s+(.+?)/s+(.+?)/s+(?P<Avail>.+?)/s+(?P<Use>.+?)/s+(?P<path>.+?)/s+") warning_msg = '' dp = os.popen("df -lh") while True: line = dp.readline() if not line: break info = diskinfo_parser.search(line) if(not info): continue #print info.group('Use') if(int(info.group('Use')) > 80): warning_msg += line if(warning_msg): return warning_msg return '' def _get_raid_message(): warning_msg = '' dp = os.popen("mdadm --detail /dev/md1 | grep 'Failed Devices' | awk -F : '{print $2}'") line = dp.readline() if(int(line)!=0): erdp = os.popen("mdadm --detail /dev/md1") error_msg = '' while True: line_msg = erdp.readline() if(not line_msg): break error_msg = error_msg + line_msg if(error_msg): return error_msg return '' ''' action lib ''' def mailx(send_mail,recive_mail,mail_content): mail_header_format = "From: %s/nTo: %s/nSubject: %s/n/n" % (smtp_username,alerts_mail_address,'Server:' + server_alerts_ip +' alerts!!!') mail_content_format = mail_header_format + mail_content handle = smtplib.SMTP(SMTP_address) handle.ehlo() handle.starttls() handle.ehlo() handle.login(smtp_username,smtp_passwd) handle.sendmail(send_mail,recive_mail,mail_content_format) handle.quit() if __name__ == '__main__': mail_content = '' mail_content = mail_content + _get_disk_message() mail_content = mail_content + _get_raid_message() if(mail_content): #print mail_content mailx(smtp_username,alerts_mail_address,mail_content)

 

 

 

你可能感兴趣的:(server,header,脚本,action,import,disk)