cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
8980
Views
0
Helpful
29
Replies

EEM script to do a write memory

Gerard Roy
Level 2
Level 2

We have a New config going to all routers in the field. We upload the config to flash and then allow the customer to login to router and copy from flash to startup and reload when they are ready to do the conversion. We created an eem script that will reload the router to the older version of the config if they do not login within 20 minutes and remove the eem script. They now want to bypass the manual disabling of the eem script and want it automated. I have most of it working except the write mem process.

Customer logs in and manually removes this: Works

event manager applet SetConfig

event timer watchdog time 1200

action 1.0 cli command "enable"

action 1.1 cli command "conf t"

action 1.2 cli command "file prompt quiet"

action 1.3 cli command "end"

action 2.0 cli command "copy original.cfg startup-config"

action 3.0 syslog msg "EEM forced reload"

action 4.0 reload

end

Automated removal of eem script and all its settings: Works

event manager applet Delete_SetConfig
event track 333 state up
event timer watchdog time 600
action 1.0 cli command "enable"
action 1.1 cli command "conf t"
action 1.2 cli command "no event manager applet SetConfig"
action 1.3 cli command "no ip sla 6"
action 1.4 cli command "no ip sla 7"
action 1.5 cli command "no track 111 rtr 6 reachability"
action 1.6 cli command "no track 222 rtr 7 reachability"
action 1.7 cli command "no track 333 list threshold weight"
action 1.8 cli command "no event manager applet Delete_SetConfig"
action 1.9 cli command "end"

Once the eem script above processes, we want to write running-config to startup-config: Fails

event manager applet Write_Memory
event cli pattern "no event manager applet Delete_SetConfig" sync yes occurs 1
action 1.0 cli command "write memory"
action 1.1 cli command "end"
!

Any Ideas on how to get this to work?           

2 Accepted Solutions

Accepted Solutions

Well, you need to readd your write mem action:

event manager applet Write_Memory

event application sub-system 798 type 1

action 1.0 cli command "enable"

action 2.0 cli command "write mem"

View solution in original post

Your policies look right to me.  Yes, in your version of IOS, if the policy is unconfigured, even by itself, it will be forcibly terminated.  That is why deleting the current policy must be its very last action.  And that appears to be the case in Timer_Delete_SetConfig.  The problem might be that the event is acted upon before the Timer_Delete_SetConfig policy can be deleted.  I had that concern from the beginning.  That is why I suggested you may need to add some delay between when the event is received and when the write mem is performed.  You can do that by having the applet that currently does the write mem install yet another nested applet that counts down a second or two, then does the write mem.

View solution in original post

29 Replies 29

Joe Clarke
Cisco Employee
Cisco Employee

EEM cannot intercept CLI commands that EEM runs.  This is to prevent infinite loops.  Why not send an application specific event from the Delete_SetConfig applet?

action 1.75 publish-event sub-system 798 type 1 arg1 WRITE-MEM

Then:

event manager applet Write_Memory

event application sub-system 798 type 1

action 1.0 wait 1

...

The wait is to ensure the last command is removed, but you could also just check to see if Delete_SetConfig is still registered with the EEM server using "show event manager policy registered | inc Delete_SetConfig".

Hi Joseph,

Thanks for the reply. I don't seem to have the wait 1 available. Maybe it's code version. You have a workaround for this?

Doesnt seem to be working.

All I have left is this in the run:

event manager applet Write_Memory

event application sub-system 798 type 1

In the start I still have all of the following:

event manager applet Delete_SetConfig
event timer watchdog time 600
action 1.0 cli command "enable"
action 1.1 cli command "conf t"
action 1.2 cli command "no event manager applet SetConfig"
action 1.3 cli command "no ip sla 6"
action 1.4 cli command "no ip sla 7"
action 1.5 cli command "no track 111 rtr 6 reachability"
action 1.6 cli command "no track 222 rtr 7 reachability"
action 1.7 cli command "no track 333 list threshold weight"
action 1.75 publish-event sub-system 798 type 1 arg1 "WRITE-MEM"
action 1.8 cli command "no event manager applet Delete_SetConfig"
action 1.9 cli command "end"
event manager applet SetConfig
event timer watchdog time 1200
action 1.0 cli command "enable"
action 1.1 cli command "conf t"
action 1.2 cli command "file prompt quiet"
action 1.3 cli command "end"
action 2.0 cli command "copy original.cfg startup-config"
action 3.0 syslog msg "EEM forced reload"
action 4.0 reload
event manager applet Write_Memory
event application sub-system 798 type 1
!

Well, you need to readd your write mem action:

event manager applet Write_Memory

event application sub-system 798 type 1

action 1.0 cli command "enable"

action 2.0 cli command "write mem"

ooops - re-added and Now It works!

Joseph,

Would this be the recommended way to add the timer?

event manager applet Write_Memory
 event application sub-system 798 type 1
 action 1.0 wait 10
 action 2.0 cli command "enable"
 action 3.0 cli command "write mem"

Yeah, this will work.  The applet will block for 10 seconds, then do the write mem.  It's not ideal as there could perhaps be a case where 10 seconds isn't enough.  But I think this will be fine in most cases.

Hi Joe,

It looks like it never triggers. I keep seeing this and it never disappears :)

SJ-9966#sh event manager statistics policy 

                                       Average        Maximum        
No.  Class     Triggered   Suppressed  Run Time       Run Time       Name
-------------------------------------------------------------------------------
1    applet    1           0           0.136          0.136          Write_Memory
 event {} application


SJ-9966#

SJ-9966#sh event manager policy registered 
No.  Class     Type    Event Type          Trap  Time Registered           Name
1    applet    user    application         Off   Fri Jul 11 01:14:27 2014  Write_Memory
 sub_system 798 type 1
 maxrun 20.000
 action 1.0 cli command "enable"
 action 2.0 cli command "write mem"

SJ-9966#

Should the text WRITE-MEM and the text in the line "event manager applet Write_Memory" Match?

Does it matter if they don't? 

action 1.75 publish-event sub-system 798 type 1 arg1 WRITE-MEM

Then:

event manager applet Write_Memory

event application sub-system 798 type 1

action 1.0 wait 1

No, these two things have no relation.  The key is the sub-system and type.  It looks like those match.  I honestly don't see a problem in what you've shown.  The policy appears to be running.  Why do you think it never triggers?

It never does a write mem :)

Enable "debug event manager action cli" and then reproduce.  Post the output.

Hi Joseph,

Can you have another look

Review Cisco Networking for a $25 gift card