This script automates the shutdown and reactivation of BGP neighbors based on the status of a tracked object, ensuring that your network can dynamically respond to changes without manual intervention. The enhancements include validation steps, improved logging for troubleshooting, and modular action design for easier maintenance and readability.
Setting Up CLI Session Defaults
event manager session cli username “gabi”
This command sets the default username for CLI sessions initiated by EEM, ensuring actions are executed under a specific user context.
Applet for Handling BGP Neighbor Shutdown
event manager applet amsix_down
event track 1 state down
action 1.0 cli command “enable”
action 2.0 cli command “conf t”
action 3.0 cli command “router bgp 56654”
action 4.0 cli command “neighbor 80.249.208.255 shutdown”
action 4.1 cli command “neighbor 80.249.209.0 shutdown”
action 4.2 syslog msg “AMS-IX BGP neighbors shutdown due to track 1 down.”
action 5.0 cli command “exit”
action 6.0 cli command “end”
action 6.1 syslog msg “EEM applet amsix_down executed successfully.”
This applet responds to the tracked object’s state changing to down. It shuts down specified BGP neighbors and logs the action to the system log for auditing and troubleshooting.
Applet for Reactivating BGP Neighbors
event manager applet amsix_up
event track 1 state up
action 1.0 cli command “enable”
action 2.0 cli command “conf t”
action 3.0 cli command “router bgp 56654”
action 4.0 cli command “no neighbor 80.249.208.255 shutdown”
action 4.1 cli command “no neighbor 80.249.209.0 shutdown”
action 4.2 syslog msg “AMS-IX BGP neighbors reactivated due to track 1 up.”
action 5.0 cli command “exit”
action 6.0 cli command “end”
action 6.1 syslog msg “EEM applet amsix_up executed successfully.”