Interface status retrieval via API call

I’m using version “VyOS 1.5-rolling-202408230022” and attempting to automate some interface configuration. Does anyone know of a data path to retrieve an interface’s link and state value? Currently the API call only returns a disable value if I manually disable an interface. Even with disable link detection enabled, the API response does not include the the value.

{“op”: “showConfig”, “path”: [“interfaces”]}

‘eth5’: {‘disable’: {}, ‘hw-id’: ‘bc:24:11:a6:0c:98’, ‘offload’: {‘gro’: {}, ‘gso’: {}, ‘sg’: {}, ‘tso’: {}}

‘eth4’: {‘hw-id’: ‘bc:24:11:2a:f2:99’, ‘offload’: {‘gro’: {}, ‘gso’: {}, ‘sg’: {}, ‘tso’: {}}}

If you can offer any help or advice, please respond.
Thank you.

What about:

curl -k --location --request POST 'https://vyos/show' \
--form data='{"op": "show", "path": ["interface", "ethernet", "eth1"]}' \
--form key='key'

Returns:

{"success": true, "data": "eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc cake state UP group default qlen 1000\n    link/ether <cut> brd ff:ff:ff:ff:ff:ff permaddr <cut>\n    altname enp0s19\n    altname ens19\n    inet <cut>/24 brd <cut> scope global eth1\n       valid_lft forever preferred_lft forever\n    inet6 <cut>/64 scope global \n       valid_lft forever preferred_lft forever\n    inet6 fe80::561e:56ff:fe36:291e/64 scope link \n       valid_lft forever preferred_lft forever\n    Description: <CUT> Network\n\n    RX:          bytes     packets  errors  dropped  overrun       mcast\n         5372412208160  2460095903       0    15580        0           0\n    TX:          bytes     packets  errors  dropped  carrier  collisions\n         4894654517710  5062385519       0        0        0           0\n", "error": null}% ```

THANK YOU! It’s not structured but I’ll just have to parse the output. Thank you so much.

1 Like

You can use graphql like this to get JSON output:

curl -k --raw 'https://localhost/graphql' \
    -H 'Content-Type: application/json' \
    -d '{"query":" { ShowInterfaces (data: {key: \"key\", intf_name: \"eth1\"}) {\n  success\n  errors\n  data {\n    result\n  }\n}\n}\n"}'
2 Likes

Try sed and jq to get the data you want.


ips=$(curl -k  -s --unix-socket /run/api.sock \
    --connect-timeout ${TIMEOUT} \
    --location \
    --request POST "http://${LOCAL_SERVER}/retrieve"  \
    --form data='{"op": "showConfig", "path": ["firewall","group","network-group","'"${domain_group}"'","network"]}' \
    --form key="${LOCAL_API_KEY}"  | jq  '.data.network' | xargs)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.