Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- arg1=$1
- case $arg1 in
- "ready")
- csvHeader="vCPU, %READY, status"
- entityMatch="vmx-vcpu.*Ready"
- maxPassValue="499"
- # i.e. 4.99
- ;;
- "vdiskread")
- csvHeader="vDisk, Read (ms), status"
- entityMatch="Virtual Disk.*scsi.*MilliSec/Read"
- maxPassValue="499"
- ;;
- "vdiskwrite")
- csvHeader="vDisk, Write (ms), status"
- entityMatch="Virtual Disk.*scsi.*MilliSec/Write"
- maxPassValue="499"
- ;;
- *)
- echo "no argument specified, use: ready, vdiskread, vdiskwrite"
- exit
- esac
- esxtopDirectory="$(ls -F *.csv)"
- outputCsv="./output/output_${arg1}.csv"
- if [ ! -f "${outputcsv}" ]
- then
- echo "${csvHeader}" > "${outputCsv}"
- else
- echo "${outputCsv} already exists"
- fi
- for esxtopBatchFile in "${esxtopDirectory}"
- do
- columnListCount=$(head -1 ${esxtopBatchFile} | tr ',' '\n' | nl | sed -e 's/^[[:space:]]*//' | sed -r 's/\s/,/' | grep -e "${entityMatch}" | wc -l)
- if [ "$columnListCount" != "0" ]
- then
- columnList=$(head -1 ${esxtopBatchFile} | tr ',' '\n' | nl | sed -e 's/^[[:space:]]*//' | sed -r 's/\s+/,/' | grep -e "${entityMatch}")
- columnNumber=$(echo -en "${columnList}" | awk -F "," '{print $1}')
- printf "%+10s %+8s %+8s %-36s\n" "Line#" "Value" "Status" "Name"
- printf -- '-%.0s' $(seq 150); echo ""
- while IFS= read -r line
- do
- entityName=$(cat ${esxtopBatchFile} | awk -F "," -v var=$line 'BEGIN{ans=var} {print $ans}' | head -1 | cut -d "\\" -f 4)
- result=$(cat ${esxtopBatchFile} | awk -F "," -v var=$line 'BEGIN{ans=var} {print $ans}' | tail -n +2 | tr -d '"'| sort -r | head -1)
- resultInteger=$(echo "${result}" | tr -dc '0-9')
- #echo ${result}
- #echo ${resultInteger}
- if [ "${resultInteger}" -ge "${maxPassValue}" ]
- then
- status="FAIL"
- else
- status="PASS"
- fi
- echo "${entityName},${resultInteger},${status}" >> "${outputCsv}"
- printf "%+10s %+8s %+8s %-36s\n" "${line}" "${result}" "${status}" "${entityName}"
- done <<<"${columnNumber}"
- else
- echo "skipping ${esxtopBatchFile}, \"${entityMatch}\" didn't match any columns"
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement