Created
April 12, 2018 11:45
-
-
Save sebge2emasphere/cb0133ec7ec144b80a8f8b65b83f90d4 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="xyz" | |
cookieFile="/tmp/cookie-refresh.txt" | |
baseUrl="https://nexis.ema.emasphere.com" | |
declare -A situations | |
situations=([ba14ee31-b3a5-4d9f-88a7-62cbdb357b91]="2018-03" [9bb1659f-061d-453f-be37-6f33b62d8558]="2018-03" [bd6268bf-ce50-4acd-8350-396c76c0c21c]="2018-02") | |
function loginEmasphere { | |
curl -c $cookieFile -i -u "#$key:" "$baseUrl/login-api" &> /dev/null | |
result=$? | |
if [[ $result -ne 0 ]]; then | |
echo "Error while login" | |
exit $result | |
fi | |
} | |
function getEmasphere { | |
curl -b $cookieFile "$baseUrl$1?situation=$2¤t-month=$3" 2> /dev/null | |
result=$? | |
if [[ $result -ne 0 ]]; then | |
echo "Error while calling $1" | |
exit $result | |
fi | |
} | |
function postEmasphere { | |
curl -b $cookieFile "$baseUrl$1?situation=$3¤t-month=$4" -H "Content-Type: application/json" -X POST --data @$2 2> /dev/null | |
result=$? | |
if [[ $result -ne 0 ]]; then | |
echo "Error while calling $1" | |
exit $result | |
fi | |
} | |
loginEmasphere | |
for situation in "${!situations[@]}"; do | |
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') | |
situationId="$situation" | |
currentMonth="${situations[$situation]}" | |
if [[ $technicalIdentifier = "new-kpi-bar" ]]; then | |
for kpi in $(echo $configuration | jq -r '.locked[] | select(.option=="kpi.kpi") | .values[]'); do | |
echo "Retrieving KPI $kpi, situation $situationId ($currentMonth)" | |
getEmasphere "/kpi-service/kpi-view/$kpi" "$situationid" "$currentMonth" > /tmp/widget-kpi-$kpi.txt 2>&1 | |
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, situation $situationId ($currentMonth)" | |
postEmasphere "/operational-query-service/matrix/rendering" "/tmp/query.json" "$situationId" "$currentMonth" > /tmp/widget-matrix-$renderingConfiguration.txt | |
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