#!/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. ############################################################################ # << global variables >> # ############################################################################ $GMonLogPath = "/nasAdmin/log/GMon"; $GMonConfPath = "/nasAdmin/conf"; $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{raidset}{info}) { &GetRAIDInfo; } 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{raidset}{help} ) # { # $~="RAIDSET_HELP"; # write; #format RAIDSET_HELP = #Sub-Command & Parameters Of [ raidset | r ] #Sub-Command Description #=================================================================== #info Parameter: None. # Fn: Display RaidSets Info. # Command: StorageInfo [raidset | r ] info [Enter] #=================================================================== #. # } 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 "raidset" || $ARGV[0] eq "r") # { # if($ARGV[1] eq "info" ) # { # $command{raidset}{info} = 1; # } # else # { # $command{raidset}{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 { $StorageRaidCtrl = `grep STORAGERAIDCTRL /nasAdmin/conf/GlueStor_option.conf 2> /dev/null | awk -F= '{ gsub(\" \",\"\");print \$2}'`; chomp($StorageRaidCtrl); $PRODUCT = `grep PRODUCT /nasAdmin/conf/GlueStor_option.conf 2> /dev/null | awk -F= '{ gsub(\" \",\"\");print \$2}'`; chomp($PRODUCT); $IsMegaRaidSAS = `lspci 2> /dev/null | grep MegaRAID.*SAS`; chomp; if( lc($StorageRaidCtrl) eq "megaraid_sas" || ( $PRODUCT eq "1000" && $IsMegaRaidSAS ) ) # if( lc($StorageRaidCtrl) eq "megaraid_sas" ) { $device = "megaraid_sas"; system("/bin/echo megaraid_sas > /nasAdmin/log/StorageDevice "); system("MegaCli -AdpAutoRbld -Enbl -aALL > /dev/null 2>&1"); if( $command{volumeset}{info} || $command{disk}{info} ) { $AdpNum = `MegaCli -AdpAllInfo -aALL 2> /dev/null | grep 'Adapter.*#[0-9]' 2> /dev/null | wc -l`; chomp($AdpNum); } } elsif( $PRODUCT eq "1000" && lc($StorageRaidCtrl) eq "megaraid_sas+" ) { $device = "megaraid_sas+"; system("/bin/echo megaraid_sas+ > /nasAdmin/log/StorageDevice "); $CLI_TOOL = "MegaCli"; 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); } } else { open(IN, "/sbin/lsmod | grep -v Module | awk '{ print \$1}' 2> /dev/null |"); while() { chomp; $module_name = $_; if( lc($StorageRaidCtrl) eq "3ware" || ( $module_name eq "3w_9xxx" || $module_name eq "3w-9xxx" ) ) { $device = "3ware"; system("/bin/echo 3ware > /nasAdmin/log/StorageDevice "); $ctrlname = `tw_cli show | egrep 'c([0-9]|[0-9][0-9])' | awk '{ print \$1}'`; chomp($ctrlname); $ctrlname =~ s/ //g; $ctrlname = "/$ctrlname"; } elsif( lc($StorageRaidCtrl) eq "highpoint" || $module_name eq "hpt374") { $device = "highpoint"; system("/bin/echo highpoint > /nasAdmin/log/StorageDevice "); } elsif( lc($StorageRaidCtrl) eq "areca" || $module_name eq "arcmsr") { $device = "areca"; system("/bin/echo areca > /nasAdmin/log/StorageDevice "); } elsif( lc($StorageRaidCtrl) eq "megaraid_2.4" || $module_name eq "megaraid2") { $device = "megaraid_2.4"; system("/bin/echo megaraid_2.4 > /nasAdmin/log/StorageDevice "); open(ADP, "/bin/ls /proc/megaraid | /bin/wc -w 2> /dev/null |"); $adp = ; chomp($adp); close(ADP); } elsif( lc($StorageRaidCtrl) eq "megaraid" || $module_name eq "megaraid_mm") { $device = "megaraid_2.6"; system("/bin/echo megaraid_2.6 > /nasAdmin/log/StorageDevice "); open(ADP,"/sbin/megarc -ctlrInfo -a0 | grep Adapter | awk '{print \$7}'| sed 's/)//g' 2> /dev/null |" ); $adp = ; chomp($adp); close(ADP); } } close(IN); } } ############################################################################ # << Areca Precede >> # ############################################################################ sub ArecaPrecede { open(IN,"/bin/ps aux | grep cli32 | grep -v grep | awk '{print \$1 }' 2> /dev/null |"); $pid = ; if($pid) { system("/bin/kill -9 $pid > /dev/null 2>&1 "); } close (IN); open(IN, "/sbin/cli32 rsf info | grep -v Name | grep -v = | grep -v GuiErrMsg | awk '{ print \$7 }' 2> /dev/null |"); while() { chomp; $line1 = $_; if($line1 eq "Incompleted") { system("/sbin/cli32 set curctrl=1 > /dev/null 2>&1"); system("/sbin/cli32 set password=0000 > /dev/null 2>&1"); system("/sbin/cli32 rsf activate raid=1 > /dev/null 2>&1"); } } close (IN); } ############################################################################ # << Get Raidset Infomation >> # ############################################################################ #sub GetRAIDInfo #{ # if( $device eq "3ware" ) # { # } # elsif($device eq "highpoint" ) # { # } # elsif( $device eq "areca" ) # { # ArecaPrecede; # $~="RAIDSET_HEADER_ARECA_FORMAT"; # write; # open(IN,"/sbin/cli32 rsf info | grep -v Name | grep -v GuiErrMsg | grep -v = | awk '{ print \$1\":\"\$2\":\"\$3\":\"\$4\":\"\$5\":\"\$6\":\"\$7 }' 2> /dev/null |"); # while() # { # chomp; # @raidinfo = split(/:/,$_); # $raidinfo[6] =~ tr/a-z/A-Z/; # if( $raidinfo[6] eq "NORMAL" ) # { # $raidinfo[6] = "OK"; # } # elsif( ($raidinfo[6] eq "DEGRADE") || ($raidinfo[6] eq "FAILED") ) # { # $raidinfo[6] = "DEGRADED"; # } # $~ = "RAIDSET_VALUE_ARECA_FORMAT"; # write; # } # close (IN); # $~ = "RAIDSET_FOOTER_ARECA_FORMAT"; # write; # } #format RAIDSET_HEADER_ARECA_FORMAT = #Num Name Disks TotalCap FreeCap DiskChannels Status #============================================================================= #. #format RAIDSET_VALUE_ARECA_FORMAT = #@<< @<<<<<<<<<<<<<<< @<<<< @<<<<<<<< @<<<<<<<< @<<<<<<<< @<<<<<<<<<<<<<<< #$raidinfo[0] $raidinfo[1] $raidinfo[2] $raidinfo[3] $raidinfo[4] $raidinfo[5] $raidinfo[6] #. #format RAIDSET_FOOTER_ARECA_FORMAT = #============================================================================= #. #} ############################################################################ # << Get Volumeset Information >> # ############################################################################ sub GetVOLUMEInfo { if( $device eq "3ware" ) { $~="VOLUMESET_HEADER_3WARE_FORMAT"; write; open(IN,"/sbin/tw_cli_9.3 $ctrlname show unitstatus | 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: $pid=open(IN,"/sbin/cli32 vsf info | grep -v Name | grep -v GuiErrMsg | grep -v = | awk '{ print \$2\":\"\$4\":\"\$5\":\"\$6\":\"\$7}' 2> /dev/null |"); while() { chomp; @volumeinfo=split(/:/,$_); if(!(@volumeinfo)) { close(IN); system("/bin/kill -9 $pid > /dev/null 2>&1 "); goto VOLUMESTATUS; } $volumeinfo[4] =~ tr/a-z/A-Z/; if( $volumeinfo[4] eq "NORMAL" ) { $volumeinfo[4] = "OK"; } elsif( ($volumeinfo[4] eq "DEGRADE") || ($volumeinfo[4] eq "FAILED") ) { $volumeinfo[4] = "DEGRADED"; } $~="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 = @<<<<<<<<<<<<<<< @<<<<<<<< @<<<<<<<< @<<<<<<<< @<<<<<<<<<<<<<<<<<<< $volumeinfo[0] $volumeinfo[1] $volumeinfo[2] $volumeinfo[3] $volumeinfo[4] . 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 | grep 'Logical drive' | wc -l 2>/dev/null |"); $adpvolume = ; chomp($adpvolume); open(ADPVOLUME1,"/bin/cat /proc/megaraid/hba1/raiddrives-0-9 | grep 'Logical drive' | wc -l 2>/dev/null |"); $adpvolume1 = ; chomp($adpvolume1); $adpvolume = $adpvolume + $adpvolume1; close(ADPVOLUME0); close(ADPVOLUME1); for($i = 0 ; $i < $adp ; $i++) { $~="VOLUMESET_HEADER1_MEGA_24_FORMAT"; write; open(VOLNAME_STATUS,"/bin/cat /proc/megaraid/hba$i/raiddrives-0-9 | grep Logical | sed 's/,//g' | awk '{ print \$3\$5}' 2>/dev/null |"); open(RAIDLEVEL,"/sbin/megarc.bin -ldInfo -a$i -Lall | grep RaidLevel | awk '{ print \$4}' 2>/dev/null | "); open(STRIPESIZE_STRIPES,"/sbin/megarc.bin -ldInfo -a$i -Lall | 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(/:/,); $OSDiskDev = `grep OSDISKDEV /nasAdmin/conf/GlueStor_option.conf 2> /dev/null | awk -F= '{ gsub(\" \",\"\");print \$2}'`; chomp($OSDiskDev); $OSDiskDev = lc($OSDiskDev); if( $PRODUCT eq "1000" && $OSDiskDev =~ /sd[a-z]/) { open(VOLSIZE,"/sbin/sfdisk -s | grep -v $OSDiskDev | grep -v hd[a-z] | grep -v total | awk '{ print \$2}' | tail -n $adpvolume 2>/dev/null |" ); } else { open(VOLSIZE,"/sbin/sfdisk -s | 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 | 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 | grep Information | wc -l 2>/dev/null |"); $adpvolume = ; chomp($adpvolume); open(ADPVOLUME1,"/sbin/megarc.bin -ldInfo -a1 -Lall | grep Information | wc -l 2>/dev/null |"); $adpvolume1 = ; chomp($adpvolume1); $adpvolume = $adpvolume + $adpvolume1; close(ADPVOLUME0); close(ADPVOLUME1); for($i = 0 ; $i < $adp ; $i++) { $~="VOLUMESET_HEADER1_MEGA_26_FORMAT"; write; open(VOLNAME_STATUS,"/sbin/megarc.bin -ldInfo -a$i -Lall | grep Status: | sed 's/(//g' | awk '{ print \$4\":\"\$9}' 2>/dev/null | "); open(RAIDLEVEL,"/sbin/megarc.bin -ldInfo -a$i -Lall | grep RaidLevel | awk '{ print \$4}' 2>/dev/null | "); open(STRIPESIZE_STRIPES,"/sbin/megarc.bin -ldInfo -a$i -Lall | 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( index($volumeinfo[1],"OPTIMAL",0) > -1 ) { $volumeinfo[1] = "OK"; } $volumeinfo[2] = ; ($volumeinfo[3],$volumeinfo[5]) = split(/:/,); $OSDiskDev = `grep OSDISKDEV /nasAdmin/conf/GlueStor_option.conf 2> /dev/null | awk -F= '{ gsub(\" \",\"\");print \$2}'`; chomp($OSDiskDev); $OSDiskDev = lc($OSDiskDev); if( $PRODUCT eq "1000" && $OSDiskDev =~ /sd[a-z]/) { open(VOLSIZE,"/sbin/sfdisk -s | grep -v $OSDiskDev | grep -v total | awk '{ print \$2}' | tail -n $adpvolume 2>/dev/null |" ); } else { open(VOLSIZE,"/sbin/sfdisk -s | 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 | grep RaidLevel | awk '{ print \$7\" / \"\$9}' 2>/dev/null |"); open(WRITE_POLICY,"/sbin/megarc.bin -ldInfo -a$i -Lall | 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.*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; $DiskCapacityMeasure = "TB"; $VolumeInfo[1] = sprintf("%.3f", $VolumeInfo[1]); $VolumeInfo[1] .= $DiskCapacityMeasure; if( index(uc($VolumeInfo[2]),"OPTIMAL",0) > -1 || index(uc($VolumeInfo[2]),"DEGRADED",0) > -1 ) { $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( index($Process,"Initialization",0) > -1 ) { $VolumeInfo[2] = "Initializing"; } elsif( index($Process,"Reconstruction",0) > -1 ) { $VolumeInfo[2] = "Rebuilding"; } else { if( index(uc($VolumeInfo[2]),"OPTIMAL",0) > -1 ) { $VolumeInfo[2] = "OK"; } $ProgRate = "---"; } } else { $ProgRate = "---"; } $~ = "VOLUMESET_VALUE1_MEGA_SAS_FORMAT"; write; ########### Check Storage Volume's Status ########## if( (index("$VolumeInfo[2]", "OK", 0) > -1 ) ) { ; } elsif( (index("$VolumeInfo[2]", "Rebuilding", 0) > -1 ) || (index("$VolumeInfo[2]","Initializing", 0) > -1) ) { $NotifyMessage[$MsgCount] = "Storage Raid[$VolName] is $VolumeInfo[2]."; $WarningCount++; $Warning++; $MsgCount++; } elsif( (index("$VolumeInfo[2]", "Degraded", 0) > -1) || (index("$VolumeInfo[2]", "Offline", 0) > -1) || (index("$VolumeInfo[2]", "Failed", 0) > -1) ) { $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 = ============================================================================ . } elsif( $device eq "megaraid_sas" ) { for( $i = 0 ; $i < $AdpNum ; $i++ ) { $AdpVolNum = 0; $CriticalCount = 0; $WarningCount = 0; $~="VOLUMESET_HEADER1_MEGA_SAS_FORMAT"; write; $AdpVolNum = `MegaCli -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 = `MegaCli -LDInfo -L$j -a$i 2> /dev/null | egrep '(RAID.*Level:|^Size:|^State|Stripe.*Size:|Number.*Of.*Drives:)' 2> /dev/null | awk -F ':|,' '{ gsub(\"Primary-| \",\"\");print \$2}' `; chomp(@VolumeInfo); $VolName = "LD".$j; if( $VolumeInfo[1] >= 0 && $VolumeInfo[1] < 1024 ) { $DiskCapacityMeasure = "MB"; } if( $VolumeInfo[1] >= 1024 && $VolumeInfo[1] < 1048576 ) { $VolumeInfo[1] /= 1024; $DiskCapacityMeasure = "GB"; } elsif( $VolumeInfo[1] >= 1048576 && $VolumeInfo[1] < 1073741824 ) { $VolumeInfo[1] /= 1048576; $DiskCapacityMeasure = "TB"; } $VolumeInfo[1] = sprintf("%.2f", $VolumeInfo[1]); $VolumeInfo[1] .= $DiskCapacityMeasure; if( index(uc($VolumeInfo[2]),"OPTIMAL",0) > -1 || index(uc($VolumeInfo[2]),"DEGRADED",0) > -1 ) { $OngoingProg = `MegaCli -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( index($Process,"Initialization",0) > -1 ) { $VolumeInfo[2] = "Initializing"; } elsif( index($Process,"Reconstruction",0) > -1 ) { $VolumeInfo[2] = "Rebuilding"; } else { if( index(uc($VolumeInfo[2]),"OPTIMAL",0) > -1 ) { $VolumeInfo[2] = "OK"; } $ProgRate = "---"; } } else { $ProgRate = "---"; } $~ = "VOLUMESET_VALUE1_MEGA_SAS_FORMAT"; write; ########### Check Storage Volume's Status ########## if( (index("$VolumeInfo[2]", "OK", 0) > -1 ) ) { ; } elsif( (index("$VolumeInfo[2]", "Rebuilding", 0) > -1 ) || (index("$VolumeInfo[2]","Initializing", 0) > -1) ) { $NotifyMessage[$MsgCount] = "Storage Raid[$VolName] is $VolumeInfo[2]."; $WarningCount++; $Warning++; $MsgCount++; } elsif( (index("$VolumeInfo[2]", "Degraded", 0) > -1) || (index("$VolumeInfo[2]", "Offline", 0) > -1) || (index("$VolumeInfo[2]", "Failed", 0) > -1) ) { $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 = `MegaCli -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 = ============================================================================ . } } ############################################################################ # << Get Disk Information >> # ############################################################################ sub GetDISKInfo { if( $device eq "3ware" ) { open(IN,"/sbin/tw_cli_9.3 $ctrlname show drivestatus | 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/cli32 disk info | 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 | 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 | 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( index($diskinfo[3],"RBLD",0) > -1) { $diskinfo[3] = "REBUILDING"; open(REBUILDRATE,"/bin/cat /proc/megaraid/hba$i/rebuild-rate | 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 | 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 | 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 | 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( index($diskinfo[3],"RBLD",0) > -1) { $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.*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|^Slot|^Raw|^Firmware|^Inquiry)' 2> /dev/null | awk -F ':' '{ gsub(\"ATA\",\"\");print \$2}'| awk '{ print \$1}' `; @DiskInfo = `$CLI_TOOL -pdInfo -PhysDrv[$EncID:$SlotSeq] -a$i 2> /dev/null | egrep '(^Enclosure.*Device|^Slot|^Raw|^Firmware|^Inquiry)' 2> /dev/null `; #print "$CLI_TOOL -pdInfo -PhysDrv[$EncID:$SlotSeq] -a$i 2> /dev/null | egrep '(^Enclosure.*Device|^Slot|^Raw|^Firmware|^Inquiry)' 2> /dev/null | awk -F ':' '{ gsub(\"ATA\",\"\");print \$2}'| awk '{ print \$1}' \n"; 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[0]; } } if( scalar @DiskInfo > 0 ) { #$DiskCapacityMeasure = "TB"; $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( index($DiskInfo[3],"Rebuild",0) > -1 ) { $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( index($DiskInfo[3],"Unconfigured(bad)",0) > -1 ) { system("$CLI_TOOL -PDMakeGood -PhysDrv[$EncID:$SlotSeq] -a$i > /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 = "---"; } 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++ ) { $AdpVolNum = ""; @AdpVolLineNum = (); $EncNum = ""; $AdpVolNum = `MegaCli -LDGetNum -a$i 2> /dev/null | grep 'Number.*Virtual' 2> /dev/null | awk -F: '{ gsub(\" \", \"\");print \$2}' `; chomp($AdpVolNum); for( $AdpVolSeq = 0 ; $AdpVolSeq < $AdpVolNum ; $AdpVolSeq++) { $LineNum = ""; $LineNum = `MegaCli -LdPdInfo -a$i 2> /dev/null | sed 's/ //g' | grep -n 'VirtualDisk:$AdpVolSeq\\>' | awk -F: '{ print \$1 }'`; chomp($LineNum); $AdpVolLineNum[$AdpVolSeq] = $LineNum; } $~="DISK_HEADER_MEGA_SAS_FORMAT"; write; $EncNum = `MegaCli -EncInfo -a$i 2> /dev/null | grep 'Number.*enclosures.*adapter' 2> /dev/null | awk -F '--' '{ gsub(\" \",\"\");print \$2}' `; chomp($EncNum); for( $EncSeq = 0 ; $EncSeq < $EncNum ; $EncSeq++ ) { @EncInfo = (); $SlotNum = 0; $PowerNum = 0; $EncSeqNum = $EncSeq+1; @EncInfo = `MegaCli -EncInfo -a$i 2> /dev/null | grep -A3 'Enclosure.*$EncSeq' 2> /dev/null | egrep '(Number.*Slots|Number.*Power.*Supplies)' 2> /dev/null | awk -F: '{ gsub(\" \",\"\");print \$2}' `; chomp(@EncInfo); $SlotNum = $EncInfo[0]; # $PowerNum = $EncInfo[1]; # if( $PowerNum > 0 ) # { for( $SlotSeq = 0; $SlotSeq < $SlotNum ; $SlotSeq++) { @DiskInfo = (); $DiskLineNum = ""; $RebuildProg = ""; @DiskInfo = `MegaCli -pdInfo -PhysDrv[$EncSeqNum:$SlotSeq] -a$i 2> /dev/null | egrep '(Enclosure.*Number|Slot.*Number|Raw.*Size:|Firmware.*state:|Inquiry.*Data:)' 2> /dev/null | awk -F ':' '{ gsub(\"ATA\",\"\");print \$2}'| awk '{ print \$1}' `; chomp(@DiskInfo); if( scalar @DiskInfo > 0 ) { if( $DiskInfo[2] >= 0 && $DiskInfo[2] < 1024 ) { $DiskCapacityMeasure = "MB"; } if( $DiskInfo[2] >= 1024 && $DiskInfo[2] < 1048576) { $DiskInfo[2] /= 1024; $DiskCapacityMeasure = "GB"; } elsif( $DiskInfo[2] >= 1048576 && $DiskInfo[2] < 2147483648) { $DiskInfo[2] /= 1048576; $DiskCapacityMeasure = "TB"; } $DiskInfo[2] = sprintf("%.2f", $DiskInfo[2]); $DiskInfo[2] .= $DiskCapacityMeasure; $DiskLineNum = `MegaCli -LdPdInfo -a$i 2> /dev/null | sed 's/ //g' | grep -A1 -n 'EnclosureNumber:$EncSeqNum\\>' | sed 's/ //g' | grep 'SlotNumber:$SlotSeq\\>' | awk -F- '{ print \$1 }'`; chomp($DiskLineNum); if( $DiskLineNum eq "" ) { $AssignedAdpVol = "---"; } else { for( $AdpVolSeq2 = scalar(@AdpVolLineNum -1); $AdpVolSeq2 >= 0 ; $AdpVolSeq2-- ) { if( $DiskLineNum > $AdpVolLineNum[$AdpVolSeq2] ) { $AssignedAdpVol = "LD".$AdpVolSeq2; last; } } } if( index($DiskInfo[3],"Rebuild",0) > -1 ) { $RebuildProg = `MegaCli -PDRbld -ShowProg -PhysDrv[$EncSeqNum:$SlotSeq] -a$i 2> /dev/null | grep Rebuild 2> /dev/null | awk '{ gsub(\"Rebuild.*Completed\",\"\");print \$1 }'`; chomp($RebuildProg); } else { $RebuildProg = "---"; } if( index($DiskInfo[3],"Unconfigured(bad)",0) > -1 ) { system("MegaCli -PDMakeGood -PhysDrv[$EncSeqNum:$SlotSeq] -a$i > /dev/null 2>&1"); $DiskInfo[3] = `MegaCli -pdInfo -PhysDrv[$EncSeqNum:$SlotSeq] -a$i | grep 'Firmware.*state' 2> /dev/null | awk -F: '{ gsub(\" \",\"\");print \$2}'`; chomp($DiskInfo[3]); } } else { $DiskInfo[0] = $EncSeqNum; $DiskInfo[1] = $SlotSeq; $DiskInfo[2] = "----"; $DiskInfo[3] = "----"; $DiskInfo[4] = "-------"; $AssignedAdpVol = "---"; $RebuildProg = "---"; } $~="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_9.3 $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/cli32 event info| 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 | 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("MegaCli -AdpEventLog -GetEvents -f /var/log/raidlog -aALL > /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("MegaCli -AdpEventLog -GetEvents -f /var/log/raidlog -aALL > /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 > /dev/null 2>&1"); } elsif( $device eq "areca" ) { ArecaPrecede; system("/sbin/cli32 event clear > /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 > /dev/null 2>&1"); } } elsif( $device eq "megaraid_sas" ) { system("MegaCli -AdpEventLog -Clear -aALL > /dev/null 2>&1"); if( -e "/var/log/raidlog" ) { system("rm -f /var/log/raidlog 2> /dev/null"); } system("MegaCli -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("MegaCli -AdpEventLog -GetEvents -f /var/log/raidlog -aALL > /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"); } } } ############################################################################ # << 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( -s "$GMonLogPath/alert_list" ) { $AlertList2 = ""; open(ALERTLIST,"+<$GMonLogPath/alert_list"); 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 "" ) { close(ALERTLIST); unlink("$GMonLogPath/alert_list"); unlink("$GMonLogPath/alarm_ringing_list"); unlink("$GMonLogPath/alarm_ringing_level"); system("$AlarmPath/AlarmPlayer stop > /dev/null 2>&1"); sleep(0.05); system("$AlarmPath/AlarmPlayer stop > /dev/null 2>&1"); } else { truncate ALERTLIST, 0; seek ALERTLIST,0,0; print ALERTLIST "$AlertList2"; close(ALERTLIST); } } ############ Update Alarm Ringing List ############################# if( -s "$GMonLogPath/alarm_ringing_list") { $AlarmRingList2 = ""; $FirstLineReaded = 0; open(ALARMLIST,"+<$GMonLogPath/alarm_ringing_list"); 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 "" ) { close(ALARMLIST); unlink("$GMonLogPath/alarm_ringing_list"); if( -e "$GMonLogPath/alarm_ringing_level" ) { unlink("$GMonLogPath/alarm_ringing_level"); } system("$AlarmPath/AlarmPlayer stop > /dev/null 2>&1"); } else { truncate ALARMLIST, 0; seek ALARMLIST,0,0; print ALARMLIST "$AlarmRingList2"; 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 > /dev/null 2>&1"); open(ALARMLEVEL,">$GMonLogPath/alarm_ringing_level"); print ALARMLEVEL "$AlertLevel2\n"; close(ALARMLEVEL); system("$AlarmPath/AlarmPlayer start $AlarmMelody loop > /dev/null &"); } } } else { if( -e "$GMonLogPath/alarm_ringing_list" ) { unlink("$GMonLogPath/alarm_ringing_list"); } if( -e "$GMonLogPath/alarm_ringing_level" ) { unlink("$GMonLogPath/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; if( $AlertLevel =~ /\d/ ) { last; } } } close(GMONCONF); } if( $AlertLevel =~ /\D/ ) { $AlertLevel = 3; } if($NotifyName =~ /_Warning/ ) { if( $AlertLevel != 1 ) { $AlertLevel--; } } } 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( -s "$GMonLogPath/alert_list" ) { $AlertExist = 0; open(ALERTLIST,"+<$GMonLogPath/alert_list"); while() { if( $_ =~ /$NotifyNameTemp/ ) { $AlertExist = 1; } else { $AlertList .= $_; } } truncate ALERTLIST, 0; seek ALERTLIST,0,0; } else { open(ALERTLIST,">$GMonLogPath/alert_list"); } &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"; close(ALERTLIST); if($AlertExist) { if($NotifyName =~ /Critical/) { unlink("$GMonLogPath/".$NotifyNameTemp."_Warning"); } elsif($NotifyName =~ /Warning/) { unlink("$GMonLogPath/".$NotifyNameTemp."_Critical"); } } } }