cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
41723
Views
25
Helpful
87
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
Shannon Sutter
Level 1
Level 1

Got it, Thank you both for your replies.

krueffer
Level 1
Level 1

Hi,

I would be VERY happy, if somebody could post the final EEM script.

:-)

Thanks!

Knut

Collin Clark
VIP Alumni
VIP Alumni

Here you go-

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[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|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 "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 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

!

krueffer
Level 1
Level 1

great! thanks Collin!

zoopcrewkid
Level 1
Level 1

Can I use NetMRI to run this script?

Joe Clarke
Cisco Employee
Cisco Employee

This is an EEM applet that's designed to be run directly on an IOS device.  It can be deployed using an external NMS, but execution will happen locally per device.

krueffer
Level 1
Level 1

Hi

the EEM script works very well, but Wireless Access Points (1252) are not discovered correctly. It seems to me that they propagate their capability as "Trans-Bridge" instead of "AIR". So I changed "Switch|Router|AIR" in action 1.1 to "Switch|Router|Trans-Bridge" but it was not working. I got an error message referring to action 4.4 related to pasing the hostname. Any hint would be appreciated. Thanks! Knut

Ramz PV
Level 1
Level 1

Hi,

       script is working well for the newly connected device. I want to use the script for giving Interface description for the existing setup. please help.

Tommy Vindvik
Level 1
Level 1

Hi Ramz,

You have to trigger a CDP event for the script to run. The easiest way to do this, is to shut/no shut the ports.

Or you could maybe do a "no cdp enable"/"cdp enable" if you don't want to affect traffic. I have not tested this.

Regards

Tommy V

Ramz PV
Level 1
Level 1

Hi Tommy,

            I think we can go ahead with the second option "no cdp enable"/"cdp enable". but the command should run only on the interfaces where the cisco devices are connected. can we incorporate the same in the same EEM script with a delay of 180+ seonds between the commands("no cdp enable"/"cdp enable").

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"

Tommy Vindvik
Level 1
Level 1

Ramz,

Since the script triggers every time CDP info is added (as in changed or just connected), disabling CDP on a port and enabling it again will trigger the same CDP info. The script would then change the description. It should anyhow be pretty safe to test.

I short: Yes

Regards

Tommy V

zoopcrewkid
Level 1
Level 1

You can also use the "clear cdp table" and it will trigger the script.

Tommy Vindvik
Level 1
Level 1

Of cause! Stupid me

Joe Clarke
Cisco Employee
Cisco Employee

You can use the CDP update events by changing the type to "all".  CDP messages are sent periodically, so that should trigger.  IT will, though, trigger multiple configuration changes.

Ramz PV
Level 1
Level 1

Hi,

          cdp "all" & "update" are making multiple configuration changes and it is populating in my logging. Is it possible to add an event only once for clearing cdp table as soon as add the EEM script. Rest of the time it should check for CDP "add" event only.

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: