← Back to Blog
monitoring isp netwatch

Get an Email When a MikroTik Goes Offline, Without Alert Spam

The worst way to learn that a client router is down is a phone call from the client. The next worst is an inbox with fifty "down" and "up" messages caused by a line that blinked for ten seconds, which teaches you to ignore every alert. This note builds a simple alert with tools already inside RouterOS: one email when a router has really been unreachable for a few minutes, and one when it comes back.

1

Decide what "down" means for you

A router can be reachable and still useless, or unreachable from the Internet and perfectly fine. Pick one clear test. For routers that you reach through a tunnel such as SSTP or WireGuard, the most reliable test is whether the tunnel address answers. Pinging the public IP of a client behind CGNAT or Starlink will fail all day even when everything works, so do not use it. Write the address you will watch for each router, for example 172.18.0.2.

2

Let the watching device send email

Run the watcher on a device that is not the one being watched, such as your central router or a server. Configure its e-mail tool with an SMTP account you control:

/tool e-mail set server=smtp.example.com port=587 from=alerts@example.com user=alerts@example.com password=YOUR_PASSWORD tls=starttls
/tool e-mail send to=you@example.com subject="MikroTik test" body="It works"

On RouterOS 6 the option is start-tls=yes instead of tls=starttls. Send the test message and make sure it arrives, and does not land in spam, before going further.

3

Watch the router with Netwatch

Netwatch pings a host at an interval and runs a script when its state changes:

/tool netwatch add host=172.18.0.2 interval=30s timeout=3s comment="Client Alpha" down-script="" up-script=""

The comment is useful: it is the name you will put in the email so you know which client is affected. The scripts are empty for now.

4

Wait before raising the alarm

To ignore short blips, the down script waits a few minutes and checks again. If the host is still down, it sends the email:

/tool netwatch set [find host=172.18.0.2] down-script={
  :delay 180s
  :if ([/tool netwatch get [find host=172.18.0.2] status] = "down") do={
    /tool e-mail send to=you@example.com subject="DOWN: Client Alpha" body="No answer from 172.18.0.2 for 3 minutes."
  }
}

Three minutes is a starting point. Short enough to react, long enough to skip most reboots and line flaps. Lower it for critical sites, raise it for lines that are known to be unstable.

5

Send one recovery message

An alert without a recovery makes you check by hand. Add the up script, which only mentions recovery if the down email was really sent. A simple way is to remember it in a global variable:

/tool netwatch set [find host=172.18.0.2] down-script={
  :delay 180s
  :if ([/tool netwatch get [find host=172.18.0.2] status] = "down") do={
    :global alpha1down true
    /tool e-mail send to=you@example.com subject="DOWN: Client Alpha" body="No answer from 172.18.0.2 for 3 minutes."
  }
}
/tool netwatch set [find host=172.18.0.2] up-script={
  :global alpha1down
  :if ($alpha1down = true) do={
    :set alpha1down false
    /tool e-mail send to=you@example.com subject="UP: Client Alpha" body="172.18.0.2 answers again."
  }
}

Use a different variable name for each router. A blip that recovers before the three minutes produces no email at all, which is exactly what you want.

6

Watch the disk, the slow killer

Not every failure is a power cut. Logs and backups can fill the internal storage until the router misbehaves. A scheduled check is enough:

/system scheduler add name=disk-check interval=1h on-event={
  :if ([/system resource get free-hdd-space] < 5000000) do={
    /tool e-mail send to=you@example.com subject="LOW DISK: router" body="Less than 5 MB free on the internal storage."
  }
}

For CPU and traffic thresholds, SNMP with a monitoring system is a better tool than scripts on the router.

7

Test the whole chain

Do not wait for a real outage to find out that the mail does not leave. Disable the tunnel or the client interface, wait longer than your delay and confirm the DOWN email arrives. Enable it again and confirm UP. Do this once after every change to the SMTP account, and remember the weak point of this design: if the watcher itself or its Internet access is down, nobody warns you.

Why do it this way

Good alerts have two properties: they arrive when something is really wrong, and they stay quiet when it is not. The waiting period is what gives you the second one. With it, an email means "go and look", and you learn to trust it. Without it, the inbox fills with noise and the one message that matters is buried among the others.

How MoniTik helps

MoniTik includes this kind of alert, with no scripts on your routers. If a device's tunnel stays down for more than a few minutes (5 by default), it emails the contact address of the account, and it sends a recovery email when the router comes back. If the router comes back before the delay, nothing is sent. The test is the tunnel and not the public IP, so a change of address, as happens with Starlink or CGNAT, does not trigger a false alarm. The language of the email (English, Spanish or Portuguese) is chosen in the account page, and alerts can be switched off there. MoniTik alerts on connectivity; it does not send alerts for CPU or disk thresholds.

Start Free Trial
Camila Torres
Camila Torres Network Engineer

Camila focuses on routing, VPNs, and hardening MikroTik deployments for small and mid-size networks.