#!/usr/bin/perl -w # # Check for RAID devices status and report status' changes for dpt supported # RAID controllers. # # WARNING: This script was developed and tested only with the Adaptec's verion # of raidutils. # # Copyright (C) 2003 ASTER s.cons.p.a # # This software is ditributed under the terms of the GNU GPL version 2.0 # or later. # # Coded by Alessandro Dotti Contra # # Revision: 1.1 # #============================================================================== # # CONFIGURATION # chomp (my $HOST = qx{ /bin/hostname --fqdn }); my $MAIL = "/usr/bin/mail"; my $RM = "/bin/rm"; my $RAIDUTIL = "/usr/local/dpt/raidutil"; my $ADMIN = "root"; my $SUBJECT = "$HOST: RAID status has changed!"; # # SET WORKING ENVIRONMENT # my $TEMP_FILE = "/tmp/dpt.warning"; # Temporary working file my $STATUS_FILE = "/var/run/dpt.status"; # Array(s) status information my $STATUS_THEN = "/bin/cat $STATUS_FILE"; # Previous disks' status my $STATUS_NOW = "/usr/local/dpt/raidutil -L physical";# Current disks' status my $NO_INFO = 0; # No previous status infos my $WARN = 0; my %status_then; # Previous status infos (structured) my %status_now; # Current status infos (structured) my @lines_then; # Previous status infos (raw) my @lines_now; # Current status infos (raw) # # READ PHYSICAL DEVICES' STATUS INFORMATION # # Read previous status informations $NO_INFO = 1 unless ( -f $STATUS_FILE ); unless ( $NO_INFO ) { @lines_then = qx{ $STATUS_THEN }; foreach (@lines_then) { chomp; my ($device, $status) = split /\t/; { $status_then{$device} = $status; } } } # Read current status information @lines_now = qx{ $STATUS_NOW }; foreach (@lines_now) { chomp; if ( $_ =~ /^(d.{1,2}b.{1,2}t.{1,2}d.{1,2})\s+.*\s+(.*)$/ ) { $status_now{$1} = $2; } } # # VERIFY IF THE STATUS HAS CHANGED # unless ($NO_INFO) { foreach my $device (sort keys %status_now) { $WARN = 1 unless ((exists $status_then{$device}) && ($status_now{$device} eq $status_then{$device})); } } # # HAS BEEN SOMETHING CHANGED? # if ($WARN) { # Warn open (TEMP, ">$TEMP_FILE") or die "Unable to open temporary file: $!\n"; print TEMP "A status change was detected for the RAID array(s)!\n"; print TEMP "\n"; print TEMP "Current RAID status:\n"; print TEMP "\n"; print TEMP qx{ $RAIDUTIL -L logical }; print TEMP "\n"; print TEMP "Current physical drives status:\n"; print TEMP "\n"; print TEMP qx{ $RAIDUTIL -L physical }; qx{ $MAIL -s "$SUBJECT" < $TEMP_FILE $ADMIN }; # Remove temporary files close TEMP; qx{ $RM $TEMP_FILE }; } # Update status informations open (STATUS, ">$STATUS_FILE") or die "Unable to update status information: $!\n"; foreach my $device (sort keys %status_now) { print STATUS "$device\t$status_now{$device}\n"; } close STATUS; exit 0;