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 f1e0132a authored by Kevin Yung's avatar Kevin Yung
Browse files

Finalisation on the code for devices - french comments are still there and need to be changed

parent 39c07faa
{"jwt":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJjaGlycHN0YWNrLWFwcGxpY2F0aW9uLXNlcnZlciIsImV4cCI6MTYxNjUxOTM3MiwiaXNzIjoiY2hpcnBzdGFjay1hcHBsaWNhdGlvbi1zZXJ2ZXIiLCJuYmYiOjE2MTY0MzI5NzIsInN1YiI6InVzZXIiLCJ1c2VybmFtZSI6IkNoaXJwc3RhY2tNb25pdG9yaW5nIn0.mVfI0vHUtjdMDy19AlPEputBc1AqfzJ8K70J0DDyRVA"}
\ No newline at end of file
{"jwt":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJjaGlycHN0YWNrLWFwcGxpY2F0aW9uLXNlcnZlciIsImV4cCI6MTYxNzExODgxNSwiaXNzIjoiY2hpcnBzdGFjay1hcHBsaWNhdGlvbi1zZXJ2ZXIiLCJuYmYiOjE2MTcwMzI0MTUsInN1YiI6InVzZXIiLCJ1c2VybmFtZSI6IkNoaXJwc3RhY2tNb25pdG9yaW5nIn0.hhkImr9ASOZlJqiEtU8cbwAUPigZpKaXhHFcS2uq-7k"}
\ No newline at end of file
#!/bin/bash
# Parameters
if [[ $# -ne 2 ]] ; then
echo "Usage: $0 DID OID"
exit 1
fi
DID="$1/devices"
OID="$2"
tmp=$(grep $DID < .devices.html)
replacement=${tmp/"null"/"$OID"}
if [ -z "$replacement" ]
then
exit
else
sed -i "/${DID//\//\\/}/c $replacement" .devices.html
fi
\ No newline at end of file
.result | sort_by(.lastSeenAt, .devEUI) | reverse [] | ("<li><a href='" + @uri "https://lns.campusiot.imag.fr/#/organizations/\(.organizationID)/applications/\(.applicationID)/devices/\(.devEUI)" + "'>" + .devEUI + "</a>: " + .name + " (profile " + .deviceProfileName + " ,org " + .organizationID + ") - " + .lastSeenAt + "</li>" )
.result | sort_by(.lastSeenAt, .devEUI) | reverse [] | select(.!=null) | ("<li><a href='" + @uri "https://lns.campusiot.imag.fr/#/organizations/\(.organizationID)/applications/\(.applicationID)/devices/\(.devEUI)" + "'>" + .devEUI + "</a>: " + .name + " (profile " + .deviceProfileName + " ,org " + .organizationID + ") - " + .lastSeenAt + "</li>" )
......@@ -61,4 +61,4 @@ ${GET} \
--header "$AUTH" ${URL}'/api/applications?limit=9999&organizationID='${OID} \
> .organization${OID}_applications.json
jq '.result[] | ( .id + ": " + .name + " - " + .organizationID + " - " + .description)' .applications.json
#jq '.result[] | ( .id + ": " + .name + " - " + .organizationID + " - " + .description)' .applications.json
......@@ -59,20 +59,34 @@ HEAD="${CURL} -X HEAD --header \""$ACCEPT_JSON"\""
ids_org=$(jq --raw-output ".result[] | .id" .organizations.json)
ids_org_array=($ids_org)
nb_devices=0
DID=() #List of Devices' IDs
OID=() #List of Organisations' IDs linked to the DID (ex OID[0] is the orgID of DID[0])
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" .organization${ids_org_array[$i]}_applications.json)
ids_app_array=($ids_app)
for ((j=0; j<${#ids_app_array[@]}; j++))
do
DID[$nb_devices]=${ids_app_array[$j]}
OID[$nb_devices]=${ids_org_array[$i]}
nb_devices=$((nb_devices+1))
${GET} \
--header "$AUTH" ${URL}'/api/devices?limit=9999&applicationID='${ids_app_array[j]} \
> .application${ids_app_array[j]}_devices.json
--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
ids=$(jq --raw-output ".result[] | select(.!=null) | .devEUI" .devices.json)
id=($ids)
tmp=$(grep "totalCount" < .devices.json)
replacement=${tmp/"1"/"${#id[@]}"}
sed -i "/"totalCount"/c $replacement" .devices.json
#${GET} \
# --header "$AUTH" ${URL}'/api/devices?limit=9999&offset=0' \
# > .devices.json
......@@ -97,3 +111,11 @@ 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
./get_id_devicesChange.sh
for ((i=0; i<${#DID[@]}; i++))
do
./change_url_orgaID.sh ${DID[$i]} ${OID[$i]}
done
#!/bin/bash
TODAY="$(date +"%Y-%m-%d")"
#On stock les ids des devices d'aujourd'hui
ids=$(jq --raw-output ".result[] | select(.!=null) | .devEUI" .devices.json)
id=($ids)
#On stock les dates de dernière activité des devices d'aujourd'hui
dates=$(jq --raw-output ".result[] | select(.!=null) | .lastSeenAt" .devices.json)
date=()
date=($dates)
state=()
full_date=()
d=()
for (( i=0; i<${#date[@]}; i++ ))
do
if [[ ${date[$i]} == "null" ]]
then
full_date[$i]=${date[$i]}
d[$i]=${full_date[$i]}
else
full_date[$i]=$(echo ${date[$i]} | tr "T" "\n")
for arg in ${full_date[$i]}
do
d[$i]=$arg
break
done
fi
done
#On stock les states des devices d'aujourd'hui dans un tableau en regardant la date
#de dernière activité des devices
for (( i=0; i<${#d[@]}; i++ ))
do
if [[ "${d[$i]}" == "$TODAY" ]]
then
state[$i]="active"
else
state[$i]="passive"
fi
done
#On stock les ids des devices d'hier
ids_2=$(jq --raw-output ".result[] | .id" lastdevicesStates.json)
id_2=()
i=0
for ID in $ids_2
do
id_2[$i]=$ID
i=$((i+1))
done
#On stock les states des devices d'hier
full_state=$(jq --raw-output ".result[] | .lastState" lastdevicesStates.json)
states_2=()
j=0
for s in $full_state
do
state_2[$j]=$s
j=$((j+1))
done
#On compare les states des devices d'aujourd'hui et hier
for (( i=0; i<${#id[@]}; i++ ))
do
for (( j=0; j<${#id_2[@]}; j++ ))
do
if [[ "$id[$i]" == "$id_2[$j]" ]]
then
if [[ "${state[$i]}" != "${state_2[$j]}" ]]
then
if [[ "${state[$i]}" == "active" ]]
then
tmp=$(grep ${id[$i]} < .devices.html)
replacement=${tmp/"<li>"/"<li style="color:green">"}
else
tmp=$(grep ${id[$i]} < .devices.html)
replacement=${tmp/"<li>"/"<li style="color:red">"}
fi
sed -i "/${id[$i]}/c $replacement" .devices.html
fi
fi
done
if [[ ${date[$i]} != "null" ]]
then
tmp=$(grep ${id[$i]} < .devices.html)
dateFromNow=$(node changeDateMomentjs.js ${date[$i]})
replacement=${tmp/${date[$i]}/"$dateFromNow"}
sed -i "/${id[$i]}/c $replacement" .devices.html
fi
done
#On met à jour les states des devices pour le prochain jour
echo "{
\"totalCount\": \"${#id[@]}\",
\"result\": [" > lastdevicesStates.json
for (( i=0; i<$((${#id[@]}-1)); i++ ))
do
echo " {
\"id\": \"${id[$i]}\",
\"lastState\": \"${state[$i]}\"
}," >> lastdevicesStates.json
done
echo " {
\"id\": \"${id[$((${#id[@]}-1))]}\",
\"lastState\": \"${state[$((${#id[@]}-1))]}\"
}
]
}" >> lastdevicesStates.json
\ No newline at end of file
#!/bin/bash
#TODAY="2021-03-02"
TODAY="$(date +"%Y-%m-%d")"
#On stock les ids des gateways d'aujourd'hui
ids=$(jq --raw-output ".result[] | .id" .gateways.json)
id=()
i=0
for ID in $ids
do
id[$i]=$ID
i=$((i+1))
done
id=($ids)
#On stock les dates de dernière activité des gateways d'aujourd'hui
dates=$(jq --raw-output ".result[] | .lastSeenAt" .gateways.json)
......@@ -27,8 +21,8 @@ do
full_date[$i]=${date[$i]}
d[$i]=${full_date[$i]}
else
full_date[$i]=$(echo $date[$i] | tr "T" "\n")
for arg in $full_date[$i]
full_date[$i]=$(echo ${date[$i]} | tr "T" "\n")
for arg in ${full_date[$i]}
do
d[$i]=$arg
break
......
{
"totalCount": "24",
"totalCount": "23",
"result": [
{
"id": "0000024b0805031a",
......@@ -89,10 +89,6 @@
"id": "0080e1ffff0153cc",
"lastState": "passive"
},
{
"id": "0080e1ffff015b18",
"lastState": "passive"
},
{
"id": "0080e1ffff015abf",
"lastState": "passive"
......
{
"totalCount": "22",
"result": [
{
"id": "e24f43fffe44d05f",
"lastState": "passive"
},
{
"id": "e24f43fffe44cf7c",
"lastState": "passive"
},
{
"id": "70b3d58ff1012b89",
"lastState": "active"
},
{
"id": "e24f43fffe44d1ca",
"lastState": "passive"
},
{
"id": "a81758fffe032273",
"lastState": "active"
},
{
"id": "0004a30b00241873",
"lastState": "passive"
},
{
"id": "0004a30b001ff623",
"lastState": "passive"
},
{
"id": "1111111111111111",
"lastState": "passive"
},
{
"id": "0025ca0a000004d2",
"lastState": "active"
},
{
"id": "244e7b0002000814",
"lastState": "active"
},
{
"id": "0004a30b00237b0c",
"lastState": "passive"
},
{
"id": "e24f43fffe44d342",
"lastState": "passive"
},
{
"id": "e24f43fffe44d333",
"lastState": "passive"
},
{
"id": "e24f43fffe44d0ca",
"lastState": "passive"
},
{
"id": "e24f43fffe44d13a",
"lastState": "passive"
},
{
"id": "e24f43fffe44cf48",
"lastState": "passive"
},
{
"id": "0025ca0a000004db",
"lastState": "active"
},
{
"id": "e24f43fffe44c2c8",
"lastState": "passive"
},
{
"id": "70b3d58ff1004297",
"lastState": "active"
},
{
"id": "e24f43fffe44cff3",
"lastState": "passive"
},
{
"id": "e24f43fffe44c2cb",
"lastState": "passive"
},
{
"id": "e24f43fffe44cf96",
"lastState": "active"
}
]
}
#!/usr/bin/env node
const moment = require('moment');
var argv = process.argv; // store the argument given
process.argv.shift(); // skip path of node file
process.argv.shift(); // skip path of js file
argv = process.argv.join(" ") // parse to keep only the string
function f(lastSeenAt) {
//console.log(lastSeenAt);
lastSeenAt = new Date(lastSeenAt);
return moment(lastSeenAt).fromNow();
}
console.log(f(argv))
\ No newline at end of file
#!/bin/bash
# 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