Sunday, 29 December 2013

Embedded Event Manager Suicide

I often use the Cisco embedded event manager to automate tasks such as applying diverts on timers etc.  Using a cron-entry this works very well, though I always test the script in GNS3 first before applying.  One slight issue has bothered me is having to return to the device and tidy off the script so it doesn't run again the following year.  What if you told the script to delete itself, would it still work?

The answer is yes, further more you can delete the script mid-operation, the script is clearly not dependent on running-config once executed.  Here is an example, with an added line to remove the script:

event manager applet update_divert 
event none
action 1.0 cli command "enable"
action 2.0 cli command "config t"
action 3.0 cli command "voice translation-rule 89"
action 4.0 cli command "rule 5 /0121111111/ /3900/"
action 4.1 cli command "exit"
action 4.2 cli command "no dial-peer voice 3420 voip"
action 4.3 cli command "no event manager applet update_divert"
action 5.0 cli command "exit"
action 6.0 cli command "write mem"
action 8.0 cli command "exit"

R1#event manager run update_divert
R1#
*Mar  1 00:05:01.955: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : CTL : cli_open called.
*Mar  1 00:05:01.955: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : IN  : 
*Mar  1 00:05:01.971: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : 
*Mar  1 00:05:01.971: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : R1>
*Mar  1 00:05:01.975: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : R1>
*Mar  1 00:05:01.975: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : R1>
*Mar  1 00:05:01.975: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : IN  : >enable
*Mar  1 00:05:02.039: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : 
*Mar  1 00:05:02.039: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : R1#
*Mar  1 00:05:02.043: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : IN  : #config t
*Mar  1 00:05:02.079: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : 
*Mar  1 00:05:02.079: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : Enter configuration commands, one per line.  End with CNTL/Z.
*Mar  1 00:05:02.079: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : R1(config)#
*Mar  1 00:05:02.079: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : IN  : #voice translation-rule 89
*Mar  1 00:05:02.115: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : 
*Mar  1 00:05:02.115: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : R1(cfg-translation-rule)#
*Mar  1 00:05:02.115: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : IN  : #rule 5 /01224585599/ /3900/
*Mar  1 00:05:02.135: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : 
*Mar  1 00:05:02.135: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : R1(cfg-translation-rule)#
*Mar  1 00:05:02.135: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : IN  : #exit
*Mar  1 00:05:02.151: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : 
*Mar  1 00:05:02.151: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : R1(config)#
*Mar  1 00:05:02.155: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : IN  : #no dial-peer voice 3420 voip
*Mar  1 00:05:02.215: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : 
*Mar  1 00:05:02.215: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : R1(config)#
*Mar  1 00:05:02.219: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : IN  : #no event manager applet update_divert
*Mar  1 00:05:02.331: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : 
*Mar  1 00:05:02.331: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : R1(config)#
*Mar  1 00:05:02.335: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : IN  : #exit
*Mar  1 00:05:02.339: %SYS-5-CONFIG_I: Configured from console by  on vty0 (EEM:update_divert)
*Mar  1 00:05:02.347: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : 
*Mar  1 00:05:02.347: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : R1#
*Mar  1 00:05:02.351: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : IN  : #write mem
*Mar  1 00:05:04.515: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : 
*Mar  1 00:05:04.515: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : Building configuration...
*Mar  1 00:05:04.515: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : [OK]
*Mar  1 00:05:04.519: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : R1#
*Mar  1 00:05:04.519: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : IN  : #exit
*Mar  1 00:05:04.587: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : 
*Mar  1 00:05:04.587: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : OUT : R1>
*Mar  1 00:05:04.587: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : IN  : >exit
*Mar  1 00:05:04.591: %HA_EM-6-LOG: update_divert : DEBUG(cli_lib) : : CTL : cli_close called.

A quick check of running-config and yes, everything is updated and the script removed.  Nice and tidy.

No comments:

Post a Comment

Found this pointless and feel you must comment? Really, there is no need, we are fully aware of the pointlessness of this article. But if you must...

Google+ Followers