# Exporting Logs With Rust

Key Point

How to use Rust to export Onna audit logs as JSON and save them to /tmp.

💡 3 min read


This guide is written for Linux and macOS, depending on your Operating System you may need to adjust.

This guide is based on Rust, tested using cargo 1.43.0 and uses the hosted Onna SaaS platform.

This guide also assumes some familiarity with Rust, if you're interested please see - Rust and Rustlings interactive tutorial.

# Requirements


Make sure that the version of Rust is up to date via rustup update stable.

The hosted platforms (e.g https://$COMPANY.onna.io or https://enterprise.onna.com/$COMPANY) only require HTTP requests.

If Python is more to your liking check out export-logs

# Prerequisite

The activitylog endpoint requires specific permissions.

If you want to run this script unattended, like as a cron job, the user account used to authenticate must be a Service Account.

Please contact Onna support (support [at] onna [dot] com) for assistance with setting up a Service Account.


To be able to export data from your Onna instance, you'll need the following credentials:

USERNAME: Service Account or username
PASSWORD: password
ACCOUNT: the Onna account name
ACCOUNT_URL: the URL of your account, e.g https://$COMPANY.onna.io or https://enterprise.onna.com/$COMPANY

# Setup

Create a directory for the script and its dependencies

mkdir $DIR #choose a name for the directory

Change into the newly created directory

cd $DIR

Download the onna-logs archive with source code and dependencies and expand it.

Build the script:

cargo build

Running onna-logs script requires some args:

cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.42s
    Running `target/debug/onna-logs`
error: The following required arguments were not provided:
    --account <account>
    --account-url <account-url>
    --fname <fname>
    --from-date <from-date>
    --password <password>
    --to-date <to-date>
    --username <username>

    onna-logs --account <account> --account-url <account-url> --container <container> --fname <fname> --from-date <from-date> --password <password> --to-date <to-date> --username <username>

For more information try --help

# Syntax

./target/debug/onna-logs --account $ACCOUNT --account_url $ACCOUNT_URL  --container $CONTAINER --fname $FNAME\ --from_date $FROM_DATE --password $PASSWORD --to_date $TO_DATE --username $USERNAME


[--container $CONTAINER] refers to the container holding all your data in the Onna instance.

For Onna accounts in the enterprise.onna.com namespace, the container name is the same as your account name. If your Onna account has its own subdomain and you don't know your container name, please contact support for assistance.

Please contact Onna support (support [at] onna [dot] com) if you need assistance.

# Example

./target/debug/onna-logs --account account --account-url https://enterprise.onna.com \
--container example --fname example-audit --from-date 2020-01-01 \
--password <secret-password> --to-date 2020-01-20 --username example1

Running the script will do the following:

It will export all audit logs from the 01-01-2020 till the 01-20-2020 of the account example running on https://enterprise.onna.com to /tmp/example-audit.json.

The script uses the username example1 with the password 1234.

Last Updated: 6/2/2020, 1:28:04 PM