PDA

View Full Version : HOWTO :: Script to Monitor functionality of Software RAID1


royong
20-04-2006, 00:42
Disclaimer :: While I take precaution to avoid any unnecessary errata, the reader is advised to perform his / her own backups. I accept no warranties, expressed or implied, with regards to any malfunction, damage, loss, deletion, removal etc. of any form, nor shall I be liable for any damages. This HOWTO has been tested on machines running Red Hat 7.2 / 7.3 / 8.0 - but as usual you are expected to practice due diligence.

Log into the server and as ROOT perform the following :-


cd /
cd etc
mkdir raidcheck
cd raidcheck
vi raidgetstatus.sh
#!/bin/sh
# filename: raidgetstatus.sh
# get active raid status
# version 1.03 4-18-00
/bin/cat /proc/mdstat | /bin/grep active
Press ":wq" to save and quit.
Next perform the following:

vi raidcheck.sh
#! /bin/sh
# filename: raidcheck.sh
# Version: 1.02 8-7-99 Michael A. Robinton
#
# Amended as required by Roy Ong
#
# raidcheck.sh This file must be executed periodically by cron
# It will check the raid status and e-mail a message if
# a status error is detected.
#
# USAGE: raidcheck.sh e-mail@addr {where to send error msg}
#
MAILTO=$1
SENDMAILCMD="/usr/lib/sendmail -t -oi -O DeliveryMode=background"
RAIDHOST=`/bin/hostname`
DATE=`/bin/date`

# you must have issued
# raidgetstatus.sh >raidgood
# in the local directory before this routine will work

# capture raid status
RAIDSTATUS=`/etc/raidcheck/./raidgetstatus.sh`

# get raid reference
RAIDREF=`cat /etc/raidcheck/raidgood`

# test for a clean shutdown with array matching reference
if [ "${RAIDSTATUS}" != "${RAIDREF}" ]; then
${SENDMAILCMD} <<EOF123xxx
To:${MAILTO}
Reply-To:root@${RAIDHOST}
Errors-To:root@${RAIDHOST}
Sender:root@${RAIDHOST}
Subject:ALERT ALERT ALERT - RAID Device Failure on ${RAIDHOST}

An error has been detected in the RAID Device status of ${RAIDHOST}
Tested on ${DATE}

A good RAID device status should be:
${RAIDREF}

The currrent device status is:
${RAIDSTATUS}
EOF123xxx
#| ${SENDMAILCMD}
fi

if [ "${RAIDSTATUS}" = "${RAIDREF}" ]; then
${SENDMAILCMD} <<EOF123xxx
To:${MAILTO}
Reply-To:root@${RAIDHOST}
Errors-To:root@${RAIDHOST}
Sender:root@${RAIDHOST}
Subject:RAID Device Functioning normally on ${RAIDHOST}

RAID Device on ${RAIDHOST} is functioning normally
Tested on ${DATE}

A good RAID device status should be:
${RAIDREF}

The current device status is:
${RAIDSTATUS}
EOF123xxx
#| ${SENDMAILCMD}
fi
Press ":wq" to save and quit.
Next perform the following:

chmod +x raidcheck.sh
chmod +x raidgetstatus.sh
./raidgetstatus.sh >raidgood
cd /
cd etc
cd cron.daily
vi checkraidstatus
#!/bin/bash
/etc/raidcheck/./raidcheck.sh root@localhost
Press ":wq" to save and quit.
Next perform the following:

chmod +x checkraidstatus
Do a RAID status check by running :-

./checkraidstatus
Check email for the output status