Created
May 12, 2015 23:52
-
-
Save ozzyjohnson/4b773c4f4eb0ce7c4473 to your computer and use it in GitHub Desktop.
ESXi CDP Neighbor to CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Parses the output of CDP neighbor information from a VMWare ESXi host. | |
# | |
#------------------------- | |
#hostname vmnic1 | |
#CdpVersion : 2 | |
#Timeout : 0 | |
#Ttl : 152 | |
#Samples : 9854 | |
#DevId : aaa-bbbb-cccc-dd | |
#Address : 10.10.1.1 | |
#PortId : GigabitEthernet1/0/4 | |
#DeviceCapability : VMware.Vim.PhysicalNicCdpDeviceCapability | |
#SoftwareVersion : unknown | |
#HardwarePlatform : cisco WS-CBS3130X-S-F | |
#IpPrefix : 0.0.0.0 | |
#IpPrefixLen : 0 | |
#Vlan : 604 | |
#FullDuplex : True | |
#Mtu : 0 | |
#SystemName : | |
#SystemOID : | |
#MgmtAddr : 10.10.1.1 | |
#Location : | |
#DynamicType : | |
#DynamicProperty : | |
#------------------------- | |
BEGIN { | |
Host = "" | |
VMNic = "" | |
Vlan = "" | |
DevId = "" | |
Address = "" | |
PortId = "" | |
CdpVersion = "" | |
Timeout = "" | |
Ttl = "" | |
Samples = "" | |
DeviceCapability = "" | |
SoftwareVersion = "" | |
HardwarePlatform = "" | |
IpPrefix = "" | |
IpPrefixLen = "" | |
FullDuplex = "" | |
Mtu = "" | |
SystemName = "" | |
SystemOID = "" | |
MgmtAddr = "" | |
Location = "" | |
DynamicType = "" | |
DynamicProperty = "" | |
printf("Host, Vlan,VMNic,DevId,Address,PortId,CdpVersion,Timeout,Ttl,Samples,DeviceCapability,SoftwareVersion,HardwarePlatform,IpPrefix,IpPrefixLen,FullDuplex,Mtu,SystemName,SystemOID,MgmtAddr,Location,DynamicType,DynamicProperty\n");} | |
function trim(field) { | |
gsub(/^[ \t]+|[ \s]+|[ \t]+$/,"",field) | |
return field; | |
} | |
/^[a-z]/ {Host = $1; VMNic = $2} | |
/^Vlan/ {split($0,a,":");Vlan = a[2];} | |
/^DevId/ {split($0,a,":");DevId = a[2];} | |
/^Address/ {split($0,a,":");Address = a[2];} | |
/^PortId/ {split($0,a,":");PortId = a[2];} | |
/^CdpVersion/ {split($0,a,":");CdpVersion = a[2];} | |
/^Timeout/ {split($0,a,":");Timeout = a[2];} | |
/^Ttl/ {split($0,a,":");Ttl = a[2];} | |
/^Samples/ {split($0,a,":");Samples = a[2];} | |
/^DeviceCapability/ {split($0,a,":");DeviceCapability = a[2];} | |
/^SoftwareVersion/ {split($0,a,":");SoftwareVersion = a[2];} | |
/^HardwarePlatform/ {split($0,a,":");HardwarePlatform = a[2];} | |
/^IpPrefix/ {split($0,a,":");IpPrefix = a[2];} | |
/^IpPrefixLen/ {split($0,a,":");IpPrefixLen = a[2];} | |
/^FullDuplex/ {split($0,a,":");FullDuplex = a[2];} | |
/^Mtu/ {split($0,a,":");Mtu = a[2];} | |
/^SystemName/ {split($0,a,":");SystemName = a[2];} | |
/^SystemOID/ {split($0,a,":");SystemOID = a[2];} | |
/^MgmtAddr/ {split($0,a,":");MgmtAddr = a[2];} | |
/^Location/ {split($0,a,":");Location = a[2];} | |
/^DynamicType/ {split($0,a,":");DynamicType = a[2];} | |
/^DynamicProperty/ {split($0,a,":");DynamicProperty = a[2];} | |
/^$/ { | |
printf("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n",Host, Vlan,VMNic,DevId,Address,PortId,CdpVersion,Timeout,Ttl,Samples,DeviceCapability,SoftwareVersion,HardwarePlatform,IpPrefix,IpPrefixLen,FullDuplex,Mtu,SystemName,SystemOID,MgmtAddr,Location,DynamicType,DynamicProperty) | |
host = "" | |
VMNic = "" | |
Vlan = "" | |
DevId = "" | |
Address = "" | |
PortId = "" | |
CdpVersion = "" | |
Timeout = "" | |
Ttl = "" | |
Samples = "" | |
DeviceCapability = "" | |
SoftwareVersion = "" | |
HardwarePlatform = "" | |
IpPrefix = "" | |
IpPrefixLen = "" | |
FullDuplex = "" | |
Mtu = "" | |
SystemName = "" | |
SystemOID = "" | |
MgmtAddr = "" | |
Location = "" | |
DynamicType = "" | |
DynamicProperty = "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment