Commit fdf8eaf6 authored by Andrew Hall's avatar Andrew Hall

Add vultrbal

parent 48a4fded
#!/bin/bash
# This is free and unencumbered software released into the public domain.
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
# of the public at large and to the detriment of our heirs and
# successors. We intend this dedication to be an overt act of
# relinquishment in perpetuity of all present and future rights to this
# software under copyright law.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
# For more information, please refer to <http://unlicense.org>
API_KEY="INSERT_API_KEY_HERE"
if [[ $API_KEY == "INSERT_API_KEY_HERE" ]];
then
echo "You forgot to add an api key!" # short text
echo "You forgot to add an api key!" # long text
exit 0
fi
RESPONSE=$(curl -w "HTTPSTATUS:%{http_code}" -sH "API-Key: $API_KEY" https://api.vultr.com/v1/account/info)
BODY=$(echo $RESPONSE | sed -e 's/HTTPSTATUS\:.*//g')
STATUS=$(echo $RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
#echo $BODY
#echo $STATUS
if [[ $STATUS == "403" ]];
then
echo "You have set an invalid API key!" # short text
echo "You have set an invalid API key!" # long text
elif [[ $STATUS == "503" ]];
then
echo "Excessive requests. Try again later." # short text
echo "Excessive requests. Try again later." # long text
elif [[ $STATUS == "200" ]];
then
bal=$(echo "$BODY" | jq ".balance" | sed -e 's/^"//' -e 's/"$//')
echo "$"$bal
echo "$"$bal
if (( $(bc <<< "$bal < -20") ));
then
echo "#00FF00" # colour - green
elif (( $(bc <<< "$bal > 0") ));
then
echo "#FF0000" # colour - red
else
echo "#FFFF00" # colour - yellow
fi
fi
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment