#!/usr/bin/perl # File Name : StorageInfo # Description : GlueStor Storage Information CLI # Developer : Yun In-Jung (daihouying@gluesys.com) # Manager : Yun In-Jung (daihouying@gluesys.com) # Version : 1.0 # Creation Time : # Last Modified Time : May 26 17:07 KST 2006 # Etc. : # Change Log # Wed July 05 16:29:15 KST 2006 : added code for the megaraid sata raid controller. # THU August 23 16:30:07 KST 2007 : the program's name is changed to "StorageInfo" # from "SataStorage". # THU August 23 16:30:07 KST 2007 : added code for the megaraid sas raid controller. require "/$ENV{PPN}/lib/bin/common.lib"; ####### exported Global Variables ######## $__PKGNAME = ( $ENV{PRODUCT_PACKAGE_NAME} ne "" )? $ENV{PRODUCT_PACKAGE_NAME} : "nasAdmin"; $__HTMLDIR = "/$__PKGNAME/gms"; $__CONFDIR = "/$__PKGNAME/conf"; $__TMPDIR = "/$__PKGNAME/tmp"; $__LOGDIR = "/$__PKGNAME/log"; $__BINDIR = "/$__PKGNAME/bin"; $__LIBDIR = "/$__PKGNAME/lib/bin"; $__HALIBDIR = "/$__PKGNAME/lib/ha"; $__HABINDIR = "$__BINDIR/HA"; ############################################################################ # << global variables >> # ############################################################################ $GMonLogPath = "$__LOGDIR/GMon"; $GMonStatusLogPath = "$__LOGDIR/GMon/Status"; $GMonConfPath = "$__CONFDIR"; $CLI_TOOL=""; $ARGC = @ARGV; $del = "=" x 75; $del2 = "=" x 70; %command = ( help => 0, raidset =>{ info => 0, help => 0 }, volumeset =>{ info => 0, help => 0 }, disk => { info => 0, status => 0, help => 0 }, event => { info => 0, clear => 0, help => 0 }, ); ############################################################################ # << Main Routine >> # ############################################################################ if ( $ARGC == 0 ) { $command{help} = 1; &PrintHelp; exit(); } &CommandParser; &DeviceRecognize; if ($command{help} || $command{volumeset}{help} || $command{disk}{help} || $command{event}{help}) { &PrintHelp; } elsif ($command{volumeset}{info}) { &GetVOLUMEInfo; } elsif ($command{disk}{info}) { &GetDISKInfo; } elsif ($command{event}{info}) { &GetEvents; } elsif ($command{event}{clear}) { &ClearEvents; } ############################################################################ # << Print Help >> # ############################################################################ sub PrintHelp { if ($command{help}) { $~ = "HELP"; write; format HELP = CMD Description ========================================================== volumeset VolumeSet Functions. disk Physical Drive Functions. event Event Functions. ========================================================== Command Format: StorageInfo [Sub-Command]. Note: Use -h or --help to get details. . } elsif ($command{volumeset}{help}) { $~ = "VOLUMESET_HELP"; write; format VOLUMESET_HELP = Sub-Command & Parameters Of [ volumeset | v ] Sub-Command Description ===================================================================== info Parameter: None. Fn: Display VolumeSet Info. Command: StorageInfo [ volumeset | v ] info [Enter] ===================================================================== . } elsif ($command{disk}{help}) { $~ = "DISK_HELP"; write; format DISK_HELP = Sub-Command & Parameters Of [ disk | d ] Sub-Command Description ===================================================================== info Parameter: None. Fn: Display Disks Info. Command: StorageInfo [ disk | d ] info [Enter] ===================================================================== . } elsif ($command{event}{help}) { $~ = "EVENT_HELP"; write; format EVENT_HELP = Sub-Command & Parameters Of [ event | e ] Sub-Command Description ===================================================================== info Parameter: None. Fn: Display System Events. Command: StorageInfo [ event | e ] info [Enter] clear Parameter: None. Fn: Clear System Events. Command: StorageInfo [ event | e ] clear [Enter] ===================================================================== . } } ############################################################################ # << Command Line Parsing >> # ############################################################################ sub CommandParser { for ($i=0; $i<@ARGV ; $i++) { $ARGV[$i] =~ tr/A-Z/a-z/ ; } if ($ARGV[0] eq "--help" || $ARGV[0] eq "-h") { $command{help} = 1; } elsif ($ARGV[0] eq "volumeset" || $ARGV[0] eq "v") { if ($ARGV[1] eq "info") { $command{volumeset}{info} = 1; } else { $command{volumeset}{help} = 1; } } elsif ($ARGV[0] eq "disk" || $ARGV[0] eq "d") { if ($ARGV[1] eq "info") { $command{disk}{info} = 1; } else { $command{disk}{help} = 1; } } elsif ($ARGV[0] eq "event" || $ARGV[0] eq "e") { if ($ARGV[1] eq "info") { $command{event}{info} = 1; } elsif ($ARGV[1] eq "clear") { $command{event}{clear} = 1; } else { $command{event}{help} = 1; } } else { $command{help} = 1; } } ############################################################################ # << Device Recognize >> # ############################################################################ sub DeviceRecognize { open (CONF, "$__CONFDIR/GlueStor_option.conf"); while () { chomp; s/^\s+//; s/\s+$//; ($item, $value) = split(/\s*=\s*/, $_, 2); $StorageRaidCtrl_option = $value if ($item eq "STORAGERAIDCTRL"); $Product_option = $value if ($item eq "PRODUCT"); } close (CONF); if ($Product_option eq "1000" && $StorageRaidCtrl_option =~ /megaraid_sas/i) { $device = "megaraid_sas"; $CLI_TOOL = "MegaCli64-V2.00.12"; system ("/bin/echo megaraid_sas 1>$__LOGDIR/StorageDevice"); system ("$CLI_TOOL -AdpAutoRbld -Enbl -aALL 1>/dev/null 2>&1"); if ($command{volumeset}{info} || $command{disk}{info}) { $AdpNum = 0; open (ADPNUM, "$CLI_TOOL -adpCount 2> /dev/null | grep 'Controller Count' 2>/dev/null | "); while () { chomp; s/\.//; (undef, $AdpNum) = split(/:/, $_); } close(ADPNUM); } } elsif ($Product_option eq "1000" && $StorageRaidCtrl_option =~ /megaraid_sas\+/i) { $device = "megaraid_sas+"; $CLI_TOOL = "MegaCli"; system ("/bin/echo megaraid_sas+ > $__LOGDIR/StorageDevice "); system ("$CLI_TOOL -AdpAutoRbld -Enbl -aALL >/dev/null 2>&1"); if ($command{volumeset}{info} || $command{disk}{info}) { $AdpNum = 0; open (ADPNUM, "$CLI_TOOL -adpCount 2> /dev/null | grep 'Controller.*Count' 2>/dev/null | "); while () { chomp; s/\.//; (undef, $AdpNum) = split(/:/, $_); } close (ADPNUM); } } elsif ($StorageRaidCtrl_option =~ /3ware/i) { $device = "3ware"; system ("/bin/echo 3ware 1>$__LOGDIR/StorageDevice"); # fix 3ware sas card(3w-sas.ko) $ctrlname = `tw_cli show | egrep 'c([0-9]|[0-9][0-9])' | head -n 1 | awk '{ print \$1}'`; chomp ($ctrlname); $ctrlname =~ s/ //g; $ctrlname = "/$ctrlname"; } elsif ($StorageRaidCtrl_option =~ /highpoint/i) { $device = "highpoint"; system ("/bin/echo highpoint 1>$__LOGDIR/StorageDevice"); } elsif ($StorageRaidCtrl_option =~ /areca/i) { $device = "areca"; system ("/bin/echo areca 1>$__LOGDIR/StorageDevice"); } elsif ($StorageRaidCtrl_option =~ /megaraid_2\.4/i) { $device = "megaraid_2.4"; system ("/bin/echo megaraid_2.4 1>$__LOGDIR/StorageDevice"); open (ADP, "/bin/ls /proc/megaraid 2>/dev/null | /bin/wc -w 2>/dev/null | "); $adp = ; chomp ($adp); close (ADP); } elsif ($StorageRaidCtrl_option =~ /megaraid/i) { $device = "megaraid_2.6"; system ("/bin/echo megaraid_2.6 1>$__LOGDIR/StorageDevice "); open (ADP, "/sbin/megarc -ctlrInfo -a0 2>/dev/null | grep Adapter | awk '{print \$7}'| sed 's/)//g' 2>/dev/null | "); $adp = ; chomp ($adp); close (ADP); } } ############################################################################ # << Areca Precede >> # ############################################################################ sub ArecaPrecede { open (IN, "/sbin/cli rsf info 2> /dev/null | egrep -v '(Name|=|GuiErrMsg)' 2> /dev/null | "); while () { if ($_ =~ /Incompleted/) { system ("/sbin/cli set curctrl=1 1>/dev/null 2>&1"); system ("/sbin/cli set password=0000 1>/dev/null 2>&1"); system ("/sbin/cli rsf activate raid=1 1>/dev/null 2>&1"); } } close (IN); } ############################################################################ # << Get Volumeset Information >> # ############################################################################ sub GetVOLUMEInfo { if ($device eq "3ware") { $~ = "VOLUMESET_HEADER_3WARE_FORMAT"; write; open (IN, "/sbin/tw_cli $ctrlname show unitstatus 2> /dev/null | grep u[0-9] | awk '{print \$1\":\"\$2\":\"\$3\":\"\$4\":\"\$5\":\"\$6\":\"\$7}' 2>/dev/null | "); while () { chomp; @volumeinfo = split(/:/, $_); $Unit = $volumeinfo[0]; $UnitType = $volumeinfo[1]; $UnitStatus = $volumeinfo[2]; $Cmpl = $volumeinfo[3]; if ($volumeinfo[4] =~ /-|%/) { $StripeSize = $volumeinfo[5]; $UnitSize = $volumeinfo[6]; } else { $StripeSize = $volumeinfo[4]; $UnitSize = $volumeinfo[5]; } if ($UnitStatus eq "BROKEN") { $UnitStatus = "DEGRADED"; } $~ = "VOLUMESET_VALUE_3WARE_FORMAT"; write; } close (IN); format VOLUMESET_HEADER_3WARE_FORMAT = Unit UnitType Stripe Size(GB) Status %Cmpl -------------------------------------------------------- . format VOLUMESET_VALUE_3WARE_FORMAT = @<<< @<<<<<< @<<<<< @<<<<<<<<<< @<<<<<<<<<<< @<<<<< $Unit $UnitType $StripeSize $UnitSize $UnitStatus $Cmpl . } elsif ($device eq "highpoint") { open (IN, "/sbin/hptraidconf query arrays 2>/dev/null | "); print ; close (IN); } elsif ($device eq "areca") { ArecaPrecede; $~ = "VOLUMESET_HEADER_ARECA_FORMAT"; write; VOLUMESTATUS: my $raidname = ""; my $raidlevel = ""; my $raidsize = ""; my $scsichidlun = ""; my $raidstatus = ""; $pid = open(IN, "/sbin/cli vsf info 2> /dev/null | grep -v Name | grep -v GuiErrMsg | grep -v = | awk '{ print \$2\":\"\$3\":\"\$4\":\"\$5\":\"\$6\":\"\$7\":\"\$8\":\"\$9\":\"\$10}' 2>/dev/null | "); while () { chomp; @volumeinfo = split(/:/, $_); if (!(@volumeinfo)) { close (IN); system ("/bin/kill -9 $pid > /dev/null 2>&1 "); goto VOLUMESTATUS; } $raidname = ""; $raidlevel = ""; $raidsize = ""; $scsichidlun = ""; $raidstatus = ""; my $CheckRaidNameStr = "$volumeinfo[1]" . "$volumeinfo[2]" . "$volumeinfo[3]" . "$volumeinfo[4]"; if ($CheckRaidNameStr =~ /^RaidSet#/) { $volumeinfo[8] =~ tr/a-z/A-Z/; if ($volumeinfo[8] eq "NORMAL") { $volumeinfo[8] = "OK"; } elsif (($volumeinfo[8] eq "DEGRADE") || ($volumeinfo[8] eq "FAILED")) { $volumeinfo[8] = "DEGRADED"; } $raidname = "$volumeinfo[0]"; $raidlevel = "$volumeinfo[5]"; $raidsize = "$volumeinfo[6]"; $scsichidlun = "$volumeinfo[7]"; $raidstatus = "$volumeinfo[8]"; } else { $volumeinfo[5] =~ tr/a-z/A-Z/; if ($volumeinfo[5] eq "NORMAL") { $volumeinfo[5] = "OK"; } elsif (($volumeinfo[5] eq "DEGRADE") || ($volumeinfo[5] eq "FAILED")) { $volumeinfo[5] = "DEGRADED"; } $raidname = "$volumeinfo[0]"; $raidlevel = "$volumeinfo[2]"; $raidsize = "$volumeinfo[3]"; $scsichidlun = "$volumeinfo[4]"; $raidstatus = "$volumeinfo[5]"; } $~ = "VOLUMESET_VALUE_ARECA_FORMAT"; write; } close (IN); $~ = "VOLUMESET_FOOTER_ARECA_FORMAT"; write; format VOLUMESET_HEADER_ARECA_FORMAT = Name Level Capacity Ch/Id/Lun Status ============================================================================= . format VOLUMESET_VALUE_ARECA_FORMAT = @<<<<<<<<<<<<<<< @<<<<<<<< @<<<<<<<< @<<<<<<<< @<<<<<<<<<<<<<<<<<<< $raidname $raidlevel $raidsize $scsichidlun $raidstatus . format VOLUMESET_FOOTER_ARECA_FORMAT = ============================================================================= . } elsif ($device eq "megaraid_2.4") { ##################### volumeset information ######################### # $volumeinfo[0] : volumeset(logical disk) name # # $volumeinfo[1] : volumeset(logical disk) status # # $volumeinfo[2] : volumeset(logical disk) raid level # # $volumeinfo[3] : volumeset(logical disk) stripe size(kb) # # $volumeinfo[4] : volumeset(logical disk) size(gb) # # $volumeinfo[5] : volumeset(logical disk) disks # # $volumeinfo[6] : volumeset(logical disk) read/write/cache policy # ##################################################################### open (ADPVOLUME0, "/bin/cat /proc/megaraid/hba0/raiddrives-0-9 2>/dev/null | grep 'Logical drive' | wc -l 2>/dev/null | "); $adpvolume = ; chomp ($adpvolume); open (ADPVOLUME1, "/bin/cat /proc/megaraid/hba1/raiddrives-0-9 2>/dev/null | grep 'Logical drive' | wc -l 2>/dev/null | "); $adpvolume1 = ; chomp ($adpvolume1); $adpvolume = $adpvolume + $adpvolume1; close (ADPVOLUME0); close (ADPVOLUME1); open (OSDISKNAME, "$__BINDIR/osdisk 2>/dev/null | "); while () { chomp; s/^\s+//; s/\s+$//; $OSDiskName = $_ if ($_ ne ""); } close (OSDISKNAME); for ($i=0; $i<$adp; $i++) { $~ = "VOLUMESET_HEADER1_MEGA_24_FORMAT"; write; open (VOLNAME_STATUS, "/bin/cat /proc/megaraid/hba$i/raiddrives-0-9 2>/dev/null | grep Logical | sed 's/,//g' | awk '{ print \$3\$5}' 2>/dev/null | "); open (RAIDLEVEL, "/sbin/megarc.bin -ldInfo -a$i -Lall 2>/dev/null | grep RaidLevel | awk '{ print \$4}' 2>/dev/null | "); open (STRIPESIZE_STRIPES, "/sbin/megarc.bin -ldInfo -a$i -Lall 2>/dev/null | grep StripSz | sed 's/0//g;s/://g;s/KB//g' | awk '{ print \$2\":\"\$4 }' 2>/dev/null | "); while () { chomp; @volumeinfo = split(/:/, $_); $volumeinfo[1] = uc($volumeinfo[1]); if ($volumeinfo[1] eq "OPTIMAL") { $volumeinfo[1] = "OK"; } $volumeinfo[2] = ; ($volumeinfo[3], $volumeinfo[5]) = split(/:/, ); if ($Product_option eq "1000" && $OSDiskName =~ /sd[a-z]/) { open (VOLSIZE, "/sbin/sfdisk -s 2>/dev/null | grep -v $OSDiskName | grep -v hd[a-z] | grep -v total | awk '{ print \$2}' | tail -n $adpvolume 2>/dev/null | "); } else { open (VOLSIZE, "/sbin/sfdisk -s 2>/dev/null | grep -v hd[a-z] | grep -v total | awk '{ print \$2}' | tail -n $adpvolume 2>/dev/null | "); } $adpvolume--; $volumeinfo[4] = ; $volumeinfo[4] = $volumeinfo[4]/1024/1024; close (VOLSIZE); $~ = "VOLUMESET_VALUE1_MEGA_24_FORMAT"; write; } close (VOLNAME_STATUS); close (RAIDLEVEL); close (STRIPESIZE_STRIPES); $~ = "VOLUMESET_HEADER2_MEGA_24_FORMAT"; write; $vol = 0; open (POLICY, "/bin/cat /proc/megaraid/hba$i/raiddrives-0-9 2>/dev/null | grep Policy | sed 's/,//g;s/Policy//g' 2>/dev/null | "); while () { chomp; $volumeinfo[6] = $_; $~ = "VOLUMESET_VALUE2_MEGA_24_FORMAT"; write; $vol++; } close (POLICY); $~ = "VOLUMESET_FOOTER_MEGA_24_FORMAT"; write; } format VOLUMESET_HEADER1_MEGA_24_FORMAT = ======================= RAID Controller Adapter #@< ======================== $i ---------------------------------------------------------------------------- Vol. RaidLevel Stripe(KB) Size(GB) Status Disks ---------------------------------------------------------------------------- . format VOLUMESET_VALUE1_MEGA_24_FORMAT = @|| @|||||| @|| @####.### @||||||||||| @|| "LD".$volumeinfo[0] "RAID".$volumeinfo[2] $volumeinfo[3] $volumeinfo[4] $volumeinfo[1] $volumeinfo[5] . format VOLUMESET_HEADER2_MEGA_24_FORMAT = ---------------------------------------------------------------------------- Vol. Policy ---------------------------------------------------------------------------- . format VOLUMESET_VALUE2_MEGA_24_FORMAT = @|| @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< "LD".$vol $volumeinfo[6] . format VOLUMESET_FOOTER_MEGA_24_FORMAT = ============================================================================ . } elsif ($device eq "megaraid_2.6") { ##################### volumeset information ######################### # $volumeinfo[0] : volumeset(logical disk) name # # $volumeinfo[1] : volumeset(logical disk) status # # $volumeinfo[2] : volumeset(logical disk) raid level # # $volumeinfo[3] : volumeset(logical disk) stripe size(kb) # # $volumeinfo[4] : volumeset(logical disk) size(gb) # # $volumeinfo[5] : volumeset(logical disk) disks # # $volumeinfo[6] : volumeset(logical disk) read/write/cache policy # ##################################################################### open (ADPVOLUME0, "/sbin/megarc.bin -ldInfo -a0 -Lall 2>/dev/null | grep Information | wc -l 2>/dev/null | "); $adpvolume = ; chomp ($adpvolume); open (ADPVOLUME1, "/sbin/megarc.bin -ldInfo -a1 -Lall 2>/dev/null | grep Information | wc -l 2>/dev/null | "); $adpvolume1 = ; chomp ($adpvolume1); $adpvolume = $adpvolume + $adpvolume1; close (ADPVOLUME0); close (ADPVOLUME1); open (OSDISKNAME, "$__BINDIR/osdisk 2>/dev/null | "); while () { chomp; s/^\s+//; s/\s+$//; $OSDiskName = $_ if ($_ ne ""); } close (OSDISKNAME); for ($i=0; $i<$adp; $i++) { $~ = "VOLUMESET_HEADER1_MEGA_26_FORMAT"; write; open (VOLNAME_STATUS, "/sbin/megarc.bin -ldInfo -a$i -Lall 2>/dev/null | grep Status: | sed 's/(//g' | awk '{ print \$4\":\"\$9}' 2>/dev/null | "); open (RAIDLEVEL, "/sbin/megarc.bin -ldInfo -a$i -Lall 2>/dev/null | grep RaidLevel | awk '{ print \$4}' 2>/dev/null | "); open (STRIPESIZE_STRIPES, "/sbin/megarc.bin -ldInfo -a$i -Lall 2>/dev/null | grep StripSz | sed 's/0//g;s/://g;s/KB//g' | awk '{ print \$2\":\"\$4 }' 2>/dev/null | "); while () { chomp; @volumeinfo = split(/:/, $_); $volumeinfo[1] = uc($volumeinfo[1]); if ($volumeinfo[1] =~ /OPTIMAL/i) { $volumeinfo[1] = "OK"; } $volumeinfo[2] = ; ($volumeinfo[3], $volumeinfo[5]) = split(/:/, ); if ($Product_option eq "1000" && $OSDiskName =~ /sd[a-z]/) { open(VOLSIZE, "/sbin/sfdisk -s 2>/dev/null | grep -v $OSDiskName | grep -v total | awk '{ print \$2}' | tail -n $adpvolume 2>/dev/null | "); } else { open (VOLSIZE, "/sbin/sfdisk -s 2>/dev/null | grep -v hd[a-z] | grep -v total | awk '{ print \$2}' | tail -n $adpvolume 2>/dev/null | "); } $adpvolume--; $volumeinfo[4] = ; $volumeinfo[4] = $volumeinfo[4]/1024/1024; close (VOLSIZE); $~ = "VOLUMESET_VALUE1_MEGA_26_FORMAT"; write; } close (VOLNAME_STATUS); close (RAIDLEVEL); close (STRIPESIZE_STRIPES); $vol = 0; $~ = "VOLUMESET_HEADER2_MEGA_26_FORMAT"; write; open (READ_CACHE_POLICY, "/sbin/megarc.bin -ldInfo -a$i -Lall 2>/dev/null | grep RaidLevel | awk '{ print \$7\" / \"\$9}' 2>/dev/null | "); open (WRITE_POLICY, "/sbin/megarc.bin -ldInfo -a$i -Lall 2>/dev/null | grep StripSz | sed 's/://g'| awk '{ print \"/ \"\$6}' 2>/dev/null | "); while() { chomp; $volumeinfo[6] = $_; $volumeinfo[7] = ; $volumeinfo[6] = "$volumeinfo[6]"."$volumeinfo[7]"; $~ = "VOLUMESET_VALUE2_MEGA_26_FORMAT"; write; $vol++; } close (READ_CACHE_POLICY); close (WRITE_POLICY); $~ = "VOLUMESET_FOOTER_MEGA_26_FORMAT"; write; } format VOLUMESET_HEADER1_MEGA_26_FORMAT = ======================= RAID Controller Adapter #@< ======================== $i ---------------------------------------------------------------------------- Vol. RaidLevel Stripe(KB) Size(GB) Status Disks ---------------------------------------------------------------------------- . format VOLUMESET_VALUE1_MEGA_26_FORMAT = @|| @|||||| @|| @####.### @|||||||||| @|| "LD".$volumeinfo[0] "RAID".$volumeinfo[2] $volumeinfo[3] $volumeinfo[4] $volumeinfo[1] $volumeinfo[5] . format VOLUMESET_HEADER2_MEGA_26_FORMAT = ---------------------------------------------------------------------------- Vol. Policy (Read Ahead / Cache / Write) ---------------------------------------------------------------------------- . format VOLUMESET_VALUE2_MEGA_26_FORMAT = @|| @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< "LD".$vol $volumeinfo[6] . format VOLUMESET_FOOTER_MEGA_26_FORMAT = ============================================================================ . } elsif ($device eq "megaraid_sas") { for ($i=0; $i<$AdpNum; $i++) { $AdpVolNum = 0; $CriticalCount = 0; $WarningCount = 0; $~ = "VOLUMESET_HEADER1_MEGA_SAS_FORMAT"; write; $AdpVolNum = `$CLI_TOOL -LDGetNum -a$i 2>/dev/null | grep 'Number of Virtual' 2>/dev/null | awk -F: '{ gsub(\" \",\"\");print \$2}' `; chomp ($AdpVolNum); for ($j=0; $j<$AdpVolNum; $j++) { @VolumeInfo = (); $VolName = ""; $OngoingProg = ""; $Process = ""; $ProgRate = ""; $MsgCount = 0; $Critical = 0; $Warning = 0; @NotifyMessage = (); @VolumeInfo = `$CLI_TOOL -LDInfo -L$j -a$i 2>/dev/null | grep -E '^(RAID Level|Size|State|Strip Size|Number Of Drives|Span Depth)' 2>/dev/null | awk -F ':' '{ print \$2 }'`; chomp (@VolumeInfo); $VolName = "LD".$j; if ($VolumeInfo[0] =~ /Primary/i) { $VolumeInfo[0] =~ /Primary-(\d)/; my $primary_level = $1; $VolumeInfo[0] =~ /Secondary-(\d)/; my $secondary_level = $1; $VolumeInfo[0] = $primary_level . "+" . $secondary_level; } if ($VolumeInfo[2] =~ /(OPTIMAL|DEGRADED)/i) { $OngoingProg = `$CLI_TOOL -LDInfo -L$j -a$i 2>/dev/null | grep -A1 'Ongoing Progresses:' 2>/dev/null | grep 'Completed [0-9]% Taken' 2>/dev/null | awk -F ':|,' '{ gsub(\"Completed| \",\"\"); print \$1\":\"\$2 }'`; chomp ($OngoingProg); ($Process, $ProgRate) = split(/:/, $OngoingProg); if ($Process =~ /"Initialization"/i) { $VolumeInfo[2] = "Initializing"; } elsif ($Process =~ /"Reconstruction"/i) { $VolumeInfo[2] = "Rebuilding"; } else { if ($VolumeInfo[2] =~ /OPTIMAL/i) { $VolumeInfo[2] = "OK"; } $ProgRate = "---"; } } else { $ProgRate = "---"; } if ($VolumeInfo[5] =~ /(\d+)/) { $VolumeInfo[4] = int($VolumeInfo[4]) * int($VolumeInfo[5]); } $~ = "VOLUMESET_VALUE1_MEGA_SAS_FORMAT"; write; ########### Check Storage Volume's Status ########## if ($VolumeInfo[2] =~ /OK/i) { ; } elsif (($VolumeInfo[2] =~ /Rebuilding/) || ($VolumeInfo[2] =~ /Initializing/)) { $NotifyMessage[$MsgCount] = "Storage Raid[$VolName] is $VolumeInfo[2]."; $WarningCount++; $Warning++; $MsgCount++; } elsif (($VolumeInfo[2] =~ /Degraded/) || ($VolumeInfo[2] =~ /Offline/) || ($VolumeInfo[2] =~ /Failed/)) { $NotifyMessage[$MsgCount] = "Storage Raid[$VolName] is $VolumeInfo[2]."; $CriticalCount++; $Critical++; $MsgCount++; } else { $NotifyMessage[$MsgCount] = "Storage Raid[$VolName] is $VolumeInfo[2]."; $WarningCount++; $Warning++; $MsgCount++; } #################### Process Status ####################### if ($Critical > 0) { &ProcessAbnormalStatus($VolName . "_Critical", @NotifyMessage); } elsif ($Warning > 0) { &ProcessAbnormalStatus($VolName . "_Warning", @NotifyMessage); } else { &ProcessNormalStatus($VolName); } } $~ = "VOLUMESET_HEADER2_MEGA_SAS_FORMAT"; write; for ($k=0; $k<$AdpVolNum; $k++) { $VolPolicy = ""; $VolName = ""; $VolPolicy = `$CLI_TOOL -LDInfo -L$k -a$i 2>/dev/null | grep 'Current.*Cache.*Policy:' 2>/dev/null | awk -F ':|,' '{ print \$2}' `; chomp ($VolPolicy); $VolName = "LD".$k; $~ = "VOLUMESET_VALUE2_MEGA_SAS_FORMAT"; write; } $~ = "VOLUMESET_FOOTER_MEGA_SAS_FORMAT"; write; } format VOLUMESET_HEADER1_MEGA_SAS_FORMAT = ====================== RAID Controller Adapter #@< ========================= $i ---------------------------------------------------------------------------- Vol. RaidLevel Stripe Size Status %Cmpl Disks ---------------------------------------------------------------------------- . format VOLUMESET_VALUE1_MEGA_SAS_FORMAT = @|||||||||| @|||||| @|||||| @||||||||| @|||||||||||| @||||| @|| $VolName $VolumeInfo[0] $VolumeInfo[3] $VolumeInfo[1] $VolumeInfo[2] $ProgRate $VolumeInfo[4] . format VOLUMESET_HEADER2_MEGA_SAS_FORMAT = ---------------------------------------------------------------------------- Vol. Policy (Write / Read Ahead / Cache) ---------------------------------------------------------------------------- . format VOLUMESET_VALUE2_MEGA_SAS_FORMAT = @|||||||||| @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $VolName $VolPolicy . format VOLUMESET_FOOTER_MEGA_SAS_FORMAT = ============================================================================ . } elsif ($device eq "megaraid_sas+") { for ($i=0; $i<$AdpNum; $i++) { $AdpVolNum = 0; $CriticalCount = 0; $WarningCount = 0; $~ = "VOLUMESET_HEADER1_MEGA_SAS_FORMAT"; write; $AdpVolNum = `$CLI_TOOL -LDGetNum -a$i 2>/dev/null | grep 'Number.*Virtual' 2>/dev/null | awk -F: '{ gsub(\" \",\"\");print \$2}'`; chomp ($AdpVolNum); for ($j=0; $j<$AdpVolNum; $j++) { @VolumeInfo = (); $VolName = ""; $OngoingProg = ""; $Process = ""; $ProgRate = ""; $MsgCount = 0; $Critical = 0; $Warning = 0; @NotifyMessage = (); @VolumeInfo = `$CLI_TOOL -LDInfo -L$j -a$i 2>/dev/null | \ egrep '(^RAID Level|^Size|^State|^Strip Size|^Number Of Drives)' 2>/dev/null | \ awk -F ':|,' '{gsub(\"Primary-| \",\"\");print \$2}'`; chomp (@VolumeInfo); $VolName = "LD".$j; if ($VolumeInfo[2] =~ /OPTIMAL/i || $VolumeInfo[2] =~ /DEGRADED/i) { $OngoingProg = `$CLI_TOOL -LDInfo -L$j -a$i 2>/dev/null | grep -A1 'Ongoing.*Progresses:' 2>/dev/null | grep 'Completed.*[0-9]%.*Taken' 2>/dev/null | awk -F ':|,' '{gsub(\"Completed| \",\"\"); print \$1\":\"\$2}' `; chomp ($OngoingProg); ($Process, $ProgRate) = split(/:/, $OngoingProg); if ($Process =~ /Initialization/i) { $VolumeInfo[2] = "Initializing"; } elsif ($Process =~ /Reconstruction/i) { $VolumeInfo[2] = "Rebuilding"; } else { if ($VolumeInfo[2] =~ /OPTIMAL/i) { $VolumeInfo[2] = "OK"; } $ProgRate = "---"; } } else { $ProgRate = "---"; } $~ = "VOLUMESET_VALUE1_MEGA_SAS_FORMAT"; write; ########### Check Storage Volume's Status ########## if ($VolumeInfo[2] =~ /OK/) { ; } elsif (($VolumeInfo[2] =~ /Rebuilding/) || ($VolumeInfo[2] =~ /Initializing/)) { $NotifyMessage[$MsgCount] = "Storage Raid[$VolName] is $VolumeInfo[2]."; $WarningCount++; $Warning++; $MsgCount++; } elsif (($VolumeInfo[2] =~ /Degraded/) || ($VolumeInfo[2] =~ /Offline/) || ($VolumeInfo[2] =~ /Failed/i)) { $NotifyMessage[$MsgCount] = "Storage Raid[$VolName] is $VolumeInfo[2]."; $CriticalCount++; $Critical++; $MsgCount++; } else { $NotifyMessage[$MsgCount] = "Storage Raid[$VolName] is $VolumeInfo[2]."; $WarningCount++; $Warning++; $MsgCount++; } ################### Process Status ####################### if ($Critical > 0) { &ProcessAbnormalStatus($VolName."_Critical",@NotifyMessage); } elsif ($Warning > 0) { &ProcessAbnormalStatus($VolName."_Warning",@NotifyMessage); } else { &ProcessNormalStatus($VolName); } } $~ = "VOLUMESET_HEADER2_MEGA_SAS_FORMAT"; write; for ($k=0; $k<$AdpVolNum; $k++) { $VolPolicy = ""; $VolName = ""; $VolPolicy = `$CLI_TOOL -LDInfo -L$k -a$i 2>/dev/null | \ grep '^Current Cache' 2>/dev/null | cut -d: -f2- `; chomp ($VolPolicy); $VolName = "LD".$k; $~ = "VOLUMESET_VALUE2_MEGA_SAS_FORMAT"; write; } $~ = "VOLUMESET_FOOTER_MEGA_SAS_FORMAT"; write; } format VOLUMESET_HEADER1_MEGA_SAS_FORMAT = ====================== RAID Controller Adapter #@< ========================= $i ---------------------------------------------------------------------------- Vol. RaidLevel Stripe Size Status %Cmpl Disks ---------------------------------------------------------------------------- . format VOLUMESET_VALUE1_MEGA_SAS_FORMAT = @|||||||||| @|||||| @|||||| @||||||||| @|||||||||||| @||||| @|| $VolName $VolumeInfo[0] $VolumeInfo[3] $VolumeInfo[1] $VolumeInfo[2] $ProgRate $VolumeInfo[4] . format VOLUMESET_HEADER2_MEGA_SAS_FORMAT = ---------------------------------------------------------------------------- Vol. Policy (Write / Read Ahead / Cache) ---------------------------------------------------------------------------- . format VOLUMESET_VALUE2_MEGA_SAS_FORMAT = @|||||||||| @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $VolName $VolPolicy . format VOLUMESET_FOOTER_MEGA_SAS_FORMAT = ============================================================================ . } } ############################################################################ # << Get Disk Information >> # ############################################################################ sub GetDISKInfo { if ($device eq "3ware") { open (IN, "/sbin/tw_cli $ctrlname show drivestatus 2>/dev/null | grep -v \^\[\\t\]\*\$ 2> /dev/null |"); print ; close (IN); } elsif ($device eq "highpoint") { open (IN, "/sbin/hptraidconf query devices 2> /dev/null | "); print ; close (IN); } elsif ($device eq "areca") { ArecaPrecede; open (IN, "/sbin/cli disk info 2> /dev/null | grep -v GuiErrMsg | sed -e 's/.*=/$del/g' 2> /dev/null | "); print ; close (IN); } elsif ($device eq "megaraid_2.4") { ################### disk information ####################### # $diskinfo[0] : channel number # # $diskinfo[1] : disk sequence number # # $diskinfo[2] : disk size(gb) # # $diskinfo[3] : disk status # # $diskinfo[4] : disk rebuild progress rate # # $diskmodel{$diskinfo[1]} : disk model # ############################################################ for ($i=0; $i<$adp; $i++) { undef %diskmodel; open (MODEL, "/sbin/megarc -phys -chAll -idall -a$i 2> /dev/null | grep Product | awk '{ print \$2}' 2>/dev/null | "); $diskseq = 1; while () { chomp; $diskmodel{"0" . $diskseq} = $_; $diskseq++; } close (MODEL); $~ = "DISK_HEADER_MEGA_24_FORMAT"; write; open (CH_SEQ_SIZE_STATUS, "/sbin/megarc -ldInfo -a$i -Lall 2> /dev/null | grep 0x | awk '{ print \$1\":\"\$2\":\"\$4\":\"\$5 }' 2> /dev/null | "); while () { @diskinfo = split(/:/,$_); $diskinfo[2] = hex($diskinfo[2])*0.5/1024/1024; $diskinfo[4] = " - "; if ($diskinfo[3] =~ /RBLD/i) { $diskinfo[3] = "REBUILDING"; open (REBUILDRATE, "/bin/cat /proc/megaraid/hba$i/rebuild-rate 2> /dev/null | awk '{ print \$3 }' 2>/dev/null | "); $diskinfo[4] = ; chomp ($diskinfo[4]); close (REBUILDRATE); } $~ = "DISK_VALUE_MEGA_24_FORMAT"; write; } close (CH_SEQ_SIZE_STATUS); open (SPARE, "/bin/cat /proc/megaraid/hba$i/diskdrives-ch0 2> /dev/null | grep spare | awk '{ print \$2\":\"\$4\":\"\$6\$7}' 2>/dev/null | "); $~ = "DISK_HEADER_SPARE_MEGA_24_FORMAT"; write; while () { chomp; @spareinfo = split(/:/,$_); $spareinfo[1] = "0".$spareinfo[1]; $spareinfo[2] = uc($spareinfo[2]); $~ = "DISK_VALUE_SPARE_MEGA_24_FORMAT"; write; } close (SPARE); $~ = "DISK_FOOTER_MEGA_24_FORMAT"; write; } format DISK_HEADER_MEGA_24_FORMAT = ====================== RAID Controller Adapter #@< ========================= $i Ch Disk Seq. Model Size(GB) Status %Cmpl ---------------------------------------------------------------------------- . format DISK_VALUE_MEGA_24_FORMAT = @|| @|| @<<<<<<<<<<<<<<< @####.### @|||||||||| @||||| $diskinfo[0] $diskinfo[1] $diskmodel{$diskinfo[1]} $diskinfo[2] $diskinfo[3] $diskinfo[4] . format DISK_HEADER_SPARE_MEGA_24_FORMAT = ---------------------------------------------------------------------------- Ch Disk Seq. Model Status ---------------------------------------------------------------------------- . format DISK_VALUE_SPARE_MEGA_24_FORMAT = @|| @|| @<<<<<<<<<<<<<<< @|||||||||| $spareinfo[0] $spareinfo[1] $diskmodel{$spareinfo[1]} $spareinfo[2] . format DISK_FOOTER_MEGA_24_FORMAT = ============================================================================ . } elsif ($device eq "megaraid_2.6") { ################### disk information ####################### # $diskinfo[0] : channel number # # $diskinfo[1] : disk sequence number # # $diskinfo[2] : disk size(gb) # # $diskinfo[3] : disk status # # $diskmodel{$diskinfo[1]} : disk model # ############################################################ for ($i=0; $i<$adp; $i++) { undef %diskmodel; open (MODEL, "/sbin/megarc -phys -chAll -idall -a$i 2> /dev/null | grep Product | awk '{ print \$2}' 2>/dev/null |"); $diskseq = 1; while () { chomp; $diskmodel{"0".$diskseq} = $_; $diskseq++; } close (MODEL); $~ = "DISK_HEADER_MEGA_26_FORMAT"; write; open (CH_SEQ_SIZE_STATUS,"/sbin/megarc -ldInfo -a$i -Lall 2> /dev/null | grep 0x | awk '{ print \$1\":\"\$2\":\"\$4\":\"\$5 }' 2> /dev/null |"); while () { @diskinfo = split(/:/,$_); $diskinfo[2] = hex($diskinfo[2])*0.5/1024/1024; $diskinfo[4] = " - "; if ($diskinfo[3] =~ /RBLD/i) { $diskinfo[3] = "REBUILDING"; } $~ = "DISK_VALUE_MEGA_26_FORMAT"; write; } close (CH_SEQ_SIZE_STATUS); $~ = "DISK_FOOTER_MEGA_26_FORMAT"; write; } format DISK_HEADER_MEGA_26_FORMAT = ====================== RAID Controller Adapter #@< ========================= $i Ch Disk Seq. Model Size(GB) Status ---------------------------------------------------------------------------- . format DISK_VALUE_MEGA_26_FORMAT = @|| @|| @<<<<<<<<<<<<<<< @####.### @|||||||||| $diskinfo[0] $diskinfo[1] $diskmodel{$diskinfo[1]} $diskinfo[2] $diskinfo[3] . format DISK_FOOTER_MEGA_26_FORMAT = ============================================================================ . } elsif ($device eq "megaraid_sas") { for ($i=0; $i<$AdpNum; $i++) { @EncInfo = (); $AdpVolNum = ""; $EncNum = ""; @EncInfo = `$CLI_TOOL -EncInfo -a$i 2>/dev/null | egrep '(Number of enclosures on adapter|Device ID|Number of Slots)' 2>/dev/null | awk -F '--|:' '{gsub(\" \",\"\"); print \$2}' `; chomp (@EncInfo); $EncNum = $EncInfo[0]; if ($EncNum =~ /^\d$/) { if ($EncNum == 0) { $DirectConnected = 1; $EncNum = 1; } else { $DirectConnected = 0; } $AdpVolNum = `$CLI_TOOL -LDGetNum -a$i 2>/dev/null | grep 'Number.*Virtual' 2>/dev/null | awk -F: '{gsub(\" \", \"\"); print \$2}' `; chomp ($AdpVolNum); $AdpVolSeq = 0; $LdPdInfoLineNum1 = 0; system ("$CLI_TOOL -LdPdInfo -a$i 2>/dev/null > $__CONFDIR/MegaraidLdPdInfo"); open (LDPDINFO, "$__CONFDIR/MegaraidLdPdInfo"); while () { chomp; s/ //g; if ($_ =~ /VirtualDisk:$AdpVolSeq/) { $AdpVolLineNum[$AdpVolSeq] = $LdPdInfoLineNum1; $AdpVolSeq++; } $LdPdInfoLineNum1++; } close (LDPDINFO); $~ = "DISK_HEADER_MEGA_SAS_FORMAT"; write; for ($EncSeq=0, $EncInfoSeqNum=1; $EncSeq<$EncNum; $EncSeq++, $EncInfoSeqNum+=2) { $EncID = ""; $SlotNum = 0; $PowerNum = 0; if ($DirectConnected) { $EncID = "?"; $SlotNum = `$CLI_TOOL -AdpAllInfo -a$i 2>/dev/null | grep 'Number of Backend Port:' | awk -F: '{ gsub(\" \", \"\"); print \$2 }'`; } else { $EncID = $EncInfo[$EncInfoSeqNum]; $SlotNum = $EncInfo[$EncInfoSeqNum+1]; } chomp ($SlotNum); for ($SlotSeq=0; $SlotSeq<$SlotNum; $SlotSeq++) { @DiskInfo = (); $DiskLineNum = ""; $RebuildProg = ""; @DiskInfo = `$CLI_TOOL -pdInfo -PhysDrv[$EncID:$SlotSeq] -a$i 2>/dev/null | grep -E '^(Enclosure Device ID|Slot Number|Raw Size|Firmware state|Inquiry Data)' 2>/dev/null | awk -F ':' '{ gsub(\"ATA\",\"\"); print \$2 }'`; chomp (@DiskInfo); if (scalar @DiskInfo > 0) { $DiskInfo[2] =~ s/ \[\p{IsAlnum}+ Sectors\]$//g; $LdPdInfoLineNum2 = 0; $EncIDMatched = 0; open (LDPDINFO, "$__CONFDIR/MegaraidLdPdInfo"); while () { chomp; s/ //g; if ($DirectConnected) { if ($_ =~ /SlotNumber:$SlotSeq/) { $DiskLineNum = $LdPdInfoLineNum2; last; } } else { if ($_ =~ /^Enclosure.*:$EncID/) { $EncIDMatched = 1; } elsif ($EncIDMatched && $_ =~ /SlotNumber:$SlotSeq/) { $DiskLineNum = $LdPdInfoLineNum2; last; } } $LdPdInfoLineNum2++; } close (LDPDINFO); if ($DiskLineNum eq "") { $AssignedAdpVol = "---"; } else { for ($AdpVolSeq2 = scalar(@AdpVolLineNum -1); $AdpVolSeq2 >= 0; $AdpVolSeq2--) { if ($DiskLineNum > $AdpVolLineNum[$AdpVolSeq2]) { $AssignedAdpVol = "LD" . $AdpVolSeq2; last; } } } if ($DiskInfo[3] =~ /Rebuild/i) { $RebuildProg = `$CLI_TOOL -PDRbld -ShowProg -PhysDrv[$EncID:$SlotSeq] -a$i 2>/dev/null | grep Rebuild 2>/dev/null | awk '{ gsub(\"Rebuild.*Completed\", \"\");print \$1}'`; chomp ($RebuildProg); } else { $RebuildProg = "---"; } if ($DiskInfo[3] =~ /Unconfigured\(bad\)/i) { system ("$CLI_TOOL -PDMakeGood -PhysDrv[$EncID:$SlotSeq] -a$i 1>/dev/null 2>&1"); $DiskInfo[3] = `$CLI_TOOL -pdInfo -PhysDrv[$EncID:$SlotSeq] -a$i | grep 'Firmware state' 2>/dev/null | awk -F: '{gsub(\" \", \"\"); print \$2}'`; chomp ($DiskInfo[3]); } $DiskInfo[4] =~ s/\s+/ /g; } else { $DiskInfo[0] = $EncID; $DiskInfo[2] = "----"; $DiskInfo[3] = "----"; $DiskInfo[4] = "-------"; $AssignedAdpVol = "---"; $RebuildProg = "---"; } if ($DirectConnected) { $DiskInfo[0] = "N/A"; } $DiskInfo[1] = $SlotSeq; $~ = "DISK_VALUE_MEGA_SAS_FORMAT"; write; } } $~ = "DISK_FOOTER_MEGA_SAS_FORMAT"; write; } } format DISK_HEADER_MEGA_SAS_FORMAT = ====================== RAID Controller Adapter #@< ========================= $i [ Enc:Slot] Model Size Assign Status %Cmpl ---------------------------------------------------------------------------- . format DISK_VALUE_MEGA_SAS_FORMAT = [@>>>:@<<] @||||||||||||||| @||||||||| @|||| @||||||||||||||||||| @||||| $DiskInfo[0] $DiskInfo[1] $DiskInfo[4] $DiskInfo[2] $AssignedAdpVol $DiskInfo[3] $RebuildProg . format DISK_FOOTER_MEGA_SAS_FORMAT = ============================================================================ . } elsif ($device eq "megaraid_sas+") { for ($i=0; $i<$AdpNum; $i++) { @EncInfo = (); $AdpVolNum = ""; $EncNum = ""; @EncInfo = `$CLI_TOOL -EncInfo -a$i 2>/dev/null | egrep '(Number.*enclosures.*adapter|Device.*ID|Number.*Slots)' 2>/dev/null | awk -F '--|:' '{ gsub(\" \", \"\"); print \$2}'`; chomp(@EncInfo); $EncNum = $EncInfo[0]; if ($EncNum =~ /^\d$/) { if ($EncNum == 0) { $DirectConnected = 1; $EncNum = 1; } else { $DirectConnected = 0; } $AdpVolNum = `$CLI_TOOL -LDGetNum -a$i 2>/dev/null | grep 'Number.*Virtual' 2>/dev/null | awk -F: '{gsub(\" \", \"\"); print \$2}'`; chomp ($AdpVolNum); $AdpVolSeq = 0; $LdPdInfoLineNum1 = 0; system ("$CLI_TOOL -LdPdInfo -a$i 2>/dev/null > $__CONFDIR/MegaraidLdPdInfo"); open (LDPDINFO,"$__CONFDIR/MegaraidLdPdInfo"); while () { chomp; s/ //g; if ($_ =~ /VirtualDisks:$AdpVolSeq/) { $AdpVolLineNum[$AdpVolSeq] = $LdPdInfoLineNum1; $AdpVolSeq++; } $LdPdInfoLineNum1++; } close (LDPDINFO); $~ = "DISK_HEADER_MEGA_SAS_FORMAT"; write; for ($EncSeq=0, $EncInfoSeqNum=1; $EncSeq<$EncNum; $EncSeq++, $EncInfoSeqNum+=2) { $EncID = ""; $SlotNum = 0; $PowerNum = 0; if ($DirectConnected) { $EncID = "?"; $SlotNum = `$CLI_TOOL -AdpAllInfo -a$i 2>/dev/null | grep 'Number.*of.*Backend.*Port:' | awk -F: '{gsub(\" \", \"\"); print \$2}'`; } else { $EncID = $EncInfo[$EncInfoSeqNum]; $SlotNum = $EncInfo[$EncInfoSeqNum+1]; } chomp ($SlotNum); for ($SlotSeq=0; $SlotSeq<$SlotNum; $SlotSeq++) { @DiskInfo = (); $DiskLineNum = ""; $RebuildProg = ""; @DiskInfo = `$CLI_TOOL -pdInfo -PhysDrv[$EncID:$SlotSeq] -a$i 2>/dev/null | egrep '(^Enclosure.*Device|^Slot|^Raw|^Firmware|^Inquiry)' 2>/dev/null `; chomp (@DiskInfo); my $div_index = 0; foreach my $info (@DiskInfo) { my @div = split /:/, $info; $div[1] =~ s/^[\t ]+|[\t ]+$//g; if ($div[0] =~ /^Enclosure.*Device/) { $DiskInfo[$div_index++] = $div[1]; } elsif ($div[0] =~ /^Slot/) { $DiskInfo[$div_index++] = $div[1]; } elsif ($div[0] =~ /^Raw/) { my @div2 = split(/ +/, $div[1]); $DiskInfo[$div_index++] = $div2[0]; $DiskCapacityMeasure = $div2[1]; } elsif ($div[0] =~ /^Firmware/) { my @div2 = split(/ +/, $div[1]); $div2[0] =~ s/,//g; $DiskInfo[$div_index++] = $div2[0]; } elsif ($div[0] =~ /^Inquiry/) { my @div2 = split(/ +/, $div[1]); $DiskInfo[$div_index++] = $div2[1]; } } if (scalar @DiskInfo > 0) { $DiskInfo[2] = sprintf("%.2f", $DiskInfo[2]); $DiskInfo[2] .= $DiskCapacityMeasure; $LdPdInfoLineNum2 = 0; $EncIDMatched = 0; open (LDPDINFO, "$__CONFDIR/MegaraidLdPdInfo"); while () { chomp; s/ //g; if ($DirectConnected) { if ($_ =~ /SlotNumber:$SlotSeq/) { $DiskLineNum = $LdPdInfoLineNum2; last; } } else { if ($_ =~ /^Enclosure.*:$EncID/) { $EncIDMatched = 1; } elsif ($EncIDMatched && $_ =~ /SlotNumber:$SlotSeq/) { $DiskLineNum = $LdPdInfoLineNum2; last; } } $LdPdInfoLineNum2++; } close (LDPDINFO); if ($DiskLineNum eq "") { $AssignedAdpVol = "---"; } else { #fixme : LD0 is hard coding !!! $AssignedAdpVol = "LD0"; } if ($DiskInfo[3] =~ /Rebuild/) { $RebuildProg = `$CLI_TOOL -PDRbld -ShowProg -PhysDrv[$EncID:$SlotSeq] -a$i 2>/dev/null | \ grep Rebuild 2>/dev/null | awk '{gsub(\"Rebuild.*Completed\", \"\");print \$1 }'`; chomp($RebuildProg); } else { $RebuildProg = "---"; } if ($DiskInfo[3] =~ /Unconfigured\(bad\)/i) { system ("$CLI_TOOL -PDMakeGood -PhysDrv[$EncID:$SlotSeq] -a$i 1>/dev/null 2>&1"); $DiskInfo[3] = `$CLI_TOOL -pdInfo -PhysDrv[$EncID:$SlotSeq] -a$i | grep 'Firmware.*state' 2>/dev/null | awk -F: '{gsub(\" \",\"\"); print \$2}'`; chomp ($DiskInfo[3]); } $DiskInfo[3] =~ s/\,//; } else { $DiskInfo[0] = $EncID; $DiskInfo[2] = "----"; $DiskInfo[3] = "----"; $DiskInfo[4] = "-------"; $AssignedAdpVol = "---"; $RebuildProg = "---"; } $DiskInfo[0] = "N/A" if ($DirectConnected); $DiskInfo[1] = $SlotSeq; $~ = "DISK_VALUE_MEGA_SAS_FORMAT"; write; } } $~ = "DISK_FOOTER_MEGA_SAS_FORMAT"; write; } } format DISK_HEADER_MEGA_SAS_FORMAT = ====================== RAID Controller Adapter #@< ========================= $i [ Enc:Slot] Model Size Assign Status %Cmpl ---------------------------------------------------------------------------- . format DISK_VALUE_MEGA_SAS_FORMAT = [@>>>:@<<] @||||||||||||||| @||||||||| @|||| @||||||||||||||||||| @||||| $DiskInfo[0] $DiskInfo[1] $DiskInfo[4] $DiskInfo[2] $AssignedAdpVol $DiskInfo[3] $RebuildProg . format DISK_FOOTER_MEGA_SAS_FORMAT = ============================================================================ . } } ############################################################################ # << Get Events >> # ############################################################################ sub GetEvents { if ($device eq "3ware") { open (IN, "/sbin/tw_cli $ctrlname show alarms 2>/dev/null | "); print ; close (IN); } elsif ($device eq "highpoint") { open (IN, "/sbin/hptraidconf events 2>/dev/null | "); print ; close (IN); } elsif ($device eq "areca") { ArecaPrecede; open (IN, "/sbin/cli event info 2>/dev/null | grep -v GuiErrMsg | sed -e 's/.*=/$del2/g' 2>/dev/null | "); print ; close (IN); } elsif ($device eq "megaraid_2.4" || $device eq "megaraid_2.6") { for ($i=0; $i<$adp; $i++) { open (IN, "/sbin/megarc -pdFailInfo -chAll -idAll -a$i 2>/dev/null | grep -v Scanning | grep -v 'No Error Information' | /usr/bin/tail +15 2>/dev/null | "); print "\n********* Physical Drive Errors Of The Sata RAID Controller Adapter #".$i." *********\n"; print ; } close (IN); } elsif ($device eq "megaraid_sas") { system ("$CLI_TOOL -AdpEventLog -GetEvents -f /var/log/raidlog -aALL 1>/dev/null 2>&1"); if (-e "/var/log/raidlog") { system ("cat /var/log/raidlog 2>/dev/null"); } else { system ("touch /var/log/raidlog 2>/dev/null"); } } elsif ($device eq "megaraid_sas+") { system ("$CLI_TOOL -AdpEventLog -GetEvents -f /var/log/raidlog -aALL 1>/dev/null 2>&1"); if (-e "/var/log/raidlog") { system ("cat /var/log/raidlog 2>/dev/null"); } else { system ("touch /var/log/raidlog 2>/dev/null"); } } } ############################################################################ # << Clear Events >> # ############################################################################ sub ClearEvents { if ($device eq "3ware") { } elsif ($device eq "highpoint") { system ("/sbin/hptraidconf events clear 1>/dev/null 2>&1"); } elsif ($device eq "areca") { ArecaPrecede; system ("/sbin/cli event clear 1>/dev/null 2>&1"); } elsif ($device eq "megaraid_2.4" || $device eq "megaraid_2.6") { for ($i=0 ; $i<$adp ; $i++) { system ("/sbin/megarc -clrErrHistory -a$i 1>/dev/null 2>&1"); } } elsif ($device eq "megaraid_sas") { system ("$CLI_TOOL -AdpEventLog -Clear -aALL 1>/dev/null 2>&1"); if (-e "/var/log/raidlog") { system ("rm -f /var/log/raidlog 2> /dev/null"); } system ("$CLI_TOOL -AdpEventLog -GetEvents -f /var/log/raidlog -aALL > /dev/null 2>&1"); unless (-e "/var/log/raidlog") { system ("touch /var/log/raidlog 2> /dev/null"); } } elsif ($device eq "megaraid_sas+") { system ("$CLI_TOOL -AdpEventLog -Clear -aALL > /dev/null 2>&1"); if (-e "/var/log/raidlog") { system ("rm -f /var/log/raidlog 2>/dev/null"); } system ("$CLI_TOOL -AdpEventLog -GetEvents -f /var/log/raidlog -aALL 1>/dev/null 2>&1"); unless (-e "/var/log/raidlog") { system ("touch /var/log/raidlog 2>/dev/null"); } } } ############################################################################ # << Process Normal Status >> # ############################################################################ sub ProcessNormalStatus { my ($NotifyName) = @_; ############## Remove Notify Name File ############################## my $NotifyFile1 = $NotifyName."_Critical"; my $NotifyFile2 = $NotifyName."_Warning"; if (-e "$GMonLogPath/$NotifyFile1") { unlink ("$GMonLogPath/$NotifyFile1"); } if(-e "$GMonLogPath/$NotifyFile2") { unlink ("$GMonLogPath/$NotifyFile2"); } ############## Update Alert List #################################### if (-e "$GMonStatusLogPath/alert_list") { $AlertList2 = ""; open (ALERTLIST, "+<$GMonStatusLogPath/alert_list"); flock ALERTLIST, $LOCK_EX; while () { if ($_ =~ /$NotifyName/) { $LOGDATE = `date '+%x %X'`; chomp ($LOGDATE); system ("echo '$LOGDATE >> GMON >> Storage Raid Status: Abnormal -> Normal.' >> /var/log/evtlog"); } else { $AlertList2 .= $_; } } if ($AlertList2 eq "") { flock ALERTLIST, $UNLOCK; close (ALERTLIST); unlink ("$GMonStatusLogPath/alert_list"); unlink ("$GMonStatusLogPath/alarm_ringing_list"); unlink ("$GMonStatusLogPath/alarm_ringing_level"); system ("$AlarmPath/AlarmPlayer stop 1>/dev/null 2>&1"); sleep (0.05); system ("$AlarmPath/AlarmPlayer stop 1>/dev/null 2>&1"); } else { truncate ALERTLIST, 0; seek ALERTLIST,0,0; print ALERTLIST "$AlertList2"; flock ALERTLIST, $UNLOCK; close (ALERTLIST); } } ############ Update Alarm Ringing List ############################# if (-e "$GMonStatusLogPath/alarm_ringing_list") { $AlarmRingList2 = ""; $FirstLineReaded = 0; open (ALARMLIST, "+<$GMonStatusLogPath/alarm_ringing_list"); flock ALARMLIST, $LOCK_EX; while () { if ($_ =~ /$NotifyName/) { ($AlertLevel, undef) = split(/:/, $_); chomp ($AlertLevel); $AlertLevel =~ s/^\s+|\s+$//g; } else { $AlarmRingList2 .= $_; if ($FirstLineReaded == 0) { ($AlertLevel2, undef) = split(/:/, $_); chomp($AlertLevel2); $AlertLevel2 =~ s/^\s+|\s+$//g; $FirstLineReaded = 1; } } } if ($AlarmRingList2 eq "") { flock ALARMLIST, $UNLOCK; close (ALARMLIST); unlink ("$GMonStatusLogPath/alarm_ringing_list"); if (-e "$GMonStatusLogPath/alarm_ringing_level") { unlink ("$GMonStatusLogPath/alarm_ringing_level"); } system ("$AlarmPath/AlarmPlayer stop 1>/dev/null 2>&1"); } else { truncate ALARMLIST, 0; seek ALARMLIST,0,0; print ALARMLIST "$AlarmRingList2"; flock ALARMLIST, $UNLOCK; close (ALARMLIST); if (($AlertLevel =~ /\d/) && ($AlertLevel2 =~ /\d/) && ($AlertLevel > $AlertLevel2)) { if ($AlertLevel2 == 3) { $AlarmMelody = $CrticalAlarmMelody; } elsif ($AlertLevel2 == 2) { $AlarmMelody = $WarningAlarmMelody; } elsif ($AlertLevel2 == 1) { $AlarmMelody = $InformationAlarmMelody; } system ("$AlarmPath/AlarmPlayer stop 1>/dev/null 2>&1"); if (-e "$GMonStatusLogPath/alarm_ringing_level") { open (ALARMLEVEL, "+<$GMonStatusLogPath/alarm_ringing_level"); flock ALARMLEVEL, $LOCK_EX; truncate ALARMLEVEL, 0; seek ALARMLEVEL, 0, 0; print ALARMLEVEL "$AlertLevel2\n"; flock ALARMLEVEL, $UNLOCK; close (ALARMLEVEL); } else { open (ALARMLEVEL, ">$GMonStatusLogPath/alarm_ringing_level"); flock ALARMLEVEL, $LOCK_EX; print ALARMLEVEL "$AlertLevel2\n"; flock ALARMLEVEL, $UNLOCK; close (ALARMLEVEL); } system ("$AlarmPath/AlarmPlayer start $AlarmMelody loop > /dev/null &"); } } } else { if (-e "$GMonStatusLogPath/alarm_ringing_list") { unlink ("$GMonStatusLogPath/alarm_ringing_list"); } if (-e "$GMonStatusLogPath/alarm_ringing_level") { unlink ("$GMonStatusLogPath/alarm_ringing_level"); } } } ############################################################################ # << Process Abnormal Status >> # ############################################################################ sub GetAlertLevel { if (-s "$GMonConfPath/gmond.conf") { open (GMONCONF, "$GMonConfPath/gmond.conf"); while () { if ($_ =~ /Storage_Raid/) { (undef, undef, undef, undef, undef, $AlertLevel, undef) = split(/\s*:\s*/, $_, 7); chomp ($AlertLevel); $AlertLevel =~ s/^\s+|\s+$//g; last if ($AlertLevel =~ /\d/); } } close (GMONCONF); } $AlertLevel = 3 if ($AlertLevel =~ /\D/); if ($NotifyName =~ /_Warning/) { $AlertLevel-- if ($AlertLevel != 1); } } sub ProcessAbnormalStatus { ###################### Update Alert List ########################## my ($NotifyName, @NotifyMessage) = @_; if (($WordIndex = index($NotifyName, "_Critical", 0)) > -1 || ($WordIndex = index($NotifyName, "_Warning", 0)) > -1 ) { $NotifyNameTemp = substr($NotifyName, 0, $WordIndex); $AlertList = ""; if (-e "$GMonStatusLogPath/alert_list") { $AlertExist = 0; open (ALERTLIST, "+<$GMonStatusLogPath/alert_list"); flock ALERTLIST, $LOCK_EX; while () { if ($_ =~ /$NotifyNameTemp/) { $AlertExist = 1; } else { $AlertList .= $_; } } truncate ALERTLIST, 0; seek ALERTLIST, 0, 0; } else { open (ALERTLIST, ">$GMonStatusLogPath/alert_list"); flock ALERTLIST, $LOCK_EX; } &GetAlertLevel; $LOGDATE1 = `date '+%F %X'`; chomp ($LOGDATE1); $LOGDATE2 = `date '+%x %X'`; chomp ($LOGDATE2); foreach $EachNotifyMessage (@NotifyMessage) { $AlertList .= "$AlertLevel:$NotifyName> $LOGDATE1 | $EachNotifyMessage\n"; system ("echo '$LOGDATE2 >> GMON >> $EachNotifyMessage' >> /var/log/evtlog"); } print ALERTLIST "$AlertList"; flock ALERTLIST, $UNLOCK; close (ALERTLIST); if ($AlertExist) { if ($NotifyName =~ /Critical/) { unlink ("$GMonLogPath/".$NotifyNameTemp."_Warning"); } elsif ($NotifyName =~ /Warning/) { unlink ("$GMonLogPath/".$NotifyNameTemp."_Critical"); } } } }