Skip to content

Instantly share code, notes, and snippets.

@furtiman
Last active February 25, 2022 15:52
Show Gist options
  • Save furtiman/c89620d6d7f3d43c1e6af15ca078ebfb to your computer and use it in GitHub Desktop.
Save furtiman/c89620d6d7f3d43c1e6af15ca078ebfb to your computer and use it in GitHub Desktop.
Tektelic OAM API test
#!/bin/bash
# Swagger URI - $https://gateway-oam.tektelic.com/swagger-ui.html
# Usage - ./oam-api-test.sh <oam_email> <oam_pw>
UN=$1
PW=$2
JWT=''
JWT_REFRESH=''
DIR=$(pwd)/'tek-oam-responses'
CRED='{
"username": "'"$UN"'",
"password": "'"$PW"'"
}';
OAM_URI='https://gateway-oam.tektelic.com'
mkdir -p $DIR
mkdir -p $DIR/$UN
DIR=$DIR/$UN
# 1. Login and get a JWT
RSP=$(curl -X POST \
-H "Content-Type: application/json" \
-d "$CRED" \
"${OAM_URI}/api/auth/login")
JWT=$(echo $RSP | python3 -c "import sys, json; token = json.load(sys.stdin)['token']; print(token)")
JWT_REFRESH=$(echo $RSP | python3 -c "import sys, json; token = json.load(sys.stdin)['refreshToken']; print(token)")
echo $JWT > $DIR/jwt.txt
echo $JWT_REFRESH > $DIR/jwt-ref.txt
# Get user that logged in
echo -e "\n---------- GET USER ----------\n"
curl -X GET \
-H 'Accept: */*' \
-H "X-Authorization: Bearer ${JWT}" \
"${OAM_URI}/api/auth/user" \
| python3 -m json.tool > $DIR/get_user.json
# Get gateway groups of a customer (customerId from GET user)
CUST_ID='22b9be80-1f91-11ec-94fb-912d4b8b01b6'
echo -e "\n---------- GET CUSTOMER GW GROUPS - CUST ${CUST_ID} ----------\n"
curl -X GET \
-H 'Accept: */*' \
-H "X-Authorization: Bearer ${JWT}" \
"${OAM_URI}/api/customer/${CUST_ID}/gatewayGroups" \
| python3 -m json.tool > $DIR/get_customer_gateway_groups.json
# Get gateways of a gateway group (gw group ID from GET gateway groups)
GW_GRP_ID='8022ff70-3281-11ec-ba82-912d4b8b01b6'
echo -e "\n---------- GET GW GROUP - ID ${GW_GRP_ID} ----------\n"
curl -X GET \
-H 'Accept: */*' \
-H "X-Authorization: Bearer ${JWT}" \
"${OAM_URI}/api/gatewayGroup/${GW_GRP_ID}/gateways" \
| python3 -m json.tool > $DIR/get_gateway_group_gateways.json
# # Get gateway by ID
GW_ID='29d491a0-78a0-11ec-9ad7-912d4b8b01b6'
echo -e "\n---------- GET GW BY ID ${GW_ID} ----------\n"
curl -X GET \
-H 'Accept: */*' \
-H "X-Authorization: Bearer ${JWT}" \
-d '{}' \
"${OAM_URI}/api/gateway/${GW_ID}" \
| python3 -m json.tool > $DIR/get_gateway_by_id.json
# Get gateway by MAC
GW_MAC='647FDAFFFE007B3F'
echo -e "\n---------- GET GW BY MAC ${GW_MAC} ----------\n"
curl -X GET \
-H 'Accept: */*' \
-H "X-Authorization: Bearer ${JWT}" \
"${OAM_URI}/api/gateway/mac/${GW_MAC}" \
| python3 -m json.tool > $DIR/get_gateway_by_mac.json
### GW Commands (only by ID?)
## ping - callback in JS
curl -X POST \
-H 'Accept: */*' \
-H "X-Authorization: Bearer ${JWT}" \
-H "Content-Type: application/json" \
-d '{}' \
"${OAM_URI}/api/gateway/${GW_ID}/command/ping" \
| python3 -m json.tool > $DIR/command_ping.json
# Get spec scan params
echo -e "\n---------- GET SS PARAMS ----------\n"
SS_PARAMS=$(curl -X POST \
-H 'Accept: */*' \
-H "X-Authorization: Bearer ${JWT}" \
-H "Content-Type: application/json" \
-d '{}' \
"${OAM_URI}/api/gateway/${GW_ID}/command/getSpectralScanParams")
echo $SS_PARAMS | python3 -m json.tool > $DIR/command_get_ss_params.json
# Start spec scan
echo -e "\n---------- START SS ----------\n"
curl -X POST \
-H 'Accept: */*' \
-H "X-Authorization: Bearer ${JWT}" \
-H "Content-Type: application/json" \
-d "$SS_PARAMS" \
"${OAM_URI}/api/gateway/${GW_ID}/command/executeSpectralScan" \
| python3 -m json.tool > $DIR/command_execute_ss.json
# Get spec scan params
touch ss_progress.txt
echo "0" > ss_progress.txt
SS_PRG="0"
while [[ "$SS_PRG" != "100" ]]
do
RSP=$(curl -X POST \
-H 'Accept: */*' \
-H "X-Authorization: Bearer ${JWT}" \
-H "Content-Type: application/json" \
-d '{}' \
"${OAM_URI}/api/gateway/${GW_ID}/command/getSpectralScanProgress")
echo $RSP
SS_PRG=$(echo $RSP | python3 -c "import sys, json; token = json.load(sys.stdin)['progress']; print(token)")
echo $SS_PRG > ss_progress.txt
sleep 10
done
echo -e "\n---------- GET SS RESULTS ----------\n"
curl -X POST \
-H 'Accept: */*' \
-H "X-Authorization: Bearer ${JWT}" \
-H "Content-Type: application/json" \
-d '{}' \
"${OAM_URI}/api/gateway/${GW_ID}/command/getSpectralScanResults" \
| python3 -m json.tool > $DIR/command_ss_results.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment