Skip to content

Instantly share code, notes, and snippets.

@Zsoldier
Created March 24, 2021 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zsoldier/4a99dc07e267e8782ec1d95bb94fef77 to your computer and use it in GitHub Desktop.
Save Zsoldier/4a99dc07e267e8782ec1d95bb94fef77 to your computer and use it in GitHub Desktop.
Gets NSX-T BGP Route Table via curl and jq.
#Have not figured out how to have jq output an array for bash to loop through.
nsxt=DNSnameORIPAddressofNSXTManager
username=admin
password='superduperSecure!'
endpoint='policy/api/v1'
#Checks to see if you have jq installed.
if ! command -v jq &> /dev/null
then
echo "jq is needed for code for below code to work. Download or use brew/apt/packagemanager to install. https://stedolan.github.io/jq/"
exit
fi
t0path=$(curl -k -u $username:$password --request GET --url https://$nsxt/$endpoint/infra/tier-0s/ | jq -r '.results[].path');
localepath=$(curl -k -u $username:$password --request GET --url https://$nsxt/${endpoint}${t0path}/locale-services | jq -r '.results[].path')
bgpneighborpaths=$(curl -k -u $username:$password --request GET --url https://$nsxt/${endpoint}${localepath}/bgp/neighbors | jq -r '.results[].path')
echo $bgpneighborpaths
echo "Copy one of the paths from above and put it into a variable, like neighbor=entryfromEcho, then run the curl command below."
echo "curl -k -u $username:$password --request GET --url https://$nsxt/${endpoint}${neighbor}/routes | jq"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment