Gateway Status via CLI/API - netstat vs /api/routing/settings/searchGateway ?

Started by LemonJohn, April 11, 2025, 11:01:53 PM

Previous topic - Next topic
I'm writing a script to kill states on my backup WAN after the primary WAN is back online. There are lots of discussions about doing that but it is necessary for me as my backup WAN has limited data. That's not the point of this though, my question is regarding how to determine the currently active gateway via the CLI or API. Right now I'm using netstat -rn | grep default | awk '{print $4}'. This works and my understanding is that it returns the "system" default gateway based on the configured priority. However, I am using a gateway group with policy routing rules. If my gateway group is configured to use Packet Loss or High Latency as the Trigger Level, the active gateway in the group could potentially be different than the "system" default gateway, correct? For example, high latency could trigger the gateway group to fail over while the system gateway would remain unchanged because it's still considered to be up. In such a scenario, my script would kill backup gateway states when I wouldn't want it to.

As an alternative, there is the api/routing/settings/searchGateway endpoint which appears to reflect the gateway group failover settings. Is that correct? With that, I'm thinking I need to use the API endpoint if my group Trigger Level is set to Packet Loss or High Latency. If I set it to Member Down, I don't think it would matter. Interested in hearing any thoughts or alternative ideas. Thanks!