A Python script to monitor SDRTrunk application status, log files, and audio recordings with automatic heartbeat reporting and Telegram notifications.
- Universal Path Detection: Automatically detects the current Windows username and SDRTrunk paths
- Process Monitoring: Checks if SDRTrunk is running
- Log File Monitoring: Scans
sdrtrunk_app.logfor errors after monitor start (ignores old errors) - Audio Quality Monitoring (Optional): Checks audio files in recordings folder and deletes after processing (can be disabled)
- Heartbeat Reporting: Sends status updates to configured endpoint
- Telegram Notifications: Sends instant alerts to Telegram channel when issues are detected
- Configurable: All settings stored in JSON configuration file
- Ignore List: Can ignore specific log lines to prevent false alerts
- Python 3.7 or higher
- Windows OS
- SDRTrunk installed in
C:\Users\{username}\SDRTrunk
Run install_everything.bat as an ADMINISTRATOR. This will:
- Check for Python and install it if missing
- Install all required Python packages
- Does NOT start the monitor automatically (run it manually after install)
-
Install Python dependencies:
pip install -r requirements.txt
-
Configure the monitor:
- Edit
monitor_config.jsonand update theheartbeat_urlto your endpoint - Adjust error keywords, ignore keywords, check intervals, and other settings as needed
- Edit
The monitor_config.json file contains all configurable settings:
{
"heartbeat_url": "https://your-heartbeat-endpoint.com/heartbeat",
"error_keywords": [
"ERROR", "Exception", "No Tuner Available", "Error getting source", "failed", "failed to load", "Pipe error", "USB error", "LibUsbException", "NullPointerException", "IndexOutOfBoundsException", "Couldn't design final output low pass filter", "AMBE CODEC failed", "JMBE audio conversion library failed", "No audio", "Audio error", "Buffer overflow", "Disk full"
],
"ignore_keywords": [
"FrequencyErrorCorrectionManager - Auto-Correcting Tuner PPM"
],
"monitor_audio": true,
"check_interval_seconds": 60,
"audio_quality_threshold_seconds": 5.0,
"max_audio_age_hours": 4,
"process_name": "sdrtrunk",
"telegram": {
"enabled": false,
"bot_token": "your_telegram_bot_token_here",
"channel_id": "your_telegram_channel_id_here",
"computer_name": "SDRTrunk-Monitor"
}
}- heartbeat_url: URL to send heartbeat status updates
- error_keywords: List of keywords that indicate errors in log files
- ignore_keywords: List of keywords/phrases to ignore in log lines (prevents false alerts)
- monitor_audio: Set to
trueto enable audio file monitoring and quality checks, orfalseto disable all audio monitoring - check_interval_seconds: How often to run monitoring checks (default: 60 seconds)
- audio_quality_threshold_seconds: Minimum audio duration to consider "good quality"
- max_audio_age_hours: Maximum age of audio files before deletion or before heartbeat is blocked (if audio monitoring is enabled)
- process_name: Name of the SDRTrunk process to monitor (substring match)
- telegram: Telegram notification settings
- enabled: Enable/disable Telegram notifications
- bot_token: Your Telegram bot token (get from @BotFather)
- channel_id: Your Telegram channel ID
- computer_name: Custom name for your computer (appears in messages)
- Open Telegram and search for
@BotFather - Send
/newbotcommand - Follow the prompts to create your bot
- Save the bot token (format:
1234567890:ABCdefGHIjklMNOpqrsTUVwxyz)
- Add your bot to your channel as an admin
- Send a message in the channel
- Visit:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates - Find the
chat_idfor your channel (usually starts with-100)
Update your monitor_config.json:
"telegram": {
"enabled": true,
"bot_token": "1234567890:ABCdefGHIjklMNOpqrsTUVwxyz",
"channel_id": "-1001234567890",
"computer_name": "My-SDRTrunk-Server"
}Run the test script to verify your setup:
python test_telegram.pypython sdrtrunk_monitor.pyDouble-click start_monitor.bat or run it from command prompt.
- Run
install_everything.batas administrator - After install, start the monitor with:
python sdrtrunk_monitor.py
You can set up the script to run as a Windows service using tools like:
- NSSM (Non-Sucking Service Manager)
- Windows Task Scheduler
The script automatically detects:
- Current Windows username
- SDRTrunk base path:
C:\Users\{username}\SDRTrunk - Logs path:
C:\Users\{username}\SDRTrunk\logs - Recordings path:
C:\Users\{username}\SDRTrunk\recordings
- Process Check: Verifies SDRTrunk is running
- Log Analysis: Scans
sdrtrunk_app.logfor errors after monitor start (ignores old errors) - Audio Processing (if enabled):
- Checks audio quality (duration ≥ threshold)
- Deletes processed files
- Tracks processing activity
- Heartbeat Decision: Determines if conditions are met for heartbeat
- Status Report: Sends heartbeat if all checks pass
- Telegram Notifications: Sends alerts when issues are detected
Heartbeat is sent ONLY when:
- ✅ SDRTrunk process is running
- ✅ No errors found in log file after monitor start (excluding ignored lines)
- ✅ Audio has been processed within last N hours (if audio monitoring is enabled)
The script monitors for these types of issues and sends Telegram alerts:
- ❌ SDRTrunk process not running
⚠️ Error keywords in log files (excluding ignored lines)⚠️ No audio processing for >N hours (if audio monitoring is enabled)⚠️ Audio quality issues (files too short, if enabled)
The script creates sdrtrunk_monitor.log with detailed monitoring information:
- Process status
- Log file errors
- Audio processing results
- Heartbeat success/failure
- Configuration warnings
-
"Log file not found"
- Ensure SDRTrunk is configured to log to
sdrtrunk_app.log - Check that the logs directory exists
- Ensure SDRTrunk is configured to log to
-
"Recordings directory not found"
- Verify SDRTrunk recordings path is correct
- Create the directory if it doesn't exist
-
"Heartbeat failed"
- Check your heartbeat URL is correct and accessible
- Verify network connectivity
- Check server endpoint is responding
-
"SDRTrunk is not running"
- Verify the process name in config matches actual SDRTrunk process
- Check if SDRTrunk is actually running
To see more detailed output, modify the logging level in the script:
logging.basicConfig(level=logging.DEBUG, ...)Edit monitor_config.json and add keywords to the error_keywords array:
"error_keywords": [
"ERROR", "Exception", "No Tuner Available", ...
]Edit monitor_config.json and add keywords/phrases to the ignore_keywords array:
"ignore_keywords": [
"FrequencyErrorCorrectionManager - Auto-Correcting Tuner PPM",
"YOUR_OTHER_IGNORE_PHRASE"
]Set monitor_audio to false in the config to skip all audio file checks and related heartbeat conditions:
"monitor_audio": falseModify check_interval_seconds in the config:
"check_interval_seconds": 30 // Check every 30 secondsChange the minimum audio duration:
"audio_quality_threshold_seconds": 3.0 // Minimum 3 seconds- The script reads log files and audio files but doesn't modify them (except deletion)
- Heartbeat payload includes username and status information
- Consider using HTTPS for heartbeat URLs in production
- Review error keywords and ignore keywords to avoid false positives
For issues or questions:
- Check the log file for detailed error messages
- Verify all paths and configurations
- Test heartbeat URL manually before running
- Ensure Python dependencies are installed correctly