| 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.collector import ConfiguredInputsResponse |
| 7 | from app.connectors.graylog.schema.collector import GraylogIndicesResponse |
| 8 | from app.connectors.graylog.schema.collector import GraylogInputsResponse |
| 9 | from app.connectors.graylog.schema.collector import RunningInputsResponse |
| 10 | from app.connectors.graylog.services.collector import get_indices_full |
| 11 | from app.connectors.graylog.services.collector import get_inputs |
| 12 | from app.connectors.graylog.services.collector import get_inputs_configured |
| 13 | from app.connectors.graylog.services.collector import get_inputs_running |
| 14 | |
| 15 | # App specific imports |
| 16 | |
| 17 | |
| 18 | graylog_collector_router = APIRouter() |
| 19 | |
| 20 | |
| 21 | @graylog_collector_router.get( |
| 22 | "/indices", |
| 23 | response_model=GraylogIndicesResponse, |
| 24 | description="Get all indices", |
| 25 | dependencies=[Security(AuthHandler().require_any_scope("admin", "analyst"))], |
| 26 | ) |
| 27 | async def get_all_indices() -> GraylogIndicesResponse: |
| 28 | """ |
| 29 | Fetches all graylog indices. |
| 30 | |
| 31 | Returns: |
| 32 | GraylogIndicesResponse: The response containing the graylog indices. |
| 33 | """ |
| 34 | logger.info("Fetching all graylog indices") |
| 35 | return await get_indices_full() |
| 36 | |
| 37 | |
| 38 | @graylog_collector_router.get( |
| 39 | "/inputs", |
| 40 | response_model=GraylogInputsResponse, |
| 41 | description="Get all inputs", |
| 42 | dependencies=[Security(AuthHandler().require_any_scope("admin", "analyst"))], |
| 43 | ) |
| 44 | async def get_all_inputs() -> GraylogInputsResponse: |
| 45 | """ |
| 46 | Fetches all graylog inputs. |
| 47 | |
| 48 | Returns: |
| 49 | GraylogInputsResponse: The response containing all graylog inputs. |
| 50 | """ |
| 51 | logger.info("Fetching all graylog inputs") |
| 52 | return await get_inputs() |
| 53 | |
| 54 | |
| 55 | @graylog_collector_router.get( |
| 56 | "/inputs/running", |
| 57 | response_model=RunningInputsResponse, |
| 58 | description="Get all running inputs", |
| 59 | dependencies=[Security(AuthHandler().require_any_scope("admin", "analyst"))], |
| 60 | ) |
| 61 | async def get_all_running_inputs() -> RunningInputsResponse: |
| 62 | """ |
| 63 | Fetches all running inputs from Graylog. |
| 64 | |
| 65 | Returns: |
| 66 | A RunningInputsResponse object containing information about all running inputs. |
| 67 | """ |
| 68 | logger.info("Fetching all graylog running inputs") |
| 69 | return await get_inputs_running() |
| 70 | |
| 71 | |
| 72 | @graylog_collector_router.get( |
| 73 | "/inputs/configured", |
| 74 | response_model=ConfiguredInputsResponse, |
| 75 | description="Get all configured inputs", |
| 76 | dependencies=[Security(AuthHandler().require_any_scope("admin", "analyst"))], |
| 77 | ) |
| 78 | async def get_all_configured_inputs() -> ConfiguredInputsResponse: |
| 79 | """ |
| 80 | Fetches all graylog configured inputs. |
| 81 | |
| 82 | Returns: |
| 83 | ConfiguredInputsResponse: The response model containing the configured inputs. |
| 84 | """ |
| 85 | logger.info("Fetching all graylog configured inputs") |
| 86 | return await get_inputs_configured() |