#!/bin/bash
set +x
LOG_FILE="/var/log/inspect.log"
G_MML_FILE_PATH="/opt/huawei/snas/script/inspect_mml"
source $G_MML_FILE_PATH/CheckItems
source $G_MML_FILE_PATH/CommonFunc.sh
CurInspectNum="122"
CurInspectFun="$(GetInspectType $CurInspectNum)"
RESULTFILE="/tmp/tmpResult${CurInspectFun}"
LOCAL_BACK_IP=""
isPass=0
>${RESULTFILE}

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

function checkSysLog()
{
    LOCAL_BACK_IP=`GetLocalIp`
    if [ "${LOCAL_BACK_IP}X" == "X" ];then
        echo "[ERR]Node:$(hostname)||INFO:Can't get backend IP." >> ${RESULTFILE} 2>&1
        LOG "[ERR]Node:$LOCAL_BACK_IP ||INFO:Command exec faild."
        isPass=1
        return
    fi

    info=$(systemctl status rsyslog | grep running | wc -l)
    iRet=$?
    if [ $iRet -ne 0 ]; then
        echo "[ERR]Node: $LOCAL_BACK_IP||INFO: Failed to execute command(systemctl status rsyslog)" >> ${RESULTFILE} 2>&1
        LOG "Node: $LOCAL_BACK_IP||INFO: Failed to execute syslog"
        isPass=1
        return
    fi

    if [ $info -ne 1 ]; then
        echo "[ERR]Node:$LOCAL_BACK_IP||INFO: service syslog is not running" >> ${RESULTFILE} 2>&1
        LOG "Node: $LOCAL_BACK_IP||INFO: service syslog is not running"
        isPass=1
    else
        isPass=0
        echo "Node: $LOCAL_BACK_IP||INFO: service syslog is running" >> ${RESULTFILE} 2>&1
    fi
}

checkSysLog
echo "${CurInspectFun}_Pass $isPass" >>${RESULTFILE} 2>&1

