Plex Backup Monitoring Integration #2

Open
opened 2025-10-29 19:44:53 -07:00 by peterwood · 0 comments
Owner

Originally created by @acedanger on GitHub (May 27, 2025).

Plex Backup Monitoring Integration

Issue Summary

Integrate the Telegram bot with the comprehensive Plex backup system to provide real-time monitoring, status reporting, and control capabilities.

Description

Develop Telegram bot commands that interface with the existing Plex backup scripts to provide monitoring, status reporting, and basic control functionality. This will leverage the extensive JSON logging and monitoring capabilities already built into the Plex backup system.

Requirements

Command Implementation

  • /plex_status - Show current Plex backup status
  • /plex_last - Display last backup summary
  • /plex_health - Run health check and integrity validation
  • /plex_monitor - Start/stop real-time monitoring
  • /plex_logs - Show recent backup logs (last 10 entries)
  • /plex_performance - Display performance metrics
  • /plex_schedule - Show backup scheduling status

Advanced Commands (Admin only)

  • /plex_backup_now - Trigger immediate backup
  • /plex_validate - Run backup validation
  • /plex_repair - Attempt database repair if issues found
  • /plex_restore - List available backups for restoration

Integration Points

Existing Scripts to Interface With

# Main backup script with extensive options
/home/acedanger/shell/plex/backup-plex.sh

# Real-time monitoring dashboard
/home/acedanger/shell/plex/monitor-plex-backup.sh

# Backup validation and health checks
/home/acedanger/shell/plex/validate-plex-backups.sh

# Restoration capabilities
/home/acedanger/shell/plex/restore-plex.sh

Log Files to Monitor

# JSON performance logs
/home/acedanger/shell/logs/plex-backup-performance.json
/home/acedanger/shell/plex/logs/plex-backup-performance.json

# Main backup logs
/home/acedanger/shell/logs/plex-backup.json
/home/acedanger/shell/plex/logs/plex-backup.json

# Validation logs
/home/acedanger/shell/plex/logs/backup-validation-*.log

Technical Implementation

Status Monitoring

def get_plex_status():
    """Parse JSON logs to determine current backup status"""
    # Read latest performance log
    # Check backup completion status
    # Return formatted status message

def get_last_backup_summary():
    """Get summary of most recent backup"""
    # Parse latest JSON log entry
    # Extract key metrics (size, duration, files)
    # Format for Telegram display

Health Checking

def run_plex_health_check():
    """Execute health check and return results"""
    # Run validate-plex-backups.sh
    # Parse output for issues
    # Return health status with recommendations

Performance Monitoring

def get_plex_performance():
    """Extract performance metrics from JSON logs"""
    # Parse performance JSON files
    # Calculate trends and averages
    # Return formatted metrics

Command Examples

/plex_status

🟢 Plex Backup Status

Last Backup: 2025-05-27 02:00:15
Status: ✅ Completed Successfully
Duration: 2m 34s
Files Backed Up: 47
Total Size: 1.2 GB

Next Scheduled: 2025-05-28 02:00:00
Health: ✅ All systems operational

/plex_performance

📊 Plex Backup Performance

Recent Averages (7 days):
├── Duration: 2m 45s (±15s)
├── File Count: 45 (±3)
├── Backup Size: 1.1 GB (±0.2 GB)
└── Success Rate: 100%

Trends:
📈 Backup size growing slowly
⚡ Performance stable
✅ No issues detected

/plex_health

🔍 Plex Health Check Results

Database Integrity: ✅ PASS
Backup Freshness: ✅ PASS (2 hours ago)
Storage Space: ✅ PASS (89% available)
Scheduling: ✅ PASS (Next in 22h 30m)

Recent Issues: None
Recommendations: All systems healthy

File Structure

telegram/bot/commands/
├── plex/
│   ├── __init__.py
│   ├── status.py           # Status and monitoring commands
│   ├── health.py           # Health check commands
│   ├── control.py          # Backup control commands (admin)
│   └── performance.py      # Performance monitoring
└── utils/
    ├── plex_parser.py      # JSON log parsing utilities
    └── script_runner.py    # Script execution utilities

Security Considerations

  • Admin commands require elevated permissions
  • Input validation for all parameters
  • Safe script execution with proper error handling
  • No direct file system access from bot commands

Success Criteria

  • All status commands working correctly
  • JSON log parsing functional
  • Health monitoring integrated
  • Performance metrics displayed properly
  • Admin controls secured and functional
  • Error handling robust

Dependencies

  • Depends on: Issue #01 (Core Infrastructure)
  • Python subprocess module for script execution
  • JSON parsing capabilities
  • File system monitoring utilities

Estimated Effort

Time: 3-4 days
Complexity: Medium-High

Testing Requirements

  • Test with various backup states (running, completed, failed)
  • Verify JSON parsing with different log formats
  • Test admin command authorization
  • Validate error handling for missing files/failed scripts
  • Performance testing with large log files

Notes

The Plex backup system is the most mature and feature-rich of the three backup systems, with extensive JSON logging, performance monitoring, and validation capabilities. This integration should serve as the template for the other backup system integrations.

