OVH: checkraid_lsi envoie un email en cas de raid dégradé (carte LSI)
Le script Perl checkraid_lsi vérifie l’état de la première partition raid 1 d’une carte LSI. Si l’état n’est pas OPTIMAL un email d’alerte est envoyé.
Ce script fonctionne sur les serveur équipé de carte raid LSI. Il exploite la commande mpt-status.
1) Commencer par trouver la ligne de commande à utiliser avec “mpt-status -p”:
# mpt-status -p
Checking for SCSI ID:0
Checking for SCSI ID:1
Checking for SCSI ID:2
Checking for SCSI ID:3
Checking for SCSI ID:4
Found SCSI id=4, use ''mpt-status -i 4`` to get more information.
Vérifier que la commande proposée fonctionne, ici : “mpt-status -i 4″:
# mpt-status -i 4
doit répondre:
ioc0 vol_id 4 type IM, 2 phy, 698 GB, state OPTIMAL, flags ENABLED
ioc0 phy 1 scsi_id 5 ATA WDC WD7501AALS-0 0K05, 698 GB, state ONLINE, flags NONE
ioc0 phy 0 scsi_id 6 ATA WDC WD7501AALS-0 0K05, 698 GB, state ONLINE, flags NONE
2) Copier le fichier checkraid_lsi sur votre serveur
checkraid_lsi: http://www.philten.com/wp-content/uploads/2010/02/checkraid_lsi.zip
(Dans certains cas le fait de copier/coller le code ci-dessous transforme des caractères comme les double-quotes, je recommande donc de récupérer le script par le fichier zip ci-dessus)
#!/usr/bin/perl -w
#——————————————-
#
#This script run “mpt-status -i 4″ and parse the reply to get
#LSI raid status in the first output line.
#
#ioc0 vol_id 4 type IM, 2 phy, 698 GB, state OPTIMAL, flags ENABLED
#ioc0 phy 1 scsi_id 5 ATA WDC WD7501AALS-0 0K05, 698 GB, state ONLINE, flags NONE
#ioc0 phy 0 scsi_id 6 ATA WDC WD7501AALS-0 0K05, 698 GB, state ONLINE, flags NONE
#
#possible state:
#OPTIMAL
#DEGRADED
#FAILED
#UNKNOWN
#
#if different then “OPTIMAL” an alert notification is sent by email
#
# version 1.0
# phil@philten.com
# http://www.philten.com
use IO::File;
#define from address
my $from=”myemail\@domain.com”;
#define to address
my $to=”myemail\@domain.com”;
#if needed, change the raid check command line
my $cmd = “/sbin/mpt-status -i 4″;
my $fd = IO::File->new (”$cmd 2>/dev/null|”);
my $raid_array = <$fd>;
chomp $raid_array;
my $raid_hdd1 = <$fd>;
chomp $raid_hdd1;
my $raid_hdd2 = <$fd>;
chomp $raid_hdd2;
close ($fd);
my $hostname = `hostname`;
chomp $hostname;
print “$raid_array\n”;
print “$raid_hdd1\n”;
print “$raid_hdd2\n”;
#parse raid status
$raid_array =~ m/(?:state )(.*)(?:,)/i;
my $state = $1;
print “Status found: $state\n”;
sub email;
sub write2syslog;
if ($state ne “OPTIMAL”)
{
my $subject = “RAID Alert on [$hostname]: $state”;
my $buf = “RAID Alert on [$hostname]\n\n$raid_array\n$raid_hdd1\n$raid_hdd2\n”;
print “RAID Alert [$state], sending email to [$to] …\n”;
write2syslog(”RAID Alert [$state]“);
email “$from”,”$to”,”$subject”,”$buf”;
}
sub email {
my ($from,$to,$subject,$message)=@_;
eval{
#change sendmail path if needed
open (MAIL, “|/usr/sbin/sendmail -t -oi -f \”$from\”");
print MAIL (”To: $to\n”);
print MAIL (”From: $from\n”);
print MAIL (”Subject: $subject\n\n”);
print MAIL (”$message”);
close (MAIL);
};
}
sub write2syslog{
my ($data)=@_;
my $fd = IO::File->new (”/usr/bin/logger -t `basename $0` $data 2>/dev/null|”);
close ($fd);
}
3) Autoriser l’execution
chmod +x checkraid_lsi
4) Renseigner les variables $from et $to pour l’envoi d’email
5) Tester l’envoi d’email
Pour tester l’envoi d’email, changer temporrairement le test sur l’état.
Remplacer
if ($state ne "OPTIMAL")
par
if ($state ne "NO OPTIMAL")
et exécuter.
5) Créer un job crontab pour lancer le script toutes les deux heures
crontab -e
0 */2 * * * /scripts/checkraid_lsi >> /dev/null 2>&1
Référence:
mpt-status: http://www.linuxcertif.com/man/8/mpt-status/
[...] Si vous voulez aller plus loin dans la gestion de votre raid hard LSI, tel que par exemple l’envoi de mail automatique en cas de RAID dégradé je vous conseil la lecture de ce billet. [...]
Ping par mpt-status : Obtenir des informations d’une carte RAID LSI | Artiflo Inside — 19 février 2010 @ 21:44