logs in swos
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user