tableau_logs package

Submodules

tableau_logs.AccessLog module

class tableau_logs.AccessLog.AccessLog(log_lines: List[str])

Bases: tableau_logs.Log.Log

Class representing an access log generated by Tableau Server’s gateway service.

static parse_timestamp(timestamp: str) → datetime.datetime

Helper function for parsing timestamps from the log.

search_by_request_type(include_types: List[str] = [], exclude_types: List[str] = []) → [typing.Dict[str, typing.Any]]

Search access log by request type(s).

You can search by inclusion, exclusion, or a combination of the two.

Parameters
  • include_types – Any request types that should be included in the search results.

  • exclude_types – Any request types that should be excluded from the search results.

Returns

A list of dictionary objects matching the provided include/exclude criteria.

Example

>>> get_and_post_requests = log.search_by_request_type(include_types=['GET', 'POST'])
>>> not_get_requests = log.search_by_request_type(exclude_types=['GET'])

tableau_logs.Field module

class tableau_logs.Field.Field

Bases: object

Defines a data field (column).

This is a helper class used in building log objects and should not be implemented directly by the end user/developer.

name

The field name.

hyper_type

The Hyper data type from tableauhyperapi.SqlType.

converter

An optional function used to convert parsed values.

nulls

A list of values that should be parsed as NULL from the logs

converter = None
hyper_type = None
name = None
nulls = []

tableau_logs.Log module

class tableau_logs.Log.Log(log_lines: List[str])

Bases: object

Base class from which all Logs should be implemented

This class represents a low level base class and, in general, should not be implemented directly. Instead, any new log class should inherit this class as a base implementation.

Tip

Developers, if you are adding support for a new log type, you should start by inheriting the Log class and customizing the private attributes _schema_name, _table_name, _pattern, and _schema.

static field(name: str, hyper_type, converter=None, nulls=[]) → Type[tableau_logs.Field.Field]

Helper method for returning properly formatted Fields representing columns of data.

Parameters
  • name – The name of the field.

  • hyper_type – The appropriate Hyper data type, as specified in the tableauhyperapi.SqlType class.

  • converter – A function that modifies the parsed value in some way.

  • nulls – A list of values that should be parsed as NULL from the logs

Returns

A new instance of Field

property field_names

Returns a list of field names derived from parsed log content.

Type

[str]

hyper_table_def() → Type[tableauhyperapi.tabledefinition.TableDefinition]

Provides a valid Hyper table definition based on the value of _schema.

Returns

A new instance of TableDefinition.

line_to_dict(line: str) → Dict[str, Any]

Parse a single line from a log into a dict using the regex supplied by _pattern.

Parameters

line – A single line from the log file.

Returns

A dictionary object where keys are field names specified by _schema and values are parsed from the provided line.

property schema_name

Get or set the schema name, used in creating Hyper files, for this log type.

Type

str

search_parsed(using: Callable[[Dict[str, Any]], bool]) → Dict[str, Any]

Search parsed log for lines where the using() function returns True.

The using() function should accept a dictionary object that represents a single line that was parsed from the log.

Returns

A list of dictionary objects that match the criteria defined by the using() function.

Example

>>> import tableau_logs as logs
>>> access_log = logs.access('/path/to/access/log/access.date1.log')
>>> get_and_post_requests = access_log.search_using(lambda line: line['request_type'] in ['GET', 'POST'])
property table_name

Get or set the table name, used in creating Hyper files, for this log type.

Type

str

to_list() → List[Dict[str, Any]]

Represent parsed log data as a Python list object.

Each element in the list is a dictionary object that has keys that correspond to the fields in _schema. The values corresponding to these keys are values parsed out of the log content.

Returns

A list of dictionary objects, each representing a line from the log.

tableau_logs.SessionBasedLog module

class tableau_logs.SessionBasedLog.SessionBasedLog(log_lines: List[str])

Bases: tableau_logs.Log.Log

