Created
June 26, 2018 06:35
-
-
Save sebge2emasphere/73edaeb8b521584326854369e60f7033 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
key="MxypbrLuFuLghheGCVHRroeiVhgULsrKgxbZQacaImQZFFeOcILGtCPYRKRlCvKt" | |
#key="JgLYiLyyLSStImodpkweYgemPHjTllXehpObXoqFBuyLfjEiOdmItVfnPGYASKyR" | |
cookieFile="/tmp/cookie-refresh.txt" | |
baseUrl="https://nexis.preprod.emasphere.com" | |
waitingTimeInSec="120" | |
situations=("ba14ee31-b3a5-4d9f-88a7-62cbdb357b91" "9bb1659f-061d-453f-be37-6f33b62d8558" "bd6268bf-ce50-4acd-8350-396c76c0c21c") | |
function loginEmasphere { | |
curl -c $cookieFile -i -u "#$key:" "$baseUrl/user?locale=EN" &> /dev/null | |
result=$? | |
if [[ $result -ne 0 ]]; then | |
echo "Error while login" | |
exit 1 | |
fi | |
} | |
function getEmasphere { | |
curl -b $cookieFile "$baseUrl$1?locale=EN" 2> /dev/null | |
result=$? | |
if [[ $result -ne 0 ]]; then | |
echo "Error while calling $1" | |
exit 1 | |
fi | |
} | |
function getMatrixValue { | |
fileBody=$1 | |
renderingConfiguration=$2 | |
situationId=$3 | |
currentMonth=$4 | |
url="$baseUrl/operational-query-service/matrix/rendering?locale=EN&situation=$situationId¤t-month=$currentMonth" | |
file="/tmp/cache-matrix-$renderingConfiguration-$situationId.txt" | |
httpStatus=$(curl -b $cookieFile $url -H "Content-Type: application/json" -w '%{http_code}' -X POST --data @$fileBody -s -o $file) | |
if [[ $httpStatus -ne 200 && $httpStatus -ne 204 ]]; then | |
echo -e " \033[0;31mError $httpStatus while calling url $url, go on file $file\033[0m" | |
sleep $waitingTimeInSec | |
fi | |
} | |
function getKpiViewValue { | |
kpi=$1 | |
situationId=$2 | |
currentMonth=$3 | |
echo " Retrieving KPI view $kpi" | |
url="$baseUrl/kpi-service/kpi-view/$kpi/value?locale=EN&situation=$situationId¤t-month=$currentMonth" | |
file="/tmp/cache-kpi-$kpi-$situationId.txt" | |
httpStatus=$(curl -b $cookieFile "$url" -w '%{http_code}' -s -o $file) | |
if [[ $httpStatus -ne 200 ]]; then | |
echo -e " \033[0;31mError $httpStatus while calling url $url, go on file $file\033[0m" | |
sleep $waitingTimeInSec | |
fi | |
} | |
function getVariableValue { | |
variableDefinition=$(echo $1 | base64 --decode) | |
situationId=$2 | |
currentMonth=$3 | |
variableId=$(echo $variableDefinition | jq -r '.variableId') | |
periodRange=$(echo $variableDefinition | jq -r '.timeFrame.periodRange') | |
periodShiftOffset=$(echo $variableiDefinition | jq -r '.timeFrame.periodShift.offset') | |
periodShiftUnit=$(echo $variableDefinition | jq -r '.timeFrame.periodShift.unit') | |
varSource=$(echo $variableDefinition | jq -r '.source') | |
varSituation=$(echo $variableDefinition | jq -r '.situationId') | |
echo " Retrieving variable $variableId $periodRange $periodShiftOffset $periodShiftUnit $varSource $varSituation" | |
url="$baseUrl/kpi-service/variable-dispatcher/variable/$variableId/value?locale=EN¤tMonth=$currentMonth&situation=$situationId" | |
if [ "$periodRange" != "null" ]; then | |
url=$url"&v_period_range=$periodRange" | |
fi | |
if [ "$varSource" != "null" ]; then | |
url=$url"&v_situation_source=$varSource" | |
fi | |
if [ "$periodShiftUnit" != "null" ]; then | |
url=$url"&v_period_shift_unit=$periodShiftUnit" | |
fi | |
if [ "$varSituation" != "null" ]; then | |
url=$url"&v_situation_id=$varSituation" | |
else | |
url=$url"&v_situation_id=$situation" | |
fi | |
if [[ ! -z "$periodShiftOffset" ]]; then | |
url=$url"&v_period_shift_offset=$periodShiftOffset" | |
fi | |
file="/tmp/cache-var-$situationId-$variableId.txt" | |
httpStatus=$(curl $url -b $cookieFile -w '%{http_code}' -s -o "$file") | |
if [[ $httpStatus -ne 200 && $httpStatus -ne 204 ]]; then | |
echo -e " \033[0;31mError $httpStatus while calling url $url, go on file $file\033[0m" | |
sleep $waitingTimeInSec | |
fi | |
} | |
loginEmasphere | |
for situation in "${situations[@]}"; do | |
situationId="$situation" | |
situationContent=$(getEmasphere "/accounting-service/situation/target-of/$situationId") | |
currentMonth=$(echo $situationContent | jq -r '.refMonth') | |
situationDescription=$(echo $situationContent | jq -r '.description') | |
situationCategory=$(echo $situationContent | jq -r '.category') | |
echo "" | |
echo "" | |
echo "Processing situation $situationId: $currentMonth-$situationDescription ($situationCategory)" | |
for page in $(getEmasphere "/dashboard-service/page" | jq -r '.[] | .id'); do | |
pageContent=$(getEmasphere "/dashboard-service/page/$page") | |
for widget in $(getEmasphere "/dashboard-service/page/$page" | jq -r '.widgets[] | @base64'); do | |
id=$(echo $widget | base64 --decode | jq -r '.id') | |
technicalIdentifier=$(echo $widget | base64 --decode | jq -r '.technicalIdentifier') | |
configuration=$(echo $widget | base64 --decode | jq -r '.configuration') | |
if [[ $technicalIdentifier = "new-kpi-bar" ]]; then | |
for kpi in $(echo $configuration | jq -r '.locked[] | select(.option=="kpi.kpi") | .values[]'); do | |
echo " Retrieving KPI $kpi" | |
kpiDefinition=$(getEmasphere "/kpi-service/kpi-definition/$kpi") | |
getVariableValue $(echo $kpiDefinition | jq -r '.mainVariable | @base64') $situation $currentMonth | |
for comparison in $(echo $kpiDefinition | jq -r 'select(.comparisons != null) | .comparisons[] | @base64'); do | |
getVariableValue $comparison $situation $currentMonth | |
done | |
getKpiViewValue $kpi $situation $currentMonth | |
done | |
fi | |
if [[ $technicalIdentifier = "operational-visualisation" ]]; then | |
filters=$(echo $configuration | jq -c -r '.locked[] | select(.option=="operational.matrix-free-filters") | .values') | |
renderingConfiguration=$(echo $configuration | jq -c -r '.locked[] | select(.option=="operational.matrix-rendering-configuration") | .values') | |
payload="{\"id\":\"""$renderingConfiguration""\",\"filters\":""$filters""}" | |
echo $payload > /tmp/query.json | |
echo " Retrieving Matrix Rendering $renderingConfiguration" | |
getMatrixValue "/tmp/query.json" "$renderingConfiguration" "$situationId" "$currentMonth" | |
echo $result | |
rm /tmp/query.json | |
fi | |
done | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment