Community discussions

MikroTik App
 
DL7JP
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 85
Joined: Sat Oct 19, 2013 4:14 pm

Routing exeptions for connections from the routers itself

Fri May 10, 2019 1:29 am

Here's a challenge for the routing experts :-)
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?
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3300
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Routing exeptions for connections from the routers itself

Fri May 10, 2019 7:57 am

You can not use Syslog?
 
DL7JP
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 85
Joined: Sat Oct 19, 2013 4:14 pm

Re: Routing exeptions for connections from the routers itself

Fri May 10, 2019 11:28 am

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.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10240
Joined: Mon Jun 08, 2015 12:09 pm

Re: Routing exeptions for connections from the routers itself

Fri May 10, 2019 1:48 pm

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?
 
DL7JP
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 85
Joined: Sat Oct 19, 2013 4:14 pm

Re: Routing exeptions for connections from the routers itself

Fri May 10, 2019 3:31 pm

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.
 
nostromog
Member Candidate
Member Candidate
Posts: 226
Joined: Wed Jul 18, 2018 3:39 pm

Re: Routing exeptions for connections from the routers itself

Fri May 10, 2019 5:23 pm

Here's a challenge for the routing experts :-)
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?
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.
 
DL7JP
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 85
Joined: Sat Oct 19, 2013 4:14 pm

Re: Routing exeptions for connections from the routers itself

Fri May 10, 2019 6:14 pm

@nostromog: Thanks a bunch! This sound quite like what I was looking for. Nice trick, I did not think about this... will test it.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3300
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Routing exeptions for connections from the routers itself

Fri May 10, 2019 10:04 pm

Well, I probably could, but I find a Telegram group more versatile and I already use it a lot to monitor Mikrotik routers.
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.

Who is online

Users browsing this forum: malks and 70 guests