src/engine/tools/api-communication/README.md
The library provides a client interface to communicate locally with wazuh-engine.
├── api-communication/
| └── src
| └── api-communication
| └── proto
| └── __init__.py
| └── components_pb2.py
| └── components_pb2.pyi
| └── __init_.py
| └── client.py
| └── command.py
| └── README.md
| └── setup.cfg
| └── setup.py
To install the library, run the following command:
`pip3 install tools/api-communication/`
The library provides a client interface to communicate with wazuh-engine.
For example, to get a resource from the engine, you can use the following code:
# Import the APIClient class
from api_communication.client import APIClient
# Import the proto file, with the request and response messages
from api_communication.proto.catalog_pb2 import ResourceGet_Request, ResourceGet_Response
client = APIClient()
client.connect()
# Create the json request
json_request = dict()
json_request['namespaceid'] = args['namespace']
json_request['name'] = args['asset']
json_request['format'] = args['format']
# Create the api request
try:
client = APIClient(api_socket)
error, response = client.jsend(
json_request, ResourceGet_Request(), ResourceGet_Response())
if error:
sys.exit(f'Error getting asset or collection: {error}')
print(response['content'])
except Exception as e:
sys.exit(f'Error getting asset or collection: {e}')
return 0