#!/bin/bash
set +x

#检查IOB卡状态
#G_INSPECT_MMLPATH="/opt/huawei/snas/script/inspect_mml"
#source ${G_INSPECT_MMLPATH}/CheckItems
source /opt/inspect/inspect_map.sh
CurInspectNum="152"
CurInspectFun="$( GetInspectType $CurInspectNum )"
RESULTFILE="${G_TMP_INSPECT_PATH}tmpResult${CurInspectFun}"
>${RESULTFILE}

LOG_FILE="/var/log/inspect.log"
source /opt/node_type_recognize.sh

function LOG
{
   time=$(date)
   echo [${time}][$$][$CurInspectFun]$@ >> $LOG_FILE
}

function CheckIOBStatus
{
    local isPass=0
    local iobType

    IsTS5280Node
    if [ $? -ne 0 ];then
        echo "IOBStatus:Do not involve to inspect(NOT TS5280Node)." >>${RESULTFILE} 2>&1
        echo "${CurInspectFun}_Pass ${isPass}" >>${RESULTFILE} 2>&1
        exit 0
    fi

    iobType=$( ipmitool raw 0x30 0x93 0xdb 0x07 0x00 0x36 0x22 0x00 0x01 0xff 0x00 0x00 0xff 0xff 0x73 0x01 0x00 0x08 0x00 2>/dev/null | awk '{print $NF}' )
    if [ "X${iobType}" != "X" -a "X${iobType}" == "X42" ]; then
        # BC82IOBB卡获取回显：db 07 00 00 08 00 73 08 42 43 38 32 49 4f 42 42
        IOBStatus=$( /usr/bin/ipmitool raw 0x30 0x93 0xdb 0x07 0x00 0x36 0x22 0x00 0x01 0x06 0x00 0x00 0x08 0x00 0x75 0x08 0x42 0x43 0x38 0x32 0x49 0x4F 0x42 0x42 0x07 0x00 | awk '{print $9}' )
    else
        # BC82IOBA卡获取回显：db 07 00 00 08 00 73 08 42 43 38 32 49 4f 42 41
        IOBStatus=$( /usr/bin/ipmitool raw 0x30 0x93 0xdb 0x07 0x00 0x36 0x22 0x00 0x01 0x06 0x00 0x00 0x08 0x00 0x75 0x08 0x42 0x43 0x38 0x32 0x49 0x4F 0x42 0x41 0x07 0x00 | awk '{print $9}' )
    fi
    #值为00，则状态正常，否则不正常
    if [ "${IOBStatus}X" == "00X" ];then
        IOBStatus=normal
    else
        IOBStatus=abnormal
        isPass=1
        ErrInfoCommon "INFO: IOBStatus is abnormal." "${RESULTFILE}"
    fi

    if [ "X${iobType}" != "X" -a "X${iobType}" == "X42" ]; then
        isPass=1
        ErrInfoCommon "INFO: IOB type is BC82IOBB,if the version is upgraded to 7.1.1.SPC600, special processing is required." "${RESULTFILE}"
    fi

    echo "IOBStatus:${IOBStatus}" >>${RESULTFILE} 2>&1
    echo "${CurInspectFun}_Pass ${isPass}" >>${RESULTFILE} 2>&1
    exit 0
}
CheckIOBStatus

