Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 39c07faa authored by Kevin Yung's avatar Kevin Yung
Browse files

Implémentation du .devices.html en générant un .devices.json avec...

Implémentation du .devices.html en générant un .devices.json avec l'implémentation de get_applications.sh en récupérant toutes les données nécessaires depuis l'API
parent caa21791
{"jwt":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJjaGlycHN0YWNrLWFwcGxpY2F0aW9uLXNlcnZlciIsImV4cCI6MTYxNTk5NTIxMiwiaXNzIjoiY2hpcnBzdGFjay1hcHBsaWNhdGlvbi1zZXJ2ZXIiLCJuYmYiOjE2MTU5MDg4MTIsInN1YiI6InVzZXIiLCJ1c2VybmFtZSI6IkNoaXJwc3RhY2tNb25pdG9yaW5nIn0.xFYJP6kBVTKT83xe_T2U25p96N3OQvFA1HWVqEmNUqA"}
\ No newline at end of file
{"jwt":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJjaGlycHN0YWNrLWFwcGxpY2F0aW9uLXNlcnZlciIsImV4cCI6MTYxNjUxOTM3MiwiaXNzIjoiY2hpcnBzdGFjay1hcHBsaWNhdGlvbi1zZXJ2ZXIiLCJuYmYiOjE2MTY0MzI5NzIsInN1YiI6InVzZXIiLCJ1c2VybmFtZSI6IkNoaXJwc3RhY2tNb25pdG9yaW5nIn0.mVfI0vHUtjdMDy19AlPEputBc1AqfzJ8K70J0DDyRVA"}
\ No newline at end of file
......@@ -13,7 +13,7 @@ PASSWORD=qX2bK6oN2iC1cQ5c
JWT=$(./get_jwt.sh $USERNAME $PASSWORD)
./get_organizations.sh $JWT
./get_gateways.sh $JWT
#./get_gateways.sh $JWT
./get_devices.sh $JWT
# TODO send reports by email
......@@ -8,12 +8,13 @@
# ------------------------------------------------
# Parameters
if [[ $# -ne 1 ]] ; then
echo "Usage: $0 JWT"
if [[ $# -ne 2 ]] ; then
echo "Usage: $0 JWT OID"
exit 1
fi
TOKEN="$1"
OID="$2"
AUTH="Grpc-Metadata-Authorization: Bearer $TOKEN"
#sudo npm install -g jwt-cli
......@@ -57,7 +58,7 @@ OPTIONS="${CURL} -X OPTIONS --header \""$ACCEPT_JSON"\""
HEAD="${CURL} -X HEAD --header \""$ACCEPT_JSON"\""
${GET} \
--header "$AUTH" ${URL}'/api/applications?limit=9999&offset=0' \
> .applications.json
--header "$AUTH" ${URL}'/api/applications?limit=9999&organizationID='${OID} \
> .organization${OID}_applications.json
jq '.result[] | ( .id + ": " + .name + " - " + .organizationID + " - " + .description)' .applications.json
......@@ -56,9 +56,28 @@ DELETE="${CURL} -X DELETE --header \""$ACCEPT_JSON"\""
OPTIONS="${CURL} -X OPTIONS --header \""$ACCEPT_JSON"\""
HEAD="${CURL} -X HEAD --header \""$ACCEPT_JSON"\""
${GET} \
--header "$AUTH" ${URL}'/api/devices?limit=9999&offset=0' \
> .devices.json
ids_org=$(jq --raw-output ".result[] | .id" .organizations.json)
ids_org_array=($ids_org)
for ((i=0; i<${#ids_org_array[@]}; i++))
do
ids_app=$(jq --raw-output ".result[] | .id" .organization${ids_org_array[i]}_applications.json)
ids_app_array=($ids_app)
for ((j=0; j<${#ids_app_array[@]}; j++))
do
${GET} \
--header "$AUTH" ${URL}'/api/devices?limit=9999&applicationID='${ids_app_array[j]} \
> .application${ids_app_array[j]}_devices.json
done
done
jq -s '.[0].result = [.[].result | add] | .[0]' .application*.json > .devices.json
#${GET} \
# --header "$AUTH" ${URL}'/api/devices?limit=9999&offset=0' \
# > .devices.json
echo '<html><head><title>CampusIoT LNS :: Devices</title></head><body style="font-family:verdana;"><h1>CampusIoT LNS :: Devices</h1>' > .devices.html
......@@ -78,5 +97,3 @@ echo '<h2>Passive devices</h2>' >> .devices.html
jq --raw-output -f devices_to_html.jq .devices.json | grep -v $TODAY >> .devices.html
echo '</body></html>' >> .devices.html
......@@ -59,4 +59,13 @@ ${GET} \
--header "$AUTH" ${URL}'/api/organizations?limit=1000&offset=0' \
> .organizations.json
jq '.result[] | ( .id + ": " + .name + " - " + .displayName)' .organizations.json
ids=$(jq --raw-output ".result[] | .id" .organizations.json)
ids_array=($ids)
for (( i=0; i<${#ids_array[@]}; i++ ))
do
./get_applications.sh $TOKEN "${ids_array[i]}"
done
#!/bin/bash
var="2021-03-16T14:20:40.327687Z"
a=$(node test.js $var)
echo "$a"
# Copyright (C) CampusIoT, - All Rights Reserved
# Written by CampusIoT Dev Team, 2016-2021
# ------------------------------------------------
# Get devices
# ------------------------------------------------
# Parameters
if [[ $# -ne 1 ]] ; then
echo "Usage: $0 JWT"
exit 1
fi
#TOKEN="$1"
TOKEN="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJjaGlycHN0YWNrLWFwcGxpY2F0aW9uLXNlcnZlciIsImV4cCI6MTYxNjUwNzA5OCwiaXNzIjoiY2hpcnBzdGFjay1hcHBsaWNhdGlvbi1zZXJ2ZXIiLCJuYmYiOjE2MTY0MjA2OTgsInN1YiI6InVzZXIiLCJ1c2VybmFtZSI6IkNoaXJwc3RhY2tNb25pdG9yaW5nIn0.oFx7qWOiGY49FpgCKXAaAt6TkDVcQgtg3dz6mIyUj6w"
AUTH="Grpc-Metadata-Authorization: Bearer $TOKEN"
#sudo npm install -g jwt-cli
#jwt $TOKEN
# Installation
if ! [ -x "$(command -v jq)" ]; then
echo 'jq is not installed. Installing jq ...'
sudo apt-get install -y jq
fi
if ! [ -x "$(command -v curl)" ]; then
echo 'curl is not installed. Installing curl ...'
sudo apt-get install -y curl
fi
# Content-Type
ACCEPT_JSON="Accept: application/json"
ACCEPT_CSV="Accept: text/csv"
CONTENT_JSON="Content-Type: application/json"
CONTENT_CSV="Content-Type: text/csv"
# LOCAL
#PORT=8888
#URL=http://localhost:$PORT
# PROD
PORT=443
URL=https://lns.campusiot.imag.fr:$PORT
# Operations
# Operations
#CURL="curl --verbose"
CURL="curl -s --insecure"
#CURL="curl -s"
GET="${CURL} -X GET --header \""$ACCEPT_JSON"\""
POST="${CURL} -X POST --header \""$ACCEPT_JSON"\""
PUT="${CURL} -X PUT --header \""$ACCEPT_JSON"\""
DELETE="${CURL} -X DELETE --header \""$ACCEPT_JSON"\""
OPTIONS="${CURL} -X OPTIONS --header \""$ACCEPT_JSON"\""
HEAD="${CURL} -X HEAD --header \""$ACCEPT_JSON"\""
jq -s '.[0].result = [.[].result | add] | .[0]' .test*.json > .test_devices.json
#${GET} \
# --header "$AUTH" ${URL}'/api/applications?limit=9999&organizationID=6'
#${GET} \
# --header "$AUTH" ${URL}'/api/devices?limit=9999&applicationID=58'
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment