Packet loss Script to GRE Tunnels

Guys,

I do connect sites over GRE tunnels in a Spine Leaf topology, each site has 2 GRE Tunnels connection to a Tunnel Concentrator each, RSTP deal with looping

I made a script to test the WAN connection to each Concentrator and disable the GRE Tunnel if it has packet loss over X %

I’m making it avaiable so other people could use it as well
Any comments is appreciated

#VARIABLES
:local totalpings 25
:local ipdest [interface pptp-client get <interface-name> connect-to]

#IF GRE TUNNEL 2 IS WORKING - RUN SCRIPT
:if ([/interface pptp-client get <interfac2-name> running]=true) do={
    :local pings ([/ping count=$totalpings $ipdest interval=600ms] * 100 / $totalpings)
    :put $pings
    :log info ("Packet Loss:". (100 - $pings). "%")
 #IF PING > 80%
    :if ($pings > 80) do={
        :if ([/interface pptp-client get <interface-name> running]=true) do={} else={
            :interface pptp-client enable <interface-name>;
            :log info ("<interface-name> Enabled");}
    }
#IF PING < 80% 
    :if ($pings < 80) do={
        interface pptp-client disable <interface-name>;
        :log info ("<interface-name> Disabled");
    }
}

Not tested, only fixed syntax and logic errors

# VARIABLES
:local interface  <interface-name>
:local interface2 <interface2-name>
:local totalpings 25
:local ipdest [/interface pptp-client get $interface connect-to]

# IF GRE TUNNEL 2 IS WORKING - RUN SCRIPT
:if ([/interface pptp-client get $interface2 running]) do={
    :local pings ([/ping count=$totalpings $ipdest interval=600ms] * 100 / $totalpings)
    :log info "Packet Loss: $(100 - $pings)%"
# IF PING > 80%
    :if ($pings > 80) do={
        :if ([/interface pptp-client get $interface running]!=true) do={
            /interface pptp-client enable $interface
            :log info "$interface Enabled"
        }
    }
#IF PING < 80% 
    :if ($pings < 80) do={
        /interface pptp-client disable $interface
        :log info "$interface Disabled"
    }
}