t5i! DdZddlmZddlmZmZddlmZGddZy)z Restic Backup Monitor (Lightweight) Checks last backup snapshot age by examining file modification times. Uses: filesystem checks only (no restic command) Repository: /mnt/backup-hdd/flotta-backup )Path)datetimetimezone)Dictc,eZdZdZedZdefdZy) BackupMonitorz;Monitor Restic backup status (lightweight file-based check)z'/mnt/backup-hdd/flotta-backup/snapshotsreturnc z |jjsdddS|jjsdddS|jjDcgc]/}|j r|j j ds|1}}|sddddSt|d }|jj}tj|tj }tjtj}||z jd z }|d krd}n |dkrd}nd}|t!|dt#||j%ddt!|dt#|ddScc}w#t&$rdddcYSt($r(} dt+| dt+| dddcYd} ~ Sd} ~ wwxYw)a Check backup status by examining snapshot files. Tests: 1. Snapshot directory accessible 2. Last snapshot file < 30h old (daily at 3 AM, allow margin) 3. Snapshot file count reasonable Returns: { 'status': 'healthy' | 'warning' | 'critical', 'last_snapshot_age_hours': X, 'snapshot_count': Y, 'last_snapshot_date': '...', 'message': '...' } criticalzSnapshot directory not found)statusmessagez Snapshot path is not a directory.rzNo backup snapshots found)r snapshot_countr c6|jjS)N)statst_mtime)fs F/mnt/ssd/data/python-lab/DaemonControl/modules/fleet/backup_monitor.pyz%BackupMonitor.check..Bs@Q@Q)key)tzihealthy0warningz%Y-%m-%d %H:%Mz Last backup zh ago (z snapshots))r last_snapshot_age_hoursrlast_snapshot_dater z/Permission denied accessing snapshots directoryzBackup check error: N2)r errorr ) SNAPSHOT_DIRexistsis_diriterdiris_filename startswithmaxrrr fromtimestamprutcnow total_secondsroundlenstrftimePermissionError Exceptionstr) selfrsnapshot_fileslatest_snapshotmtime last_timer, age_hoursr es rcheckzBackupMonitor.checks$@ $$++-(= $$++-(A ,,44699;qvv'8'8'=N "(&':".6QRO$((*33E ..uFI,,x||,Cy779D@I2~"R"#!+0A+>"%n"5&/&8&89I&J)% *:);73~CVBWWbc  ?N #L  #Q1#a&"+?  sGE:E:E:4E5 E:CE:5E::F: F:F5/F:5F:N)__name__ __module__ __qualname____doc__rr"rr;rrrrsEABLRtRrrN)r?pathlibrrrtypingrrr@rrrCs!'WWr