GithubHelp home page GithubHelp logo

dannietjoh / grapi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from interputed/grapi

0.0 1.0 0.0 20 KB

Python 3 bindings for Graylog's REST API

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%

grapi's Introduction

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 [email protected]: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.

grapi's People

Contributors

interputed avatar dbaklikov avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.