IT & + si affinités

Encore un blog de sysadmin … mais pas uniquement ;-)

Script de monitoring de cartes MegaRaid

Ci dessous un petit script personnel qui surveille l’état de votre raid (une seule grappe gérée ici). Il utilise la commande megacli qui permet de gérer en ligne de commande les cartes MegaRaid de LSI.

Ce script interroge la carte et en cas de statut dégradé, recherche quel est le disque fautif et envoi un email.

Il est possible de demander une reconstruction du raid avec l’option « run ».

#!/bin/bash

# use "./thisscript" to only check raid state (report send by email)
# use "./thisscript run" to start raid rebuild if needed
action="off"
megacli="/opt/MegaRAID/MegaCli/MegaCli"
mail_dest="monitoring@mycompany.tld"

if [ "$#" = "1" ] && [ "$1" = "run" ]
then
action="on"
fi

#Get general RAID status
raid_status=`./MegaCli -CfgDsply -aALL |grep ^State`
if [ "$raid_status" != "Online" ]; then

#get infos from raid config
enclosure=`$megacli -CfgDsply -aALL |grep ^Enclosure |head -n 1|cut -d" " -f 4`
nb=`$megacli -CfgDsply -aALL |grep "Number of PDs:" |cut -d" " -f 4`

counter=$(($nb-1))
#search the disk problem
for (( c=0; c<=$counter; c++ ))
do
state=`$megacli -pdInfo -PhysDrv[$enclosure:$c] -aALL | grep "Firmware state:" |cut -d" " -f 3`
case $state in
"Online")

;;

"Rebuild")
$megacli -PDRbld -ShowProg -PhysDrv [$enclosure:$c] -aALL |grep Rebuild > /tmp/rebuild_statut.txt
avancee=`cat /tmp/rebuild_statut.txt | cut -d" " -f 11`
mail -s "Rebuild status disk slot $c on $HOSTNAME "$avancee $mail_dest < /tmp/rebuild_statut.txt
;;

"Offline")
$megacli -pdInfo -PhysDrv[$enclosure:$c] -aALL | mail -s "Error : Offline disk slot $c on $HOSTNAME" $mail_dest
#Rebuilding raid on drive or not
if [ "$action" = "on" ]; then
$megacli -PDRbld -Start -PhysDrv [$enclosure:$c] -aALL |mail -s "Starting rebuild disk slot $c on $HOSTNAME" $mail_dest
fi
;;

*)
echo "Reported state : $state" | mail -s "Unknown state disk slot $c on $HOSTNAME" $mail_dest
;;
esac
done
fi
Catégorie : IT