2.7. API
2.7.1. Introduction
Note
The list of endpoints is given in the Endpoints list.
The execution of these endpoints can be done:
- Via SWAGGER (Use via the swagger GUI)This allows the use of endpoints and to understand its configuration and to test its execution and analyze its results
- Via CURL (Use via CURL)This allows to execute a Curl request directly and not to go through the GUI
2.7.2. Use via the swagger GUI
Each endpoint of the API:
Performs a specific operation. Its name and description are indicated in the graphical interface (or in the Endpoints list)
Performs one of four possible methods: GET, DELETE, POST, PUT
Needs authentication rights that are the same as for the GUI (Operators or Administrators)
May need operating parameters (input and/or output): for example, in the case of a filter, the value of this filter must be indicated
This interface enables to:
Have a list of existing endpoints (listed by theme)
Have details of possible parameters for running an endpoint
Have information on the expected result (data model and an example with default values)
Execute queries
Retrieve the Curl command equivalent to the request via the API
Note
A known bug affects the /api/alerts endpoint (see GCenter release note). It is recommended to use the elasticsearch API to query data on the/api/data/es/search endpoint.
2.7.3. Use via CURL
`Responses`
area.For a user called username and with operators rights.
- Recovery of the API token:
curl -X POST "https://<hostname>/api/auth/login" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"username\": \"username\", \"password\": \"password\"}" -k
where hostname is GCenter.
Answer:
{"token":"urxn5hlezbk3vnlgq1t45rifhg0vi951","expiration_date":"2021-04-13T16:26:45.743826"}
Sending a request:
curl -X POST "https://<hostname>/api/<endpoint> -H "accept: application/json" -H "Content-Type: application/json" -H "API-KEY: x0zc5py1e2lrppe6ws0kgc8le0oxm9hg" -d "{\"test\": \"test\"}" -k
Example of a query that will query elasticsearch on its suricata* indexes and retrieve 100 logs over the last 24 hours:
curl -X POST "https://<hostname>/api/<endpoint> -H "accept: application/json" -H "Content-Type: application/json" -H "API-KEY: x0zc5py1e2lrppe6ws0kgc8le0oxm9hg" -d "{ \"size\" : 100, \"query\" : { \"bool\": { \"must\": [], \"filter\": [ { \"match_all\": {} }, { \"range\": { \"@timestamp\": { \"gte\": \"now-24h\", \"lte\": \"now\" } } } ], \"should\": [], \"must_not\": [] } } }" -k
2.7.4. Authentication and access to the API
`API`
button.