#!/bin/bash
set +x

CurInspectNum="218"
G_INSPECT_MMLPATH="/opt/huawei/snas/script/inspect_mml"
source $G_INSPECT_MMLPATH/CheckItems
LOG_FILE="/var/log/inspect.log"
isPass=0
Result=""
CurInspectFun="$(GetInspectType $CurInspectNum)"
RESULTFILE="/tmp/tmpResult${CurInspectFun}"
>${RESULTFILE}

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

function checkSystemFileOpened()
{
	SystemFileOpenedInfo=$(cat /proc/sys/fs/file-nr)

	usedunm=`echo "${SystemFileOpenedInfo}"|awk '{print $1}'`
	unusedunm=`echo "${SystemFileOpenedInfo}"|awk '{print $2}'`
	maxCount=`echo "${SystemFileOpenedInfo}"|awk '{print $3}'`
	fileCount=`expr $usedunm + $unusedunm`

	percentage=$(echo "scale=4; $fileCount*100/$maxCount"|bc -l| awk '{printf "%.4f", $0}')

	Result="FileCount:$fileCount||MaxFileCount:$maxCount||Percentage(%):$percentage"
	percentage=`echo $fileCount*100/$maxCount|bc -l`
	if [ `echo "$percentage > 80" | bc` -eq 1  ];then
		isPass=1
		echo "[ERR]INFO:FileCount($fileCount) is great than 80% of MaxFileCount($maxCount)." >> ${RESULTFILE}
	fi

	echo "$Result" >>${RESULTFILE} 2>&1
    echo "${CurInspectFun}_Pass ${isPass}" >>${RESULTFILE} 2>&1
	LOG "[$LINENO]:usedunm:$usedunm,unusedunm:$unusedunm,fileCount:$fileCount,maxCount:$maxCount,percentage:$percentage"

    return 0
}

checkSystemFileOpened
