Java教程

磁盘阵列中磁盘状态监控及邮件告警

本文主要是介绍磁盘阵列中磁盘状态监控及邮件告警,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

邮件发送脚本

cat > sendMail.py << EOF
#!/usr/bin/python
#python2
#-*- coding: UTF-8 -*-
import smtplib
import sys
from email.mime.text import MIMEText
from email.utils import formataddr
#发送邮件的地址
mailHost="mail.xxx.com"
#发送邮件的用户名地址
mailUser="user@xxx.com"
#邮箱密码
mailPass="********"

#邮件格式
sender = mailUser
#接收到邮件的成员邮箱地址
receivers = ['xxxx@qq.com', 'xxxxx@qq.com']
#消息主体
message = MIMEText(sys.argv[2], "plain", "utf-8")
message['From'] = formataddr([sender, sender])
message['To'] = formataddr(receivers)
#消息主题
message['Subject'] = "'" + sys.argv[1] + " '" + 'ipfs存储磁盘告警!!!'


try:
    smtpObj = smtplib.SMTP()
    smtpObj.connect(mailHost, 25)
    smtpObj.login(mailUser, mailPass)
    smtpObj.sendmail(sender, receivers, message.as_string())
    print "发送成功!"
except smtplib.SMTPException as e :
    print e
    print "发送失败 !"
smtpObj.close()
EOF

阵列中磁盘检测脚本

cat > checkDisk.sh << EOF
#!/bin/bash
info=' '
ip=' '
function printInfo(){
info=`/opt/MegaRAID/storcli/storcli64 /call show`
}

function check(){
statu=`/opt/MegaRAID/storcli/storcli64 /call show| grep ^[0-9]|awk '{print $3}'`
count=0
for i in $statu
do
    i=`echo $i | sed 's/ //g'`
    if [ "${i}" = "Onln" ]||[ "${i}" = "Optl" ]
    then
        count=$[$count+1]
    else
        return 0
        break
    fi
done
return $count
}

function call(){
check
if [ $? = 0 ]
then
    printInfo
    hostName=`hostname`
    ip=`ip add | grep inet | awk 'NR==2{print $2}'`
    /opt/sendMail.py "${hostName} ${ip}" "${info}"
fi
}

call
EOF

下载阵列卡管理工具StorCLI

wget https://downloadmirror.intel.com/27654/eng/StorCLI_MR7.4p1.zip

解压

unzip StorCLI_MR7.4p1.zip
StorCLI_MR7.4p1
├── Cajun\ C++\ API\ for\ JSON\ license.txt
├── EFI
│   ├── Debug
│   │   └── storcli.efi
│   └── storcli.efi
├── FreeBSD
│   ├── FreeBSD_readme.txt
│   ├── license.txt
│   ├── storcli64.tar
│   └── storcli.tar
├── License_v2.pdf
├── Linux
│   ├── license.txt
│   ├── LINUX_Readme.txt
│   ├── splitpackage.sh
│   └── storcli-007.0415.0000.0000-1.noarch.rpm
├── StorCli_MR7.4_rel-notes.txt
├── Ubuntu
│   ├── read_me.txt
│   └── storcli_007.0415.0000.0000_all.deb
├── VMwareOP
│   ├── readme.txt
│   └── vmware-storcli-007.0415.0000.0000.vib
└── Windows
    ├── license.txt
    ├── storcli64.exe
    ├── storcli.exe
    └── WIN_ReadMe.txt

进入对应版本目录安装

  • centos
rpm -ivh storcli-007.0415.0000.0000-1.noarch.rpm
  • 安装好后会在MegaRAID目录下生成二进制文件
/opt/
├── checkDisk.sh
├── dayDisk.sh
├── MegaRAID
│   ├── MegaCli
│   │   ├── install.log
│   │   ├── libstorelibir-2.so -> /opt/MegaRAID/MegaCli/libstorelibir-2.so.14.07-0
│   │   ├── libstorelibir-2.so.14.07-0
│   │   └── MegaCli64
│   └── storcli
│       ├── install.log
│       └── storcli64

测试

/opt/MegaRAID/storcli/storcli64 /call show
Generating detailed summary of the adapter, it may take a while to complete.

CLI Version = 007.0415.0000.0000 Feb 13, 2018
Operating system = Linux 3.10.0-prsys.2.0.0.0.x86_64
Controller = 0
Status = Success
Description = None
..................
.................
..............
.........
.....
...
这篇关于磁盘阵列中磁盘状态监控及邮件告警的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!