#shut, no shutHave you tried turning it off and on again?

Cisco EEM – Automatic Interface Descriptions

Preamble

These are my own versions of the ever-evolving Port Description EEM applet for Cisco IOS/IOS-XE; based on Joe Clarke’s Cisco Communities thread, Automatically Set Port Descriptions.

These applets will automatically update the description of an interface where a new CDP neighbor is detected, if not already described accordingly.

  • The description will only be updated if the existing description does not match the new description.
  • A syslog message is generated regarding the new CDP neighbor and whether or not the interface description was changed.
  • Any time a description is changed, the configuration is written (to startup).

Considerations

My personal preference/best-practice is to keep interface descriptions concise so all relevant information can be seen when show int status is ran…

See the examples in the tables below for each description’s meaning/syntax.

ASW-TR01-01#show int status | i connected
Gi1/0/1   [SEP]8865/ABCD     connected    1          a-full  a-100 10/100/1000BaseTX
Gi1/0/13  [ATA]190/ABCD      connected    1          a-full  a-100 10/100/1000BaseTX
Te1/0/37  [AP]3802I/abcd     connected    2          a-full a-5000 100/1000/2.5G/5G/10GBaseTX
Te1/1/4   DIST-01:1/1/1      connected    trunk        full    10G SFP-10GBase-LR
Te2/1/4   DIST-02:1/1/1      connected    trunk        full    10G SFP-10GBase-LR
Po1       DIST-01:Po101      connected    trunk      a-full  a-10G 

Applets

There are two versions of the applet;

  • cdp_desc updates descriptions without neighbor platform check, general use-case: core/dist switches.
  • cdp_desc_plat updates descriptions with neighbor platform check, general use-case: access switches.

cdp_desc

This version of the applet sets the interface description to the neighbor hostname and interface.

$nei : $neiint Example
Neighbor hostname Delimiter Neighbor interface DIST-02:1/1/1
event manager applet cdp_desc
 event neighbor-discovery interface regexp Ethernet[1-9]/[0-1]/[0-9]+$ cdp add
 action 00.00 cli command "enable"
 action 00.01 string range "$_nd_local_intf_name" 0 1
 action 00.02 set type "$_string_result"
 action 00.03 regexp "[/0-9]+$" "$_nd_local_intf_name" int
 action 00.04 regexp "[/0-9]+$" "$_nd_port_id" neiint
 action 00.05 if $neiint eq "0"
 action 00.06  set neiint "mgmt"
 action 00.07 end
 action 00.08 regexp "^[^\.\(]+" "$_nd_cdp_entry_name" nei
 action 00.09 set newdesc "$nei:$neiint"
 action 01.00 cli command "show int $_nd_local_intf_name | i ^[\ ]*[Dd]escription"
 action 01.01 set output "$_cli_result"
 action 01.02 regexp "^\ *[Dd]escription" "$output"
 action 01.03 if $_regexp_result ne "1"
 action 01.04  set olddesc "<none>"
 action 01.05 else
 action 01.06  set i "0"
 action 01.07  foreach line "$output" "\n"
 action 01.08   increment i
 action 01.09   if $i eq "1"
 action 01.10    string trim "$line"
 action 01.11    set line "$_string_result"
 action 01.12    regexp "^\ *[Dd]escription:\ *(.*)" "$line" match olddesc
 action 01.13   end
 action 01.14  end
 action 01.15 end
 action 02.00 if $newdesc eq $olddesc
 action 02.01  syslog msg "  ## New CDP neighbor on $type$int ($newdesc), description does not require updating."
 action 02.02 else
 action 02.03  syslog msg "  ## New CDP neighbor on $type$int ($newdesc), updating description (was: $olddesc)." 
 action 02.04  cli command "conf t"
 action 02.05  cli command   "int $_nd_local_intf_name"
 action 02.06  cli command   "desc $newdesc"
 action 02.07  cli command   "end"
 action 02.08  cli command "write mem" pattern "confirm|#"
 action 02.09  cli command ""
 action 02.10 end

cdp_desc_plat

This version of the applet gathers more information if AIR, Phone, or ATA is found in the CDP neighbor’s platform string ($_nd_cdp_platform), otherwise it does exactly what the cdp_desc applet does.

This is intended for use on access switches where devices such as wireless APs and IP Phones or ATAs are connected. Quite often some (or all) of these devices aren’t adequately renamed once adopted to the network; i.e. their hostnames are not set. Their default hostnames can be quite long, so to adhere with the aforementioned consideration (personal best-practice) the applet does the following for each platform type…

