EEM Script for CDP and interface descriptions

Upgraded script to support 25Gig.

event manager applet auto-update-port-description authorization bypass
description "Auto-update port-description based on CDP neighbor info"
event neighbor-discovery interface regexp .[1-2]/[0-1]/[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 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 "Convert long interface name to short"
action 3.1 string first "E" "$_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 elseif $_string_result eq "13"
action 3.51 string replace "$_nd_port_id" 0 9 "25"
action 4.0 syslog msg "Found local interface $_nd_local_intf_name with a neighbor of $_nd_port_id"
action 4.1 end
action 4.2 set int "$_string_result"
action 5.0 comment "Check old description if any, and do no change if same host:int"
action 5.1 cli command "enable" action 5.11 cli command "config t"
action 5.2 cli command "do show interface $_nd_local_intf_name | incl Description:"
action 5.21 set olddesc ""
action 5.22 set olddesc_sub1 ""
action 5.23 regexp "Description: ([a-zA-Z0-9:/-])([a-zA-Z0-9:/-\ ]*)" "$_cli_result" olddesc olddesc_sub1
action 5.24 if $olddesc_sub1 eq "$host:$int"
action 5.25 syslog msg "EEM script did NOT change description on $_nd_local_intf_name, since remote host and interface is unchanged"
action 5.26 exit 10
action 5.27 end
action 5.3 cli command "interface $_nd_local_intf_name"
action 5.4 cli command "description $host [$int]"
action 5.5 cli command "do write"
action 5.6 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.2 exit 1