A RouterOS box can send its own alerts to your phone — no collector, no middleware. /tool fetch POSTs to the Telegram Bot API, and from there any netwatch, scheduler, or script fires a message. The trick is to write the notifier once, as a reusable function, then wire triggers to it. The three things that quietly stop it working aren't code — they're device-mode, TLS trust, and a token you must keep out of your configs. For the durable, filtered record see Logging & Remote Syslog; for graphs and thresholds over time, MikroTik + Prometheus.
On-device alerting answers a narrow question: something just changed on this router and no one is watching the dashboard. A dropped WAN at 02:00, a CPU pegged at 100%, a temperature climbing in a hot cabinet. You don't need a monitoring stack for that — RouterOS can reach out to Telegram itself with one HTTPS request.
This is complementary to a real collector, not a replacement. Telegram push is for the handful of events a human should see now; syslog and metrics are for the full record and the trends. Think of the router as the fallback alarm when the operator box is unreachable — or when there is no operator box at all.
token — and your numeric chat_id (message the bot, then read getUpdates)fetch and scheduler enabled in device-mode (a physical step — see §2)01
Register a global function $tgSend. Every trigger calls it with a string. It builds the Bot API request, escapes the body, and sends it — so the Telegram plumbing lives in exactly one place.
# Secrets come from globals you set elsewhere (see §2) — never hardcode them. [admin@edge] > /system/script/add name=tg-init dont-require-permissions=yes \ policy=read,write,test source={ :global tgToken; :global tgChat :global tgSend do={ :global tgToken; :global tgChat :local m [:tostr $1] # JSON-escape the message body: backslash, double-quote, newline :local e "" :for i from=0 to=([:len $m] - 1) do={ :local c [:pick $m $i] :if ($c = "\\") do={ :set e ($e . "\\\\") } else={ :if ($c = "\"") do={ :set e ($e . "\\\"") } else={ :if ($c = "\n") do={ :set e ($e . "\\n") } else={ :set e ($e . $c) }}} } :local url ("https://api.telegram.org/bot" . $tgToken . "/sendMessage") :local body ("{\"chat_id\":\"" . $tgChat . "\",\"text\":\"" . $e . "\"}") :do { /tool/fetch http-method=post url=$url check-certificate=yes-without-crl \ http-header-field="Content-Type: application/json" \ http-data=$body output=none as-value } on-error={ :log warning "tgSend: fetch failed" } } } [admin@edge] > /system/script/run tg-init # arm it (globals live until reboot)
Globals in RouterOS are lost on reboot, so $tgSend has to be re-registered at startup — a one-line /system/scheduler with start-time=startup running tg-init does it. And prefer POST with a JSON body over a GET query string: the message rides in the body, so you escape for JSON (three characters) instead of URL-encoding every space and symbol in the text. The small :for loop above is the entire escaper.
02
None of these throw a clear error. The fetch just fails, or never runs. Clear all three before you wire any trigger.
# (1) DEVICE-MODE: fetch + scheduler are gated off by default on RouterOS 7.13+. # This prints a prompt that needs a COLD power-cycle / reset-button press # physically at the device — by design, so no one arms it remotely. [admin@edge] > /system/device-mode/update fetch=yes scheduler=yes # (2) CLOCK: TLS cert validation fails on a wrong date. NTP by IP so it # doesn't depend on DNS. Confirm status: synchronized before testing fetch. [admin@edge] > /system/ntp/client/set enabled=yes servers=10.0.0.1 # (3) SECRET: set the token/chat as globals from a file you DON'T commit, # not inline in your exported config. Keep them out of version control. [admin@edge] > :global tgToken "123456:AA...bot-token..." [admin@edge] > :global tgChat "111111111"
Out of the box there is no trusted CA store, so an HTTPS /tool/fetch to api.telegram.org fails certificate verification and your alert silently never sends. Two honest choices: import the CA chain (/certificate import) and keep check-certificate=yes-without-crl — the right answer for anything production — or set check-certificate=no, which works instantly but sends your bot token over a connection whose server identity you never verified. Don't ship no to a client site; it's a lab shortcut. Either way, a wrong clock defeats a valid cert, so fix NTP first.
03
Netwatch pings a host and runs a script on each state change — not on every probe. That edge-triggering is exactly what you want: one message when the link drops, one when it comes back.
# host = what "WAN up" means to you. 1.1.1.1 tests real reachability; # your ISP gateway tests the link only. up/down scripts call the function. [admin@edge] > /tool/netwatch/add name=wan-tg host=1.1.1.1 type=simple \ interval=10s timeout=2s \ up-script=":global tgSend; \$tgSend (\"WAN UP - 1.1.1.1 reachable\")" \ down-script=":global tgSend; \$tgSend (\"WAN DOWN - 1.1.1.1 unreachable\")"
If you point host at the next-hop gateway, you'll catch a dead cable but miss the far more common failure: the link is up but the internet is gone (upstream outage, PPPoE down, CGNAT black hole). Ping something past your ISP — a public resolver — to alert on reachability. For a dual-WAN box, set src-address to pin the probe to the uplink you actually want to test, so a healthy backup doesn't mask a failed primary.
04
There's no event for "CPU got busy," so you poll on a scheduler. The discipline that makes it usable is hysteresis: alert once when it crosses high, once when it recovers — never a message per tick.
# A script the scheduler runs every minute. The flag turns a level into an edge. [admin@edge] > /system/script/add name=tg-health dont-require-permissions=yes \ policy=read,test source={ :global tgSend; :global tgCpuHot :local cpu [/system/resource/get cpu-load] :if ($cpu > 90) do={ :if ($tgCpuHot != true) do={ $tgSend ("CPU HIGH - " . $cpu . "%"); :set tgCpuHot true } } else={ :if ($cpu < 70 and $tgCpuHot = true) do={ $tgSend ("CPU recovered - " . $cpu . "%"); :set tgCpuHot false } } # Temperature only if the board has a sensor (many small hAPs don't). :if ([:len [/system/health/find where name=temperature]] > 0) do={ :local t [/system/health/get [find where name=temperature] value] :if ($t > 70) do={ $tgSend ("TEMP HIGH - " . $t . "C") } } } [admin@edge] > /system/scheduler/add name=tg-health interval=1m \ on-event="/system/script/run tg-health" policy=read,test
Without the flag, a CPU hovering at 89–91% sends an alert every single poll as it jitters across the line. The fix is two thresholds: fire at > 90, and only re-arm once it drops back under 70 (tgClear). That gap is the hysteresis band — the same idea as a thermostat's deadband. It's also why temperature needs its own flag, not a shared one: a hot CPU and a hot board are different alarms. And guard the temperature read with find where name=temperature — calling get on a board with no sensor errors out and kills the whole script.
05
# 1. The function itself — you should get a Telegram message instantly. [admin@edge] > :global tgSend; $tgSend ("test alert from edge") # 2. Device-mode actually enabled (fetch: yes, scheduler: yes). [admin@edge] > /system/device-mode/print # 3. Force a threshold low to confirm the health trigger fires, then restore. [admin@edge] > /system/script/run tg-health # temporarily drop 90→1 while testing # 4. Watch for failures — a failed fetch logs, it doesn't shout. [admin@edge] > /log/print where message~"tgSend"
Takeaways
$tgSend function; wire every trigger to it. Re-register it at startup, because globals don't survive a reboot.fetch and scheduler on RouterOS 7.13+; enabling them needs a physical power-cycle. It can't be fully provisioned over SSH alone.A dropped WAN or a dying link shouldn't wait for someone to notice. I wire RouterOS fleets to alert on the events that matter — uplink, load, config change, auth — pushed to Telegram and backed by proper logging and metrics, so small sites stay watched without a NOC. Let's set yours up.
Book a Discovery Call →