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

Finalisation et Strucutration code Sparkline Generated

parent 10927829
{"jwt":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJjaGlycHN0YWNrLWFwcGxpY2F0aW9uLXNlcnZlciIsImV4cCI6MTYxNTM5Mjk3NiwiaXNzIjoiY2hpcnBzdGFjay1hcHBsaWNhdGlvbi1zZXJ2ZXIiLCJuYmYiOjE2MTUzMDY1NzYsInN1YiI6InVzZXIiLCJ1c2VybmFtZSI6IkNoaXJwc3RhY2tNb25pdG9yaW5nIn0.8eOiKM6QRAzpZSV0rOt8LU0oxawxlzVWakHscdOiWBQ"}
\ No newline at end of file
{"jwt":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJjaGlycHN0YWNrLWFwcGxpY2F0aW9uLXNlcnZlciIsImV4cCI6MTYxNTk5NzcxNSwiaXNzIjoiY2hpcnBzdGFjay1hcHBsaWNhdGlvbi1zZXJ2ZXIiLCJuYmYiOjE2MTU5MTEzMTUsInN1YiI6InVzZXIiLCJ1c2VybmFtZSI6IkNoaXJwc3RhY2tNb25pdG9yaW5nIn0.-aWPrSO4-UGKWWKMInIC8foCHxiW7XZsekJF2nJZNJ4"}
\ No newline at end of file
.result | sort_by(.lastSeenAt, .id) | reverse [] | ("<li><a href='" + @uri "https://lns.campusiot.imag.fr/#/organizations/\(.organizationID)/gateways/\(.id)" + "'>" + .id + "</a>: " + .name + " - (org " + .organizationID + ") - " + .lastSeenAt + "</li>" )
#!/bin/bash
# -------------------------------------------------
# Description: Generate HTML report of gateways
# List Command: x
# Usage: runned by get_gateways.sh (à détailler)
# Create by: CampusIoT Dev Team, 2021 - Copyright (C) CampusIoT, - All Rights Reserved
# Since: 09/09/2560 (DD/MM/YYYY)
# -------------------------------------------------
# Version: 1.0
# -------------------------------------------------
# Bug:
# -------------------------------------------------
# Parameters
if [[ $# -eq 0 ]]; then
echo "Aucun arguments renseignées : Usage: $0 GATEWAYS_LENGTH GATEWAYS TODAY"
exit 1
fi
GATEWAYS_LENGTH="$1"
args_len=$(($GATEWAYS_LENGTH + 2))
if [[ $# -ne args_len ]]; then
echo "Usage: $0 GATEWAYS_LENGTH GATEWAYS TODAY"
exit 1
fi
GATEWAYS=${@:2:$GATEWAYS_LENGTH} #on recupère les données de la gateway passés en paramètre en subsituant la taille et la date du jour.
TODAY="${@:$#}" # last parameter
# gateways_to_html : Step 1 : Generate header.
cat report_header.html >.gateways.html
echo '<title>CampusIoT LNS :: Gateways</title>' >>.gateways.html
echo '</head>' >>.gateways.html
echo '<body style="font-family:verdana;"><h1>CampusIoT LNS :: Gateways</h1>' >>.gateways.html
# 2.Generate Time
echo '<p>generated at ' >>.gateways.html
date +"%Y-%m-%d %T %Z" >>.gateways.html
echo ' - ' >>.gateways.html
TZ=GMT date +"%Y-%m-%d %T %Z" >>.gateways.html
echo '</p>' >>.gateways.html
# 3.Generate Active Gateways
echo '<h2>Active gateways</h2>' >>.gateways.html
echo "generate_sparkline_packets : \n ========== \n ========== \n "
for g in $GATEWAYS; do
packet_received=$(jq -r '.result | map(.rxPacketsReceivedOK) | join(",")' .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
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)
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
done
echo '</body></html>' >>.gateways.html
......@@ -12,7 +12,7 @@ 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
......
......@@ -55,19 +55,9 @@ 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
......
......@@ -59,26 +59,11 @@ ${GET} \
--header "$AUTH" ${URL}'/api/gateways?limit=1000&offset=0' \
> .gateways.json
echo '<html><head><title>CampusIoT LNS :: Gateways</title></head><body style="font-family:verdana;"><h1>CampusIoT LNS :: Gateways</h1>' > .gateways.html
TODAY=$(date +"%Y-%m-%d")
echo '<p>generated at ' >> .gateways.html
date +"%Y-%m-%d %T %Z" >> .gateways.html
echo ' - ' >> .gateways.html
TZ=GMT date +"%Y-%m-%d %T %Z" >> .gateways.html
echo '</p>' >> .gateways.html
echo '<h2>Active gateways</h2>' >> .gateways.html
jq --raw-output -f gateways_to_html.jq .gateways.json | grep $TODAY >> .gateways.html
echo '<h2>Passive gateways</h2>' >> .gateways.html
jq --raw-output -f gateways_to_html.jq .gateways.json | grep -v $TODAY >> .gateways.html
echo '</body></html>' >> .gateways.html
#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)
for g in $GATEWAYS
do
echo "get details for $g"
......@@ -86,4 +71,8 @@ echo "get details for $g"
./get_gateway_stats.sh $TOKEN $g $TODAY
done
./get_id_gatewaysChange.sh
echo "generate html (with sparkline)"
./gateways_to_html.sh $GATEWAYS_LEN $GATEWAYS $TODAY
echo "Passive Active Check"
./get_id_gatewaysChange.sh
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="jQuery_Sparklines/jquery-1.js"></script>
<script type="text/javascript" src="jQuery_Sparklines/jquery.js"></script>
<script type="text/javascript">
$(function () {
/** This code runs when everything has been loaded on the page */
/* Inline sparklines take their values from the contents of the tag */
$('.inlinesparkline').sparkline();
});
</script>
\ 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