HumioClient

class humiolib.HumioClient.BaseHumioClient(base_url)

Base class for other client types, is not meant to be instantiated

class humiolib.HumioClient.HumioClient(repository, user_token, base_url='http://localhost:3000')

A Humio client that gives full access to the underlying API. While this client can be used for ingesting data, we recommend using the HumioIngestClient made exclusivly for ingestion.

add_file_contents(file_name, file_headers, changed_rows, column_changes=[], offset=0, limit=200)

Add contents to a file

Parameters:
  • file_name (string) – Name of file
  • file_headers (list) – Headers of the file
  • changed_rows (list) – Rows within the offset and limit to overwrite existing rows
  • column_changes (list, optional) – Column changes that will be applied to all rows in the file
  • offset (int, optional) – Starting index to replace the old rows with the updated ones.
  • limit (int, optional) – Used to determine when to stop replacing rows, by adding the limit to the offset
Returns:

Response data to web request as json string

Return type:

str

create_file(file_name)

Create new file.

Parameters:file_name (string) – Name of file
Returns:Response data to web request as json string
Return type:str
create_queryjob(query_string, start=None, end=None, is_live=None, timezone_offset_minutes=None, arguments=None, raw_data=None, **kwargs)

Creates a queryjob on Humio, which executes asynchronously of the calling code. The returned QueryJob instance can be used to get the query results at a later time. Queryjobs are good to use for live queries, or static queries that return smaller amounts of data.

Parameters:
  • query_string (str) – Humio query
  • start (Union[int, str], optional) – Starting time of query
  • end (Union[int, str], optional) – Ending time of query
  • is_live (int, optional) – Ending time of query
  • is_live – Timezone offset in minutes
  • argument (dict(string->string), optional) – Arguments specified in query
  • raw_data (dict(string->string), optional) – Additional arguments to add to POST body under other keys
Returns:

An instance that grants access to the created queryjob and associated results

Return type:

QueryJob

create_user(email, isRoot=False)

Create user on Humio instance. Method is idempotent

Parameters:
  • email (str) – Email of user to create
  • isRoot (bool, optional) – Indicates whether user should be root
Returns:

Response to web request as json string

Return type:

str

delete_file(file_name)

Delete an existing file.

Parameters:file_name (string) – Name of file
Returns:Response to web request as json string
Return type:str
delete_user_by_email(email)

Delete user by email.

Parameters:email (string) – Email of user to delete.
Returns:Response to web request as json string
Return type:str
delete_user_by_id(user_id)

Delete user from Humio instance.

Parameters:user_id (string) – Id of user to delete.
Returns:Response to web request as json string
Return type:str
get_file(file_name, encoding=None)

Get specific file on repository

Parameters:file_name (string) – Name of file to get.
Returns:Response to web request as json string
Return type:str
get_file_content(filename, offset=0, limit=200, filter_string=None)

Get the contents of a file

Parameters:
  • file_name – Name of file.
  • offset (int) – Starting index to replace the old rows with the updated ones.
  • limit (int) – Used to find when to stop replacing rows, by adding the limit to the offset
  • filter_string (string, optional) – Used to apply a filter string
Returns:

Response to web request as json string

Return type:

str

get_status(**kwargs)

Gets status of Humio instance

Returns:Response to web request as json string
Return type:str
get_user_by_email(email)

Get a user associated with Humio instance by email

Parameters:email (str) – Email of queried user
Returns:Response to web request as json string
Return type:str
get_users()

Gets users registered to Humio instance

Returns:Response to web request as json string
Return type:str
ingest_json_data(json_elements=None, **kwargs)

Ingest structured json data to repository. Structure of ingested data is discussed in: https://docs.humio.com/reference/api/ingest/#structured-data

Parameters:
  • messages (list(string), optional) – A list of event strings.
  • parser (string, optional) – Name of parser to use on messages.
  • fields (dict(string->string), optional) – Fields that should be added to events after parsing.
  • tags (dict(string->string), optional) – Tags to associate with the messages.
Returns:

Response to web request as json string

Return type:

str

ingest_messages(messages=None, parser=None, fields=None, tags=None, **kwargs)

Ingest unstructred messages to repository. Structure of ingested data is discussed in: https://docs.humio.com/reference/api/ingest/#parser

Parameters:
  • messages (list(string), optional) – A list of event strings.
  • parser (string, optional) – Name of parser to use on messages.
  • fields (dict(string->string), optional) – Fields that should be added to events after parsing.
  • tags (dict(string->string), optional) – Tags to associate with the messages.
Returns:

Response to web request as json string

Return type:

str

list_files()

List uploaded files on repository

Returns:Response to web request as json string
Return type:str
remove_file_contents(file_name, offset=0, limit=200)

Remove contents of a file

Parameters:
  • file_name (string) – Name of file
  • offset (int, optional) – Starting index to replace the old rows with the updated ones.
  • limit (int, optional) – Used to find when to stop replacing rows, by adding the limit to the offset
Returns:

Response data to web request as json string

Return type:

str

streaming_query(query_string, start=None, end=None, is_live=None, timezone_offset_minutes=None, arguments=None, raw_data=None, **kwargs)

Humio Query type that opens up a streaming socket connection to Humio. This is the preferred way to do static queries with large result sizes. It can be used for live queries, but not that if data is not passed back from Humio for a while, the connection will be lost, resulting in an error.

Parameters:
  • query_string (str) – Humio query
  • start (Union[int, str], optional) – Starting time of query
  • end (Union[int, str], optional) – Ending time of query
  • is_live (bool, optional) – Ending time of query
  • timezone_offset_minutes (int, optional) – Timezone offset in minutes
  • argument (dict(string->string), optional) – Arguments specified in query
  • raw_data (dict(string->string), optional) – Additional arguments to add to POST body under other keys
Returns:

A generator that returns query results as python objects

Return type:

Generator

class humiolib.HumioClient.HumioIngestClient(ingest_token, base_url='http://localhost:3000')

A Humio client that is used exclusivly for ingesting data

ingest_json_data(json_elements=None, **kwargs)

Ingest structured json data to repository. Structure of ingested data is discussed in: https://docs.humio.com/reference/api/ingest/#structured-data

Parameters:json_elements (str) – Structured data that can be parsed to a json string.
Returns:Response to web request as json string
Return type:str
ingest_messages(messages=None, parser=None, fields=None, tags=None, **kwargs)

Ingest unstructred messages to repository. Structure of ingested data is discussed in: https://docs.humio.com/reference/api/ingest/#parser

Parameters:
  • messages (list(string), optional) – A list of event strings.
  • parser (string, optional) – Name of parser to use on messages.
  • fields (dict(string->string), optional) – Fields that should be added to events after parsing.
  • tags (dict(string->string), optional) – Tags to associate with the messages.
Returns:

Response to web request as json string

Return type:

str