cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2084
Views
40
Helpful
5
Replies

EEM with IF statement while checking Uptime

JoseChek9
Level 1
Level 1

Hi Community, 

 

Currently I am having issues monitoring BFD's uptime on my routers and based on the uptime to run an X action. Basically I have an applet monitoring BFDs state which if its Up, then triggers an Action and it works fine, however, if BFD flaps, the action will be executed everytime BFD's state is UP. Instead I am looking to monitor BFD's uptime time and based on the amount of hours UP, then run an action.

This only checks BFDs Up:


Original part of config:

action 2.7 cli command "action 5.5 cli command \"sh bfd neighbors ipv4X.X.X.X details | i Session state is UP\""
action 2.8 cli command "action 5.6 regexp \"Session state is UP*\" \$_cli_result\""
action 2.9 cli command "action 5.7 if \$_regexp_result eq \"1\""

action 3.0 cli command "action 5.8 syslog msg \"Neighbor X.X.X.X - BFD is UP - REVERTING Tunnel1 Blocked_ALL_IPv4\""

 

I need to be able to run this action

action 3.0 cli command "action 5.8 syslog msg \"Neighbor X.X.X.X - BFD is UP - REVERTING Tunnel1 Blocked_ALL_IPv4\""


Only after Uptime is GE than 2:00:00 hours

 

How do I set it up in the script to revert the config after BFD's has been up for 2 hrs straight?

action 2.7 cli command "action 5.5 cli command \"sh bfd neighbors ipv4 X.X.X.X details | inc Uptime\""
action 2.8 cli command "action 5.6 regexp \"Uptime*\" \$_cli_result\""
action 2.9 cli command "action 5.7 if \$_regexp_result ge "02:00:00"" <<< This value doesnt work
action 3.0 cli command "action 5.8 syslog msg \"Neighbor X.X.X.X- BFD is UP after 2 hours - REVERTING Tunnel1 Blocked_ALL_IPv4\""

 

 

thanks Everyone

1 Accepted Solution

Accepted Solutions

Need to transpose the hours and minutes to seconds, then add all the seconds together and see if it exceed the threshold or not.  Here is an example.

event manager applet test
 event none
 action 010 set t "02:10:01"
 action 020 regexp "([0-9]+):([0-9]+):([0-9]+)" "$t" match hours min sec
 action 025 set threshold "7200"
 action 030 multiply $hours 3600
 action 040 set hours "$_result"
 action 050 multiply $min 60
 action 055 set min "$_result"
 action 060 add $hours $min
 action 070 set hoursmin "$_result"
 action 080 add $hoursmin $sec
 action 100 if $_result ge "$threshold"
 action 110  puts "uptime $_result >=  $threshold threshold"
 action 120 else
 action 130  puts "uptime $_result < than $threshold threshold"
 action 140 end
!
end

lab-csr2#event manager run test
uptime 7801 >=  7200 threshold

View solution in original post

5 Replies 5

balaji.bandi
Hall of Fame
Hall of Fame

You can do the logic like this, i need to test this also.

 

You need to store the 2 hours in a variable. and compare with results and action.

are you able to get the results output BFD value with regex?

 

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

Ill tri it today and see if the results can be done with the Regex. If so... How would I store the result in a Variable? in seconds? o by the number displayed by IOS?

Predefined one example : (still this need to test)

 

set X "1"
while $X le $regex value

 

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

Need to transpose the hours and minutes to seconds, then add all the seconds together and see if it exceed the threshold or not.  Here is an example.

event manager applet test
 event none
 action 010 set t "02:10:01"
 action 020 regexp "([0-9]+):([0-9]+):([0-9]+)" "$t" match hours min sec
 action 025 set threshold "7200"
 action 030 multiply $hours 3600
 action 040 set hours "$_result"
 action 050 multiply $min 60
 action 055 set min "$_result"
 action 060 add $hours $min
 action 070 set hoursmin "$_result"
 action 080 add $hoursmin $sec
 action 100 if $_result ge "$threshold"
 action 110  puts "uptime $_result >=  $threshold threshold"
 action 120 else
 action 130  puts "uptime $_result < than $threshold threshold"
 action 140 end
!
end

lab-csr2#event manager run test
uptime 7801 >=  7200 threshold

Thanks you Daniel, this did the trick!!! I really appreciate it