#!/bin/sh
set +x
G_MML_FILE_PATH="/opt/huawei/snas/script/inspect_mml"
source $G_MML_FILE_PATH/CheckItems
CurInspectNum="332"
CurInspectFun="$(GetInspectType $CurInspectNum)"
RESULTFILE="${G_TMP_INSPECT_PATH}tmpResult${CurInspectFun}"
LOG_FILE="/var/log/inspect.log"

>${RESULTFILE}

function CheckiBMA
{
    local isPass=0
    local productPartNum="02355NEX"    # ƶı
    local curProductPartNum=""
    local result="No iBMA"
    local isArm=$(arch)
    if [ X"$isArm" = X"x86_64" ];then
        result="No need check(x86)."
    else
        # ƶiBMAҪͬʱļڴй¶
        curProductPartNum=$( ipmitool fru | grep "Product Part Number" | awk '{print $NF}' | sed "s/ *//g" | sed "s/ *$//g" )
        if [ X"${curProductPartNum}" != X"${productPartNum}" ]
        then
            systemctl status iBMA 2>/dev/null | dos2unix | grep -q "Active: active (running)"
            if [ $? -eq 0 ];then
                isPass=1
                result="The iBMA has been deployed."
            else
                result="No iBMA."
            fi
        else
            systemctl status iBMA 2>/dev/null | dos2unix | grep -q "Active: active (running)"
            if [ $? -ne 0 ];then
                isPass=1
                result="The iBMA is not running status."
            
            else
                # ƶɵMonitorļõģҪг
                grep -A10 "\"iBMA\"" /opt/huawei/ibma/config/Monitor.ini | grep enabled | grep -qi true
                ibmaEnable=$?
                if [ ${ibmaEnable} -ne 0 ]; then
                    isPass=1
                    result="The iBMA has been deployed,Product Part Number:${curProductPartNum},but /opt/huawei/ibma/config/Monitor.ini format is correct."
                else
                    result="The iBMA status is normal."
                fi
            fi
        fi
    fi
    echo "result:${result}" >>${RESULTFILE} 2>&1
    echo "${CurInspectFun}_Pass ${isPass}" >>${RESULTFILE} 2>&1
}

CheckiBMA
exit 0

