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

First implementation Display Stats of Gateways

parent ccd901f9
{"jwt":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJjaGlycHN0YWNrLWFwcGxpY2F0aW9uLXNlcnZlciIsImV4cCI6MTYxNTM4NzM2NCwiaXNzIjoiY2hpcnBzdGFjay1hcHBsaWNhdGlvbi1zZXJ2ZXIiLCJuYmYiOjE2MTUzMDA5NjQsInN1YiI6InVzZXIiLCJ1c2VybmFtZSI6IkNoaXJwc3RhY2tNb25pdG9yaW5nIn0.H5mO2AL35i-0BK4YBTZTZ_5MHDKqq-7c7HPqexnKQOU"}
\ No newline at end of file
{"jwt":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJjaGlycHN0YWNrLWFwcGxpY2F0aW9uLXNlcnZlciIsImV4cCI6MTYxNTM5Mjk3NiwiaXNzIjoiY2hpcnBzdGFjay1hcHBsaWNhdGlvbi1zZXJ2ZXIiLCJuYmYiOjE2MTUzMDY1NzYsInN1YiI6InVzZXIiLCJ1c2VybmFtZSI6IkNoaXJwc3RhY2tNb25pdG9yaW5nIn0.8eOiKM6QRAzpZSV0rOt8LU0oxawxlzVWakHscdOiWBQ"}
\ No newline at end of file
......@@ -12,8 +12,8 @@ PASSWORD=$(jq --raw-output ".password" .credentials.json)
JWT=$(./get_jwt.sh $USERNAME $PASSWORD)
./get_organizations.sh $JWT
# ./get_organizations.sh $JWT
./get_gateways.sh $JWT
./get_devices.sh $JWT
# ./get_devices.sh $JWT
# TODO send reports by email
#!/bin/bash
# Copyright (C) CampusIoT, - All Rights Reserved
# Written by CampusIoT Dev Team, 2016-2021
# ------------------------------------------------
# Get the stats of a get gateway
# ------------------------------------------------
# Parameters
if [[ $# -ne 3 ]] ; then
echo "Usage: $0 JWT GWID TODAY"
exit 1
fi
TOKEN="$1"
GWID="$2"
TODAY="$3"
AUTH="Grpc-Metadata-Authorization: Bearer $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
#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"\""
echo "timestamp actuel : ${TODAY}T00:00:00Z"
LAST_MONTH=TODAY;
TODAY="$(date +"%Y-%m-%d")"
PAST_MONTH=$(date -d "-1 month" +%Y-%m-%d)
echo "timestamp ya un moins : ${PAST_MONTH}T00:00:00Z"
INTERVAL="day"
DEBUG=' --header "$AUTH" ${URL}'/api/gateways/'${GWID}'/stats?interval='${INTERVAL}'&startTimestamp=$'${PAST_MONTH}'T00:00:00Z&endTimestamp='${TODAY}'T00:00:00Z' \
'
echo "${DEBUG}"
${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
# 'https://lns.campusiot.imag.fr/api/gateways/7276ff0039030724/stats?interval=day&startTimestamp=2021-02-09T00%3A00%3A00Z&endTimestamp=2021-03-09T00%3A00%3A00Z'
# https://lns.campusiot.imag.fr:443'/api/gateways/'7276ff0039030871'/stats?interval='day'&startTimestamp=$'2021-02-09'T00:00:00Z&endTimestamp='2021-03-09'T00:00:00Z'
\ No newline at end of file
......@@ -83,6 +83,7 @@ for g in $GATEWAYS
do
echo "get details for $g"
./get_gateway.sh $TOKEN $g
./get_gateway_stats.sh $TOKEN $g $TODAY
done
./get_id_gatewaysChange.sh
......@@ -18,7 +18,7 @@ dates=$(jq --raw-output ".result[] | .lastSeenAt" .gateways.json)
date=()
date=($dates)
state=()
full_date==()
full_date=()
d=()
for (( i=0; i<${#date[@]}; i++ ))
do
......
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