Community discussions

MikroTik App
 
anc
just joined
Topic Author
Posts: 7
Joined: Fri Sep 01, 2023 4:38 pm

Notifications script for Telegram after a route change while failover

Thu Nov 02, 2023 9:47 am

Hi guys,

I need to catch changed routes and pass this to the notification script. Now I see 2 ways so far:
1. Check immediate-gw. When switching to ISP2 occurs, the /ip route get [find immediate-gw=9.9.9.9%ISP1] command displays "no such item"
2. Catch route flags, if possible in ROS 7. In the case when ISP1 is unavailable and the connection goes through ISP2, the following is displayed:

[admin@Test] > /ip/route/print
Flags: D - DYNAMIC; I - INACTIVE, A - ACTIVE; c - CONNECT, s - STATIC; H - HW-OFFLOADED
Columns: DST-ADDRESS, GATEWAY, DISTANCE
# DST-ADDRESS GATEWAY DISTANCE
;;; ISP2
0 As 0.0.0.0/0 lte1 5
1 IsH 0.0.0.0/0 9.9.9.9 2
2 As 9.9.9.9/32 ISP1 2
DAc 10.11.11.0/24 bridge1 0
DAc 10.100.100.0/24 lte1 0
DAc 172.16.25.1/32 ISP1 0

After the connection to ISP1 is restored, the route flag IsH changes to As:

[admin@Test] > /ip/route/print
Flags: D - DYNAMIC; A - ACTIVE; c - CONNECT, s - STATIC
Columns: DST-ADDRESS, GATEWAY, DISTANCE
# DST-ADDRESS GATEWAY DISTANCE
;;; ISP2
0 s 0.0.0.0/0 lte1 5
1 As 0.0.0.0/0 9.9.9.9 2
2 As 9.9.9.9/32 ISP1 2
DAc 10.11.11.0/24 bridge1 0
DAc 10.100.100.0/24 lte1 0
DAc 172.16.25.1/32 ISP1 0

Scripting for ROS is not my strong point. I tried writing this, but it doesn't work properly :/
:if ([/ip route get [find immediate-gw=9.9.9.9%ISP2]]="no such item") do={
:local DeviceName [/system identity get name];
:local ChatID "xxxxxxxxxx";
:local SendText "\E2\9A\A0 <b>Router - $DeviceName:</b>%0AMain ISP on $DeviceName is DOWN!";
#:log info "ISP1 gateway is down";
/tool fetch url="https://api.telegram.org/botxxxxx:xxxxxxxxxxxxxx/sendMessage?chat_id=$ChatID&parse_mode=HTML&text=$SendText" keep-result=no;
}
If someone help me get it to work I'd really appreciate it.

Who is online

Users browsing this forum: No registered users and 5 guests