Skip to main content

maillogger

PyPI PyPI - Python Version PyPI - License

Analysis tool for Postfix log in /var/log/maillog

Feature

  • Load maillog file
    • Identify text or gzip automatically
  • Parse maillog
    • Use regex
    • Convert to Python dictionary
  • Output the parsed maillog to files
    • Supported data format is CSV, TSV and JSON
    • Compression (gzip) is possible

Installation

pip install maillogger

Usage

usage: maillogger [-h] [-f {csv,tsv,json}] [-c] [-V] source_file target_file

Analysis tool for Postfix log in /var/log/maillog

positional arguments:
  source_file           Specify Postfix maillog file
  target_file           Specify the filename to write parsed maillog. The file
                        extension is automatically added to the end of
                        filename.

optional arguments:
  -h, --help            show this help message and exit
  -f {csv,tsv,json}, --format {csv,tsv,json}
                        File data format to write the parsed maillog (Default:
                        csv)
  -c, --compress        Compress the output file with gzip
  -V, --version         Show maillogger command version

Examples

Output a CSV file

maillogger /var/log/maillog result

or

maillogger /var/log/maillog result -f csv

Then, result.csv is generated in current working directory.

Output a JSON file

maillogger /var/log/maillog result -f json

Output a TSV file

maillogger /var/log/maillog result -f tsv

Output a compressed CSV file

maillogger /var/log/maillog result -f csv -c

Then, result.csv.gz is generated in current working directory.

Use Case

Analysis using MySQL

  1. Convert maillog text to CSV file
maillogger /var/log/maillog /path/to/any -f csv
  1. Create Table
CREATE TABLE maillog
(
    mail_id VARCHAR(15) NOT NULL,
    to_address VARCHAR(50) NOT NULL,
    relay text,
    delay VARCHAR(10),
    delays VARCHAR(20),
    dsn VARCHAR(10),
    status VARCHAR(10),
    description text,
    datetime DATETIME NOT NULL,
    PRIMARY KEY (mail_id, datetime),
    INDEX i_status(status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  1. Load CSV file
LOAD DATA INFILE '/path/to/any.csv'
IGNORE INTO TABLE maillog
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES;

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

maillogger-0.2.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

maillogger-0.2.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file maillogger-0.2.0.tar.gz.

File metadata

  • Download URL: maillogger-0.2.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.8.5 Linux/5.3.0-1034-azure

File hashes

Hashes for maillogger-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ed955cb9aac03b99b3e4f7bad6c3bc12339cdfb5abb54367599c1bcf4e5d3ccc
MD5 6cc7f598ea230cbd9de6707880251ae9
BLAKE2b-256 cfa27783c35b676e2bb4cc6c20f2ab87698e7f52fe7dc244ca954e7f63b86122

See more details on using hashes here.

File details

Details for the file maillogger-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: maillogger-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.8.5 Linux/5.3.0-1034-azure

File hashes

Hashes for maillogger-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 117968bd7fa78364b037a23edb953df5fe8dec2a80833118f9b6b754d85ce0e2
MD5 ce7b124aa341395cb63f205c4de610fd
BLAKE2b-256 682bcc1775eec3db82c9c4646b086687e44c166ef86fb45474eda1c3d30c1ed5

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page