For those who use PlexPy and notifications, does anyone have an idea how to be alerted if the Plex media server drive runs low on disk space? As when Plex disk is full, things stop working. Would be amazing to be alerted when the drive reaches a point for me to take action…
I use Pulseway for that (and a few other things) but I don’t think it’s free anymore (they used to have a free option for 5 machines or less).
Thank you WilhelmStroker, however I currently host my system in the cloud; no public access to SNMP.
But PlexPy fully works with alerts like when the host is down or offline, just no feature for low disk space. But you can create a custom script, just don’t know what to write…
I just threw something together using Python. Save the code below as notify_disk_usage.py and add it to the Recently Added script in PlexPy. The code will check the disk usage each time something is added to your server and notify you if the disk usage exceeds the specified threshold. I haven’t really tested the script yet.
You will need to install the psutil and requests modules:
pip install psutil
pip install requests
Code:
import psutil
import requests
import urllib
## EDIT THESE SETTINGS ##
DISK = '/' # The root of the disk
USAGE_THRESHOLD = 95.0
PLEXPY_URL = 'http://localhost:8181/' # Your PlexPy URL
PLEXPY_APIKEY = '#####' # Enter your PlexPy API Key
AGENT_ID = 10 # The PlexPy notifier agent id found here: https://github.com/drzoidberg33/plexpy/blob/master/plexpy/notifiers.py#L43
NOTIFY_SUBJECT = 'PlexPy' # The notification subject
NOTIFY_BODY = 'The Plex disk usage has exceeded %s' % str(USAGE_THRESHOLD) # The notification body
## CODE BELOW ##
# Find disk usage
disk_usage = psutil.disk_usage(DISK)
# Check if the usage exceeds the threshold
if disk_usage.percent >= USAGE_THRESHOLD:
# Send notification to PlexPy using the API
data = {'apikey': PLEXPY_APIKEY,
'cmd': 'notify',
'agent_id': int(AGENT_ID),
'subject': NOTIFY_SUBJECT,
'body': NOTIFY_BODY}
if PLEXPY_URL.endswith('/'): url = PLEXPY_URL + 'api/v2?' + urllib.urlencode(data)
else: url = PLEXPY_URL + '/api/v2?' + urllib.urlencode(data)
r = requests.post(url)
else:
pass