Files
Christian Heusel f37d11d830 fastly-textcollector: Upgrade to v3 API
Fastly seems to have changed their API to the new v3 billing api, so we
also have to adapt our code to match the new structure.

Fixes https://gitlab.archlinux.org/archlinux/infrastructure/-/issues/700

Link: https://www.fastly.com/documentation/reference/api/account/invoices/
Signed-off-by: Christian Heusel <christian@heusel.eu>
2025-10-13 20:07:50 +02:00

31 lines
948 B
Django/Jinja

#!/bin/bash
set -o errexit -o nounset -o pipefail
fastly_token="{{ vault_fastly_billing_token }}"
fastly_customer_id="{{ vault_fastly_customer_id }}"
if (( $# != 1 )); then
echo "Missing textcollector directory argument"
exit 1
fi
TEXTFILE_COLLECTOR_DIR=${1}
PROM_FILE=$TEXTFILE_COLLECTOR_DIR/fastly.prom
TMP_FILE=$PROM_FILE.$$
[ -e $TMP_FILE ] && rm -f $TMP_FILE
trap "rm -f $TMP_FILE" EXIT
MTD="$(curl --silent \
--show-error \
--fail \
--header @<(echo Fastly-Key: ${fastly_token}) \
--header "Accept: application/json" \
"https://api.fastly.com/billing/v3/invoices/month-to-date" | jq '.monthly_transaction_amount | tonumber')"
echo "# HELP fastly_mtd_estimate_dollars_total month-to-date billing estimate" >> $TMP_FILE
echo "# TYPE fastly_mtd_estimate_dollars_total gauge" >> $TMP_FILE
echo "fastly_mtd_estimate_dollars_total $MTD" >> $TMP_FILE
mv -f $TMP_FILE $PROM_FILE