#!/bin/bash

#检查xml文件是否破损
G_INSPECT_MMLPATH="/opt/huawei/snas/script/inspect_mml"
source ${G_INSPECT_MMLPATH}/CheckItems
CurInspectNum="313"
CurInspectFun="$( GetInspectType $CurInspectNum )"
RESULTFILE="/tmp/tmpResult${CurInspectFun}"
>${RESULTFILE}

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

function CheckXML()
{
    local deployfile="/opt/huawei/deploy/etc/deployconfig.xml"
    local checkToolName="checkxml.py"
    local isPass=0
    
    if [ ! -s "${deployfile}" ];then
        isPass=1
        echo "INFO:The file ${deployfile} does not exist or is empty." >>${RESULTFILE} 2>&1
        echo "${CurInspectFun}_Pass ${isPass}" >>${RESULTFILE} 2>&1
        LOG "[$FUNCNAME]${CurInspectFun}_Pass ${isPass}. The file ${deployfile} does not exist or is empty"
        return 
    fi
    
    #检查xml的良构性
    if [ ! -f "${G_INSPECT_MMLPATH}/${checkToolName}" ];then
        isPass=1
        echo "INFO:The check tool ${G_INSPECT_MMLPATH}/${checkToolName} does not exist,can not check the xml file." >>${RESULTFILE} 2>&1
        echo "${CurInspectFun}_Pass ${isPass}" >>${RESULTFILE} 2>&1
        LOG "[$FUNCNAME]${CurInspectFun}_Pass ${isPass}. The check tool ${G_INSPECT_MMLPATH}/${checkToolName} does not exist,can not check the xml file."
        return
    fi
    
    ${G_INSPECT_MMLPATH}/${checkToolName} "${RESULTFILE}" "${deployfile}"
    if [ $? -ne 0 ];then
        isPass=1
        #错误信息输出在checkxml.py文件中
        echo "${CurInspectFun}_Pass ${isPass}" >>${RESULTFILE} 2>&1
        LOG "[$FUNCNAME]${CurInspectFun}_Pass ${isPass}"
        return
    fi
    
    echo "INFO:The file ${deployfile} structure is in order." >>${RESULTFILE} 2>&1
    echo "${CurInspectFun}_Pass ${isPass}" >>${RESULTFILE} 2>&1
    LOG "[$FUNCNAME]${CurInspectFun}_Pass ${isPass}"
    return
}

CheckXML



