If your account does not have credits, you instances may be suspended, which may not be what you want. To get notified before the account runs out of credit, you could set up a script that automatically checks that for you.
Vultr API Support
Vultr provides the API to return the account information, so you will first need to enable API support in your dashboard. Then, you will also add the IPv4/IPv6 address that you want to make API calls to the white list.
JSON parser
You will need JSON parser because the API returns JSON data. You can install package jq on Linux shell by running
1 2 3 | apt-get install jq # e.g. Ubuntu # or yum install jq # e.g. Fedora |
apt-get install jq # e.g. Ubuntu # or yum install jq # e.g. Fedora
Write your Script Checker
Use your favorite text-editor e.g. VIM to create the following script e.g. check_balance.sh, please remember to update your API key and email address. The script will send a email when the account is below $5 credit (can be changed accordingly).
1 2 3 4 5 6 7 8 | #!/bin/bash threshold=-5 # -5 means $5 in credit balance=`curl -H 'API-Key: YOUR_KEY' https://api.vultr.com/v1/account/info | jq -r '.balance'` > /dev/null 2>&1 if (( "$balance" >= "$threshold" )); then echo "Please Top Up Your Vultr Account!" mail -s "Account Low Credit Warnings" youremail@example.com fi |
#!/bin/bash threshold=-5 # -5 means $5 in credit balance=`curl -H 'API-Key: YOUR_KEY' https://api.vultr.com/v1/account/info | jq -r '.balance'` > /dev/null 2>&1 if (( "$balance" >= "$threshold" )); then echo "Please Top Up Your Vultr Account!" mail -s "Account Low Credit Warnings" youremail@example.com fi
Setup Crontab
Now, you can add this to your crontab by crontab -e. It is recommended to run this hourly to match the billing update of Vultr.
–EOF (The Ultimate Computing & Technology Blog) —
loading...
Last Post: How to Add Next and Previous Posts Links in WordPress?
Next Post: PPAP in C++ and Javascript for Beginner