Send Slack notifications when a partition size exceeds a threshold
Here is a script to send notifications to a Slack channel when a server’s main partition size exceeds a safe threshold. It is tested on Red Hat 7 and macOS Mojave.
- Set up an incoming webhook for a Slack channel.
- Install the python
requestsmodule on the server or computer on which the script will be run. Either:
pip install requestson macOS
yum install python-requestson Red Hat 7
Add your Slack webhook to the script:
slack_webhook_url = 'https://hooks.slack.com/services/XXXXXXX/YYYYYYYY/ZZZZZZZZZ'
Set the percentage threshold for partition capacity. I set it to 80%:
threshold = 80
If you need to add more partitions to the search, add them to the
partitions = ['/', '/data', '/boot']
- If running on a Red Hat server, copy the script to
/etc/cron.dailydepending on how often you want notifications. If running on macOS, you will have to create a LaunchDaemon to run the script on an hourly basis (for an example on how to do that, see the answer to this StackOverflow question).