Class representing any log that utilizes sessions in Tableau Server.

The primary differentiator between session-based and non-session-based logs is that any log that is session-based will contain a set of info, directly following the timestamp and enclosed in parenthesis that represents info about the session. This information includes the username of the logged in user, a session ID, a unique ID (assigned by the gateway), and (in some cases) another currently unknown identifier.

static parse_timestamp(timestamp: str) → datetime.datetime

Helper function for parsing timestamps from the log.

Module contents

tableau_logs.access(path_to_log_files: Union[str, List[str]]) → Type[tableau_logs.AccessLog.AccessLog]

Parse content from an access log generated by the gateway service.

On Tableau Server, these logs are typically located at: …/tableau_server/data/tabsvc/logs/httpd

Parameters

path_to_log_files – The full path and file name of the log (or logs) you want to parse.

Returns

A new instance of Type[AccessLog]

Example

>>> import tableau_logs as logs
>>> single_access_log = logs.access('/path/to/access/log/access.date1.log')
>>> multiple_access_logs = logs.access(['/path/to/access/log/access.date1.log', '/path/to/access/log/access.date2.log'])
tableau_logs.to_hyper(logs: [typing.Union[typing.Type[tableau_logs.AccessLog.AccessLog], typing.Type[tableau_logs.SessionBasedLog.SessionBasedLog]]], output_path: str = 'logs.hyper', send_telemetry_to_tableau: bool = True) → None

Build a hyper file from one or more logs.

Uses the tableauhyperapi to build a valid Hyper file that can subsequently be imported to Tableau for analysis.

Parameters
  • logs – A list of logs to include in the hyper file.

  • output_path – The full path and filename of the Hyper file to be generated.

  • send_telemetry_to_tableau – If True, usage data about tableauhyperapi will be sent to Tableau automatically.

Example

>>> import tableau_logs as logs
>>> access_log = logs.access('/path/to/access/log/access.date1.log')
>>> vizportal_logs = logs.vizportal(['/path/to/vizportal/log/vizportal_node1-0.log', '/path/to/vizportal/log/vizportal_node1-1.log'])
>>> logs.to_hyper([access_log, vizportal_logs], output_path='/path/to/output/my_logs.hyper', send_telemetry_to_tableau=True)
tableau_logs.vizportal(path_to_log_files: Union[str, List[str]]) → Type[tableau_logs.SessionBasedLog.SessionBasedLog]

Parse content from a vizportal log.

On Tableau Server, these logs are typically located at: …/tableau_server/data/tabsvc/logs/vizportal

Parameters

path_to_log_files – The full path and file name of the log (or logs) you want to parse.

Returns

A new instance of Type[SessionBasedLog]

Example

>>> import tableau_logs as logs
>>> single_vizportal_log = logs.vizportal('/path/to/vizportal/log/vizportal_node1-0.log')
>>> multiple_vizportal_logs = logs.vizportal(['/path/to/vizportal/log/vizportal_node1-0.log', '/path/to/vizportal/log/vizportal_node1-1.log'])
tableau_logs.vizqlserver(path_to_log_files: Union[str, List[str]]) → Type[tableau_logs.SessionBasedLog.SessionBasedLog]

Parse content from a vizqlserver log.

On Tableau Server, these logs are typically located at: …/tableau_server/data/tabsvc/logs/vizqlserver

Parameters

path_to_log_files – The full path and file name of the log (or logs) you want to parse.

Returns

A new instance of Type[SessionBasedLog]

Example

>>> import tableau_logs as logs
>>> single_vizqlserver_log = logs.vizqlserver('/path/to/vizqlserver/log/vizqlserver_node1-0.log')
>>> multiple_vizqlserver_logs = logs.vizqlserver(['/path/to/vizqlserver/log/vizqlserver_node1-0.log', '/path/to/vizqlserver/log/vizqlserver_node1-1.log'])