03-03-2022 08:14 AM
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
Solved! Go to Solution.
03-04-2022 01:11 PM - edited 03-04-2022 01:22 PM
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
03-03-2022 09:05 AM
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?
03-03-2022 09:11 AM
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?
03-03-2022 09:19 AM
Predefined one example : (still this need to test)
set X "1"
while $X le $regex value
03-04-2022 01:11 PM - edited 03-04-2022 01:22 PM
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
03-04-2022 07:26 PM
Thanks you Daniel, this did the trick!!! I really appreciate it
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide