mirror of
https://github.com/Telecominfraproject/wlan-cloud-analytics.git
synced 2026-01-27 10:22:33 +00:00
Initial commit
This commit is contained in:
237
test_scripts/curl/cli
Executable file
237
test_scripts/curl/cli
Executable file
@@ -0,0 +1,237 @@
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
# License type: BSD 3-Clause License
|
||||
# License copy: https://github.com/Telecominfraproject/wlan-cloud-ucentralgw/blob/master/LICENSE
|
||||
#
|
||||
# Created by Stephane Bourque on 2021-03-04.
|
||||
# Arilia Wireless Inc.
|
||||
#
|
||||
|
||||
if [[ "$(which jq)" == "" ]]
|
||||
then
|
||||
echo "You need the package jq installed to use this script."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$(which curl)" == "" ]]
|
||||
then
|
||||
echo "You need the package curl installed to use this script."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "${OWSEC}" == "" ]]
|
||||
then
|
||||
echo "You must set the variable OWSEC in order to use this script. Something like"
|
||||
echo "OWSEC=security.isp.com:16001"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "${FLAGS}" == "" ]]
|
||||
then
|
||||
FLAGS="-s"
|
||||
fi
|
||||
|
||||
token=""
|
||||
result_file=result.json
|
||||
browser_list=(firefox sensible-browser xdg-open w3m links links2 lynx youtube-dl)
|
||||
browser=""
|
||||
|
||||
if [ -z ${OWSEC_USERNAME+x} ]; then
|
||||
username="script.runner@arilia.com"
|
||||
else
|
||||
username=${OWSEC_USERNAME}
|
||||
fi
|
||||
if [ -z ${OWSEC_PASSWORD+x} ]; then
|
||||
password="Snoopy99!!!"
|
||||
else
|
||||
password=${OWSEC_PASSWORD}
|
||||
fi
|
||||
|
||||
login() {
|
||||
payload="{ \"userId\" : \"$username\" , \"password\" : \"$password\" }"
|
||||
token=$(curl ${FLAGS} -X POST -H "Content-Type: application/json" -d "$payload" "https://${OWSEC}/api/v1/oauth2" | jq -r '.access_token')
|
||||
|
||||
if [[ "${token}" == "null" ]]
|
||||
then
|
||||
echo "Could not login. Please verify the host and username/password."
|
||||
exit 13
|
||||
fi
|
||||
echo "${token}" > token.json
|
||||
setprov
|
||||
setanalytics
|
||||
}
|
||||
|
||||
findbrowser() {
|
||||
if [[ "${browser}" != "" ]]
|
||||
then
|
||||
echo
|
||||
elif [[ "$(uname)" == "Darwin" ]]
|
||||
then
|
||||
browser=open
|
||||
else
|
||||
BROWSER_LIST=(firefox sensible-browser xdg-open w3m links links2 lynx youtube-dl)
|
||||
for br_name in "${browser_list[@]}"
|
||||
do
|
||||
if [[ $(which ${br_name}) != "" ]]
|
||||
then
|
||||
browser=${br_name}
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
setprov() {
|
||||
if [ -z ${OWPROV_OVERRIDE+x} ]; then
|
||||
curl ${FLAGS} -X GET "https://${OWSEC}/api/v1/systemEndpoints" \
|
||||
-H "accept: application/json" \
|
||||
-H "Authorization: Bearer ${token}" > ${result_file}
|
||||
rawurl="$(cat ${result_file} | jq -r '.endpoints[] | select( .type == "owprov" ) | .uri')"
|
||||
if [[ ! -z "${rawurl}" ]]; then
|
||||
proto="$(echo $rawurl | grep :// | sed -e's,^\(.*://\).*,\1,g')"
|
||||
url="$(echo ${rawurl/$proto/})"
|
||||
user="$(echo $url | grep @ | cut -d@ -f1)"
|
||||
hostport="$(echo ${url/$user@/} | cut -d/ -f1)"
|
||||
host="$(echo $hostport | sed -e 's,:.*,,g')"
|
||||
port="$(echo $hostport | sed -e 's,^.*:,:,g' -e 's,.*:\([0-9]*\).*,\1,g' -e 's,[^0-9],,g')"
|
||||
path="$(echo $url | grep / | cut -d/ -f2-)"
|
||||
export OWPROV=${url}
|
||||
echo "Using ${OWPROV}..."
|
||||
else
|
||||
echo "OWPROV endpoint is not found:"
|
||||
jq < ${result_file}
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
export OWPROV=${OWPROV_OVERRIDE}
|
||||
fi
|
||||
}
|
||||
|
||||
setanalytics() {
|
||||
if [ -z ${OWPROV_OVERRIDE+x} ]; then
|
||||
curl ${FLAGS} -X GET "https://${OWSEC}/api/v1/systemEndpoints" \
|
||||
-H "accept: application/json" \
|
||||
-H "Authorization: Bearer ${token}" > ${result_file}
|
||||
rawurl="$(cat ${result_file} | jq -r '.endpoints[] | select( .type == "owanalytics" ) | .uri')"
|
||||
if [[ ! -z "${rawurl}" ]]; then
|
||||
proto="$(echo $rawurl | grep :// | sed -e's,^\(.*://\).*,\1,g')"
|
||||
url="$(echo ${rawurl/$proto/})"
|
||||
user="$(echo $url | grep @ | cut -d@ -f1)"
|
||||
hostport="$(echo ${url/$user@/} | cut -d/ -f1)"
|
||||
host="$(echo $hostport | sed -e 's,:.*,,g')"
|
||||
port="$(echo $hostport | sed -e 's,^.*:,:,g' -e 's,.*:\([0-9]*\).*,\1,g' -e 's,[^0-9],,g')"
|
||||
path="$(echo $url | grep / | cut -d/ -f2-)"
|
||||
export OWANALYTICS=${url}
|
||||
echo "Using ${OWANALYTICS}..."
|
||||
else
|
||||
echo "OWANALYTICS endpoint is not found:"
|
||||
jq < ${result_file}
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
export OWANALYTICS=${OWANALYTICS_OVERRIDE}
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
logout() {
|
||||
curl ${FLAGS} -X DELETE -H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer ${token}" \
|
||||
"https://${OWSEC}/api/v1/oauth2/${token}"
|
||||
rm -rf token.json
|
||||
}
|
||||
|
||||
venuecount() {
|
||||
curl ${FLAGS} "https://${OWPROV}/api/v1/venue?countOnly=true" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer ${token}" \
|
||||
-H "accept: application/json" > ${result_file}
|
||||
jq < ${result_file}
|
||||
}
|
||||
|
||||
contactcount() {
|
||||
curl ${FLAGS} "https://${OWPROV}/api/v1/contact?countOnly=true" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer ${token}" \
|
||||
-H "accept: application/json" > ${result_file}
|
||||
jq < ${result_file}
|
||||
}
|
||||
|
||||
setloglevel() {
|
||||
payload="{ \"command\" : \"setloglevel\" , \"subsystems\" : [ { \"tag\" : \"$1\" , \"value\" : \"$2\" } ] }"
|
||||
curl ${FLAGS} -X POST "https://${OWPROV}/api/v1/system" \
|
||||
-H "accept: application/json" \
|
||||
-H "Authorization: Bearer ${token}" \
|
||||
-d "$payload"
|
||||
}
|
||||
|
||||
getloglevels() {
|
||||
payload="{ \"command\" : \"getloglevels\" }"
|
||||
curl ${FLAGS} -X POST "https://${OWPROV}/api/v1/system" \
|
||||
-H "accept: application/json" \
|
||||
-H "Authorization: Bearer ${token}" \
|
||||
-d "$payload"
|
||||
}
|
||||
|
||||
getloglevelnames() {
|
||||
payload="{ \"command\" : \"getloglevelnames\" }"
|
||||
curl ${FLAGS} -X POST "https://${OWPROV}/api/v1/system" \
|
||||
-H "accept: application/json" \
|
||||
-H "Authorization: Bearer ${token}" \
|
||||
-d "$payload"
|
||||
}
|
||||
|
||||
getsubsystemnames() {
|
||||
payload="{ \"command\" : \"getsubsystemnames\" }"
|
||||
curl ${FLAGS} -X POST "https://${OWPROV}/api/v1/system" \
|
||||
-H "accept: application/json" \
|
||||
-H "Authorization: Bearer ${token}" \
|
||||
-d "$payload"
|
||||
}
|
||||
|
||||
systeminfo() {
|
||||
curl ${FLAGS} -X GET "https://${OWPROV}/api/v1/system?command=info" \
|
||||
-H "accept: application/json" \
|
||||
-H "Authorization: Bearer ${token}" > ${result_file}
|
||||
jq < ${result_file}
|
||||
}
|
||||
|
||||
reloadsubsystem() {
|
||||
payload="{ \"command\" : \"reload\", \"subsystems\" : [ \"$1\" ] }"
|
||||
curl ${FLAGS} -X POST "https://${OWPROV}/api/v1/system" \
|
||||
-H "accept: application/json" \
|
||||
-H "Authorization: Bearer ${token}" \
|
||||
-d "$payload"
|
||||
}
|
||||
|
||||
tree() {
|
||||
curl ${FLAGS} "https://${OWPROV}/api/v1/entity?getTree=true" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer ${token}" \
|
||||
-H "accept: application/json" > ${result_file}
|
||||
jq < ${result_file}
|
||||
}
|
||||
|
||||
createboard() {
|
||||
payload="{ \"name\" : \"MegaLab\", \"venueList\" : [ { \"id\" : \"$1\" , \"name\" : \"MegaLab Venue\" , \"retention\" : 86000 , \"interval\" : 60, \"monitorSubVenues\" : true } ] }"
|
||||
curl ${FLAGS} -X POST "https://${OWANALYTICS}/api/v1/board/0" \
|
||||
-H "accept: application/json" \
|
||||
-H "Authorization: Bearer ${token}" \
|
||||
-d "$payload" > ${result_file}
|
||||
jq < ${result_file}
|
||||
}
|
||||
|
||||
shopt -s nocasematch
|
||||
case "$1" in
|
||||
"login") login; echo "You are logged in..." ; logout ;;
|
||||
"tree") login; tree ; logout;;
|
||||
"setloglevel") login; setloglevel "$2" "$3" ; logout ;;
|
||||
"getloglevels") login; getloglevels; logout ;;
|
||||
"getloglevelnames") login; getloglevelnames; logout ;;
|
||||
"getsubsystemnames") login; getsubsystemnames; logout ;;
|
||||
"reloadsubsystem") login; reloadsubsystem "$2"; logout ;;
|
||||
"systeminfo") login; systeminfo ; logout;;
|
||||
*) help ;;
|
||||
esac
|
||||
|
||||
1
test_scripts/curl/result.json
Normal file
1
test_scripts/curl/result.json
Normal file
@@ -0,0 +1 @@
|
||||
{"children":[{"children":[{"children":[{"children":[],"name":"Ottawa Operations","type":"entity","uuid":"323054d0-3ff0-11ec-82ff-061b87871e04","venues":[{"children":[],"name":"Living Lab","type":"venue","uuid":"4159ea84-3ff0-11ec-9edb-061b87871e04"}]}],"name":"Ontario","type":"entity","uuid":"21dfa464-3ff0-11ec-9a86-061b87871e04","venues":[]},{"children":[{"children":[],"name":"Quebec","type":"entity","uuid":"27b74e1b-52d7-4414-a1b4-47574c799beb","venues":[]},{"children":[],"name":"Ontario","type":"entity","uuid":"3cb15a80-3550-11ec-9a22-061b87871e04","venues":[{"children":[],"name":"CN Tower","type":"venue","uuid":"3cb28f0e-3550-11ec-acfa-061b87871e04"},{"children":[],"name":"Rogers Center","type":"venue","uuid":"3cb3c798-3550-11ec-8c1a-061b87871e04"}]},{"children":[],"name":"BC","type":"entity","uuid":"3cb503c4-3550-11ec-b436-061b87871e04","venues":[{"children":[],"name":"BC Place","type":"venue","uuid":"3cb76452-3550-11ec-a5ab-061b87871e04"},{"children":[],"name":"Stanley Park","type":"venue","uuid":"3cb8b230-3550-11ec-bbe6-061b87871e04"},{"children":[],"name":"MegaLab","type":"venue","uuid":"a73a23c4-6f3d-4031-bc92-d28c205f2d85"},{"children":[],"name":"Bowen Development","type":"venue","uuid":"d656500b-9f00-4c09-9096-e209085c2a3e"}]}],"name":"Provinces","type":"entity","uuid":"3cac92ca-3550-11ec-b360-061b87871e04","venues":[]}],"name":"Canada","type":"entity","uuid":"3cab2c32-3550-11ec-8a03-061b87871e04","venues":[]},{"children":[],"name":"USA","type":"entity","uuid":"6392c6b3-ef48-4b81-8785-1b5b4888bbd2","venues":[]},{"children":[{"children":[],"name":"Hamburg","type":"entity","uuid":"5939f995-e059-439d-ab0c-29a6f7c0a495","venues":[]}],"name":"Germany","type":"entity","uuid":"6fb5662d-dc48-4fbd-b8f9-69d0308bb902","venues":[]},{"children":[],"name":"Test Land","type":"entity","uuid":"70161a6f-98af-45d7-b0ed-e6b15ba5d84e","venues":[{"children":[],"name":"Test","type":"venue","uuid":"1d06b289-449e-4669-abc9-1f2dcdd1fbbc"}]}],"name":"World","type":"entity","uuid":"0000-0000-0000","venues":[]}
|
||||
Reference in New Issue
Block a user