############################################################
# 所属模块	: OceanStor9000 巡检工具
# 功能      : NTP 服务
# 创建时间	:
# 描述		：
#
#
#
############################################################
#!/bin/sh
set +x

G_MML_FILE_PATH="/opt/huawei/snas/script/inspect_mml"
source $G_MML_FILE_PATH/CheckItems
CurInspectNum="205"
CurInspectFun="$(GetInspectType $CurInspectNum)"
RESULTFILE="/tmp/tmpResult${CurInspectFun}"
LOG_FILE="/var/log/inspect.log"
>${RESULTFILE}


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

function main()
{
    local tmpNtpCfgFile="/tmp/tmpfileNtpCfgFile$$"
    local tmpStatusFile="/tmp/tmpfileNtpStatusFile$$"
    local iRet=0

    systemctl status ntpd > ${tmpStatusFile} 2>&1
    iRet=$?
    if [ -f "/etc/ntp.conf" ];then
        cat /etc/ntp.conf > ${tmpNtpCfgFile} 2>&1
    else
        iRet=1
    fi

    if [ ${iRet} -eq 0 ];then
        cat ${tmpStatusFile} >> ${RESULTFILE}
        echo "${G_SEPARATOR}" >> ${RESULTFILE}
        cat ${tmpNtpCfgFile} >> ${RESULTFILE}
    else
        echo "[ERR]INFO:Failed to execute(systemctl status ntpd) or /etc/ntp.conf is not exist." >> ${RESULTFILE}
        LOG "[$LINENO]Can not get service ntp information,iRet=${iRet}"
    fi

    if [ -f ${tmpNtpCfgFile} ];then
        rm -f ${tmpNtpCfgFile}
    fi

    if [ -f ${tmpStatusFile} ];then
        rm -f ${tmpStatusFile}
    fi
}
main
exit 0
