logs in swos

This commit is contained in:
Mateusz Gruszczyński
2026-04-13 12:18:23 +02:00
parent 4d2356f60b
commit d661079bd1
3 changed files with 95 additions and 4 deletions

View File

@@ -16,6 +16,10 @@ from app.services.settings_service import settings_service
class BackupService:
def _device_label(self, router: Router) -> str:
platform = 'SwitchOS' if router.device_type == 'switchos' else 'RouterOS'
return f'{platform} device {router.name}'
def _router_for_user(self, db: Session, user: User, router_id: int) -> Router:
router = db.query(Router).filter(Router.id == router_id, Router.owner_id == user.id).first()
if not router:
@@ -218,14 +222,14 @@ class BackupService:
db.add(backup)
db.commit()
db.refresh(backup)
log_service.add(db, f'Binary backup OK for device {router.name}')
log_service.add(db, f'Binary backup OK for {self._device_label(router)}')
notification_service.notify(settings, f'Backup {router.name} OK', True)
return backup
except HTTPException:
raise
except Exception as exc:
notification_service.notify(settings, f'Backup {router.name} FAIL: {exc}', False)
log_service.add(db, f'Binary backup FAILED for device {router.name}: {exc}')
log_service.add(db, f'Binary backup FAILED for {self._device_label(router)}: {exc}')
raise HTTPException(status_code=500, detail=str(exc)) from exc
def upload_backup_to_router(self, db: Session, user: User, router_id: int, backup_id: int):