############################################################
# ģ	: OceanStor9000 Ѳ칤
#       : ϵͳǷдĿ¼
# ʱ	: 20140716
#       
#           MDSͳƵĿ¼ж
#           ڴ򿪾̬ѹܵ£Ŀ¼200000Ѳ첻ͨ
#           ڹرվ̬ѹܵ£Ŀ¼10000Ѳ첻ͨ
############################################################

#!/bin/sh
set +x

SNAS_LOG_FILE="/var/log/snasmessages"
LOG_FILE="/var/log/inspect.log"
MDS_INI_FILE="/opt/huawei/snas/static/mds.ini"
NEW_FILE_CNT="10000"
NEW_FILE_BIG_CNT="200000"

tmpBigDirInfo=""

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

function CheckBigDir
{
    local Result=""
    local FileCnt=""
    local iRet=""


    tmpBigDirInfo=`grep "BigDir" $SNAS_LOG_FILE | grep CRI | tail -n 1`
    iRet=$?
    if [ $iRet -ne 0 ];then
        Result="[ERR]Failed to check key words 'BigDir' in log"
        LOG "Failed to check key words 'BigDir' in log"

    elif [ "$tmpBigDirInfo" == "" ];then
        Result="These is no big directory"

    else
        echo $tmpBigDirInfo | grep "BigDirRestore" &> /dev/null
        iRet=$?
        if [ $iRet -eq 0 ];then
            Result="These is no big directory"
        else
            NewFileCnt=`echo $tmpBigDirInfo | awk '{print $5}' | awk '{sub(/^.*-->\(/,"");sub(/)\.].*$/,"");print}'`
            grep "bal_split=0" $MDS_INI_FILE &> /dev/null
            iRet=$?
            if [ $iRet -eq 0 ];then
                if [ "$NewFileCnt" -ge "$NEW_FILE_CNT" ]; then
                    Result="[ERR]There are some big directories"
                else
                    Result="These is no big directory"
                fi
            else
                if [ "$NewFileCnt" -ge "$NEW_FILE_BIG_CNT" ]; then
                    Result="[ERR]There are some big directories"
                else
                    Result="These is no big directory"
                fi
            fi
        fi
    fi

    echo $Result
    return 0

}

CheckBigDir
#Always exit with 0
exit 0
