Skip to main content

Python SDK for connecting to Humio

Project description

The humiolib library is a wrapper for Humio’s web API, supporting easy interaction with Humio directly from Python. Full documentation for this repository can be found at https://python-humio.readthedocs.io/en/latest/readme.html.

Vision

The vision for humiolib is to create an opinionated wrapper around the Humio web API, supporting most if not all exposed endpoints. The project does not simply expose web endpoints as Python methods, but attempts to improve upon the usability experience of the API. In addition the project seeks to add non-intrusive quality of life features, so that users can focus on their primary goals during development.

Governance

This project is maintained by employees at Humio ApS. As a general rule, only employees at Humio can become maintainers and have commit privileges to this repository. Therefore, if you want to contribute to the project, which we very much encourage, you must first fork the repository. Maintainers will have the final say on accepting or rejecting pull requests. As a rule of thumb, pull requests will be accepted if:

  • The contribution fits with the project’s vision

  • All automated tests have passed

  • The contribution is of a quality comparable to the rest of the project

The maintainers will attempt to react to issues and pull requests quickly, but their ability to do so can vary. If you haven’t heard back from a maintainer within 7 days of creating an issue or making a pull request, please feel free to ping them on the relevant post.

The active maintainers involved with this project include:

Installation

The humiolib library has been published on PyPI, so you can use pip to install it:

pip install humiolib

Usage

The examples below seek to get you going with humiolib. For further documentation have a look at the code itself.

HumioClient

The HumioClient class is used for general interaction with Humio. It is mainly used for performing queries, as well as managing different aspects of your Humio instance.

from humiolib.HumioClient import HumioClient

# Creating the client
client = HumioClient(
     base_url= "https://cloud.humio.com",
     repository= "sandbox",
     user_token="*****")

# Using a streaming query
webStream = client.streaming_query("Login Attempt Failed", is_live=True)
for event in webStream:
    print(event)

# Using a queryjob
queryjob = client.create_queryjob("Login Attempt Failed", is_live=True)
poll_result = queryjob.poll()
for event in poll_result.events:
    print(event)

# With a static queryjob you can poll it iterativly until it has been exhausted
queryjob = client.create_queryjob("Login Attempt Failed", is_live=False)
for poll_result in queryjob.poll_until_done():
    print(poll_result.metadata)
    for event in poll_result.events:
            print(event)

HumioIngestClient

The HumioIngestClient class is used for ingesting data into Humio. While the HumioClient can also be used for ingesting data, this is mainly meant for debugging.

 from humiolib.HumioClient import HumioIngestClient

# Creating the client
client = HumioIngestClient(
   base_url= "https://cloud.humio.com",
   ingest_token="*****")

# Ingesting Unstructured Data
messages = [
      "192.168.1.21 - user1 [02/Nov/2017:13:48:26 +0000] \"POST /humio/api/v1/ingest/elastic-bulk HTTP/1.1\" 200 0 \"-\" \"useragent\" 0.015 664 0.015",
      "192.168.1..21 - user2 [02/Nov/2017:13:49:09 +0000] \"POST /humio/api/v1/ingest/elastic-bulk HTTP/1.1\" 200 0 \"-\" \"useragent\" 0.013 565 0.013"
  ]

client.ingest_messages(messages)

# Ingesting Structured Data
structured_data = [
      {
          "tags": {"host": "server1" },
          "events": [
              {
                  "timestamp": "2020-03-23T00:00:00+00:00",
                  "attributes": {"key1": "value1", "key2": "value2"}
              }
          ]
      }
  ]

client.ingest_json_data(structured_data)

Changelog

0.2.0 (2020-03-30)

Initial real release to PyPI

Added:

  • Tests, mocking out API calls with vcr.py

  • Custom error handling to completly wrap url library used

  • QueryJob class

Changed:

  • Whole API interface has been updated

  • Updated Sphinx documentation

Removed:

  • A few configuration files left over from earlier versions

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

humiolib-0.2.2.tar.gz (36.5 kB view details)

Uploaded Source

Built Distribution

humiolib-0.2.2-py2.py3-none-any.whl (18.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file humiolib-0.2.2.tar.gz.

File metadata

  • Download URL: humiolib-0.2.2.tar.gz
  • Upload date:
  • Size: 36.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.5

File hashes

Hashes for humiolib-0.2.2.tar.gz
Algorithm Hash digest
SHA256 28e62445f5f8485cea9787f9920c7089faee46c2bea4bce1f2eb7dbdd29789de
MD5 368641062b82549180e53fbab266ea2c
BLAKE2b-256 aabf3123ac550f9997f30f6af4b455be5f5a7100a8b7e7c24e36ee5cba8c7a64

See more details on using hashes here.

File details

Details for the file humiolib-0.2.2-py2.py3-none-any.whl.

File metadata

  • Download URL: humiolib-0.2.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.5

File hashes

Hashes for humiolib-0.2.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 89d6a71f718e16be39ea9c2af128b6de2be3f6acca0c12ab3c524aadb237ef7a
MD5 ece14abc2ce0c68d8d182481d8b29bdc
BLAKE2b-256 1bb04a8cbb12239069435183751cf849999086832e07223599b80d311ef31fb5

See more details on using hashes here.

Supported by

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