| 1 | from fastapi import APIRouter |
| 2 | from fastapi import Security |
| 3 | from loguru import logger |
| 4 | |
| 5 | from app.auth.utils import AuthHandler |
| 6 | from app.connectors.graylog.schema.monitoring import GraylogEventNotificationsResponse |
| 7 | from app.connectors.graylog.schema.monitoring import GraylogMessagesResponse |
| 8 | from app.connectors.graylog.schema.monitoring import GraylogMetricsResponse |
| 9 | from app.connectors.graylog.services.monitoring import get_event_notifications |
| 10 | from app.connectors.graylog.services.monitoring import get_messages |
| 11 | from app.connectors.graylog.services.monitoring import get_metrics |
| 12 | |
| 13 | # App specific imports |
| 14 | |
| 15 | |
| 16 | graylog_monitoring_router = APIRouter() |
| 17 | |
| 18 | |
| 19 | @graylog_monitoring_router.get( |
| 20 | "/messages", |
| 21 | response_model=GraylogMessagesResponse, |
| 22 | description="Get all messages", |
| 23 | dependencies=[Security(AuthHandler().require_any_scope("admin", "analyst"))], |
| 24 | ) |
| 25 | async def get_all_messages(page_number: int = 1) -> GraylogMessagesResponse: |
| 26 | """ |
| 27 | Retrieve all graylog messages. |
| 28 | |
| 29 | Args: |
| 30 | page_number (int, optional): The page number to retrieve. Defaults to 1. |
| 31 | |
| 32 | Returns: |
| 33 | GraylogMessagesResponse: The response containing the graylog messages. |
| 34 | """ |
| 35 | logger.info("Fetching all graylog messages") |
| 36 | logger.info(f"Page number: {page_number}") |
| 37 | return await get_messages(page_number) |
| 38 | |
| 39 | |
| 40 | @graylog_monitoring_router.get( |
| 41 | "/metrics", |
| 42 | response_model=GraylogMetricsResponse, |
| 43 | description="Get all metrics", |
| 44 | dependencies=[Security(AuthHandler().require_any_scope("admin", "analyst"))], |
| 45 | ) |
| 46 | async def get_all_metrics() -> GraylogMetricsResponse: |
| 47 | """ |
| 48 | Fetches all graylog metrics. |
| 49 | |
| 50 | Returns: |
| 51 | GraylogMetricsResponse: The response containing all the metrics. |
| 52 | """ |
| 53 | logger.info("Fetching all graylog metrics") |
| 54 | return await get_metrics() |
| 55 | |
| 56 | |
| 57 | @graylog_monitoring_router.get( |
| 58 | "/event_notifications", |
| 59 | response_model=GraylogEventNotificationsResponse, |
| 60 | description="Get all event notifications", |
| 61 | dependencies=[Security(AuthHandler().require_any_scope("admin", "analyst"))], |
| 62 | ) |
| 63 | async def get_all_event_notifications() -> GraylogEventNotificationsResponse: |
| 64 | """ |
| 65 | Fetches all graylog event notifications. |
| 66 | |
| 67 | Returns: |
| 68 | GraylogEventNotificationsResponse: The response containing all the event notifications. |
| 69 | """ |
| 70 | logger.info("Fetching all graylog event notifications") |
| 71 | return await get_event_notifications() |