Showing results for 
Search instead for 
Did you mean: 

LLDP and scripting - EEM


Hi All,

we have a lab network and different things are connected/re-connected/moved etc all the time.  We have 2960x switches that i want to enable lldp on this in because we have multi vendor devices connecting into them. 

I was hoping that when we enable lldp that the information like the hostname can be automatically updated to the port description on the 2960x - version universalk9-mz.150-2.EX5.bin?

if this is possible can you point me in the right direction on a script we can use?


8 Replies 8

From theory view you can, but I need to lab it to check.

CDP and LLDP are link layer protocols for directly-connected CDP/LLDP capable devices to advertise themselves and their capabilities

if this is possible can you point me in the right direction on a script we can use?

- what script you looking, Once you enabled based on LLDP device, you would like to change the port description ?

what if the device moved to differnt port - you looking to change weekly or daily basis this information ?


***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help


copy and paste this script:

event manager applet LLDP_UPDATE_PORT_DESCRIPTION authorization bypass
description "Auto-update port-description based on LLDP neighbor info"
event neighbor-discovery interface regexp .*GigabitEthernet[1-9]/[0-9]/[0-9]+$ lldp add
action 0.0 comment "Event line regexp: Decide which interface to auto-update description on"
action 1.0 comment "Verify LLDP neighbor to be Switch or Router"
action 1.1 regexp "(Switch|Router|AIR)" "$_nd_lldp_capabilities_string"
action 1.2 if $_regexp_result eq "1"
action 2.0 comment "Trim domain name"
action 2.1 regexp "^([^\.]+)" "$_nd_lldp_entry_name" match host
action 3.0 comment "Convert long interface name to short"
action 3.1 string first "Ethernet" "$_nd_port_id"
action 3.2 if $_string_result eq "7"
action 3.21 string replace "$_nd_port_id" 0 14 "Gi"
action 3.3 elseif $_string_result eq 10
action 3.31 string replace "$_nd_port_id" 0 17 "Te"
action 3.4 elseif $_string_result eq 4
action 3.41 string replace "$_nd_port_id" 0 11 "Fa"
action 3.5 end
action 3.6 set int "$_string_result"
action 4.0 comment "Check old description if any, and do no change if same host:int"
action 4.1 cli command "enable"
action 4.11 cli command "config t"
action 4.2 cli command "do show interface $_nd_local_intf_name | incl Description:"
action 4.21 set olddesc "<none>"
action 4.22 set olddesc_sub1 "<none>"
action 4.23 regexp "Description: ([a-zA-Z0-9:/\-]*)([a-zA-Z0-9:/\-\ ]*)" "$_cli_result" olddesc olddesc_sub1
action 4.24 if $olddesc_sub1 eq "$host:$int"
action 4.25 syslog msg "EEM script did NOT change description on $_nd_local_intf_name, since remote host and interface is unchanged"
action 4.26 exit 10
action 4.27 end
action 4.3 cli command "interface $_nd_local_intf_name"
action 4.4 cli command "description LINK TO: $host:$int"
action 4.5 cli command "do write"
action 4.6 syslog msg "EEM script updated description on $_nd_local_intf_name from $olddesc to Description: $host:$int and saved config"
action 5.0 end
action 6.0 exit



sorry i should of been more clear. The model is - "WS-C2960XR-48TD-I"

does the config above still stand? if so please can you provide a high level of what this is doing for example how often is it checking the lldp output?

Thanks and appreciate your response.


the script would run every time a new neighbor sends an LLDP message.

I am not sure if that script can run on your 2960XR. Paste it in and see if you get any error messages...

thanks - i need to upgrade first as it's not taking the command.

What command not accept?

EEM script needs to be run in each device if you looking to do this task - I would suggest making a python script and out of the box making automation.

EEM Script can be any device - you need to provide more evidence of what error you getting while you implement that commands, 

if you running first-time EEM script, suggest pasting line by line to capture the correct error and line number.


***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: