Query status of gateways via API

Started by Hüpf3R, April 06, 2020, 04:40:17 PM

Previous topic - Next topic
Hello,
Is it possible to query the status of the gateways via the API? I have 3 gateways and would like to use the API to query which is online and which is offline. I would also like to be able to manually mark a gateway as offline.
Can anyone help me?

Thanks in advance.


I know this is not helpful, but I have the same request. I looked through the api docs and can't find it anywhere. I'm assuming you can't. I am trying to solve my other problem, documented here https://forum.opnsense.org/index.php?topic=16460.msg74953#msg74953, by writing a script that queries the gateway status and tells opnsenes/frr to stop advertising a default route if the gateway is down. I have multiple opnsense boxes at my edges and I want them to stop advertising to ospf that they can get to the internet if they actually can't. None of the options in the GUI accomplish this so I want to orchestrate it via api or cli, but I have yet to find a way to programatticaly get the gateway status that is so nicely displayed right on the dashboard.

I've added a feature request https://github.com/opnsense/core/issues/4261, and Ad Schellevis also gave me the cli equivalent if that helps you in the comments there.

pluginctl -r return_gateways_status

Time-machine post for googlers...

Use API endpoint /api/routing/settings/searchGateway.

It will return a json object detailing all the gateways. One of them will have:

"defaultgw": true,
which gets translated into the words "(active)" in the GUI. You can use that to determine the active routing gateway status.