Merge pull request #61 from NebulousLabs/health-script-cleanup

Check allocation not spent in allowance. Cleanup msg format
This commit is contained in:
Marcin Jachymiak 2020-03-06 14:04:32 -05:00 committed by GitHub
commit 7c5303929e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View File

@ -135,22 +135,22 @@ async def check_health():
allowance = renter_get['settings']['allowance'] allowance = renter_get['settings']['allowance']
allowance_funds = int(allowance['funds']) allowance_funds = int(allowance['funds'])
unspent_funds = int(renter_get['financialmetrics']['unspent']) allocated_funds = int(renter_get['financialmetrics']['totalallocated'])
spent_funds = allowance_funds - unspent_funds unallocated_funds = allowance_funds - allocated_funds
# Send an alert if there is less than 1 allowance worth of money left. # Send an alert if there is less than 1 allowance worth of money left.
if balance < allowance_funds: if balance < allowance_funds:
await send_msg("Wallet balance running low. Balance: `{}SC` Allowance Funds: `{}SC`".format(balance/sc_precision, allowance_funds/sc_precision), force_notify=True) await send_msg("Wallet balance running low. Balance: `{} SC` Allowance Funds: `{} SC`".format(round(balance/sc_precision), round(allowance_funds/sc_precision)), force_notify=True)
return return
# Alert devs when 1/2 the allowance is gone # Alert devs when 1/2 the allowance is gone
if spent_funds >= unspent_funds: if allocated_funds >= unallocated_funds:
await send_msg("Allowance half spent: \nUnspent: {}\nSpent: {}".format(unspent_funds/sc_precision, spent_funds/sc_precision), force_notify=True) await send_msg("Allowance half spent: \nUnallocated: `{} SC`\nAllocated: `{} SC`".format(round(unallocated_funds/sc_precision), round(allocated_funds/sc_precision)), force_notify=True)
return return
# Send an informational heartbeat if all checks passed. # Send an informational heartbeat if all checks passed.
pretty_renter_get = json.dumps(siac.get_renter(), indent=4) pretty_renter_get = json.dumps(siac.get_renter(), indent=4)
await send_msg("Health checks passed:\n\nWallet Balance: `{}SC`\n\n Renter Info:\n```\n{}\n```".format(balance/sc_precision, pretty_renter_get)) await send_msg("Health checks passed:\n\nWallet Balance: `{} SC`\n\n Renter Info:\n```\n{}\n```".format(round(balance/sc_precision), pretty_renter_get))
async def run_checks(): async def run_checks():

View File

@ -5,6 +5,7 @@ sudo apt-get update
sudo apt-get -y install python3-pip sudo apt-get -y install python3-pip
pip3 install discord.py pip3 install discord.py
pip3 install python-dotenv
downloadCheck="0 0,8,16 * * * ~/skynet-webportal/setup-scripts/health-checker.py ~/.sia/sia.env" downloadCheck="0 0,8,16 * * * ~/skynet-webportal/setup-scripts/health-checker.py ~/.sia/sia.env"
uploadCheck="0 0,8,16 * * * ~/skynet-webportal/setup-scripts/health-checker.py ~/.sia/sia-upload.env" uploadCheck="0 0,8,16 * * * ~/skynet-webportal/setup-scripts/health-checker.py ~/.sia/sia-upload.env"