Skip to main content

Python 3 bindings for Graylog's REST API

Project description

grapi

(Pronounced: gray-P-I)

Python3 bindings for Graylog's REST API

Install

First, make sure you have at least Python 3.7 installed.

Development

git clone git@github.com:interputed/grapi.git
cd grapi
pipenv install

Library Usage

pip3 install grapi

Example Usage

To use, you must first create an access token following the instructions at: Graylog REST API Documentation API does not support username/password logins as it makes it easier to accidentally expose user credentials.

Import after installation with pip: from grapi.grapi import Grapi

Import access token string: token = "<your_access_token_string>"

Set URL to desired API path: url = "https://<your Graylog URL>/api/search/universal/absolute"

All currently implemented URL endpoints can be found in: grapi/endpoints.py

The list of all possible endpoints that may be implemented in the future is found by adding /api/api-browser to the URL of your Graylog server.

Setup the Grapi object with url and token: my_api = Grapi(url, token)

Build a dictionary of parameters mapped to string values for every parameter of your request:

my_params = {
  "query": "<your query string (lucene syntax)>", # Required
  "fields": "<fields you wish returned>", # Required
  "from": "<YYYY-MM-DD HH-MM-SS>", # Required
  "to": "<YYYY-MM-DD HH-MM-SS>", # Required
  "limit": 10 # Optional: Default limit is 150 in Graylog
}

Now, simply call the send method of my_api with the type of request method (get, post, put, delete): response = my_api.send("get", **my_params)

That's it for a simple search in Python 3 using Graylog's REST API! Now you can manipulate the data however you wish directly in Python. To see the output of your search you can just print it as with anything else in Python:

print(response.json())
OR
print(response.text)

This is a work in progress, so if the method or endpoint you need isn't yet implemented, add it yourself and send a pull request, post to issues, or simply check back later and it should be added.

Project details


Download files

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

Source Distribution

grapi-0.1.4.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

grapi-0.1.4-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file grapi-0.1.4.tar.gz.

File metadata

  • Download URL: grapi-0.1.4.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for grapi-0.1.4.tar.gz
Algorithm Hash digest
SHA256 2a004d142020fcd185abd57cf7697d878711e26c67c05bed178cbfcc41234951
MD5 306d1bd48f9bdd5de31ad1a4532167a2
BLAKE2b-256 3bd514fa9de61ff6b9a1b42aa426b45b6612065c30e20658548619eadf517f4d

See more details on using hashes here.

File details

Details for the file grapi-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: grapi-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for grapi-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 95f3fb7ec17e80b131fff6b08af295d1250dad1fd120de17cb93356363070d9b
MD5 446c2cc6018153712e7eafe86841be16
BLAKE2b-256 978f01e0c7fb06048dcfd9260d52982b111a05dbd72ab4a6fcb9e0c3fb2e564b

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