def main(): config = Config() ds = DiskSpace(path=config.path) percent_limit = config.threshold if ds.used_over_limit(percent_limit): message = "Your hard disk is getting full. You are using %s%% of the available space."\ "(Warning Threshold: %s%%)" % (ds.percent_used(), percent_limit) + "\n" message += "Total: %s" % ds.humanize_bytes(ds.bytes_capacity(), 1000) + "\n" message += "Used: %s" % ds.humanize_bytes(ds.bytes_used(), 1000) + "\n" message += "Avail: %s" % ds.humanize_bytes(ds.bytes_free(), 1000) sendMail = SendMail(config) sendMail.setMessage(message) sendMail.send()
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys import requests import json sys.path.insert(0, '../') from diskspace import DiskSpace ds = DiskSpace() free = (ds.percent_free()) print free def send_request(): # call function # POST https://api.particle.io/v1/devices/330048000547343233323032/led try: response = requests.post( url="https://api.particle.io/v1/devices/330048000547343233323032/led", headers={ "Authorization": "Bearer ad84d0f05262309428b7fa8595c360a33609537b", "Content-Type": "application/json", }, data=json.dumps({ "led": free }) ) print('Response HTTP Status Code: {status_code}'.format( status_code=response.status_code))
Avail: 22.77GB The idea would be to put this in a Cron Job and have it email you when the free disk space is lower than "n" percent. """ import sys import requests import json sys.path.insert(0, '../') from diskspace import DiskSpace ds = DiskSpace() perc_arg = len(sys.argv) > 1 and sys.argv[1] or None percent_limit = perc_arg or 20 def send_request(): # call function # POST https://api.particle.io/v1/devices/330048000547343233323032/led try: response = requests.post( url="https://api.particle.io/v1/devices/330048000547343233323032/led", headers={ "Authorization": "Bearer ad84d0f05262309428b7fa8595c360a33609537b", "Content-Type": "application/json", },