cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
4537
Views
0
Helpful
6
Replies

EEM scripting assistance: Switch, router and AP CDP

Leo Laohoo
Hall of Fame
Hall of Fame

We would like to create an EEM script which will let the switch populate the interface description based on the CDP neighbour, however, we want the script to only populate the interface if (and only if) the CDP is a Cisco wireless access point (AP), a Cisco Catalyst switch and a Cisco router.   We DO NOT want the interface description to be edited if the CDP neighbour is a Cisco phone or a Cisco DMP (for example). 

This is our EEM script: 

event manager applet update-port

event none

event neighbor-discovery interface regexp GigabitEthernet.* cdp add

action 100 if $_nd_cdp_capabilities_string eq "Router" goto 200

action 110 elseif $_nd_cdp_capabilities_string eq "Switch" goto 200

action 120 if $_nd_cdp_capabilities_string eq "Switch" goto 200

action 200 cli command "enable"

action 210 cli command "config t"

action 220 cli command "interface $_nd_local_intf_name"

action 230 cli command "description $_nd_cdp_entry_name"

action 400 else

action 500 end

And this is a sample of our “sh cdp neighbor” output:

Switch#sh cdp n d

-------------------------

Device ID: Wireless

Entry address(es):

  IP address: <REMOVED>

Platform: cisco AIR-CAP3602I-N-K9   ,  Capabilities: Router Trans-Bridge

Interface: GigabitEthernet0/8,  Port ID (outgoing port): GigabitEthernet0.1

Holdtime : 146 sec

Version :

Cisco IOS Software, C3600 Software (AP3G2-K9W8-M), Version 15.2(2)JB, RELEASE SOFTWARE (fc1)

Technical Support: http://www.cisco.com/techsupport

Copyright (c) 1986-2012 by Cisco Systems, Inc.

Compiled Mon 10-Dec-12 23:52 by prod_rel_team

advertisement version: 2

Duplex: full

Power drawn: 15.400 Watts

Power request id: 19701, Power management id: 2

Power request levels are:15400 0 0 0 0

Power Available TLV:

    Power request id: 0, Power management id: 0, Power available: 0, Power management level: 0

Management address(es):

-------------------------

Device ID: 00:0f:44:02:c5:29

Entry address(es):

  IP address: <REMOVED>

Platform: Cisco DMP 4310G,  Capabilities: Host

Interface: GigabitEthernet0/3,  Port ID (outgoing port): eth0

Holdtime : 157 sec

Version :

5.4

advertisement version: 2

Duplex: full

Power Available TLV:

    Power request id: 0, Power management id: 0, Power available: 0, Power management level: 0

Management address(es):

-------------------------

Device ID: CALM040.mgmt.educ

Entry address(es):

  IP address: <REMOVED>

Platform: cisco WS-C3750E-24PD,  Capabilities: Switch IGMP

Interface: GigabitEthernet0/10,  Port ID (outgoing port): GigabitEthernet1/0/22

Holdtime : 126 sec

Version :

Cisco IOS Software, C3750E Software (C3750E-UNIVERSALK9-M), Version 15.0(2)SE, RELEASE SOFTWARE (fc1)

Technical Support: http://www.cisco.com/techsupport

Copyright (c) 1986-2012 by Cisco Systems, Inc.

Compiled Fri 27-Jul-12 23:26 by prod_rel_team

advertisement version: 2

Protocol Hello:  OUI=0x00000C, Protocol ID=0x0112; payload len=27, value=00000000FFFFFFFF010221FF0000000000000023AC075300FF0000

VTP Management Domain: 'ACTEducation'

Native VLAN: 99

Duplex: full

Power Available TLV:

    Power request id: 0, Power management id: 1, Power available: 0, Power management level: -1

Management address(es):

  IP address: <REMOVED>

-------------------------

Device ID: 00:0f:44:02:b6:31

Entry address(es):

  IP address: <REMOVED>

Platform: Cisco DMP 4310G,  Capabilities: Host

Interface: GigabitEthernet0/2,  Port ID (outgoing port): eth0

Holdtime : 169 sec

Version :

5.4

advertisement version: 2

Duplex: full

Power Available TLV:

    Power request id: 0, Power management id: 0, Power available: 0, Power management level: 0

Management address(es):

Best Regards/Leo

3 Accepted Solutions

Accepted Solutions

Joe Clarke
Cisco Employee
Cisco Employee

You use regexp to do what you want:

event manager applet update-port

event neighbor-discovery interface regexp GigabitEthernet.* cdp add

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

action 110 if $_regexp_result eq 1

action 200 cli command "enable"

action 210 cli command "config t"

action 220 cli command "interface $_nd_local_intf_name"

action 230 cli command "description $_nd_cdp_entry_name"

action 500 end

This would only set the port description if the capabilities string contains the words Router or Switch.

View solution in original post

You can still use regexp for this:

action 221 regexp "^([^\.])\." $_nd_cdp_entry_name match host

action 230 cli command "description $host"

View solution in original post

Sorry, I forgot a '+':

action 230 regexp "^([^\.]+)\." $_nd_cdp_entry_name match host

View solution in original post

6 Replies 6

Joe Clarke
Cisco Employee
Cisco Employee

You use regexp to do what you want:

event manager applet update-port

event neighbor-discovery interface regexp GigabitEthernet.* cdp add

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

action 110 if $_regexp_result eq 1

action 200 cli command "enable"

action 210 cli command "config t"

action 220 cli command "interface $_nd_local_intf_name"

action 230 cli command "description $_nd_cdp_entry_name"

action 500 end

This would only set the port description if the capabilities string contains the words Router or Switch.

Thanks Joe.   This works very, very well.

Can I ask for another "tweak"?

In the CDP, we get the domain extension like "Switch.Domain".  How do I concatinate the ".Domain"-bit so I will only get "Switch"?

You can still use regexp for this:

action 221 regexp "^([^\.])\." $_nd_cdp_entry_name match host

action 230 cli command "description $host"

action 221 regexp "^([^\.])\." $_nd_cdp_entry_name match host

action 230 cli command "description $host"

Hi Joe,

So the EEM is going to look like this: 

event manager applet update-port

event neighbor-discovery interface regexp GigabitEthernet.* cdp add

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

action 110 if $_regexp_result eq 1

action 200 cli command "enable"

action 210 cli command "config t"

action 220 cli command "interface $_nd_local_intf_name"

action 230 regexp "^([^\.])\." $_nd_cdp_entry_name match host

action 240 cli command "description $host"

action 500 end

Is this correct?

Sorry, I forgot a '+':

action 230 regexp "^([^\.]+)\." $_nd_cdp_entry_name match host

THANKS JOE!