01-04-2023 07:11 AM
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?
Thanks
01-04-2023 07:17 AM
From theory view you can, but I need to lab it to check.
01-04-2023 07:22 AM
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 ?
01-04-2023 07:47 AM
Hello,
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
01-04-2023 08:13 AM
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.
01-04-2023 08:46 AM
Hello,
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...
01-04-2023 10:06 AM
thanks - i need to upgrade first as it's not taking the command.
01-04-2023 10:11 AM
What command not accept?
01-04-2023 01:20 PM
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.
01-16-2024 07:01 AM
I'm not so sure that one will work Georg.
First of all there is no "nd_lldp_capabilities_string". You could use the "nd_lldp_enabled_capabilities_string" but then you have to match B|R|W for Bridge/Switch Router or AP.
There is also no "nd_lldp_entry_name" but you have to use "nd_lldp_system_name"
Then there is the top level regex ".*GigabitEthernet[1-9]/[0-9]/[0-9]+$". If you want it to work on a 9500 you would have to add something to match interfaces ending with GigE.
To find more information on what you would like to be in there depending on protocol in use, have a look here and adjust the script accordingly.
https://www.cisco.com/c/en/us/td/docs/ios/netmgmt/configuration/guide/nm_eem_3-2.html#wp1059592
If you need deeper knowledge on LLDP wikipedia is you place.
Cheers!
01-16-2024 07:46 AM
Here is a simple EEM to automate interface descriptions.
event manager applet update-port-description
event neighbor-discovery interface regexp GigabitEthernet.* lldp add
action 1.0 cli command "enable"
action 2.0 cli command "config t"
action 3.0 cli command "interface $_nd_local_intf_name"
action 4.0 cli command "description $_nd_lldp_system_name:$_nd_lldp_port_description
01-16-2024 03:09 PM - edited 01-16-2024 03:27 PM
Yes, but it wont do the job if you run PNP, use a 9500 nor if you would migrate without po link down or just disconnect the circuit. So in real life, your script just doesn't apply or cut it and i don't understand why you post that.
01-16-2024 04:01 PM
01-16-2024 09:48 PM
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide