초기 커밋
This commit is contained in:
36
app/repositories/monitoring_repo.py
Normal file
36
app/repositories/monitoring_repo.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.models.mariadb.monitoring import Alert, AlertRule
|
||||
from app.repositories.base import BaseRepository
|
||||
|
||||
|
||||
class AlertRuleRepository(BaseRepository[AlertRule]):
|
||||
def __init__(self, session: AsyncSession):
|
||||
super().__init__(AlertRule, session)
|
||||
|
||||
async def get_enabled_rules(self) -> list[AlertRule]:
|
||||
stmt = select(AlertRule).where(AlertRule.is_enabled == True) # noqa: E712
|
||||
result = await self.session.execute(stmt)
|
||||
return list(result.scalars().all())
|
||||
|
||||
|
||||
class AlertRepository(BaseRepository[Alert]):
|
||||
def __init__(self, session: AsyncSession):
|
||||
super().__init__(Alert, session)
|
||||
|
||||
async def get_unacknowledged(self, skip: int = 0, limit: int = 50) -> list[Alert]:
|
||||
stmt = (
|
||||
select(Alert)
|
||||
.where(Alert.is_acknowledged == False) # noqa: E712
|
||||
.order_by(Alert.created_at.desc())
|
||||
.offset(skip)
|
||||
.limit(limit)
|
||||
)
|
||||
result = await self.session.execute(stmt)
|
||||
return list(result.scalars().all())
|
||||
|
||||
async def count_active(self) -> int:
|
||||
return await self.count(filters={"is_acknowledged": False})
|
||||
Reference in New Issue
Block a user