Skip to content

Instantly share code, notes, and snippets.

@JonnyWong16
Last active June 29, 2025 21:43
Show Gist options
  • Save JonnyWong16/f561f06a6266db66dad9 to your computer and use it in GitHub Desktop.
Save JonnyWong16/f561f06a6266db66dad9 to your computer and use it in GitHub Desktop.
Send a Tautulli notification when disk usage exceeds a threshold.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Description: Send a Tautulli notification when disk usage exceeds a threshold.
Author: /u/SwiftPanda16
Requires: psutil, requests
Tautulli script trigger:
* Notify on recently added
Tautulli script arguments:
* Recently Added:
--disk "D:/" --threshold 95.0 --notifier_id 2 --subject "Tautulli" --body "Disk {disk} usage exceeded threshold {threshold}%%."
Usage:
python notify_disk_usage.py --disk "D:/" --threshold 95.0 --notifier_id 2 --subject "Tautulli" --body "Disk {disk} usage exceeded threshold {threshold}%%."
'''
import argparse
import os
import psutil
import requests
TAUTULLI_URL = ''
TAUTULLI_APIKEY = ''
# Environmental Variables
TAUTULLI_URL = os.getenv('TAUTULLI_URL', TAUTULLI_URL)
TAUTULLI_APIKEY = os.getenv('TAUTULLI_APIKEY', TAUTULLI_APIKEY)
## CODE BELOW ##
def disk_exceed_threshold(disk, threshold):
disk_usage = psutil.disk_usage(disk)
return disk_usage.percent >= THRESHOLD
def notify_tautulli(notifier_id, subject, body):
params = {
'apikey': TAUTULLI_APIKEY,
'cmd': 'notify',
'notifier_id': notifier_id,
'subject': subject,
'body': body
}
requests.post(TAUTULLI_URL.rstrip('/') + 'api/v2', params=params)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--disk', required=True)
parser.add_argument('--threshold', type=float, required=True)
parser.add_argument('--notifier_id', type=int, required=True)
parser.add_argument('--subject')
parser.add_argument('--body')
opts = parser.parse_args()
if disk_exceed_threshold(opts.disk, opts.threshold):
subject = opts.subject.format(disk=opts.disk, threshold=opts.threshold)
body = opts.body.format(disk=opts.disk, threshold=opts.threshold)
notify_tautulli(opts.notifier_id, subject, body)
@Laiteux
Copy link

Laiteux commented Jun 29, 2025

def disk_exceed_threshold(disk, threshold):
    disk_usage = psutil.disk_usage(disk)
    return disk_usage.percent >= THRESHOLD

this should be: threshold (instead of THRESHOLD)

@Laiteux
Copy link

Laiteux commented Jun 29, 2025

 requests.post(TAUTULLI_URL.rstrip('/') + 'api/v2', params=params)

and this should be: /api/v2 (missing / readd)

(fixes @timespacedecay error from 7 years ago)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment