#set -x
# getinfoesx V1.0

infoesx=`uname -n`
if [ ! -d $infoesx ];then
	mkdir $infoesx
	else
	rm $infoesx/*
fi
vmware -v | grep -F 5.5. > /dev/null
if [ $? -eq 0 ] ; then
version=55
fi
vmware -v | grep -F 5.1. > /dev/null
if [ $? -eq 0 ] ; then
version=51
fi
vmware -v | grep -F 5.0. > /dev/null
if [ $? -eq 0 ] ; then
version=50
fi

echo " getinfoesx V1 "
echo " getinfoesx V1 " > $infoesx/getinfoesx.txt
vmware -l -v >> $infoesx/getinfoesx.txt
echo " " >> $infoesx/getinfoesx.txt
echo " ***************** uname ****************" >> $infoesx/getinfoesx.txt
uname -a >> $infoesx/getinfoesx.txt
echo " " >> $infoesx/getinfoesx.txt
echo " ***************** time *****************" >> $infoesx/getinfoesx.txt
esxcli system time get >> $infoesx/getinfoesx.txt
echo " " >> $infoesx/getinfoesx.txt
echo " *****************   boot device ***************** " >> $infoesx/getinfoesx.txt
esxcli system boot device get >> $infoesx/getinfoesx.txt
echo " " >> $infoesx/getinfoesx.txt

echo " getting software info. "
esxcli software vib list > $infoesx/vib_list.txt
esxcli system module list > $infoesx/module_list.txt
lspci > $infoesx/lspci.txt
smbiosDump > $infoesx/smbiosDump.txt

# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# Network adapter info.
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo " getting network info. "
esxcli network nic list > $infoesx/nic_list.txt

# recup info par vmnic
grep -i 'vmnic' $infoesx/nic_list.txt | sed -n "s/vmnic//p" | cut -d ' ' -f1 > $infoesx/workfile
for i in `cat $infoesx/workfile`
do
echo vmnic$i >> $infoesx/vmnic_versions.txt
ethtool -i vmnic$i >> $infoesx/vmnic_versions.txt
ethtool -e vmnic$i offset 0 length 0x6f >> $infoesx/vmnic_versions.txt
echo ' ' >> $infoesx/vmnic_versions.txt

echo " ethtool -S : adapter statistics " >> $infoesx/vmnic$i".txt"
ethtool -S vmnic$i >> $infoesx/vmnic$i".txt"
echo " " >> $infoesx/vmnic$i".txt" 

# recup stats et config par vmnic
echo " ethtool -a : pause options " >> $infoesx/vmnic$i".txt"
ethtool -a vmnic$i >> $infoesx/vmnic$i".txt"
echo " " >> $infoesx/vmnic$i".txt" 

echo " ethtool -c : coalesce options " >> $infoesx/vmnic$i".txt"
ethtool -c vmnic$i >> $infoesx/vmnic$i".txt"
echo " " >> $infoesx/vmnic$i".txt" 

echo " ethtool -g : RX/TX ring parameters " >> $infoesx/vmnic$i".txt"
ethtool -g vmnic$i >> $infoesx/vmnic$i".txt"
echo " " >> $infoesx/vmnic$i".txt" 

echo " ethtool -k : protocol offload information " >> $infoesx/vmnic$i".txt"
ethtool -k vmnic$i >> $infoesx/vmnic$i".txt"
echo " " >> $infoesx/vmnic$i".txt"

done

# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# Storage info.
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo " getting storage info. "
esxcli storage core device list > $infoesx/storage_info.txt
esxcfg-scsidevs -a > $infoesx/vmhba_list.txt
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# Emulex hba info. (lpfc820 module)
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if [ $version -eq 51 ] || [ $version -eq 50 ]; then
ls /proc/scsi/lpfc820 > $infoesx/workfile

for i in `cat $infoesx/workfile`
do
echo '****************** Start lpfc820_'$i' section *****************' >> $infoesx/emulex_hba_info.txt
cat /proc/scsi/lpfc820/$i >> $infoesx/emulex_hba_info.txt
echo '****************** End lpfc820_'$i' section *****************' >> $infoesx/emulex_hba_info.txt
echo ' ' >> $infoesx/emulex_hba_info.txt
done
fi

if [ $version -eq 55 ]; then
# Note: In ESXi 5.5, you do not see native drivers in the /proc nodes. To view native driver information, run the command:
/usr/lib/vmware/vmkmgmt_keyval/vmkmgmt_keyval -a >> $infoesx/emulex_hba_info.txt
fi

# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# copy of log files
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# esxcli system settings kernel list > $infoesx/kernel-settings.txt
echo " getting log files "
cp /var/log/sysboot.log $infoesx/.
cp /var/log/boot.gz $infoesx/.
cp /var/log/syslog.log $infoesx/.	
cp /var/log/vmkernel.log $infoesx/.
cp /var/log/vmkwarning.log $infoesx/.
 
rm $infoesx/workfile
echo " compressing files "
echo " "
tar zcvf $infoesx.tar.gz $infoesx
echo " "
echo "***********************"
echo " output file generated "
echo " Please send the file " $infoesx".tar.gz to Support team"
echo "***********************"
echo " "
