I am quite new to the Mikrotik world, having gotten my HeX S about a year ago after I figured that my EdgeRouter X was not cutting it anymore.
I very briefly delved into Mikrotik years ago when Squid proxies were still a thing, but I'm definitely far from a power user when it comes to scripting.
I have a situation where I have two WAN connections, configured with PCC and failover which is working pretty flawlessly for the most part. I also have queues that I dynamically adjust the bandwidth on as these WAN connections go online and offline quite frequently due to power outages. Ideally, if both connections are up, I want the limits to be 100M/100M, but when WAN1 is down, I want it to be 50M/50M and when WAN2 is down, it has to be 15M/15M due to the WAN speeds being asymmetric (WAN1=30mbps, WAN2=100mbps)
This used to work fine when my WAN1 was quite stable and only WAN2 would go offline often, but lately, even WAN1 is going offline quite a bit, and my issue is that my script isn't smart enough to cover all scenarios and sometimes the wrong queue speeds are applied.
What I had in mind was a script that can run every ten seconds and check which connections are up, either by checking the Netwatch status or the route status. I would then like to assign a value to each WAN link (ie. 1 for WAN1 and 2 for WAN2) so that if the variable value is 1, I know WAN1 is up but WAN2 is down, and if the value is 2, I know that WAN1 is down and WAN2 is up, and finally when the value is 3, then I know both links are up and I can apply the queues accordingly.
What I have managed to do is get a value of 1 or 0 depending on the WAN link status with this snippet of code:
Code: Select all
[:len [/tool netwatch find comment=wan2 and status=up]]
Code: Select all
if $wan_status=1 do /queue simple set [find comment="limit"] max-limit=15M/15M
if $wan_status=2 do /queue simple set [find comment="limit"] max-limit 50M/50M
if $wan_status=3 do /queue simple set [find comment="limit"] max-limit 100M/100M
I need assistance in writing a script to do the following:
Take values from netwatch, transform the variables to something I can use (ie. 1 for WAN1 and 2 for WAN2), script it so that it knows which queue speeds to apply given the current WAN situation. Apologies for any brevity and my overall lack of scripting experience; I know what I want to achieve but I lack the know-how of making it machine-readable and I would appreciate any tips or hints if there is another way of handing this!