Originally created by @acedanger on GitHub (May 27, 2025). # Plex Backup Monitoring Integration ## Issue Summary Integrate the Telegram bot with the comprehensive Plex backup system to provide real-time monitoring, status reporting, and control capabilities. ## Description Develop Telegram bot commands that interface with the existing Plex backup scripts to provide monitoring, status reporting, and basic control functionality. This will leverage the extensive JSON logging and monitoring capabilities already built into the Plex backup system. ## Requirements ### Command Implementation - [ ] `/plex_status` - Show current Plex backup status - [ ] `/plex_last` - Display last backup summary - [ ] `/plex_health` - Run health check and integrity validation - [ ] `/plex_monitor` - Start/stop real-time monitoring - [ ] `/plex_logs` - Show recent backup logs (last 10 entries) - [ ] `/plex_performance` - Display performance metrics - [ ] `/plex_schedule` - Show backup scheduling status ### Advanced Commands (Admin only) - [ ] `/plex_backup_now` - Trigger immediate backup - [ ] `/plex_validate` - Run backup validation - [ ] `/plex_repair` - Attempt database repair if issues found - [ ] `/plex_restore` - List available backups for restoration ### Integration Points #### Existing Scripts to Interface With ```bash # Main backup script with extensive options /home/acedanger/shell/plex/backup-plex.sh # Real-time monitoring dashboard /home/acedanger/shell/plex/monitor-plex-backup.sh # Backup validation and health checks /home/acedanger/shell/plex/validate-plex-backups.sh # Restoration capabilities /home/acedanger/shell/plex/restore-plex.sh ``` #### Log Files to Monitor ```bash # JSON performance logs /home/acedanger/shell/logs/plex-backup-performance.json /home/acedanger/shell/plex/logs/plex-backup-performance.json # Main backup logs /home/acedanger/shell/logs/plex-backup.json /home/acedanger/shell/plex/logs/plex-backup.json # Validation logs /home/acedanger/shell/plex/logs/backup-validation-*.log ``` ### Technical Implementation #### Status Monitoring ```python def get_plex_status(): """Parse JSON logs to determine current backup status""" # Read latest performance log # Check backup completion status # Return formatted status message def get_last_backup_summary(): """Get summary of most recent backup""" # Parse latest JSON log entry # Extract key metrics (size, duration, files) # Format for Telegram display ``` #### Health Checking ```python def run_plex_health_check(): """Execute health check and return results""" # Run validate-plex-backups.sh # Parse output for issues # Return health status with recommendations ``` #### Performance Monitoring ```python def get_plex_performance(): """Extract performance metrics from JSON logs""" # Parse performance JSON files # Calculate trends and averages # Return formatted metrics ``` ### Command Examples #### `/plex_status` ``` 🟢 Plex Backup Status Last Backup: 2025-05-27 02:00:15 Status: ✅ Completed Successfully Duration: 2m 34s Files Backed Up: 47 Total Size: 1.2 GB Next Scheduled: 2025-05-28 02:00:00 Health: ✅ All systems operational ``` #### `/plex_performance` ``` 📊 Plex Backup Performance Recent Averages (7 days): ├── Duration: 2m 45s (±15s) ├── File Count: 45 (±3) ├── Backup Size: 1.1 GB (±0.2 GB) └── Success Rate: 100% Trends: 📈 Backup size growing slowly ⚡ Performance stable ✅ No issues detected ``` #### `/plex_health` ``` 🔍 Plex Health Check Results Database Integrity: ✅ PASS Backup Freshness: ✅ PASS (2 hours ago) Storage Space: ✅ PASS (89% available) Scheduling: ✅ PASS (Next in 22h 30m) Recent Issues: None Recommendations: All systems healthy ``` ### File Structure ``` telegram/bot/commands/ ├── plex/ │ ├── __init__.py │ ├── status.py # Status and monitoring commands │ ├── health.py # Health check commands │ ├── control.py # Backup control commands (admin) │ └── performance.py # Performance monitoring └── utils/ ├── plex_parser.py # JSON log parsing utilities └── script_runner.py # Script execution utilities ``` ### Security Considerations - Admin commands require elevated permissions - Input validation for all parameters - Safe script execution with proper error handling - No direct file system access from bot commands ### Success Criteria - [ ] All status commands working correctly - [ ] JSON log parsing functional - [ ] Health monitoring integrated - [ ] Performance metrics displayed properly - [ ] Admin controls secured and functional - [ ] Error handling robust ## Dependencies - Depends on: Issue #01 (Core Infrastructure) - Python subprocess module for script execution - JSON parsing capabilities - File system monitoring utilities ## Estimated Effort **Time**: 3-4 days **Complexity**: Medium-High ## Testing Requirements - [ ] Test with various backup states (running, completed, failed) - [ ] Verify JSON parsing with different log formats - [ ] Test admin command authorization - [ ] Validate error handling for missing files/failed scripts - [ ] Performance testing with large log files ## Notes The Plex backup system is the most mature and feature-rich of the three backup systems, with extensive JSON logging, performance monitoring, and validation capabilities. This integration should serve as the template for the other backup system integrations.
peterwood added the enhancement label 2025-10-29 19:44:53 -07:00
Sign in to join this conversation.