Copy
#!/bin/bash
KEY="YOUR-API-KEY-HERE"
HOST="api.halosecurity.com"
### INITIATE REPORT GENERATOR
JSON=$(curl -s --header "x-apikey: $KEY" "https://$HOST/api/v1/report/generate.json?id=executive-summary")
WORK_ID=$(echo $JSON | jq -r .work_id)
FILE_ID=$(echo $JSON | jq -r .file_id)
echo "report work id $WORK_ID"
echo "report file id $FILE_ID"
### WAIT FOR REPORT COMPLETE
while true; do
sleep 1
echo report working
JSON=$(curl -s --header "x-apikey: $KEY" "https://$HOST/api/v1/work/get.json?id=$WORK_ID")
DONE=$(echo $JSON | jq -r .work.complete)
if [ $DONE == 1 ]; then
echo pdf ready
break
fi
done
### WAIT FOR REPORT FILE PROCESSING
while true; do
sleep 1
echo report file processing
JSON=$(curl -s --header "x-apikey: $KEY" "https://$HOST/api/v1/file/get.json?file_id=$FILE_ID")
DONE=$(echo $JSON | jq -r .file.ready)
if [ $DONE == 1 ]; then
echo file ready
echo $JSON | jq
URL=$(echo $JSON | jq -r .file.url)
break
fi
done
### DOWNLOAD REPORT FILE
echo "Downloading File $URL"
curl --header "x-apikey: $KEY" $URL > report.pdf
ls -lah report.pdf