Configure audit log export via API
We have prepared a script for working with Audit Logs API, which allows you to export audit logs to a file, send them to an IP address via the syslog protocol, or to an endpoint via the HTTP/HTTPS.
- Create a service user.
- Obtain an IAM token for your account.
- Obtain the script for exporting audit logs.
- Configure and run the script.
1. Create a service user
Add a service user with the role audit_logs.admin.
Users can be added by the Account Owner or users with the role iam.admin.
2. Get an account IAM token
Get an account IAM token for the service user you created in step 1.
3. Get the script for exporting audit logs to a SIEM system
We have prepared a script for exporting audit logs—it allows you to export logs to a file, as well as send them to a specified IP address or endpoint via the syslog or HTTP/HTTPS protocol.
-
Open the CLI.
-
Clone the script repository:
git clone https://github.com/t-rex-general/auditlog-integration.gitThe script files will be saved in the working directory to the
auditlog-integrationfolder.
4. Configure and run the script
The script allows you to receive logs in several ways:
- export to a file;
- send to an IP address using the
syslogprotocol; - send to an endpoint using the
HTTP/HTTPSprotocol.
Configure the script based on your preferred log retrieval method:
Export to a file
Send via syslog
Send via HTTP/HTTPS
-
Open the CLI.
-
Create a virtual environment:
python3 -m venv .venv -
Activate the virtual environment:
source .venv/bin/activate -
Go to the script directory:
cd auditlog-integration -
Install the necessary dependencies:
pip3 install -r requirements.txt -
Create a
.envconfiguration file:touch .env -
Open the
.envconfiguration file:nano .env -
Fill in the
.envconfiguration file:8.1. Add a block with parameters for authenticating to the Audit Logs service API:
AUDIT_LOGS_URL=<base_url>/v1/logsUSERNAME=<username>PASSWORD=<password>ACCOUNT_ID=<account_id>Specify:
<base_url>— the URL for accessing the audit logs API in the required pool. See the list of URLs in the List of URLs guide;<username>— the name of the service user you created at step 1;<password>— the service user password. If the password contains[]\^$.|?*+()characters, escape them by placing a backslash\before the character;<account_id>— account ID, which can be viewed in the Control Panel in the top-right corner.
8.2. Add a block with event delivery parameters:
TRANSPORT_TYPE=fileBy default, logs are saved to the script directory in the
events.txtfile.8.3. Add a line with the API polling interval:
POLL_INTERVAL=<poll_interval>Specify
<poll_interval>— the API polling interval in seconds (default is 30).8.4. Exit the file while saving changes by pressing Ctrl+X → Y → Enter.
8.5. Optional: change the file name where logs are saved. To do this, in the script folder in the
savers.pyfile, within theclass FileSaverblock, change the value in theself.filenamefield. -
Run the script:
python3 main.py