Lahiru Pathirage edited this page Apr 14, 2017 · 2 revisions

Log Tracker is a pythonic wrapper around paramiko, created to capture/read/tail text files using SSH. It gives you the ability to create any kind of custom python function to track text files on demand. To use this YAML file with credential data and a slight understanding about python(version 3) programming is more than enough.

This is the Log Tracker's wiki to guide you how to use it.

Log Tracker configurations

Currently, Log Tracker only has the following configuration parameters. You can find them in the YAML file config.yml file in Log Tracker root directory.

  • resource_path path to the directory which contains YAML files with credentials data and details.

A resource YAML file configuration

For each log file, a YAML configuration file with credentials is required. Put these resource configuration files in the resource_path with a custom name. File extension must be .yml and YAML formatted.

  • name name of the log tracking task
  • hostname hostname of the remote machine to create SSH connection
  • username SSH username of the remote host
  • password SSH password, if user requires a password for SSH login
  • key_file SSH key file, if user requires a key file for SSH login
  • private_key SSH private key, if user requires a private key for SSH login
  • log path to log file in remote machine

Custom function definition

First Put your custom python function in tasks.py for the appropriate log file and inject a TextStreamReader object as an argument. Then mention it in TASKS list in tasks_list.py by mapping the function to log tracking task name mentioned in the resource configuration file.

Mapping the custom function for log

TASKS = {
    "example": tasks.example_function
}

Implement the custom function

def example_function(text_stream):
    # prepare text stream object
    text_stream.load()

    # tail log file, equals to tail -f in unix
    for line in text_stream.tail():
        print(line.rstrip("\n"))

TextStreamReader object

Log Tracker will provide every custom function a TextStreamReader object if it is injected as an argument. A TextStreamReader object has function definitions as below.

  • text_stream.close() close the opened text file object object using SFTP
  • text_stream.get_text_stream() returns the text file object opened with SFTP(read only)
  • text_stream.load() open a text file object using SFTP(read only)
  • text_stream.tail() returns a generator object which contains the tail of the text file

Development

Log Tracker works only for python version 3. To configure the environment and run it please refer Log Tracker's read me.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.