Skip to content

Latest commit

 

History

History
100 lines (79 loc) · 2.29 KB

README.md

File metadata and controls

100 lines (79 loc) · 2.29 KB

Python Humio library

This is still in early development. If you find something missing create an issue or contact us via community.humio.com and let us know.

Documentation for our API can be found here.

Example scripts

See the "examples" folder

run query script example

Query examples

from humio_api.humio_api import HumioApi

# Init the API
api = HumioApi(baseUrl='https://cloud.humio.com', dataspace='<YOUR_DATASPACE>',
               token='<YOUR_TOKEN>')

# creating query
initQueryRes = api.initQuery(queryString='timechart()')
# getting query result
if initQueryRes.status_code == 200:
    queryId = initQueryRes.json()['id']
    res = api.getQueryResult(queryId)
    # printing json
    if res.status_code == 200:
        HumioApi.prettyPrintJson(res.json())

User management examples (only for local on prem install)

from humio_api.humio_api import HumioApi

# Init the API
h = HumioApi(baseUrl='https://cloud.humio.com', dataspace='<YOUR_DATASPACE>',
             token='<YOUR_TOKEN>')

# Get all users
users = h.getUserList()

# Pretty print users list
HumioApi.prettyPrintJson(users)

# Get user by email
user = h.getUserByEmail('[email protected]')

# Pretty print user details
HumioApi.prettyPrintJson(user)

# Create user
api.createUser('[email protected]')

Data ingest examples

from humio_api.humio_api import HumioApi

# Init the API
h = HumioApi(baseUrl='https://cloud.humio.com', dataspace='<YOUR_DATASPACE>',
             token='<YOUR_TOKEN>')

# some test data
jsonDt=[
    {
        "tags": {
            "host": "server1",
            "source": "application.log"
        },
        "events": [
            {
                "timestamp": "2016-06-06T12:00:00+02:00",
                "attributes": {
                    "key1": "value1",
                    "key2": "value2"
                }
            },
            {
                "timestamp": "2016-06-06T12:00:01+02:00",
                "attributes": {
                    "key1": "value1"
                }
            }
        ]
    }
]

# Ingesting the data
h.ingestJsonData(jsonDt)