Monitoring HP Raid Array on Ubuntu Server

I wanted to monitor our HP server raid array on Ubuntu 12.04.  I  am sure that there is a good way of setting this up with Nagios or SMNP – however, I thought I would write a little bash script which emails me if any of the hard drives in the raid array fail.  I assume that you have already installed the HP Proliant Support Pack perhaps using these instructions.

To send an email from command line you will also need mailx.  This is a virtual package on Ubuntu and I tend to install bsd-mailx.  To install it run:

sudo apt-get install bsd-mailx

It will also install Postfix (if this isn’t already setup).  When configuring Postfix, I selected “Internet Site” and entered the hostname of the server.

Here is the bash script that I wrote.  The indentation seems to have got lost but you should be able to recreate it.

#!/bin/bash

# Email settings
email_recipient=”your.email@somewhere.com”

# Current datetime in YYYY-MM-DD_HH-MM-SS
date=`date +”%Y-%m-%d_%H-%M-%S”`

# Make sure the log directory exists.
/bin/mkdir -p /root/harddrive_check/log

log_filename=”/root/harddrive_check/log/$date.log”

hostname=`hostname`

if hpacucli ctrl all show config | grep -q “Failed”; then

echo -e “Harddrive Check Run: `date`” > $log_filename

echo -e “\nUsing Command: hpacucli ctrl all show config” >> $log_filename

hpacucli ctrl all show config >> $log_filename

email_subject=”Harddrive Failed On $hostname”

/usr/bin/mailx -s “$email_subject” “$email_recipient” < $log_filename

fi

I then setup a cronjob on the server.

crontab -e

Adding the line:

0 * * * * /root/harddrive_check.sh

I hope this is helpful to someone.  Let me know if you know a better way of doing this. Thanks for reading.

Leave a Reply