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

restructuation of HTML generated files / report

parent cbf66739
#!/bin/bash
# Copyright (C) CampusIoT, - All Rights Reserved
# Written by CampusIoT Dev Team, 2016-2021
# Parameters
if [[ $# -ne 2 ]] ; then
echo "Usage: $0 JWT GWID"
exit 1
fi
TOKEN="$1"
GWID="$2"
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
#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"\""
${GET} \
--header "$AUTH" ${URL}'/api/gateways/'${GWID} \
> .gateway-${GWID}.json
......@@ -3,7 +3,7 @@
# -------------------------------------------------
# Description: Generate HTML report of gateways
# List Command: x
# Usage: runned by get_gateways.sh (à détailler)
# Usage: runned by get_gateways.sh
# Create by: CampusIoT Dev Team, 2021 - Copyright (C) CampusIoT, - All Rights Reserved
# -------------------------------------------------
# Version: 1.0
......@@ -28,57 +28,56 @@ fi
# DATA REPOSITORY
DATA_APP_FOLDER="data/applications/"
DATA_GAT_FOLDER="data/gateways/"
DATA_HTML_FOLDER="data/generated_files/"
gateways_html="${DATA_HTML_FOLDER}.gateways.html"
gateways_without_spark_html="${DATA_HTML_FOLDER}.gateways_without_sparkline.html"
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
# 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
cat header_sparkline.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
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}
# Create a copy of .gateways.html to get one with sparkline data, and one without them
cp .gateways.html .gateways_without_sparkline.html
cp ${gateways_html} ${gateways_without_spark_html}
# 3.Generate Active Gateways without sparkline data
echo '<h2>Active gateways</h2>' >>.gateways_without_sparkline.html
echo "generate_sparkline_packets : \n ========== \n ========== \n "
echo '<h2>Active gateways</h2>' >>${gateways_without_spark_html}
for g in $GATEWAYS; do
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
+ \"</li>\" )" ${DATA_GAT_FOLDER}.gateway-${g}.json | grep $TODAY >>.gateways_without_sparkline.html
+ \"</li>\" )" ${DATA_GAT_FOLDER}.gateway-${g}.json | grep $TODAY >>${gateways_without_spark_html}
done
# 4.Generate Passive Gateways without sparkline data
echo '<h2>Passive gateways</h2>' >>.gateways_without_sparkline.html
echo '<h2>Passive gateways</h2>' >>${gateways_without_spark_html}
for g in $GATEWAYS; do
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
+ \"</li>\" )" ${DATA_GAT_FOLDER}.gateway-${g}.json | grep -v $TODAY >>.gateways_without_sparkline.html
+ \"</li>\" )" ${DATA_GAT_FOLDER}.gateway-${g}.json | grep -v $TODAY >>${gateways_without_spark_html}
done
echo '</body></html>' >>.gateways_without_sparkline.html
echo '</body></html>' >>${gateways_html}
# 5.Generate Active Gateways with sparkline data
echo '<h2>Active gateways</h2>' >>.gateways.html
echo "generate_sparkline_packets : \n ========== \n ========== \n "
echo '<h2>Active gateways</h2>' >>${gateways_html}
for g in $GATEWAYS; do
......@@ -89,11 +88,11 @@ for g in $GATEWAYS; do
+ .gateway.name + \" - (org \" + .gateway.organizationID + \") - \"
+ .lastSeenAt
+ \" - packets received last month : <span class='inlinesparkline'>${packet_received}</span>\"
+ \"</li>\" )" ${DATA_GAT_FOLDER}.gateway-${g}.json | grep $TODAY >>.gateways.html
+ \"</li>\" )" ${DATA_GAT_FOLDER}.gateway-${g}.json | grep $TODAY >>${gateways_html}
done
# 6.Generate Passive Gateways with sparkline data
echo '<h2>Passive gateways</h2>' >>.gateways.html
echo '<h2>Passive gateways</h2>' >>${gateways_html}
for g in $GATEWAYS; do
packet_received=$(jq -r '.result | map(.rxPacketsReceivedOK|tostring) | join(",")' ${DATA_GAT_FOLDER}.gateway-${g}_stats.json)
......@@ -103,8 +102,8 @@ for g in $GATEWAYS; do
+ .gateway.name + \" - (org \" + .gateway.organizationID + \") - \"
+ .lastSeenAt
+ \" - packets received last month : <span class='inlinesparkline'>${packet_received}</span>\"
+ \"</li>\" )" ${DATA_GAT_FOLDER}.gateway-${g}.json | grep -v $TODAY >>.gateways.html
+ \"</li>\" )" ${DATA_GAT_FOLDER}.gateway-${g}.json | grep -v $TODAY >>${gateways_html}
done
echo '</body></html>' >>.gateways.html
echo '</body></html>' >>${gateways_html}
......@@ -55,8 +55,9 @@ URL=https://lns.campusiot.imag.fr:$PORT
DATA_APP_FOLDER="data/applications/"
DATA_ORG_FOLDER="data/organizations/"
DATA_DEV_FOLDER="data/devices/"
DATA_HTML_FOLDER="data/generated_files/"
devices_html="${DATA_HTML_FOLDER}.devices.html"
# Operations
# Operations
#CURL="curl --verbose"
CURL="curl -s --insecure"
......@@ -105,29 +106,29 @@ sed -i "/"totalCount"/c $replacement" ${DATA_DEV_FOLDER}.devices.json
echo '<html><head><title>CampusIoT LNS :: Devices</title></head><body style="font-family:verdana;"><h1>CampusIoT LNS :: Devices</h1>' > .devices.html
echo '<html><head><title>CampusIoT LNS :: Devices</title></head><body style="font-family:verdana;"><h1>CampusIoT LNS :: Devices</h1>' > ${devices_html}
TODAY=$(date +"%Y-%m-%d")
echo '<p>generated at ' >> .devices.html
date +"%Y-%m-%d %T %Z" >> .devices.html
echo ' - ' >> .devices.html
TZ=GMT date +"%Y-%m-%d %T %Z" >> .devices.html
echo '</p>' >> .devices.html
echo '<p>generated at ' >> ${devices_html}
date +"%Y-%m-%d %T %Z" >> ${devices_html}
echo ' - ' >> ${devices_html}
TZ=GMT date +"%Y-%m-%d %T %Z" >> ${devices_html}
echo '</p>' >> ${devices_html}
echo '<h2>Active devices</h2>' >> .devices.html
echo '<h2>Active devices</h2>' >> ${devices_html}
jq --raw-output -f devices_to_html.jq ${DATA_DEV_FOLDER}.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
echo '<h2>Passive devices</h2>' >> ${devices_html}
jq --raw-output -f devices_to_html.jq ${DATA_DEV_FOLDER}.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
echo '</body></html>' >> ${devices_html}
./get_id_devices_change.sh
for ((i=0; i<${#DID[@]}; i++))
do
./change_url_orgaID.sh ${DID[$i]} ${OID[$i]}
./update_url_orga_id.sh ${DID[$i]} ${OID[$i]}
done
......@@ -82,10 +82,11 @@ echo "get details for $g"
done
echo "generate html (2 copies : one with sparkline and one without sparkline)"
./gateways_to_html.sh $GATEWAYS_LEN $GATEWAYS $TODAY
./generate_gateways_report.sh $GATEWAYS_LEN $GATEWAYS $TODAY
echo "Passive Active Check"
./get_id_gateways_change.sh
./get_id_gateways_change.sh ".gateways.html"
./get_id_gateways_change.sh ".gateways_without_sparkline.html"
# Generate an image of the page html with sparkline
node download_sparkline.js
\ No newline at end of file
node generate_sparkline_image.js
\ No newline at end of file
......@@ -17,6 +17,8 @@ TODAY="$(date +"%Y-%m-%d")"
# DATA REPOSITORY
DATA_DEV_FOLDER="data/devices/"
DATA_HTML_FOLDER="data/generated_files/"
devices_html="${DATA_HTML_FOLDER}.devices.html"
#We store devices' ids of the present day
ids=$(jq --raw-output ".result[] | select(.!=null) | .devEUI" ${DATA_DEV_FOLDER}.devices.json)
......@@ -91,22 +93,22 @@ do
then
if [[ "${state[$i]}" == "active" ]]
then
tmp=$(grep ${id[$i]} < .devices.html)
tmp=$(grep ${id[$i]} < ${devices_html})
replacement=${tmp/"<li>"/"<li style="color:green">"}
else
tmp=$(grep ${id[$i]} < .devices.html)
tmp=$(grep ${id[$i]} < ${devices_html})
replacement=${tmp/"<li>"/"<li style="color:red">"}
fi
sed -i "/${id[$i]}/c $replacement" .devices.html
sed -i "/${id[$i]}/c $replacement" ${devices_html}
fi
fi
done
if [[ ${date[$i]} != "null" ]]
then
tmp=$(grep ${id[$i]} < .devices.html)
tmp=$(grep ${id[$i]} < "${devices_html}")
dateFromNow=$(node change_date_momentjs.js ${date[$i]})
replacement=${tmp/${date[$i]}/"$dateFromNow"}
sed -i "/${id[$i]}/c $replacement" .devices.html
sed -i "/${id[$i]}/c $replacement" ${devices_html}
fi
done
......
......@@ -11,10 +11,14 @@
# Bug:
# -------------------------------------------------
TODAY="$(date +"%Y-%m-%d")"
# DATA REPOSITORY
DATA_GAT_FOLDER="data/gateways/"
DATA_HTML_FOLDER="data/generated_files/"
gateways_html="${DATA_HTML_FOLDER}$1"
#We store gateways' ids of the present day
ids=$(jq --raw-output ".result[] | .id" ${DATA_GAT_FOLDER}.gateways.json)
......@@ -25,7 +29,10 @@ id=($ids)
dates=$(jq --raw-output ".result[] | .lastSeenAt" ${DATA_GAT_FOLDER}.gateways.json)
date=()
date=($dates)
state=()nerate_reports i++ ))
state=()
full_date=()
d=()
for (( i=0; i<${#date[@]}; i++ ))
do
if [[ ${date[$i]} == "null" ]]
then
......@@ -86,22 +93,22 @@ do
then
if [[ "${state[$i]}" == "active" ]]
then
tmp=$(grep ${id[$i]} < .gateways.html)
tmp=$(grep ${id[$i]} < ${gateways_html})
replacement=${tmp/"<li>"/"<li style="color:green">"}
else
tmp=$(grep ${id[$i]} < .gateways.html)
tmp=$(grep ${id[$i]} < ${gateways_html})
replacement=${tmp/"<li>"/"<li style="color:red">"}
fi
sed -i "/${id[$i]}/c $replacement" .gateways.html
sed -i "/${id[$i]}/c $replacement" ${gateways_html}
fi
fi
done
if [[ ${date[$i]} != "null" ]]
then
tmp=$(grep ${id[$i]} < .gateways.html)
tmp=$(grep ${id[$i]} < "${gateways_html}")
dateFromNow=$(node change_date_momentjs.js ${date[$i]})
replacement=${tmp/${date[$i]}/"$dateFromNow"}
sed -i "/${id[$i]}/c $replacement" .gateways.html
sed -i "/${id[$i]}/c $replacement" ${gateways_html}
fi
done
......
......@@ -22,23 +22,24 @@
# DATA REPOSITORY
DATA_CONFIG_FOLDER="data/configuration/"
DATA_IMAGES_FOLDER="data/images/"
DATA_HTML_FOLDER="data/generated_files/"
gateways_without_spark_html="${DATA_HTML_FOLDER}.gateways_without_sparkline.html"
devices_html="${DATA_HTML_FOLDER}.devices.html"
TO=$(jq --raw-output ".report_email_to" ${DATA_CONFIG_FOLDER}.config.json)
SUBJECT="Monitoring Report"
CONTENT_TYPE_HTML="Content-type: text/html"
CONTENT_TYPE_MUL="Content-Type: multipart/mixed; boundary=\"GvXjxJ+pjyke8COw\""
CONTENT_TYPE_IMG="Content-type: image/png"
# CONTENT_TYPE="Content-type: multipart/mixed"
ATTACHMENT="../images/operators.png"
# mail -a "$CONTENT_TYPE" -s "$SUBJECT" -u monitoring $TO <.gateways.html #généré avec pièce jointe
mail -a "$CONTENT_TYPE_HTML" -s "$SUBJECT" -u monitoring $TO <.devices.html
mail -a "$CONTENT_TYPE_HTML" -s "$SUBJECT" -u monitoring $TO < ${devices_html}
# mail -a "$CONTENT_TYPE" -s "$SUBJECT" -u monitoring $TO <${gateways_without_spark_html} #générée avec pièce jointe dorénavant. (voir ci-dessous)
IMAGE="sparkline_report.png"
IMAGE_LOC="${DATA_IMAGES_FOLDER}${IMAGE}"
outputFile=".gateways.html"
outputFile="${gateways_without_spark_html}"
(
echo "To: $TO"
echo "Subject: $SUBJECT"
......
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