cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
46677
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
Collin Clark
VIP Alumni
VIP Alumni

It works for routers (ASR1001) but fails on switches (remote 3750-X stack to be specific).

If you see something obvious can you give me a hint (ie what line to look at)?

Collin Clark
VIP Alumni
VIP Alumni

Sorry for the last post Joe, your regex above got the switches working. I greatly appreciate your help (as always).

Tommy Vindvik
Level 1
Level 1

Joseph Clarke wrote:

                       

Thanks for the mod!

Why not do something like this to shorten the port names:

action 3.1 string range $_nd_port_id 0 1

action 3.6 set int "$_string_result"

                   

Hmmmm....well....

That gives "Gi" for "GigabitEthernet", but it also removes the interface number part (1/1/1)......

Regards,

Tommy V

Tommy Vindvik
Level 1
Level 1

Collin:

The event "event neighbor-discovery interface regexp .*GigabitEthernet[1-9]/1/[1-4]$ cdp add" controls what the script should act on. In this case cdp add events from the interfaces specified in the regexp. Regexp in my examples are adapted to only include the uplink/network modules on a 3750-X or a stack of 3750-X.

.*GigabitEthernet allows for interfaces GigabitEthernet with zero or more characters in front. Thus also including TenGigabitEthernet. Remembering the port numbering in a 3750 stack, the [1-9]/1/[1-4]$ part of the regexp says "switch 1-9, module 1, port 1-4". This matches the network/uplink module.

To match "any" Gigabit ports, you could use the regexp from Joseph: .*GigabitEthernet[1-9]/[0-9]/[0-9]+$

This "reads": Any interface with zero or more characters in front of GigabitEthernet, switch 1-9, modules 0-9, port 0-9999999 (the + sign equals that the digits in the square brackets in front could be repeated zero or more times).

Or you could use the regexp from the first post: GigabitEthernet.*

This reads:  Any GigabitEthernet interface with zero or more characters following.

Understanding the power of regexp could be a bit challenging, but the it's worth it

(somewhat of a regexp newbie my self )

Regards,

Tommy V

Tommy Vindvik
Level 1
Level 1

Joseph,

Any inprovements in regexp for applets i EEM v4.0?

Tried using something like:

action 3.1 regexp "(^[a-zA-Z]{2})[a-zA-Z]*([0-9/]*)" "$_nd_port_id" short_int sub1 sub2

to shorten portnames and get the interface number part, but it seems like EEM v3.2 does not support curly bracket quantifiers?

Collin Clark
VIP Alumni
VIP Alumni

I was a little confused on how it grabbed the info but I think I understand it now. Regex is one of things (for me) where I learn it, then forget it. I don't use it enough for it to stick   I have a question for you. I'm trying to AP's as well. I added

action 1.1 regexp "(Switch|Router|Trans-Bridge)" $_nd_cdp_capabilities_string

but it doesn't see the AP's. Is there another place I should be looking?

Joe Clarke
Cisco Employee
Cisco Employee

Unfortunately, no.  CLI-based EEM uses the built-in basic regexp engine, and that is not likely to change.  If you use Tcl, you get full Tcl 8.3.4 regexp support, though.

Joe Clarke
Cisco Employee
Cisco Employee

You may want to print the capabilities string just to make sure EEM is capturing the whole thing.  You could also try matching on "AIR" in the $_nd_cdp_platform.

Tommy Vindvik
Level 1
Level 1

....or you could remove the following lines to allow the script to run on any CDP speaking neighbor:

action 1.1 regexp "(Switch|Router)" $_nd_cdp_capabilities_string

action 1.2 if $_regexp_result eq 1

action 5.0 end

mtimm
Cisco Employee
Cisco Employee

Debugs can be enabled which will display the environmental variables that are published and what values those variables are set to. 

debug event manager policydir       

That may be helpful in determining what the capabilities string is set to for an AP.

Mike

Collin Clark
VIP Alumni
VIP Alumni

Bingo that did it!

Collin Clark
VIP Alumni
VIP Alumni

Very helpful. I'll probably use that except on access layer switches (dang IP Phones).

Shannon Sutter
Level 1
Level 1

Hi,

I've tried the short script on post 1 on my C3560 switches. At first the script didn't work until I realized I had to change GigabitEthernet to FastEthernet since I have no gig ports on my 3560s.

The script now works but I am only getting the MAC of the IP Phones connected to the switchports and hostname of router connected to the switch. For some reason I don't get the mac of windows servers connected to the switch or Wireless access Points.

I've also tried the other two extended scripts from this thread without modification (only GigabitEthernet to FastEthernet) and didn't get any resutls.

Does anyone have a a working script for C3560-48 or C3560-24 switches?

I am running IOS c3560-ipservicesk9-mz.122-55.SE6.bin on all my switches.

Thanks in advance.

Zeek

Collin Clark
VIP Alumni
VIP Alumni

Zeek-

This script does not pull the MAC address of non-Cisco devices and update the description. You could try and install the CDP client on the server. I'm not sure how that would look in CDP (a good thing to lab when I get some time).

http://www.tallsoft.com/cdpmonitor.htm

The extended scripts won't work with the 3560 because of the interface numbering scheme. Use the OP script.

Joe Clarke
Cisco Employee
Cisco Employee

Collin is right, but you could use the MAC Address event detector as well to create an applet that matches on learning a MAC address on a port.  Use this to set the initial description, then if CDP overwrites it you have more details.  You ED line would be something like:

event mat interface regexp ".*Ethernet.*" type add

Then you can use $_mat_intf_name to get the interface on which the event occurred and $_mat_mac_address to get the learned MAC address.

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:

Review Cisco Networking for a $25 gift card