02-20-2023 10:06 PM
I am looking for an EEM script, when VLAN number is included in the switch interface description, switch port VLAN configuration will be changed accordingly.
Suppose I configured "Connected to PC VLAN 12" on description field of interface G1/0/1 then switch port will be automatically configured as
switchport mode access
switchport access vlan 12
spanning tree portfast
02-20-2023 11:15 PM - edited 02-20-2023 11:29 PM
Hello @bibekananda
Assume that the interface description field contains the string "PC VLAN" followed by the VLAN number. If your description field has a different format, you may need to modify the regular expression in action 3.0 to match your format:
event manager applet configure-vlan
event syslog pattern "Interface.* changed state to up"
action 1.0 cli command "enable"
action 2.0 cli command "show interfaces description | include PC VLAN"
action 3.0 regexp "Interface (.*) .*PC VLAN ([0-9]+)" "$_cli_result" match intf vlan
action 4.0 if $_regexp_result == 1
action 5.0 cli command "configure terminal"
action 6.0 cli command "interface $intf"
action 7.0 cli command "switchport mode access"
action 8.0 cli command "switchport access vlan $vlan"
action 9.0 cli command "spanning-tree portfast"
action 10.0 cli command "end"
In this script, the event manager applet is triggered whenever an interface changes state to up. It searches for the string "PC VLAN" in the interface description using the command "show interfaces description | include PC VLAN".
It then uses a regular expression to extract the interface name and VLAN number from the description field. If the regular expression matches, the script configures the interface with the necessary settings for access mode, VLAN assignment, and portfast.
Also, you should find othet information if you follow this Cisco Documentation.
02-21-2023 12:43 AM
Hi,
Thanks for your response. but unfortunately its not working. After applying this script getting follwoing log message
%HA_EM-6-FMPD_EEM_CONFIG: configure-vlan: Missing "end" action in conditional block.
02-21-2023 03:28 AM
Hello,
I am not really sure what is supposed to trigger this event. I have adapted the script posted by M02@rt37 and used 'event none', which means you have to run it manually.
event manager applet INTF_DESC_VLAN
event none
action 1.0 cli command "enable"
action 2.0 cli command "show interfaces description | include PC VLAN"
action 2.2 foreach line "$_cli_result" "\n"
action 3.0 regexp "(Gi[0-9/]+).*PC VLAN ([0-9]+)" "$line" match intf vlan
action 4.0 if $_regexp_result eq "1"
action 5.0 cli command "configure terminal"
action 6.0 cli command "interface $intf"
action 7.0 cli command "switchport mode access"
action 8.0 cli command "switchport access vlan $vlan"
action 9.0 cli command "spanning-tree portfast"
action 9.1 end
action 9.2 end
02-21-2023 04:04 AM - edited 02-21-2023 04:13 AM
Please @bibekananda
Add this at the end of the script:
action 11.0 end if
action 12.0 cli command "end"
Also I modified a little bit action 3.0
Please find this script:
event manager applet configure-vlan
event syslog pattern "Interface.* changed state to up"
action 1.0 cli command "enable"
action 2.0 cli command "show interfaces description | include PC VLAN"
action 3.0 regexp "Interface (.*) .*VLAN ([0-9]+)" "$_cli_result" match intf vlan
action 4.0 if $_regexp_result == 1
action 5.0 cli command "configure terminal"
action 6.0 cli command "interface $intf"
action 7.0 cli command "switchport mode access"
action 8.0 cli command "switchport access vlan $vlan"
action 9.0 cli command "spanning-tree portfast"
action 10.0 cli command "end"
action 11.0 end if
action 12.0 cli command "end"
I let you try also what @Georg Pauwen tell you about the command:
'event none', which means you have to run it manually.
Thanks
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide