cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
5485
Views
15
Helpful
12
Replies

EEM change configuration every 60 minutes

ngtransge
Level 1
Level 1

Hello,

I am interesting how it is possible to change Router configuration every 60 minutes. So I have about 10 configuration template, and want to apply each configuration template every 60 minutes. After applying first configuration template, wait 60 minutes and apply second configuration, then wait 60 minutes, and apply third configuration template and so on. After applying tenth configuration template, then wait again 60 minutes and then apply first. So that to form a loop.

Is it possible to do it with EEM ?

2 Accepted Solutions

Accepted Solutions

You can only save once unless you do a retrieve.  Instead of saving at the top, set a to its final value, then save at the end of your applet.

View solution in original post

Do you have multiple "router ospf" statements?  I would typically do this to ensure proper extraction:

action a1 regexp "router ospf ([0-9]+)" "$_cli_result" ignore pid

action a2 puts $pid

View solution in original post

12 Replies 12

Joe Clarke
Cisco Employee
Cisco Employee

Something like this may work:

event manager applet change-config

event timer watchdog time 3600

action 001 cli command "enable"

action 002 cli command "show clock"

action 003 regexp "([0-9]+):[0-9]:[0-9]" "$_cli_result" match hour

action 004 divide $hour 3

action 005 if $_remainer eq 0

action 006  cli command "copy flash:config1 runn"

action 007 elseif $_remainder eq 1

action 008  cli command "copy flash:config2 runn"

action 009 else

action 010  cli command "copy flash:config3 runn"

action 011 end

Hello Joseph,

Thank you for helping. I have write something more simple than your configuration, but it did't work. Coul you please check what can be problem.

event manager applet TEST

event none

action a0000  set a 0

action a0010  increment a

action a0011  cli command "enable"

action a0012  cli command "conf t"

action a0013  cli command "hostname TEST-1"

action a0014  cli command "end"

action a0015  cli command "write memory"

action a0016  syslog priority informational msg "NEW CONFIGURATION APPLIED SUCCESFULLY 'hostname TEST-1'"

action a0017  wait 60

action a0020  increment a

action a0021  cli command "enable"

action a0022  cli command "conf t"

action a0023  cli command "hostname TEST-2"

action a0024  cli command "end"

action a0025  cli command "write memory"

action a0026  syslog priority informational msg "NEW CONFIGURATION APPLIED SUCCESFULLY 'hostname TEST-2'"

action a0027  wait 60

!......

!......

!......

!......

action a0190  increment a

action a0191  cli command "enable"

action a0192  cli command "conf t"

action a0193  cli command "hostname TEST-19"

action a0194  cli command "end"

action a0195  cli command "write memory"

action a0196  syslog priority informational msg "NEW CONFIGURATION APPLIED SUCCESFULLY 'hostname TEST-19'"

action a0197  wait 60

action a0200  increment a

action a0201  cli command "enable"

action a0202  cli command "conf t"

action a0203  cli command "hostname TEST-20"

action a0204  cli command "end"a

action a0205  cli command "write memory"

action a0206  syslog priority informational msg "NEW CONFIGURATION APPLIED SUCCESFULLY 'hostname TEST-20'"

action a0207  wait 60

action a9999 if $a eq 20 goto a0000

Only first section of commands are performed. It never goes to a0020 and a0021 and so on.

I have also tried with different event. Like "event timer absolute time 60", but it also did't helped.

What can be problem in this case ?

This won't work since the applet will terminate after 20 seconds.  What you're doing with the waits is not recommended.  You can do it by extending the maxrun of the applet to something like 200 seconds (event none maxrun 200), but my approach is more of a recommended strategy since the applet will not block a VTY for long periods of time.

In case I want to change configuration every 5 minute. Which approach will be best?

Also, if I will go with this way: How can I determine from EEM syntax if it was already ran, or it is running for the first time.  Hire is pseudo code I am thinking of:

!

event manager applet TEST

event timer watchdog time 300

If (applet is running for first time)

a set 0

end

increment a

if a eq 1

do first config template

end

if a eq 2

do second config template

end

if a eq 19

do nineteenth  config template

end


if a eq 20

do first twentieth template

set a 0

end

!

You can use contexts for this.  Do your increment, then save the variable to a context with the context save action.  Use context retrieve to grab it back.  To handle the first run, you'll need to do:

handle-error type ignore

context retrieve key MYCTXT variable a

if $_error ne FH_EOK

set a 0

end

handle-error type exit

Is it possible to overwrite valu in same context key. I have written followinf applet, but it did't works.

event manager applet TEST

event timer watchdog time 60

action a0000 handle-error type ignore

action a0001 context retrieve key MYCTXT variable "a"

action a0002 if $_error ne FH_EOK

action a0003  set a "0"

action a0004 end

action a0005 handle-error type exit

action a0010 increment a

action a0011 context save key MYCTX variable a

action a0013 if a eq 1

action a0014 cli command "enable"

action a0015 cli command "conf t"

action a0016 cli command "hostname TEST-1"

action a0017 cli command "end"

action a0018 cli command "write memory"

action a0019 syslog priority informational msg "NEW CONFIGURATION APPLIED SUCCESFULLY 'hostname TEST-1'"

action a0020 end

action a0021 if a eq 2

action a0022 cli command "enable"

action a0023 cli command "conf t"

action a0024 cli command "hostname TEST-2"

action a0025 cli command "end"

action a0026 cli command "write memory"

action a0027 syslog priority informational msg "NEW CONFIGURATION APPLIED SUCCESFULLY 'hostname TEST-2'"

action a0028 end

action a0031 if a eq 3

action a0032 cli command "enable"

action a0033 cli command "conf t"

action a0034 cli command "hostname TEST-3"

action a0035 cli command "end"

action a0036 cli command "write memory"

action a0037 syslog priority informational msg "NEW CONFIGURATION APPLIED SUCCESFULLY 'hostname TEST-3'"

action a0038 end

action a0041 if a eq 4

action a0042 cli command "enable"

action a0043 cli command "conf t"

action a0044 cli command "hostname TEST-4"

action a0045 cli command "end"

action a0046 cli command "write memory"

action a0047 syslog priority informational msg "NEW CONFIGURATION APPLIED SUCCESFULLY 'hostname TEST-4'"

action a0048 set a "0"

action a0049 context save key MYCTX variable a

action a0050 end

I got following error:

%HA_EM-3-FMPD_ERROR: Error executing applet TEST statement a0011

%HA_EM-6-FMPD_CONTEXT_SAVE: Failed to save variable context for key MYCTX: 'Embedded Event Manager' detected the 'fatal' condition 'duplicate application info key'

You can only save once unless you do a retrieve.  Instead of saving at the top, set a to its final value, then save at the end of your applet.

Hello Joseph,

Thank you for helping.

Could you please help me with this regex.  I am trying to match ospf process id in router running configuration, but my regex seems doesn’t work. hire is config

no event manager applet TEST
event manager applet TEST
event none sync yes
action a cli command "show runn | include router ospf"
action a1 regexp "[0-9]" "$_cli_result" _match
action a2 puts $_match

with this eem, i always get result 2. in router running config i have :

router ospf 8

router-id 1.2.3.4

how can i solve this problem ?

Do you have multiple "router ospf" statements?  I would typically do this to ensure proper extraction:

action a1 regexp "router ospf ([0-9]+)" "$_cli_result" ignore pid

action a2 puts $pid

Hello,

Thank you for helping. I have last question regarding eem operation. In previous post you say:

This won't work since the applet will terminate after 20 seconds.  What you're doing with the waits is not recommended.  You can do it by extending the maxrun of the applet to something like 200 seconds (event none maxrun 200), but my approach is more of a recommended strategy since the applet will not block a VTY for long periods of time.

Could you please explain what you mean in block VTY. Does it mean that when eem applet is running VTY is busy and network administrator can't access router ?

On my applet last version I have used watchdog timer, for every 5 minutes. Will my applet block VTY ?

When a policy runs that executes CLI commands it will allocate a VTY.  For an applet, that VTY will remain in use for the life of the policy.  So, if you keep a long-running applet, its VTY line will not be released, and that is one less line you can use to access the device.  The line is not blocked if the applet is not running.

mustafahanci
Level 1
Level 1

Hi.

You can form a snmp RW variable and use it in generating configuration names. For axample "conf""$_info_snmp_value"".cfg" for config file.

And for reload time you can use sysUpTime (1.3.6.1.2.1.1.3) in cisco oid. If the value of sysUpTime is reached 1 hour you can trigger for reload.


Mustafa..

Review Cisco Networking for a $25 gift card