Our company is trying to implement a time-based WAN failover schedule. We want to use EEM for this purpose and have created some applets with syslog event detectors to fire off various shutdown commands on the router when site router detects it's BGP peer go down, and suppress the failover event if it is after 9pm local time to the router.
Now I was thinking about approaching this from various angles, but one of the most promising angles requires a few question.
First, is there any way to parse the system time for conditional statement for the execution of the failover, basically forcing an "action if goto" conditional to skip to the last action of the applet instead of going through with the various no shut commands necessary to bring up the backup WAN link.
Second, I was thinking about using the applets to define a variable i.e. variable = 1 (when the BGP peer is down), variable = 0 (when the BGP peer is up). But there are a couple of applets that would use this, so I was wondering if the variables defined in a given applet are considered local variables, and are cleared from memory once the applet actions are completed (after the event detector finishes executing the actions that caused the applet to start in the first place), or are they global variables that stay in RAM persistently, and can be referenced by other applets if needed. I am hoping that they are global and persistent, or if there is such a thing that can be modified by an EEM applet so I can use that feature. My purpose for having this global variable is to have another EEM applet run at 8AM every morning to check to see if the BGP peer is still down, and if so it will automatically fire off the failover commands manually, which should have been supressed when the other applet I mentioned would fire.
I cannot imagine this is a difficult script, I am trying to find, and define the various mechanisms within the framework of the EEM system.
I will be more than happy to explain in detail what our goals are if anything is unclear. Thanks for any responses in this regard.
Here are some examples I think should do what you want. They require EEM 3.0.
event manager applet BGP-State-Down
event syslog pattern "%BGP-5-ADJCHANGE: neighbor x.x.x.x Down BGP Notification sent"
action 001 set bgp_down "1"
action 002 context save key BGPCTXT variable "bgp_down"
action 003 cli command "show clock"
action 004 string trim "$_cli_result"
action 005 regexp "^([0-9]+):" "$_string_result" ignore hours
action 006 if $hours ge 22
action 007 exit
action 008 end
action 009 if $hours le 8
action 010 exit
action 011 end
action 012 cli command "enable"
action 013 cli command "config t"
action 014 cli command "int fa3"
action 015 cli command "no shut"
action 016 cli command "int tun201"
action 017 cli command "no shut"
action 018 cli command "end"
event manager applet BGP-State-UP
event syslog pattern "%BGP-5-ADJCHANGE: neighbor x.x.x.x Up"
action 001 context retrieve key BGPCTXT
action 002 handle-error type ignore
action 003 cli command "enable"
action 004 cli command "config t"
action 005 cli command "int fa3"
action 006 cli command "shut"
action 007 cli command "int tun201"
action 008 cli command "shut"
action 009 cli command "end"
event manager applet BGP-State-Down-Opening
event timer cron name Opening cron-entry "0 8 * * *" maxrun 15
action 001 context retrieve key BGPCTXT variable "bgp_down"
action 002 handle-error type exit
action 003 if $bgp_error ne 1
action 004 exit
action 005 end
action 006 cli command "enable"
action 007 cli command "config t"
action 008 cli command "int fa3"
action 009 cli command "no shut"
action 010 cli command "int tun201"
action 011 cli command "no shut"
action 012 cli command "end"