Thursday, October 10, 2013

Script to report the HBA cards status

I have a small function to detect the emulex, and qlogic HBA cards for a quick one. If you find it useful in your automation you can embed this function to your script and start calling it. Hope that it helps you in your works. Thanks!

function check_hba ()
{

        # Checking Emulex HBA cards status

        if grep -q -i "online" /sys/class/fc_host/host*/port_state 2>/dev/null
        then
                num_online_hba=`grep -i "online" /sys/class/fc_host/host*/port_state | wc -l`
                total_hbas=`ls -1 /sys/class/fc_host/host*/node_name | wc -l`

                echo "Linux discovered $num_online_hba HBAs is online out of $total_hbas cards."

                for h in `ls -1 /sys/class/fc_host/host*/node_name | awk -F/ '{print $5}'`
                do
                        wwn=`cat /sys/class/fc_host/$h/port_name`
                        state=`cat /sys/class/fc_host/$h/port_state`
                        #modelname=`cat /sys/class/scsi_host/$h/modelname`
                        #echo "HBA $modelname : $wwn is $state"
                        echo "HBA : $wwn is $state"
                done
        fi

        # Checking Qlogic HBA cards status
        if grep -q -i "ready" /proc/scsi/qla2xxx/* 2>/dev/null
        then
                total_hbas=`ls -1 /proc/scsi/qla2xxx/* | wc -l`
                num_online_hba=`grep -i "ready" /proc/scsi/qla2xxx/*| wc -l`

                echo "Linux discovered $num_online_hba is online out of $total_hbas cards."

                for h in `ls -1 /proc/scsi/qla2xxx/*`
                do
                        wwn=`cat $h|grep "scsi-qla.-adapter-port*" | awk -F= '{print $2}' | sed -e 's|;||g'`
                        grep -i -q "Host adapter.*ready" $h && echo "HBA : $wwn is Online" || echo "HBA : $wwn is Offline"
                done
        fi

}

No comments: