cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
169
Views
0
Helpful
0
Replies
Highlighted
Beginner

EEM Configure interface based on description

I am trying to create a script that configures an interface based on what description you have configured it as. For example if I set "description PRINT" on a interface I want the interface to get configured as a trunk interface. I have managed to complete both the EEM applet and the python script but it is not working as I want it to. The python script need to know the interface to be able to configure, I have done this by writing %s as you can see below. But when I write the action for the EEM applet where it says "guestshell run python /flash/confscript1.py" I need to write a interface, for example GigabitEthernet1/0/1. I can for example write GigabitEthernet1/0/1 instead of GigabitEthernet* and it works to configure that interface. However I want it to be able to configure any interface and not just one specific. Is there any simple way to do this?

 

EEM

event manager applet AUTO_CONFIGURE
event cli pattern "description ADM" sync no skip yes
action 0.0 cli command "enable"
action 1.0 cli command "guestshell run python /flash/confscript1.py GigabitEthernet*"

 

Python script

import sys
from cli import cli,clip,execute,executep,configure,configurep

intf= sys.argv[1:]
intf = ''.join(intf[0])

print ('This script is going configure interface %s'%intf)

if intf != 'Fo1/1/2':
cmd='int %s,switchport mode trunk, switchport trunk allowed vlan 540,end' % intf

configurep(cmd.split(','))

executep('show ip interface brief')

 

Thanks in advance!

Everyone's tags (3)
CreatePlease to create content
Content for Community-Ad
July's Community Spotlight Awards