cancel
Showing results forĀ 
Search instead forĀ 
Did you mean:Ā 
cancel
1328
Views
0
Helpful
8
Replies

EEM Script to Reload when BGP goes down

Jrod0809
Level 1
Level 1

Hello everyone, 

I'm new to the EEM scripts creation and I'm currently in the process of learning how to use it. I have a cellular switch IR1101 that uses EEM version 4.0. I am having issues with my routers where sometimes the cellular connection goes down and the link recovery feature on the switch tries to reboot the modem but it seems to get stuck and the modem reboot never takes place. Even if I try to reboot the modem manually, I get an error saying there is a reboot already taking place. The only solution that I've found so far is reloading the switch. With all this being said, I created the following script that waits for 15 minutes after BGP goes down and then calls another script that will actually reload the switch. I also have a third script that cancels the switch reload if BGP comes back up. Let me paste the scripts so that I can explain you better what's happening and maybe I could get some guidance for the solution. The script is the following: 

--------------The script belows waits for 15 minutes after BGP goes down and then triggers the bgp-wait-15-minutes applets.------------ 

event manager applet bgp-neighbor-monitor authorization bypass
description Monitor BGP Neighbor Status
event syslog pattern "BGP-5-ADJCHANGE: neighbor.*Down" maxrun 1800
trigger delay 900
action 1.0 cli command "enable"
action 2.0 syslog msg "BGP is down. Initiating a 15 minutes reload timer"
action 3.0 cli command "event manager run bgp-wait-15-minutes"

---------------The applet below actually reloads the switch-------------------------

event manager applet bgp-wait-15-minutes
event none maxrun 1800
description Wait for 15 minutes after BGP goes down
action 1.0 syslog msg "15-minutes timer complete. Reloading device"
action 2.0 reload
action 3.0 cli command "end"

------------The applet below cancels the reload by using the no event manager applet bgp-wait-15-minutes applet---------

event manager applet bgp-up-monitor authorization bypass
description Monitor BGP Neighbor Status (Up)
event syslog pattern "BGP-5-ADJCHANGE: neighbor.*Up"
action 1.0 cli command "enable"
action 2.0 cli command "config t"

action 3.0 cli command "no event manager applet bgp-wait-15-minutes"
action 4.0 cli command "end"

The issue here is that since I'm using the no event manager applet-wait-15-minutes command, this actually deletes the applet from the registered policies, therefore, if BGP goes down again, there won't be an applet that will reload the switch. Is there a way to do this? Again, I'm just learning about EEM scripts and I'm trying to grasp the concept. I also don't have an idea on how to create TCL scripts. Any help/guidance would be really appreciated. 



1 Accepted Solution

Accepted Solutions

Dan Frey
Cisco Employee
Cisco Employee

I would consolidate this into a single policy by keeping the trigger the same, then manually check the BGP neighbor.   If BGP neighbor is NOT Established; reload.

event manager applet bgp-neighbor-monitor authorization bypass
 description Monitor BGP Neighbor Status
 event syslog pattern "BGP-5-ADJCHANGE: neighbor.*Down" maxrun 1800
 action 010 regexp "BGP-5-ADJCHANGE: neighbor ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)" "$_syslog_msg" match neighborIp
 action 020 cli command "enable"
 action 030 wait 900
 action 040 cli command "sh ip bgp neighbor $neighborIp | inc BGP state"
 action 050 regexp "BGP state = Established" "$_cli_result"
 action 060 if $_regexp_result eq "0"
 action 070  reload
 action 080 end

View solution in original post

8 Replies 8

Dan Frey
Cisco Employee
Cisco Employee

I would consolidate this into a single policy by keeping the trigger the same, then manually check the BGP neighbor.   If BGP neighbor is NOT Established; reload.

event manager applet bgp-neighbor-monitor authorization bypass
 description Monitor BGP Neighbor Status
 event syslog pattern "BGP-5-ADJCHANGE: neighbor.*Down" maxrun 1800
 action 010 regexp "BGP-5-ADJCHANGE: neighbor ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)" "$_syslog_msg" match neighborIp
 action 020 cli command "enable"
 action 030 wait 900
 action 040 cli command "sh ip bgp neighbor $neighborIp | inc BGP state"
 action 050 regexp "BGP state = Established" "$_cli_result"
 action 060 if $_regexp_result eq "0"
 action 070  reload
 action 080 end

Thank you much Dan for the info. I've seen the reference to regexp_results on some of the research that I've done but for some reason, I haven't been able to make it work on my device. It seems that if I can't use it using the if statement. I would assume that since my device is using EEM 4.0 that option would be available but it seems like if it isn't or maybe I'm not using it correctly. I see that you are using it on your script as well on action 060 but this is what I get when I try to use it:
Van_0009(config-applet)#action 060 if $_regexp_result eq "0"
                                                                    ^
% Invalid input detected at '^' marker.

Applets are good for most things but when there are gaps TCL can be used.   Go to this site to convert the applet to a TCL file.  TCL will be able to support the regexp match.

https://www.marcuscom.com/convert_applet/

 

understood. I converted the applet to a tcl file as suggested and this is what I got:

array set arr_einfo [event_reqinfo]


if [catch {cli_open} result] {
error $result $errorInfo
} else {
array set cli1 $result
}

set _regexp_result [regexp {BGP-5-ADJCHANGE: neighbor ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)} $arr_einfo(msg) match neighborIp]
if [catch {cli_exec $cli1(fd) "enable"} _cli_result] {
error $_cli_result $errorInfo
}

after 900000
if [catch {cli_exec $cli1(fd) "sh ip bgp neighbor $neighborIp | inc BGP state"} _cli_result] {
error $_cli_result $errorInfo
}

set _regexp_result [regexp {BGP state = Established} $_cli_result]
if {$_regexp_result == "0"} {
action_reload
}

# Close open cli before exit.
catch {cli_close $cli1(fd) $cli1(tty_id)} result

After I did this, I uploaded the file to flash and then tried to run it and received the following error: 
Van_0009(tcl)#source flash:bgp-monitoring.tcl
invalid command name "event_reqinfo" ^
% Invalid input detected at '^' marker.

Any idea on what I'm doing wrong?

EEM has libraries that extend the usefulness of TCL and can only be used in an EEM environment.  The syntax you have is to run a normal TCL file in IOS.   TCL does not know about the EEM libraries and this is what is generating the error.   You need to trigger the EEM script with the BGP syslog message so that TCL will import the EEM extensions.  You also need all the syntax that that web site translates starting at the top line to include in the tcl file.  

Dan, 

your solution worked very well for me. Thank you much for your help. Once I converted the file to tcl format, I then had to register it in EEM. Basically the process was to convert the applet to TCL and save it to a folder in flash. After that I had to register the directory in EEM by running this command: event manager directory user policy flash:/NAME OF DIRECTORY. As the last step was to register the tcl by running this command: event manager policy NAME_OF_SCRIPT.TCL

Again, Thank you so much for pointing me in the right direction. 

 

Friend 

Use ip sla tcp instead of monitor bgp session.

It simple not complicate.

Thank you MHM Cisco World for the suggestion. I also thought about that. My concern is that I still want to wait 15 minutes or so for the device to start responding and in the event that it start responding again, then I don't want the reload to happen.  Once the applet starts running, I haven't found a way to prevent the reload other than deleting the applet completely but if I do that, then the applet won't be there to reload the switch again in the event that it becomes unreachable again. 

Review Cisco Networking for a $25 gift card