cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
57091
Views
26
Helpful
110
Comments
Joe Clarke
Cisco Employee
Cisco Employee

In preparing for CiscoLive! in San Diego, I am provisioning our access layer 3560-E switches.  Since things have a tendency to change a lot at an event like CiscoLive! I thought it would be best to make sure our port descriptions are always up-to-date when it comes to reflecting what devices are connected.  To help me do that, I wrote up this small EEM applet policy.  It will update the port's description based on the CDP neighbor learned on that port.  This policy requires EEM 3.2, so you're looking at 12.2(55)SE or higher for the 3560s.  It will also work on 3750s and ISR G2 routers running 15.x code.

event manager applet update-port-description

event neighbor-discovery interface regexp GigabitEthernet.* cdp 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_cdp_entry_name:$_nd_port_id"

The result of this will be a description like the following on switch ports:

description SDCC_IDF_1.11:TenGigabitEthernet0/1
Comments
Ethan Campbell
Level 1
Level 1

@derek-shnosh @balaji.bandi  I am very close to having this working. Here is my EEM Script:

event manager applet auto-update-port-description authorization bypass
description "Auto-update port-description based on CDP neighbor info"
event neighbor-discovery interface regexp .*(GigabitEthernet|TenGigabitEthernet|TwentyFiveGigE|FortyGigabitEthernet|HundredGigE)[0-9]/[0-9]/[0-9]+$ cdp add lldp add
action 0.0 comment "Event line regexp: Deside which interface to auto-update description on"
action 1.0 comment "Verify CDP neighbor to be Switch or Router"
action 1.1 regexp "(Switch|Router|AIR)" "$_nd_cdp_capabilities_string"
action 1.2 if $_regexp_result eq "1"
action 2.0 comment "Trim domain name"
action 2.1 regexp "^([^\.]+)" "$_nd_cdp_entry_name" match host
action 3.0 comment \\"Normalize neighbor port-id to short form\\"
action 3.1 regexp "\\"^(GigabitEthernet|TenGigabitEthernet|TwentyFiveGigE|FortyGigabitEthernet|HundredGigE)\s*([0-9/]+)$\\"" "\\"$_nd_port_id\\"" match type num
action 3.12 if $_regexp_result eq "1"
action 3.13 if $type eq "\\"GigabitEthernet\\""
action 3.14 set int "\\"Gi$num\\""
action 3.15 elseif $type eq \\"TenGigabitEthernet\\"
action 3.16 set int "\\"Te$num\\""
action 3.17 elseif $type eq \\"TwentyFiveGigE\\"
action 3.18 set int "\\"Twe$num\\""
action 3.19 elseif $type eq \\"FortyGigabitEthernet\\"
action 3.20 set int "\\"Fo$num\\""
action 3.21 elseif $type eq \\"HundredGigE\\"
action 3.22 set int "\\"Hu$num\\""
action 3.23 end
action 3.24 else
action 3.25 regexp "\\"^(Gi|Te|Twe|Fo|Hu)\s*([0-9/]+)$\\"" "\\"$_nd_port_id\\"" _match abbr num
action 3.26 if $_regexp_result eq "1"
action 3.27 set int "\\"$abbr$num\\""
action 3.28 else
action 3.29 set int "\\"$_nd_port_id\\""
action 3.30 end
action 3.31 end
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 desciption 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 $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 1
!
end

 

The only part that isn't working for me now is the conversion to short form. These are the results I am getting:

EthanCampbell_0-1763563847049.png

I think I have an error somewhere between action 3.1 and 3.24

balaji.bandi
Hall of Fame
Hall of Fame

What is the real outcome of the CDP neighbour before updating the description?

Ethan Campbell
Level 1
Level 1

@balaji.bandi Is this what you are wanting?

 

Device ID: stlswcor001a
Entry address(es):
IP address: ***.***.***.***
Platform: cisco C9500-48Y4C, Capabilities: Router Switch IGMP
Interface: TenGigabitEthernet1/1/1, Port ID (outgoing port): TwentyFiveGigE1/0/15
Holdtime : 152 sec

Version :
Cisco IOS Software [Dublin], Catalyst L3 Switch Software (CAT9K_IOSXE), Version 17.12.5, RELEASE SOFTWARE (fc5)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2025 by Cisco Systems, Inc.
Compiled Fri 14-Mar-25 02:41 by mcpre

advertisement version: 2
Peer Source MAC: **********
VTP Management Domain: '***'
Native VLAN: 1
Duplex: full
Management address(es):
IP address: ***.***.***.***

 

Ethan Campbell
Level 1
Level 1

@balaji.bandi Or even this? 

 

stlswcor001a Ten 1/1/1 139 R S I C9500-48Y Twe 1/0/15

Ethan Campbell
Level 1
Level 1

@balaji.bandi I even attempted this script but I can't seem to get the Twe interfaces working.

 

event manager applet auto-update-port-description authorization bypass
description "Auto-update port-description based on CDP neighbors info"
event neighbor-discovery interface regexp .*GigabitEthernet[1-9]/[0-9]/[0-9]+$ cdp add
action 0.0 comment "Event line regexp: Deside which interface to auto-update description on"
action 1.0 comment "Verify CDP neighbor to be Switch or Router"
action 1.1 regexp "(Switch|Router)" "$_nd_cdp_capabilities_string"
action 1.2 if $_regexp_result eq "1"
action 2.0 comment "Trim domain name"
action 2.1 regexp "^([^\.]+)" "$_nd_cdp_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 16
action 3.41 string replace "$_nd_port_id" 0 22 "Twe"
action 3.45 elseif $_nd_port_id eq "Gig 0"
action 3.451 set int "Gi0"
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 ""
action 4.22 set olddesc_sub1 ""
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 desciption 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 $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 1
!

