Script to reboot router when vpn disconnects

Hi guys, I’m a RouterOS newbie and I’m trying to learn scripting. The company I work for has thousands of Mikrotiks all over the US and Canada. We monitor these routers via a vpn connection. Sometimes when our routers are down, our helpdesk guys just have to have the person onsite power cycle the router. I’m wanting to create a script that will automatically reboot the router when the vpn disconnects from the server. Any advice is welcomed. Thanks in advance!

I’ll post something when I get back to a computer tonight…

Basically just have a script that runs every couple of minutes then reboots if the connection is down..

Sent from my SCH-I545 using Tapatalk 2

Sorry, got home really late last night. Here is something to get you started. I haven’t tested it, but basically just run this every minute or so. The first if statement ensures that the connection has been up at some point… this prevents you from “boot looping” if the vpn never comes up and the device just keeps restarting… the second checks the status as long as it has been connected once.

Like I said. I haven’t tested it, but it gives you a starting point.

:global rebootActive false

:local status [/interface sstp-client monitor 0 as-value]

:if (!rebootActive && [:typeof [:find $status "connected" -1]] != "nil") do={
  :set rebootActive true
} 

:if (rebootActive && [:typeof [:find $status "connected" -1]] = "nil") do={
  /system reboot
}