In Linux, monitoring for a MegaRaid controller can be done using MegaCLI tools.
Some prerequisites for it are required, let’s install them.
For Debian like systems:
apt install mailutils postfix libncurses5 alien vim unzip wget
For CentOS like systems:
yum install mailx postfix ncurses-devel vim unzip wget
Then let’s download MegaCLI sources, extract, install it and clean-up.
For Debian like systems:
cd /opt wget https://docs.broadcom.com/docs-and-downloads/raid-controllers/raid-controllers-common-files/8-07-14_MegaCLI.zip unzip 8-07-14_MegaCLI.zip cd Linux alien MegaCli-8.07.14-1.noarch.rpm dpkg -i megacli_8.07.14-2_all.deb cd .. rm -rf 8.07.14_MegaCLI.txt 8-07-14_MegaCLI.zip DOS/ FreeBSD/ Linux/ Solaris/ Windows/
For CentOS like systems:
cd /opt wget https://docs.broadcom.com/docs-and-downloads/raid-controllers/raid-controllers-common-files/8-07-14_MegaCLI.zip unzip 8-07-14_MegaCLI.zip cd Linux rpm -i MegaCli-8.07.14-1.noarch.rpm cd .. rm -rf 8.07.14_MegaCLI.txt 8-07-14_MegaCLI.zip DOS/ FreeBSD/ Linux/ Solaris/ Windows/
Create a link for easier access:
ln -s /opt/MegaRAID/MegaCli/MegaCli64 /bin/megacli
Check the actual status for disks:
/bin/megacli -PDList -aALL |grep "Drive has flagged a S.M.A.R.T alert"
Normally it will indicate “Drive has flagged a S.M.A.R.T alert : No” for each disk.
Create the script for monitoring:
vim /opt/raidmon.sh
Put the content:
#!/bin/bash set -ex RESP=$(/bin/megacli -PDList -aALL |grep "Drive has flagged a S.M.A.R.T alert") SUBJ="RAID status on server.example.com" echo "$RESP" | mail -a "From: monitoring@server.example.com" -s "$SUBJ" your@mailaddress.com
Make the script executable:
chmod 700 /opt/raidmon.sh
Add a cronjob to execute the script periodically:
crontab -e
First time when you edit the crontab it will ask to choose an editor, choose 2 and hit Enter:
Select an editor. To change later, run 'select-editor'. 1. /bin/nano <---- easiest 2. /usr/bin/vim.basic 3. /usr/bin/mcedit 4. /usr/bin/vim.tiny Choose 1-4 [1]: 2
For me it was enough to get an update daily (at 12:04 AM):
4 0 * * * /bin/sh /opt/raidmon.sh
But it can be easily updated to notify only in case of issues:
#!/bin/bash set -ex RESP=$(/bin/megacli -PDList -aALL |grep "Drive has flagged a S.M.A.R.T alert") SUBJ="RAID status alert" if [[ "$RESP" == *"Yes"* ]]; then echo "$RESP" | mail -a "From: monitoring@server.example.com" -s "$SUBJ" your@mailaddress.com done
Set the crontab to run it every minute:
* * * * * /bin/sh /opt/raidmon.sh