Ask Your Question

Revision history [back]

for example the logical of my script, who download under the admin tab the csv usage reports, are:

#first curl to get the token on cookie file
$CURL -c $COOKIE_FILE -b $COOKIE_FILE --output /dev/null -s "$HORIZON_HOST/dashboard/auth/login/"

TOKEN=`cat $COOKIE_FILE | grep csrftoken | sed 's/^.*csrftoken\s*//'`

DATA="username=$HORIZON_USER&password=$HORIZON_PASSWORD&region=$HORIZON_REGION&csrfmiddlewaretoken=$TOKEN"

#now we can authenticate
$CURL -c $COOKIE_FILE -b $COOKIE_FILE --output /dev/null -s -d "$DATA" --referer "$HORIZON_HOST/dashboard/" "$HORIZON_HOST/dashboard/auth/login/"

#verify the presence of sessionid
SESSIONID=`cat $COOKIE_FILE | grep sessionid | sed 's/^.*sessionid\s*//'`
if [ "$SESSIONID" == "" ]; then
    log_debug "Error: sessionid not present on file $COOKIE_FILE ...Exit"
    exit 1
fi

#ADAPT TO YOUR ENVIRONMENT!!!!
TENANT_URL="https://your_fqdn/dashboard/auth/switch/xPUT_HERE_YOUR_TENANTIDx/?next=/dashboard/project/"
$CURL -c $COOKIE_FILE -b $COOKIE_FILE --output /dev/null -s "$TENANT_URL"

#finally you can get your csv :)
URL="$HORIZON_HOST/dashboard/admin/?start=$DATE_START&end=$DATE_END&format=csv"
$CURL -c $COOKIE_FILE -b $COOKIE_FILE --output $CSV_FILE -s "$URL"

HTH Amedeo