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 a6fc7149 authored by Antoine Blanquet's avatar Antoine Blanquet
Browse files

Big code restructuring, and cleaning code. Adding a data folder for jsons files

parent 08dafc8b
......@@ -3,10 +3,20 @@
# Copyright (C) CampusIoT, - All Rights Reserved
# Written by CampusIoT Dev Team, 2016-2021
rm -f *.token.json
rm -f .organizations.*
rm -f .gateways.*
rm -f .gateway-.*
rm -f .gateway-*
rm -f .devices.*
rm -f .applications.*
# DATA REPOSITORY
DATA_CONFIG_FOLDER="data/configuration/"
DATA_ORG_FOLDER="data/organizations/"
DATA_APP_FOLDER="data/applications/"
DATA_GAT_FOLDER="data/gateways/"
DATA_DEV_FOLDER="data/devices/"
rm -f ${DATA_CONFIG_FOLDER}*.token.json
rm -f ${DATA_ORG_FOLDER}.organizations.*
rm -f ${DATA_GAT_FOLDER}.gateways.*
rm -f ${DATA_GAT_FOLDER}.gateway-.*
rm -f ${DATA_GAT_FOLDER}.gateway-*
rm -f ${DATA_DEV_FOLDER}.devices.*
rm -f ${DATA_DEV_FOLDER}.application*
rm -f ${DATA_APP_FOLDER}.organization*
......@@ -26,6 +26,10 @@ if [[ $# -ne args_len ]]; then
exit 1
fi
# DATA REPOSITORY
DATA_APP_FOLDER="data/applications/"
DATA_GAT_FOLDER="data/gateways/"
GATEWAYS=${@:2:$GATEWAYS_LENGTH} # We get data from the gateway which is passed in parameter and we are replacing the length and date time
TODAY="${@:$#}" # last parameter
......@@ -49,28 +53,28 @@ echo "generate_sparkline_packets : \n ========== \n ========== \n "
for g in $GATEWAYS; do
packet_received=$(jq -r '.result | map(.rxPacketsReceivedOK) | join(",")' .gateway-${g}_stats.json)
packet_received=$(jq -r '.result | map(.rxPacketsReceivedOK) | join(",")' ${DATA_GAT_FOLDER}.gateway-${g}_stats.json)
jq --raw-output "( \"<li><a \"
+ \"href='https://lns.campusiot.imag.fr/#/organizations/\(.gateway.organizationID)/gateways/\(.gateway.id)'\" + \">\" + .gateway.id + \"</a>: \"
+ .gateway.name + \" - (org \" + .gateway.organizationID + \") - \"
+ .lastSeenAt
+ \" - packets received last month : <span class='inlinesparkline'>${packet_received}</span>\"
+ \"</li>\" )" .gateway-${g}.json | grep $TODAY >>.gateways.html
+ \"</li>\" )" ${DATA_GAT_FOLDER}.gateway-${g}.json | grep $TODAY >>.gateways.html
done
# 4.Generate Passive Gateways
echo '<h2>Passive gateways</h2>' >>.gateways.html
for g in $GATEWAYS; do
packet_received=$(jq -r '.result | map(.rxPacketsReceivedOK) | join(",")' .gateway-${g}_stats.json)
packet_received=$(jq -r '.result | map(.rxPacketsReceivedOK) | join(",")' ${DATA_GAT_FOLDER}.gateway-${g}_stats.json)
jq --raw-output "( \"<li><a \"
+ \"href='https://lns.campusiot.imag.fr/#/organizations/\(.gateway.organizationID)/gateways/\(.gateway.id)'\" + \">\" + .gateway.id + \"</a>: \"
+ .gateway.name + \" - (org \" + .gateway.organizationID + \") - \"
+ .lastSeenAt
+ \" - packets received last month : <span class='inlinesparkline'>${packet_received}</span>\"
+ \"</li>\" )" .gateway-${g}.json | grep -v $TODAY >>.gateways.html
+ \"</li>\" )" ${DATA_GAT_FOLDER}.gateway-${g}.json | grep -v $TODAY >>.gateways.html
done
......
......@@ -7,8 +7,11 @@
# Generate the reports
# ------------------------------------------------
USERNAME=$(jq --raw-output ".username" .credentials.json)
PASSWORD=$(jq --raw-output ".password" .credentials.json)
# DATA REPOSITORY
DATA_CONFIG_FOLDER="data/configuration/"
USERNAME=$(jq --raw-output ".username" ${DATA_CONFIG_FOLDER}.credentials.json)
PASSWORD=$(jq --raw-output ".password" ${DATA_CONFIG_FOLDER}.credentials.json)
JWT=$(./get_jwt.sh $USERNAME $PASSWORD)
......
......@@ -45,6 +45,9 @@ CONTENT_CSV="Content-Type: text/csv"
PORT=443
URL=https://lns.campusiot.imag.fr:$PORT
# DATA REPOSITORY
DATA_APP_FOLDER="data/applications/"
# Operations
# Operations
#CURL="curl --verbose"
......@@ -59,6 +62,6 @@ HEAD="${CURL} -X HEAD --header \""$ACCEPT_JSON"\""
${GET} \
--header "$AUTH" ${URL}'/api/applications?limit=9999&organizationID='${OID} \
> .organization${OID}_applications.json
> ${DATA_APP_FOLDER}.organization${OID}_applications.json
# jq '.result[] | ( .id + ": " + .name + " - " + .organizationID + " - " + .description)' .applications.json
......@@ -44,6 +44,11 @@ CONTENT_CSV="Content-Type: text/csv"
PORT=443
URL=https://lns.campusiot.imag.fr:$PORT
# DATA REPOSITORY
DATA_APP_FOLDER="data/applications/"
DATA_ORG_FOLDER="data/organizations/"
DATA_DEV_FOLDER="data/devices/"
# Operations
# Operations
#CURL="curl --verbose"
......@@ -57,21 +62,21 @@ OPTIONS="${CURL} -X OPTIONS --header \""$ACCEPT_JSON"\""
HEAD="${CURL} -X HEAD --header \""$ACCEPT_JSON"\""
ids_org=$(jq --raw-output ".result[] | .id" .organizations.json)
ids_org=$(jq --raw-output ".result[] | .id" ${DATA_ORG_FOLDER}.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=$(jq --raw-output ".result[] | .id" ${DATA_APP_FOLDER}.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
> ${DATA_DEV_FOLDER}.application${ids_app_array[j]}_devices.json
done
done
jq -s '.[0].result = [.[].result | add] | .[0]' .application*.json > .devices.json
jq -s '.[0].result = [.[].result | add] | .[0]' ${DATA_DEV_FOLDER}.application*.json > ${DATA_DEV_FOLDER}.devices.json
#${GET} \
# --header "$AUTH" ${URL}'/api/devices?limit=9999&offset=0' \
......@@ -90,10 +95,10 @@ echo '</p>' >> .devices.html
echo '<h2>Active devices</h2>' >> .devices.html
jq --raw-output -f devices_to_html.jq .devices.json | grep $TODAY >> .devices.html
jq --raw-output -f devices_to_html.jq ${DATA_DEV_FOLDER}.devices.json | grep $TODAY >> .devices.html
echo '<h2>Passive devices</h2>' >> .devices.html
jq --raw-output -f devices_to_html.jq .devices.json | grep -v $TODAY >> .devices.html
jq --raw-output -f devices_to_html.jq ${DATA_DEV_FOLDER}.devices.json | grep -v $TODAY >> .devices.html
echo '</body></html>' >> .devices.html
......@@ -45,6 +45,9 @@ CONTENT_CSV="Content-Type: text/csv"
PORT=443
URL=https://lns.campusiot.imag.fr:$PORT
# DATA REPOSITORY
DATA_GAT_FOLDER="data/gateways/"
# Operations
#CURL="curl --verbose"
CURL="curl -s --insecure"
......@@ -58,4 +61,4 @@ HEAD="${CURL} -X HEAD --header \""$ACCEPT_JSON"\""
${GET} \
--header "$AUTH" ${URL}'/api/gateways/'${GWID} \
> .gateway-${GWID}.json
> ${DATA_GAT_FOLDER}.gateway-${GWID}.json
......@@ -44,6 +44,9 @@ CONTENT_CSV="Content-Type: text/csv"
PORT=443
URL=https://lns.campusiot.imag.fr:$PORT
# DATA REPOSITORY
DATA_GAT_FOLDER="data/gateways/"
# Operations
#CURL="curl --verbose"
CURL="curl -s --insecure"
......@@ -60,7 +63,7 @@ INTERVAL="day"
${GET} \
--header "$AUTH" ${URL}'/api/gateways/'${GWID}'/stats?interval='${INTERVAL}'&startTimestamp='${PAST_MONTH}'T00:00:00Z&endTimestamp='${TODAY}'T00:00:00Z' \
> .gateway-${GWID}_stats.json
> ${DATA_GAT_FOLDER}.gateway-${GWID}_stats.json
# 'https://lns.campusiot.imag.fr/api/gateways/7276ff0039030724/stats?interval=day&startTimestamp=2021-02-09T00%3A00%3A00Z&endTimestamp=2021-03-09T00%3A00%3A00Z'
......
......@@ -44,6 +44,9 @@ CONTENT_CSV="Content-Type: text/csv"
PORT=443
URL=https://lns.campusiot.imag.fr:$PORT
# DATA REPOSITORY
DATA_GAT_FOLDER="data/gateways/"
# Operations
#CURL="curl --verbose"
CURL="curl -s --insecure"
......@@ -57,13 +60,13 @@ HEAD="${CURL} -X HEAD --header \""$ACCEPT_JSON"\""
${GET} \
--header "$AUTH" ${URL}'/api/gateways?limit=1000&offset=0' \
> .gateways.json
> ${DATA_GAT_FOLDER}.gateways.json
TODAY=$(date +"%Y-%m-%d")
#generates json files of gateways informations and gateways statistics.
GATEWAYS=$(jq --raw-output ".result | sort_by(.lastSeenAt, .id) | reverse [] | (.id)" .gateways.json)
GATEWAYS_LEN=$(jq --raw-output ".totalCount" .gateways.json)
GATEWAYS=$(jq --raw-output ".result | sort_by(.lastSeenAt, .id) | reverse [] | (.id)" ${DATA_GAT_FOLDER}.gateways.json)
GATEWAYS_LEN=$(jq --raw-output ".totalCount" ${DATA_GAT_FOLDER}.gateways.json)
for g in $GATEWAYS
do
echo "get details for $g"
......
......@@ -15,7 +15,6 @@ fi
USERNAME=$1
PASSWORD=$2
# TODO get AUTH_JSON from the $(echo .credentials.json)
AUTH_JSON="{ \"username\": \"${USERNAME}\", \"password\": \"${PASSWORD}\" }"
# Installation
......@@ -43,6 +42,9 @@ CONTENT_CSV="Content-Type: text/csv"
PORT=443
URL=https://lns.campusiot.imag.fr:$PORT
# DATA REPOSITORY
DATA_CONFIG_FOLDER="data/configuration/"
# Doc
URL_SWAGGER=${URL}/swagger/api.swagger.json
......@@ -70,9 +72,10 @@ HEAD="${CURL} -X HEAD --header \""$ACCEPT_JSON"\""
USERNAME_LOWERCASE=${USERNAME,,} #lowercasing the name of json token file for a clean cleaning git ignore.
# Get the Bearer token for the user
rm *.token.json #delete old tokens
${POST} --header "$CONTENT_JSON" -d "$AUTH_JSON" ${URL}/api/internal/login > $USERNAME_LOWERCASE.token.json
TOKEN=$(jq -r '.jwt' $USERNAME_LOWERCASE.token.json)
rm -f ${DATA_CONFIG_FOLDER}*.token.json #delete old tokens
${POST} --header "$CONTENT_JSON" -d "$AUTH_JSON" ${URL}/api/internal/login > ${DATA_CONFIG_FOLDER}$USERNAME_LOWERCASE.token.json
TOKEN=$(jq -r '.jwt' ${DATA_CONFIG_FOLDER}$USERNAME_LOWERCASE.token.json)
AUTH="Grpc-Metadata-Authorization: Bearer $TOKEN"
echo "$TOKEN"
......
......@@ -44,6 +44,9 @@ CONTENT_CSV="Content-Type: text/csv"
PORT=443
URL=https://lns.campusiot.imag.fr:$PORT
# DATA REPOSITORY
DATA_ORG_FOLDER="data/organizations/"
# Operations
#CURL="curl --verbose"
CURL="curl --insecure"
......@@ -57,12 +60,12 @@ HEAD="${CURL} -X HEAD --header \""$ACCEPT_JSON"\""
${GET} \
--header "$AUTH" ${URL}'/api/organizations?limit=1000&offset=0' \
> .organizations.json
> ${DATA_ORG_FOLDER}.organizations.json
jq '.result[] | ( .id + ": " + .name + " - " + .displayName)' .organizations.json
jq '.result[] | ( .id + ": " + .name + " - " + .displayName)' ${DATA_ORG_FOLDER}.organizations.json
ids=$(jq --raw-output ".result[] | .id" .organizations.json)
ids=$(jq --raw-output ".result[] | .id" ${DATA_ORG_FOLDER}.organizations.json)
ids_array=($ids)
for (( i=0; i<${#ids_array[@]}; i++ ))
......
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