02-20-2018 09:47 AM - edited 03-08-2019 01:56 PM
Hi, is it possible to have some kind of data structure that's accessible from an EEM applet?
So what id like to do is this. when the EEM applet is called and run, i'd like it to find the switches serial number and depending on the serial number apply a specific config. something like this
event manager applet update_confg event none action 1.0 cli command "enable" action 2.0 cli command "show version | include system serial number" action 3.0 cli command regex "[A-Z0-9]{11}" "$_cli_result" serial action 4.0 if $serail eq "123456789" action 4.1 cli command "run config1.sh" action 5.0 elif $serail eq "987654321" action 5.1 cli command "run config2.sh" action 6.0 elif $serail eq "123123123" action 6.1 cli command "run config3.sh" action 7.0 end ! do event manager run update_config
so instead of having lots of IF statements it would be better if it simply did a lookup of some kind. i.e. return me a string(config file name) where serial number == $serial. This would prevent having lots of IF statements.
Any idea how i might do this?
Solved! Go to Solution.
02-23-2018 06:44 AM
thanks so much for your help. Here is the current working applet i'm using.
event manager applet configlookup event none maxrun 1000 action 1.0 cli command "enable" action 2.0 cli command "show version | include System Serial Number" action 2.1 regexp "[A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9]" "$_cli_result" serial action 3.0 cli command "conf t" action 4.0 cli command "file prompt quiet" action 5.0 cli command "end" action 6.0 cli command "copy ftp://192.168.0.128/serial_data.yml flash:" action 6.1 cli command "more flash:serial_data.yml | inc $serial" action 7.8 regexp "^[A-Z0-9]+.txt" "$_cli_result" file action 8.0 cli command "copy ftp://192.168.0.128/$file nvram:startup-config" ! exit do event manager run configlookup
02-20-2018 07:23 PM - edited 02-20-2018 07:25 PM
Hello,
You would have to play with it but if you had a file that had the SNs and the corresponding filenames, you could use that to do the lookup. The syntax below might not be exact but hopefully it helps:
Contents of flash:SNtoConfigFile.txt
Serial1:Config1.txt
Serial2:Config2.txt
Serial3:Config3.txt
Serial4:Config3.txt
event manager applet configlookup event none
action 1.0 cli command "show version | include system serial number" action 1.1 cli command regex "[A-Z0-9]{11}" "$_cli_result" serial
action 1.2 set snumber $serial
action 1.3 cli command "more flash:SNtoConfigFile.txt | inc $snumber"
action 1.4 cli command regex "Config\d.txt" "$_cli_result" file
action 1.5 set config $file
action 1.6 cli command "copy flash:$config start"
Hope that helps!
02-21-2018 02:33 AM - edited 02-21-2018 02:37 AM
Ah, so do you think it would be possible to do something more like this?
more serial_data.cfg
config1.txt: 123456789, 987654321, 147258369
config2.txt: 784512235, 326598875, 786453159
event manager applet configlookup event none action 1.0 cli command "show version | include system serial number" action 1.1 cli command regex "[A-Z0-9]{11}" "$_cli_result" serial action 1.2 set snumber $serial <--- not sure why you created another variable?
action 1.3 cli command "copy ftp://192.168.0.128/serial_data.cfg flash:" action 1.4 cli command "more flash:serial_data.cfg | inc $snumber" action 1.5 cli command regex "^config\d.txt:" "$_cli_result" file action 1.5 set config $file <-- and again? but i'll roll with it. action 1.6 cli command "copy ftp://192.168.0.128/$config flash:$config start" <-- not sure if this will work?
action 1.7 end
What do you think? feasible?
02-21-2018 05:01 AM
Looks about right. You might also need to set your default FTP username/pass if you have one ahead of time. You will need two things though as the copy command asks for more information and will cause your script to get stuck:
event manager applet configlookup event none maxrun 1000 <-----EEM will timeout in 20 seconds by default. This might run a little longer. action 1.0 cli command "show version | include system serial number" action 1.1 cli command regex "[A-Z0-9]{11}" "$_cli_result" serial action 1.2 set snumber $serial <--- Not required. Force of habit from other scripts
action 1.3 cli command "conf t"
action 1.4 cli command "file prompt quiet" <----You have to do this or you will get stuck on the copy command
action 1.5 cli command "end"
action 1.6 cli command "copy ftp://192.168.0.128/serial_data.cfg flash:" action 1.7 cli command "more flash:serial_data.cfg | inc $snumber" action 1.8 cli command regex "^config\d.txt:" "$_cli_result" file action 1.9 set config $file action 2.0 cli command "copy ftp://192.168.0.128/$config flash:$config start" <---Should be fine.
action 2.1 end
Hope that helps!
02-23-2018 06:44 AM
thanks so much for your help. Here is the current working applet i'm using.
event manager applet configlookup event none maxrun 1000 action 1.0 cli command "enable" action 2.0 cli command "show version | include System Serial Number" action 2.1 regexp "[A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9]" "$_cli_result" serial action 3.0 cli command "conf t" action 4.0 cli command "file prompt quiet" action 5.0 cli command "end" action 6.0 cli command "copy ftp://192.168.0.128/serial_data.yml flash:" action 6.1 cli command "more flash:serial_data.yml | inc $serial" action 7.8 regexp "^[A-Z0-9]+.txt" "$_cli_result" file action 8.0 cli command "copy ftp://192.168.0.128/$file nvram:startup-config" ! exit do event manager run configlookup
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