Skip to content

Instantly share code, notes, and snippets.

@maxpoletaev
Last active May 9, 2019 08:56
Show Gist options
  • Save maxpoletaev/57291ce6f461f52b4739818a40552f6c to your computer and use it in GitHub Desktop.
Save maxpoletaev/57291ce6f461f52b4739818a40552f6c to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
VSCALE_TOKEN=""
SLACK_WEBHOOK_URL=""
MIN_BALANCE=20000
log() {
ts=$(date '+%Y-%m-%d %H:%M:%S')
echo "$ts INFO $1"
}
log "Getting balance..."
balance=$(curl --silent 'https://api.vscale.io/v1/billing/balance' -H "X-Token: $VSCALE_TOKEN" | jq -r .balance)
if [[ $balance == "" ]]; then
log "Unable to get balance"
exit 1
fi
log "Current balance is $balance"
log "Minimal balance is $MIN_BALANCE"
if (( "$balance" <= "$MIN_BALANCE" )); then
balance_rub=$((balance/100))
log "Sending notification to Slack..."
text="На vscale деньги заканчиваются, осталось $balance_rub руб."
curl --silent -X POST -d "{\"text\": \"$text\", \"username\": \"Vscale.io\"}" $SLACK_WEBHOOK_URL
fi
log "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment