Community discussions

MikroTik App
 
nerfmikro
just joined
Topic Author
Posts: 1
Joined: Fri Mar 31, 2023 6:22 pm

Ping Monitor - Success / Fail

Fri Mar 31, 2023 6:32 pm

Hi, I've been wrecking my head with this script. When I can successfully ping 8.8.8.8 I want to set the priority to 142 of VRRP1 and when unsuccessful after 15 seconds change the priority to 140. The success part sets the priority to 142 works, but failed priority to 140 never kicks in. Any ideas?

I can't use Netwatch; Life would be straightforward if I could. It thinks everything is down except local devices.
:local pingHost "8.8.8.8"
:local pingInterval 5
:local pingThreshold 3
:local vrrpprioritylow 140
:local vrrppriorityhigh 142
:local srcaddress "10.19.4.77"
:local pingCount 0
:local vrrpStatus 140
:local vrrpInterface vrrp1

:log info "Starting ping monitor script..."

while (true) do={
    /ping count=1 src-address=$srcaddress address=$pingHost interval=$pingInterval
    :if ($pingCount >= $pingThreshold) do={
            :log warning "Ping failed $pingThreshold times. Decreasing VRRP priority on interface $vrrpInterface..."
            /interface vrrp set $vrrpInterface priority=$vrrpprioritylow
            :set vrrpStatus 140
        
        :set pingCount 0
    }
    :if ($pingCount < $pingThreshold) do={
            :log warning "Ping successful. Increasing VRRP priority on interface $vrrpInterface..."
            /interface vrrp set $vrrpInterface priority=$vrrppriorityhigh
            :set vrrpStatus 142
    }
    :set pingCount ($pingCount + 1)
    :delay $pingInterval
}

Who is online

Users browsing this forum: alexantao and 24 guests