Routing exeptions for connections from the routers itself

Here’s a challenge for the routing experts :slight_smile:
I have a script that uses the Telegram messenger API to notify about logins, errors, etc. on a router; this is done by "/tool fetch url=“https://api.telegram.org/bot…” in a script. Since api.telegram.org is blocked in several countries, I want this request to be routed via an existing VPN tunnel on the router - without changing the default route. I guess mangle and connection/routing marking is the tool to use, but I could not figure out how to set this up for a connection originating from the router itself: The source address of the router is not fixed (being assigned by dhcp), neither is there any interface I could use in the mangle rule…any ideas?

You can not use Syslog?

Well, I probably could, but I find a Telegram group more versatile and I already use it a lot to monitor Mikrotik routers.

When you apparently don’t mind sending your alert messages through your VPN (which will fail whenever the internet connection is down or the VPN is down) why not send the telegram message from your central system as an action on the syslog server there?

The reason is that there is no central system with a syslog server.

If you don’t mind that any client of the router uses your VPN tunnel to access the existing VPN tunnel, you could run something like

/ip route add comment=api.telegram.org dst-address=[:resolve api.telegram.org] gateway=yourvpninterface

You would need to run periodically something like

:if ("$[/ip route get [f comment="api.telegram.org"] dst-address ]"!="$[:resolve api.telegram.org]/32") do={/ip route set [f comment="api.telegram.org"] dst-address=[:resolve api.telegram.org]}

to ensure that the address resolved is kept current. Routing ipv6 it would be far trickier, due to the disfunctional :resolve function.

If you only want to route traffic to api.telegram.org from the router you could use more sophisticated your or forbid api.telegram.org in the forward chain.

@nostromog: Thanks a bunch! This sound quite like what I was looking for. Nice trick, I did not think about this… will test it.

You can look at my Splunk project link in my signature.
It’s created to monitor many Router at the same time.
All config on the Routers are equal so easy to add extra routers.