AIR (Cisco AP)

  1. Applet gets the AP model number from $_nd_cdp_platform.
  2. Applet gets the last four of the AP’s ethernet MAC address; i.e. checks the connected interface for a MAC address in the CAPWAP VLAN, this should be the AP.

    NOTE: In action 00.23, replace {{vlan.mgmt-ap.id}} with the CAPWAP VLAN ID.

  3. Applet will describe the interface as follows;
    [AP] $model / $macaddr Example
    Descriptor AP Model Delimiter Last four digits of AP’s ethernet MAC [AP]3802I/abcd

Phone

  1. Applet gets the phone model number from $_nd_cdp_platform.
  2. Applet gets the last four of the phone’s ethernet MAC address (from the hostname).
  3. Applet will describe the interfaces as follows;
    [SEP] $model / $macaddr Example
    Descriptor Phone Model Delimiter Last four digits of phone’s ethernet MAC [SEP]8865/ABCD

ATA (Analog Telephone Adapter)

  1. Applet gets the ATA model number from $_nd_cdp_platform.
  2. Applet gets the last four of the ATA’s ethernet MAC address (from the hostname).
  3. Applet will describe the interfaces as follows;
    [ATA] $model / $macaddr Example
    Descriptor ATA Model Delimiter Last four digits of ATA’s ethernet MAC [ATA]190/ABCD
event manager applet cdp_desc_plat
 event neighbor-discovery interface regexp Ethernet[1-9]/[0-1]/[0-9]+$ cdp add
 action 00.00 cli command "enable"
 action 00.01 string range "$_nd_local_intf_name" 0 1
 action 00.02 set type "$_string_result"
 action 00.03 regexp "[/0-9]+$" "$_nd_local_intf_name" int
 action 00.04 regexp "[/0-9]+$" "$_nd_port_id" neiint
 action 00.05 if $neiint eq "0"
 action 00.06  set neiint "mgmt"
 action 00.07 end
 action 00.08 regexp "AIR|Phone|ATA" "$_nd_cdp_platform" neiplat
 action 00.09 if $_regexp_result ne "1"
 action 00.10   regexp "^[^\.\(]+" "$_nd_cdp_entry_name" nei
 action 00.11   set newdesc "$nei:$neiint"
 action 00.12 else
 action 00.20  if $neiplat eq "AIR"
 action 00.21   regexp "AIR-AP([A-Z0-9]+)" "$_nd_cdp_platform" match model
 action 00.22   cli command "show mac addr int $type$int | i $int.*$"
 action 00.23   regexp "^\ *{{vlan.mgmt_ap.id}}\ *[a-f0-9]+\.[a-f0-9]+\.([a-f0-9]+)" "$_cli_result" match macaddr
 action 00.24   set newdesc "[AP]$model/$macaddr"
 action 00.30  elseif $neiplat eq "Phone"
 action 00.31   regexp "[0-9]+$" "$_nd_cdp_platform" model
 action 00.32   regexp "....$" "$_nd_cdp_entry_name" macaddr
 action 00.33   set newdesc "[SEP]$model/$macaddr"
 action 00.40  elseif $neiplat eq "ATA"
 action 00.41   regexp "[0-9]+$" "$_nd_cdp_platform" model
 action 00.42   regexp "....$" "$_nd_cdp_entry_name" macaddr
 action 00.43   set newdesc "[ATA]$model/$macaddr"
 action 00.98  end
 action 00.99 end
 action 01.00 cli command "show int $_nd_local_intf_name | i ^\ *[Dd]escription"
 action 01.01 set output "$_cli_result"
 action 01.02 regexp "^\ *[Dd]escription" "$output"
 action 01.03 if $_regexp_result ne "1"
 action 01.04  set olddesc "<none>"
 action 01.05 else
 action 01.06  set i "0"
 action 01.07  foreach line "$output" "\n"
 action 01.08   increment i
 action 01.09   if $i eq "1"
 action 01.10    string trim "$line"
 action 01.11    set line "$_string_result"
 action 01.12    regexp "^\ *[Dd]escription:\ *(.*)" "$line" match olddesc
 action 01.13   end
 action 01.14  end
 action 01.15 end
 action 02.00 if $newdesc eq $olddesc
 action 02.01  syslog msg "  ## New CDP neighbor on $type$int ($newdesc), description does not require updating."
 action 02.02 else
 action 02.03  syslog msg "  ## New CDP neighbor on $type$int ($newdesc), updating description (was: $olddesc)." 
 action 02.04  cli command "conf t"
 action 02.05  cli command   "int $_nd_local_intf_name"
 action 02.06  cli command   "desc $newdesc"
 action 02.07  cli command   "end"
 action 02.08  cli command "write mem" pattern "confirm|#"
 action 02.09  cli command ""
 action 02.10 end

Tags: , , , , , ,

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.