Get email Notifications From an HP Smart Array Raid Controller on Ubuntu

I wanted to get notified about the status of my raid array, so I...

Posted on March 7, 2015

I have an older HP Proliant server with Ubunut 14.04 installed. I switched from using mdadm to the onboard P400 Smart Array Controller for my raid setup. I needed a way to get notifications out whenever drive failure occurs. If you find yourself in a similar situation, then this is what you do:

Pre-requisite:

You need a mail server running. Something like postfix and mailutils will work: sudo apt-get install postfix mailutils

Getting the HP Proliant tools:

First, you need to get the command line tool from hp. The old command-line tool was hpacucli. but that has been replaced with hpssacli. The easiest way to get that tool, and others is to edit your /etc/apt/sources.list and add:

deb http://downloads.linux.hp.com/downloads/ManagementComponentPack/ubuntu trusty current/non-free

Then run, sudo apt-get update

followed by, sudo apt-get install hpssacli

The command-line tool has a bit of a learning curve, but it's really not that bad once you understand the syntax.

Type sudo hpssacli to get started. You can then find your slot number using this command: => ctrl all show

Email Script

Once you have the tool installed you can create a script such as array_health.sh that can check the status of your array(s). This will generate an html email whenever it detects an issue.

#!/bin/sh
SLOT="2" # Your controller slot number
ARRAY=( "A" "B" ) # Your array letters. If you have only one: ARRAY=( "A" )
EMAIL="you@yourserver.com" # You can put your e-mail address here

This function is called if checks don't pass. Send e-mail.

Notify()
{
SUBJECT=$1
{
echo "<h3>$SUBJECT</h3>"
echo
echo "<small>Check date: "
echo $(date +"%F %T%:::z")
echo "</small><hr>"
echo "<p><strong>Controller Status:</strong><hr>"
echo "<pre>"
hpssacli ctrl slot=$SLOT show
echo "</pre></p>"

echo "<p><strong>Array Status:</strong><hr>"
for i in "${ARRAY[@]}"
do
echo "<pre>"
hpssacli ctrl slot=$SLOT array $i show
echo "</pre>"
done
echo "</p>"

echo "<p><strong>Physical Drives:</strong><hr>"
echo "<pre>"
hpssacli ctrl slot=$SLOT physicaldrive all show
echo "</pre>"
echo "<p><strong>Physical Drive Details:</strong><hr>"
echo "<pre>"
for DRIVE in $(hpssacli ctrl slot=$SLOT physicaldrive all show | grep physicaldrive | awk '{ print $2 }')
do
hpssacli ctrl slot=$SLOT physicaldrive $DRIVE show
done
echo "</pre></p>"
} | mail -s "$(echo -e "$SUBJECT\nContent-Type: text/html")" $EMAIL
}

Now, Check that there's a line saying 'Controller Status: OK' etc.

hpssacli ctrl slot=$SLOT show status \
| grep -q 'Controller Status: OK' \
|| Notify "Smart Array CONTROLLER FAILURE at $(hostname)"
hpssacli ctrl slot=$SLOT show status \
| grep -q 'Cache Status: OK' \
|| Notify "Smart Array CACHE FAILURE at $(hostname)"
hpssacli ctrl slot=$SLOT show status \
| grep -q 'Battery/Capacitor Status: OK' \
|| Notify "Smart Array BATTERY FAILURE at $(hostname)"
hpssacli ctrl slot=$SLOT array $ARRAY show \
| grep -q 'Status: OK' \
|| Notify "Smart Array ARRAY FAILURE at $(hostname)"
# This is for testing:
#Notify "This is a test"

Then setup this script in a cron to run as often as you like, like every 4 hours. Don't forget to chmod +x your script!


← Return