Skip to main content

A tool to parse syslog-like messages into word sequences

Project description

PyPI release Python support BSD 3-Clause License Travis CI Documentation Status

Log2seq is a python package to help parsing syslog-like messages into word sequences that is more suitable for further automated analysis. It is based on a procedure customizable with rules in order, using regular expressions.

Installation

You can install log2seq with pip.

pip install log2seq

Tutorial

Log2seq is designed mainly for preprocessing of automated log template generation. Many implementations of template generation methods requires input log messages in segmented format, but they only support simple preprocessing, using white spaces. Log2seq enables more flexible preprocessing enough for parsing practical log messages.

For example, sometimes you may face following format of log messages:

Jan  1 12:34:56 host-device1 system[12345]: host 2001:0db8:1234::1 (interface:eth0) disconnected

This message cannot well segmented with str.split() or re.split(), because the usage of : is not consistent.

log2seq processes this message in multiple steps (in default):

  1. Process message header (i.e., timestamp and source hostname)

  2. Split message body into word sequence by standard symbol strings (e.g., spaces and brackets)

  3. Fix words that should not be splitted later (e.g., ipv6 addr)

  4. Split words by inconsistent symbol strings (e.g., :)

Following is a sample code:

mes = "Jan  1 12:34:56 host-device1 system[12345]: host 2001:0db8:1234::1 (interface:eth0) disconnected"

import log2seq
parser = log2seq.init_parser()

parsed_line = parser.process_line(mes)

Here, you can get the parsed information like:

>>> parsed_line["timestamp"]
datetime.datetime(2020, 1, 1, 12, 34, 56)

>>> parsed_line["host"]
'host-device1'

>>> parsed_line["words"]
['system', '12345', 'host', '2001:0db8:1234::1', 'interface', 'eth0', 'disconnected']

You can see : in IPv6 address is left as is, and other : are removed.

This example is using a default parser, but you can also customize your own parser. For defails, please see the document.

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

log2seq-0.3.1.tar.gz (21.0 kB view details)

Uploaded Source

File details

Details for the file log2seq-0.3.1.tar.gz.

File metadata

  • Download URL: log2seq-0.3.1.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.1

File hashes

Hashes for log2seq-0.3.1.tar.gz
Algorithm Hash digest
SHA256 18bdd7f5925ffa99af3a4960475b2b57943288304746a42887c23b91c0ce1922
MD5 0aba6dcdfb18dc9a5762cd2e73d38f8b
BLAKE2b-256 aeb4b5b28879a27c60dadb36d0db100b7af484e0b79cbe01c47ed7b95fa2a89e

See more details on using hashes here.

Supported by

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