derek-shnosh
Level 1
Level 1

@Ethan Campbell - your actions 3.1 - 3.41 can be summarized down to two actions using string range, much more simplistic.

action 3.1 string range "$_nd_local_intf_name" 0 2
action 3.2 set intf_type "$_string_result"

This will take the first three characters (0-2) of the neighbor interface name and store them in $intf_type for you to use.

GigabitEthernet becomes Gig
TenGigabitEthernet becomes Ten
TwentyFiveGigE becomes Twe

I provide an example applet using this method in my blog here: https://shnosh.io/blog/eem-cdp-description/

Ethan Campbell
Level 1
Level 1

@derek-shnosh I rewrote as this:

 

event manager applet auto-update-port-description authorization bypass
description "Auto-update port-description based on CDP neighbors info"
event neighbor-discovery interface regexp .*GigabitEthernet[1-9]/[0-9]/[0-9]+$ cdp add
action 0.0 comment "Event line regexp: Deside which interface to auto-update description on"
action 1.0 comment "Verify CDP neighbor to be Switch or Router"
action 1.1 regexp "(Switch|Router)" "$_nd_cdp_capabilities_string"
action 1.2 if $_regexp_result eq "1"
action 2.0 comment "Trim domain name"
action 2.1 regexp "^([^\.]+)" "$_nd_cdp_entry_name" match host
action 3.0 comment "Convert long interface name to short"
action 3.1 string range "$_nd_local_intf_name" 0 2
action 3.2 set intf_type "$_string_result"
action 3.3 end
action 3.4 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 ""
action 4.22 set olddesc_sub1 ""
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 desciption 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 $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 1
!

 

Now I get no description.

derek-shnosh
Level 1
Level 1

@Ethan Campbell - apologies... replace $_nd_local_intf_name with $_nd_port_id in your action 3.1.

Ethan Campbell
Level 1
Level 1

@derek-shnosh Still have no description being generated 

EthanCampbell_0-1764008034711.png

 

 

EthanCampbell_1-1764008053591.png

 

derek-shnosh
Level 1
Level 1

@Ethan Campbell - I didn't really look at the rest of your applet, there are a few other things that need correction. I'm not 100% sure the action 4's will accurately capture the existing interface description, but give this a shot.

event manager applet auto-update-port-description authorization bypass
 description "Auto-update port-description based on CDP neighbors info"
 event neighbor-discovery interface regexp .* cdp add
 action 0.0 comment "Event line regexp: Decide which interface to auto-update description on"
 action 0.1 cli command "enable"
 action 1.0 comment "Verify CDP neighbor to be Switch or Router"
 action 1.1 regexp "Switch|Router" "$_nd_cdp_capabilities_string"
 action 1.2 if $_regexp_result eq "1"
 action 2.0  comment "Trim domain name from host name"
 action 2.1  regexp "^([^\.]+)" "$_nd_cdp_entry_name" match cdp_nei
 action 3.0  comment "Convert neighbor long interface name to short, create newdesc string"
 action 3.1  string range "$_nd_port_id" 0 2
 action 3.2  set nei_intf_type "$_string_result"
 action 3.3  regexp "[/0-9]+$" "$_nd_port_id" nei_intf
 action 3.4  set newdesc "$cdp_nei:$nei_intf_type$nei_intf"
 action 4.0  comment "Check old description, if any"
 action 4.1  cli command "show int $_nd_local_intf_name | i ^[\ ]*[Dd]escription"
 action 4.2  regexp "[Dd]escription:\ *(.*)" "$_cli_result" match olddesc
 action 5.0  comment "Update the description, if necessary"
 action 5.1  if $newdesc eq $olddesc
 action 5.2   syslog msg "EEM script did NOT change desciption on $_nd_local_intf_name, since remote host and interface is unchanged"
 action 5.3  else
 action 5.4   cli command "interface $_nd_local_intf_name"
 action 5.5   cli command "description $newdesc"
 action 5.6   cli command "end"
 action 5.7   cli command "write mem" pattern "confirm|#"
 action 5.8   cli command ""
 action 5.9   syslog msg "EEM script updated description on $_nd_local_intf_name from $olddesc to Description: $host:$int and saved config"
 action 6.0  end
 action 6.1 end

... if that doesn't work, look at my example on my blog (no tracking/ads).

EDIT: Updated action 3.4 to action 3.4 set newdesc "$cdp_nei:$nei_intf_type$nei_intf".

Ethan Campbell
Level 1
Level 1

@derek-shnosh That still didn't work. I am getting no description at all. I will review your blog but so far I'm still at square 1

derek-shnosh
Level 1
Level 1

Turn on EEM debug with debug event manager action cli and share the output...

Ethan Campbell
Level 1
Level 1

@derek-shnosh I'm at a loss. I copied your cdp_desc_platdirectly and I'm still not getting a description. I will attempt a reboot, maybe the switch is bugged out. 

Ethan Campbell
Level 1
Level 1

@derek-shnosh I can see where it is attempting

EthanCampbell_0-1764010903275.png

However, I still don't get a description 

EthanCampbell_1-1764010944565.png

 

derek-shnosh
Level 1
Level 1

That is not showing the debug output, so there is no way to tell where its failing. Please see my last comment and trigger the applet.

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: