#!/bin/bash
#
# This script is an "out of the box" script that goes through
# Login and GET /audit-logs with the authentication
# token from Login
#
source apiHostInfo
eval $(cat loginCredentials)
source helpers
login
echo "* GET /audit-logs from $EXPORT_ENGINE"
EXPORT_RESPONSE=$(curl $SSL_CERT -X GET -H ''"$AUTH_HEADER"'' -H 'Accept: application/json' $MASKING_ENGINE/audit-logs)
# Calculate the number of audit log entries and the proximity to the entry limit.
AUDIT_ENTRY_COUNT=$(jq '._pageInfo.total' <<<"$EXPORT_RESPONSE")
MAX_ENTRIES=1000000
DIFFERENCE=$((MAX_ENTRIES-AUDIT_ENTRY_COUNT))
# Retrieve the date of the oldest audit entry retained.
OLDEST_DATE=$(jq '.responseList[1].activityTime' <<<"$EXPORT_RESPONSE")
echo "There are $AUDIT_ENTRY_COUNT entries in the audit log. After $DIFFERENCE more audits you will hit the $MAX_ENTRIES limit and will begin to overwrite entries starting from the oldest, which was created on: $OLDEST_DATE"