Provides the WazuhApiConnection class which simplifies the
communication with the wazuh API.
- class WazuhApiConnection(wazuh_api_url: str, wazuh_api_username: str, wazuh_api_password: str, wazuh_api_insecure: bool = False, legacy_auth: bool = False, token_lifetime: int = 840, rate_limiter: RateLimiter = None)#
Bases:
objectThis class allows to safely perform requests against the Wazuh API with guardrails that automatically handle the most common faults, such as expired authorization tokens and exceeded rate limits.
- get_api_info() WazuhApiInfo#
Retrieves the potentially cached Wazuh API information. Alternatively it will trigger the authentication process which will fetch the information.
- Returns:
Object representation of the received Wazuh API info.
- Return type:
- Raises:
WazuhApiError – Exception which contains the error response’s details.
- get_stream(path: str, page_size: int = 500, parameters: dict[slice(<class 'str'>, <built-in function any>, None)] | None = None, mapping: ~typing.Callable[[any], T] = <function WazuhApiConnection.<lambda>>) Iterator#
Exhaustively stream all entries of HTTP GET API endpoints which respond with pages of entries. (e.g. List users: GET /security/users)
- Parameters:
path (str) – Path to the API endpoint.
page_size (int, optional) –
Optional page size limitation. Defines the maximum number of entries that will be returned for each request.
Default: 500
parameters (dict[str:any], optional) – Optional request parameter dictionary. Default value: {}
map (Callable[T]) –
Mapping function which will be applied to every item.
Default: lambda raw_value: raw_value
- Returns:
Iterator of the requested entries.
- Return type:
Iterator[T]
- Raises:
WazuhApiError – Exception which contains the error response’s details.
- request(method: HTTPMethod, path: str, parameters: dict[slice(<class 'str'>, <built-in function any>, None)]=None, payload: str = None) WazuhResponse#
Allows to perform a request against the Wazuh API. It will automatically refresh the authorization token if required and ensure that the rate limit won’t be exceeded.
- Parameters:
method (HTTPMethod) – HTTP request method. Supported values: {GET, PUT, POST, DELETE}
path (str) – Path to the API endpoint.
parameters (str, optional) – Optional request parameter dictionary. Default value: None
parameters – Optional payload. Default value: None
- Returns:
Object representation of the json response.
- Return type:
- Raises:
WazuhApiError – Exception which contains the error response’s details.
HTTPError – Non Wazuh API related exception regarding the request.