Skip to main content

Python CLI wrapper for VAST - Visibility Across Space and Time

Project description

PyVAST - VAST Python CLI Wrapper

With pyvast we provide a very minimal python wrapper around the VAST command line interface. The wrapper features fluent method chaining and works asynchronously.

All VAST commands can be used with the wrapper. However, the wrapper does not implement any commands itself. It simply passes all received arguments to the vast binary. It is hence very easy to make mistakes in form of typos, given this minimalistic implementation. Please refer to the vast documentation for details about valid vast commands.

Installation

Use pip to install the package.

virtualenv --system-site-packages venv
source venv/bin/activate
pip install pyvast

Usage

Commands are simply chained via .-notation. Parameters can be passed as python keyword arguments. The following examples provide an overview of VAST commands and the analogous pyvast commands.

  • Query for an IP address and return 10 results in JSON
    # CLI call
    vast export --max-event=10 json ':addr == 192.168.1.104'
    
    # python wrapper
    proc = await vast.export(max_events=10).json("192.167.1.102").exec()
    stdout, stderr = await proc.communicate()
    print(stdout)
    
  • Import a Zeek log file
    # CLI call
    vast import zeek --read=/path/to/file
    
    # python wrapper
    proc = await vast.import_().zeek(read="/path/to/file").exec()
    stdout, stderr = await proc.communicate()
    print(stdout)
    

Module Parameterization

You can use PyVAST as Python module. After installing it via pip, simply import it normally in your Python application.

from pyvast import VAST

Once imported, there are three optional keyword arguments to instruct PyVAST with: binary, endpoint, and logger. The binary keyword defaults to "vast". In case the vast binary is not in your $PATH, set this to the actual path to the VAST binary. The endpoint keyword refers to the endpoint of the VAST node (e.g., localhost:42000). Lastly, use the logger keyword to provide a custom logging.logger object for your application.

See also the full example below.

Full Example

The following example shows a minimalistic working example with all required import statements.

#!/usr/bin/env python3

import asyncio
from pyvast import VAST

async def example():
  vast = VAST(binary="/opt/tenzir/bin/vast")
  await vast.test_connection()

  proc = await vast.export(max_events=10).json("192.168.1.103").exec()
  stdout, stderr = await proc.communicate()
  print(stdout)

asyncio.run(example())

See also the example folder for a demo using pyarrow for data export and a demo for continuous queries.

Testing

The tests are written with the python unittest library and its asynchronous analogon aiounittest. Install the requirements.txt first to run the tests.

pip install --user -r requirements.txt
python -m unittest discover .

Development

Use the setup.py for local installation of a development setup.

virtualenv --system-site-packages venv # create a virtual env
source venv/bin/activate
python setup.py develop # or python setup.py install

Project details


Release history Release notifications | RSS feed

This version

1.1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyvast-1.1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyvast-1.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file pyvast-1.1.0.tar.gz.

File metadata

  • Download URL: pyvast-1.1.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for pyvast-1.1.0.tar.gz
Algorithm Hash digest
SHA256 a7c811e8db94b67a2d1399671511c8337267bc401b47cf8da8ef0d0d8caebed1
MD5 a6c57f89dc0ab0327c124770d0e64620
BLAKE2b-256 8202c05714c9a0b62d78a6e510bee031f1e3988c6dab2cef4c4e42ecc533e738

See more details on using hashes here.

File details

Details for the file pyvast-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyvast-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for pyvast-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 58da09dd8e8b364395af8cd2d630d0a07057249f23500c33e514f4e1e0ac2ce7
MD5 df0c0ea7356ab22a600ca5cb193cc933
BLAKE2b-256 3b97084027a26939156bb6ed443aaf5de4df75be9487c974c289e50f8bee5f31

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page