磁碟陣列中磁碟狀態監控及郵件告警
阿新 • • 發佈:2021-06-30
郵件傳送指令碼
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="[email protected]" #郵箱密碼 mailPass="********" #郵件格式 sender = mailUser #接收到郵件的成員郵箱地址 receivers = ['[email protected]', '[email protected]'] #訊息主體 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
..................
.................
..............
.........
.....
...