This is a Cisco Embedded Event Manager (EEM) applet script designed to automatically update interface descriptions on a switch/router based on CDP (Cisco Discovery Protocol) neighbor information. Let me break it down step by step:
What the script does
Trigger: It runs whenever a new CDP neighbor is discovered on an interface (event neighbor-discovery interface regexp .*E*[0-9\/]+$ cdp add).
Neighbor validation: It checks if the neighbor device is a Cisco platform (router, switch, UCS, Nexus, etc.) using regex on the CDP platform string.
Hostname processing: It trims the neighbor’s DNS name to just the hostname (removes domain suffix).
Interface type parsing: It extracts the neighbor’s interface type (e.g., GigabitEthernet, TenGigabitEthernet, FortyGigabitEthernet, etc.) and converts it into a short format (Gi, Te, Fo, etc.) with the port number.
Local interface classification: It inspects the local interface configuration to see if it has:
Root guard → marks as "DOWNLINK"
QoS policy → marks as "UPLINK"
Description building: It constructs a new description string in the format:
<UPLINK/DOWNLINK> - <NeighborHostname> - <NeighborInterface>
Change check: If the current description already matches the new one, it does nothing (logs a syslog message saying no change was needed).
Update action: If different, it enters interface configuration mode and updates the description, then logs the change to syslog.
Example outcome
Suppose interface GigabitEthernet1/0/1 connects to a neighbor switch named SW1 on its GigabitEthernet0/24 port.
Local interface has root guard → "DOWNLINK"
New description becomes:
DOWNLINK - SW1 - Gi0/24
The script applies this description automatically.
event manager applet auto-update-host-description authorization bypass
description "Auto-update port-description based on CDP neighbor info"
event neighbor-discovery interface regexp .*E*[0-9\/]+$ cdp add
action 0.0 comment "Event line regexp: Decide which interface to auto-update description on"
action 1.0 comment "Verify CDP neighbor to be Switch or Router"
action 1.1 comment "auto port description script Version 001"
action 1.2 regexp "(cisco|AIR|UCS|N5K|N9K)" "$_nd_cdp_platform"
action 1.3 if $_regexp_result eq "1"
action 1.4 comment "Trim domain name"
action 1.5 regexp "^([^\.]+)" "$_nd_cdp_entry_name" match dnsname
action 4.0 regexp "([a-zA-z-]*)([0-9\/]*)" "$_nd_port_id" portm portn portnum
action 4.10 regexp "GigabitEthernet" "$_nd_port_id"
action 4.11 if $_regexp_result eq "1"
action 4.12 set port_type "Gi$portnum"
action 4.13 end
action 4.14 regexp "TenGigabitEthernet" "$_nd_port_id"
action 4.15 if $_regexp_result eq "1"
action 4.16 set port_type "Te$portnum"
action 4.17 end
action 4.18 regexp "TwentyFiveGigE" "$_nd_port_id"
action 4.19 if $_regexp_result eq "1"
action 4.20 set port_type "Twe$portnum"
action 4.21 end
action 4.22 regexp "HundredGigE" "$_nd_port_id"
action 4.23 if $_regexp_result eq "1"
action 4.24 set port_type "Hu$portnum"
action 4.25 end
action 4.26 regexp "Br-Ethernet" "$_nd_port_id"
action 4.27 if $_regexp_result eq "1"
action 4.28 set port_type "Eth$portnum"
action 4.29 end
action 4.30 regexp "TwoGigabitEthernet" "$_nd_port_id"
action 4.31 if $_regexp_result eq "1"
action 4.32 set port_type "Tw$portnum"
action 4.33 end
action 4.34 regexp "FortyGigabitEthernet" "$_nd_port_id"
action 4.35 if $_regexp_result eq "1"
action 4.36 set port_type "Fo$portnum"
action 4.37 end
action 4.99 set int "$port_type"
action 4.5 regexp "([a-zA-z]*)" "$_nd_port_id"
action 5.10 comment "Check interface config for root guard or qos"
action 5.14 cli command "enable"
action 5.15 cli command "config t"
action 5.16 cli command "do show running-config interface $_nd_local_intf_name | i guard root|QOS"
action 5.17 regexp "Interface: (.*)" "$_cli_result" match $_nd_local_intf_name
action 5.18 set interface_config "$_cli_result"
action 5.19 set plat2 ""
action 5.20 regexp "guard root" "$interface_config"
action 5.21 if $_regexp_result eq "1"
action 5.22 set plat2 "DOWNLINK"
action 5.23 else
action 5.24 regexp "QOS-OUT|QOS_OUT" "$interface_config"
action 5.25 if $_regexp_result eq "1"
action 5.26 set plat2 "UPLINK"
action 6.37 end
action 6.38 end
action 6.40 set idt1 "$plat2"
action 8.0 comment "Check old description if any, and do no change if same idt - dnsname - int"
action 8.2 cli command "do show interface $_nd_local_intf_name | incl Description:"
action 8.21 set olddesc "<none>"
action 8.22 set olddesc_sub1 "<none>"
action 8.23 regexp "Description: (.+)\r" "$_cli_result" olddesc olddesc_sub1
action 8.24 set newdesc "$idt1 - $dnsname - $int"
action 8.25 if $olddesc_sub1 eq "$newdesc"
action 8.26 syslog msg "EEM script did NOT change description on $_nd_local_intf_name, since remote dnsname and interface is unchanged"
action 8.27 exit 10
action 8.28 end
action 8.3 cli command "interface $_nd_local_intf_name"
action 8.4 cli command "description $newdesc"
action 8.6 syslog msg "EEM script updated description on $_nd_local_intf_name from $olddesc to Description: $newdesc"
action 9.10 exit
action 9.9 end