Community discussions

MikroTik App
 
alexvdk
just joined
Topic Author
Posts: 2
Joined: Mon Jan 24, 2022 8:46 am

bgp peer disable/enable script based on packet loss

Mon Jan 24, 2022 9:11 am

Grretings. I'll greatly appreciate some help with script as my scripting and programming skills are below zero.
I need bgp peer which "name" ends with "asr1" to be disable at site-A-router if icmp packet loss to WAN ip address at site-B-router is above 5%.

I tried to figure this out myself and ended up with script below, but it does not work :(
# VARIABLES
:local asr1 "212.2.33.84";
:local pingCount 20;
:local stableConnectionFrom 95;
:local quality ([/ping count=$pingCount $asr1] * 100 / $pingCount)
# Connection quality check and bgp peers disable or enable
:if ($quality < $stableConnectionFrom) do={
/routing bgp peer disable [find where name~"asr1" and disabled=no]
} 
elese={
do={/routing bgp peer enable [find where name~"asr1" and disabled=yes]
}
}
Thanks in advance.
Last edited by alexvdk on Tue Jan 25, 2022 2:43 am, edited 1 time in total.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 2838
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: bgp peer disable/enable script based on packet loss  [SOLVED]

Mon Jan 24, 2022 11:43 pm

Post it in Code tags and tabs, makes it easier to read.
PS I have not tested it.
fixed: elese-else
removed extra: }
removed: do
removed not needed ; at end of lines
# VARIABLES
:local asr1 "212.2.33.84"
:local pingCount 20
:local stableConnectionFrom 95
:local quality ([/ping count=$pingCount $asr1] * 100 / $pingCount)
# Connection quality check and bgp peers disable or enable
:if ($quality < $stableConnectionFrom) do={
	/routing bgp peer disable [find where name~"asr1" and disabled=no]
} else={
	/routing bgp peer enable [find where name~"asr1" and disabled=yes]
}
 
Use Splunk> to log/monitor your MikroTik Router(s). See link below. :mrgreen:

MikroTik->Splunk
 
 
alexvdk
just joined
Topic Author
Posts: 2
Joined: Mon Jan 24, 2022 8:46 am

Re: bgp peer disable/enable script based on packet loss

Tue Jan 25, 2022 2:38 am

Thank you for editing the script, but it does not work still despite I've made artificial icmp packet drop.

I found some issue in CLI print mode. After "else" operator "=" is marked red as if there is some syntax error.

UPDT: when doing copy-paste missed a "space" before "else". Now script is working.
Thanks for help!

Who is online

Users browsing this forum: userslgk20 and 7 guests