Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

Welcome to Cisco Support Community. We would love to have your feedback.

For an introduction to the new site, click here. And see here for current known issues.

New Member

Automatic switchport configuration with EEM script ...

Hi,

I have  2 EEM applets that configured switch port as a trunk when CDP indicate that Cisco switch is connected to activated port. When port is disconnected another script reconfigure it to the access vlan. 

However with this is vulnerable to any disconnections.

For example, when switch is connected to the upstream/root switch/switches via port channel and one of interfaces gets disconnected/ connected again  – script will overwrite existing configuration and port channel statements will be lost. I wanted to put in description some keyword as "UPLINK" and tried to catch it somehow but unfortunately cannot make it.

I will very much appreciate if someone can give me a hand with this.

Best regards,

Paul.

Here are my scripts:

event manager applet DETECT_CDP_SW

event neighbor-discovery interface regexp .*GigabitEthernet.* cdp add

action 10 puts "CDP Device Type $_nd_cdp_platform detected on Interface $_nd_local_intf_name"

action 20 set result "0"

action 20.1 string equal length 12 "cisco WS-C35*" "$_nd_cdp_platform"

action 20.2 if $_string_result eq 1

action 20.3 set result "1"

action 20.4 end

action 30.1 string equal length 13 "cisco WS-C365*" "$_nd_cdp_platform"

action 30.2 if $_string_result eq 1

action 30.3 set result "1"

action 30.4 end

action 40 if $result eq 1

action 40.1 cli command "enable"

action 40.2 cli command "conf t"

action 40.3 cli command "default interface $_nd_local_intf_name"

action 40.4 cli command "interface $_nd_local_intf_name"

action 40.5 cli command "switchport"

action 40.6 cli command "switchport trunk encapsulation dot1q"

action 40.7 cli command "switchport trunk native vlan 999"

action 40.8 cli command "switchport mode trunk"

action 40.9 cli command "ip dhcp snooping trust"

action 50.1 cli command "description $_nd_cdp_entry_name via EEM_CDP - $_nd_cdp_platform"

action 50.2 puts "Configured Interface $_nd_short_local_intf_name for Switch $_nd_cdp_entry_name $_nd_cdp_platform in trunk mode"

action 60 else

action 70 puts "CDP Neighbor not recognized as switch."

action 99 end

 

event manager applet DETECT_SW_INT_DOWN

event syslog pattern "%LINK-3-UPDOWN: Interface.* changed state to down"

action 10 regexp "Interface ([^ ]+)," "$_syslog_msg" match intf

action 20 cli command "enable"

action 20.1 cli command "show run interface $intf | inc desc"

action 30 regexp "([^,]\EEM_CDP)" "$_cli_result"

action 40 if $_regexp_result eq 1

action 50 puts "AP Trunk Interface went down. Putting back default config on Interface $intf"

action 60 cli command "enable"

action 60.1 cli command "conf t"

action 60.2 cli command "default interface $intf"

action 60.3 cli command "interface $intf"

action 60.4 cli command "switchport"

action 60.5 cli command "switchport mode access"

action 60.6 cli command "switchport access vlan 3"

action 60.7 cli command "spanning-tree portfast"

action 60.8 cli command "no shut"

action 70 else

action 80 puts "Non-EMM port Interface $intf went down."

action 99 end

  

2 ACCEPTED SOLUTIONS

Accepted Solutions
Cisco Employee

Have a look at this document,

Have a look at this document, especially the discussion thread below (and my follow-up from 11 months ago).  I have built a rather complex set of applets to do auto-config (I don't use a CDP neighbor delete, though), and I use a STATIC keyword to denote a port that is not to be reconfigured.

https://supportforums.cisco.com/document/100791/automatically-set-port-descriptions

Cisco Employee

Please post your current

Please post your current policy in its entirety.

4 REPLIES
Cisco Employee

Have a look at this document,

Have a look at this document, especially the discussion thread below (and my follow-up from 11 months ago).  I have built a rather complex set of applets to do auto-config (I don't use a CDP neighbor delete, though), and I use a STATIC keyword to denote a port that is not to be reconfigured.

https://supportforums.cisco.com/document/100791/automatically-set-port-descriptions

New Member

Joe,

Joe,

Thanks a lot for your help – I was able to fix the script and it works perfectly on Cisco WS-C3650-48PS IOS XE Version 03.06.04.E;   WS-C3560CG Version 12.2(55r)EX1.

However I absolutely cannot copy/paste script into stack of 4 Cisco WS-C3850: WS-C3850-48P and WS-C3850-24S running Version 16.3.3.

I am always getting error:

%HA_EM-6-FMPD_EEM_CONFIG: DETECT_CDP_DEVICE: "end" action found outside of conditional block.

Thanks,

Paul

Cisco Employee

Please post your current

Please post your current policy in its entirety.

New Member

Joe,

Joe,

thanks a lot for your help, I was able to figure out what was the source of issue, it was not a script itself but leftovers from previous installation.

Best regards,

Paul Keselman.

131
Views
0
Helpful
4
Replies