This PHP script monitors the disk usage of cPanel accounts under a WHM reseller, sending consolidated alerts via Telegram when accounts exceed a specified threshold.
- Reseller-Specific Monitoring: Only checks accounts owned by the specified reseller.
- Telegram Notifications: Sends well-formatted, consolidated alerts to a Telegram chat or channel.
- Configurable Threshold: Set a custom disk usage percentage to trigger alerts.
- Robust API Handling: Gracefully handles various WHM API response formats and errors.
- Detailed Logging: Logs all actions and errors to a file for easy debugging.
- CLI Interface: Easy to run from the command line or a cron job.
- Test Modes: Includes options to test both WHM API and Telegram connections.
- PHP 7.4 or higher
- cURL extension for PHP
- WHM reseller account with API access
- A Telegram bot and chat/channel ID
-
Clone the repository or download the script:
git clone https://github.com/Freekers/whm-reseller-telegram-disk-monitor.git cd whm-reseller-telegram-disk-monitor -
Configure the script (
disk_usage_monitor.php):Open
disk_usage_monitor.phpand fill in your details in theConfigclass:WHM_HOST: Your server's hostname.WHM_USER: Your WHM reseller username.WHM_API_TOKEN: Your WHM API token. You can generate one in WHM -> Development -> Manage API Tokens. The token needsaccount-summaryandlist-acctspermissions. For security, it's recommended to whitelist the IP address that will be running the script.TELEGRAM_BOT_TOKEN: Your Telegram bot token from @BotFather.TELEGRAM_CHAT_ID: The ID of the chat or channel where you want to receive alerts. You can get this from @userinfobot.DEFAULT_THRESHOLD: The disk usage percentage that triggers an alert.TIMEZONE: The timezone for timestamps. A list of supported timezones can be found here.
The script is designed to be run from the command line or via a cron job.
To run a manual check with the settings from your Config class:
php disk_usage_monitor.php-
--test-telegram: Send a test message to your configured Telegram chat to verify the connection.php disk_usage_monitor.php --test-telegram
-
--helpor-h: Display the help message.
To automate the monitoring, set up a cron job in your cPanel.
-
Find the full path to your PHP executable. You can usually find this by running
which phpin an SSH session or by checking your cPanel's "Select PHP Version" page. -
Go to cPanel -> Advanced -> Cron Jobs.
-
Add a new cron job with the following command, adjusting the paths as necessary:
/usr/local/bin/php /home/your_cpanel_user/path/to/disk_usage_monitor.php
Example Cron Schedule (runs daily at 2:00 AM):
0 2 * * *
This project is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. See the LICENSE file for details.
