Skip to content

Commit

Permalink
Merge branch 'develop' for update to release v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
brunato committed Aug 27, 2020
2 parents b1f09fe + 28d659e commit c15867b
Show file tree
Hide file tree
Showing 34 changed files with 1,497 additions and 816 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ __pycache__/
.pytest_cache/
.tox/
*.egg-info/
htmlcov/
.coverage*
7 changes: 5 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ system logs analysis. The log analysis is based on application or device
that originated the message, using a set of rules for matching and for
report composition.

The project uses parts of Epylog under LGPL terms with author's permission.
The project uses parts of Epylog package under LGPL terms with author's permission.

Please send feedback for bugs, feature requests, suggestions, comments and
criticism.
Expand Down Expand Up @@ -53,6 +53,9 @@ After the installation copy the default configuration files of the package sourc
/etc/lograptor/report_template.txt Report plain text template
/etc/lograptor/conf.d/*.conf Configuration files for applications

For configuring the package at user level put your configuration in
`~/.config/lograptor/lograptor.conf`.

For more info about main configuration file please see "man lograptor.conf".
For each application a configuration file is needed. Logs of unconfigured
applications are simply ignored by the program. For more info please see
Expand All @@ -73,7 +76,7 @@ For more information on usage options see "lograptor --help" or

LICENSE
-------
Copyright (C), 2011-2017, by SISSA - International School for Advanced Studies.
Copyright (C), 2011-2020, by SISSA - International School for Advanced Studies.

Lograptor is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down
13 changes: 6 additions & 7 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ def setup(app):
master_doc = 'index'

# General information about the project.
project = u'lograptor'
copyright = u'2012-2017, Scuola Internazionale Superiore di Studi Avanzati, Trieste (Italy)'
project = 'lograptor'
copyright = '2012-2020, Scuola Internazionale Superiore di Studi Avanzati, Trieste (Italy)'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '1.2'
version = '1.3'
# The full version, including alpha/beta/rc tags.
release = '1.2.4'
release = '1.3.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -272,9 +272,8 @@ def setup(app):
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'lograptor', u'Lograptor Documentation',
u'Davide Brunato', 'Lograptor', 'One line description of project.',
'Miscellaneous'),
('index', 'lograptor', 'Lograptor Documentation', 'Davide Brunato',
'Lograptor', 'One line description of project.', 'Miscellaneous'),
]

# Documents to append as an appendix to all manuals.
Expand Down
2 changes: 1 addition & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ delimitation options. Each search run can be sent to an output channel (stdout,
file) and can produces a customizable report.

The program can parse logs written in RFC 3164 and RFC 5424 formats. Lograptor requires
Python >= 2.7, and is provided with a base configuration for a set of well known applications.
Python >= 3.5, and is provided with a base configuration for a set of well known applications.
You can easily add new applications or new rules to match other unparsed logs.

The project uses parts of Epylog under LGPL terms with author's permission.
Expand Down
11 changes: 5 additions & 6 deletions lograptor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# -*- coding: utf-8 -*-
"""
Command line tools for lograptor package.
"""
#
# Copyright (C), 2011-2018, by SISSA - International School for Advanced Studies.
# Copyright (C), 2011-2020, by SISSA - International School for Advanced Studies.
#
# This file is part of lograptor.
#
Expand All @@ -21,5 +17,8 @@
# @Author Davide Brunato <brunato@sissa.it>
#
from .core import LogRaptor
from .exceptions import *
from .exceptions import LogRaptorException
from .api import lograptor


__all__ = ['LogRaptor', 'lograptor', 'LogRaptorException']
2 changes: 1 addition & 1 deletion lograptor/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Execute lograptor module as a script (see PEP-338).
"""
#
# Copyright (C), 2011-2018, by SISSA - International School for Advanced Studies.
# Copyright (C), 2011-2020, by SISSA - International School for Advanced Studies.
#
# This file is part of lograptor.
#
Expand Down
71 changes: 37 additions & 34 deletions lograptor/api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Command line interface of the lograptor package.
"""
#
# Copyright (C), 2011-2018, by SISSA - International School for Advanced Studies.
# Copyright (C), 2011-2020, by SISSA - International School for Advanced Studies.
#
# This file is part of lograptor.
#
Expand All @@ -21,8 +20,6 @@
#
# @Author Davide Brunato <brunato@sissa.it>
#
from __future__ import unicode_literals, absolute_import

import sys
import argparse
import time
Expand All @@ -38,6 +35,7 @@
from .timedate import get_datetime_interval, parse_date_period, parse_last_period, TimeRange


# noinspection PyShadowingBuiltins
class StoreOptionAction(argparse.Action):
"""
An action that stores the max length option as value, useful when
Expand All @@ -64,17 +62,21 @@ def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest, self.const)


def positive_integer(string):
value = int(string)
if value <= 0:
msg = "%r is not a positive integer" % string
raise argparse.ArgumentTypeError(msg)
return value
def positive_integer(arg):
try:
value = int(arg)
if value <= 0:
raise ValueError()
except ValueError:
msg = "%r is not a positive integer" % arg
raise argparse.ArgumentTypeError(msg) from None
else:
return value


def filter_spec(string):
def filter_spec(arg):
_filter = dict()
for flt in string.split(','):
for flt in arg.split(','):
try:
field, pattern = flt.split('=', 1)
field, pattern = field.lower(), pattern.strip('\'"')
Expand All @@ -93,24 +95,24 @@ def filter_spec(string):
return _filter


def comma_separated_string(string):
return [x.strip() for x in string.split(',')]
def comma_separated_string(arg):
return [x.strip() for x in arg.split(',')]


def last_period_spec(string):
def last_period_spec(arg):
try:
diff = parse_last_period(string)
except TypeError:
raise argparse.ArgumentTypeError('wrong format: %r' % string)
diff = parse_last_period(arg)
except ValueError:
raise argparse.ArgumentTypeError('wrong format: %r' % arg)
else:
return get_datetime_interval(int(time.time()), diff, 3600)


def date_interval_spec(string):
def date_interval_spec(arg):
try:
return parse_date_period(string)
return parse_date_period(arg)
except (TypeError, ValueError):
raise argparse.ArgumentTypeError('%r: wrong format, use [YYYY]MMDD[,[YYYY]MMDD]' % string)
raise argparse.ArgumentTypeError('%r: wrong format, use [YYYY]MMDD[,[YYYY]MMDD]' % arg)


def create_argument_parser():
Expand Down Expand Up @@ -188,7 +190,7 @@ def create_argument_parser():
action="append", help="obtain patterns from FILE"
)
group.add_argument(
"-i", "--ignore-case", action="store_true", dest="case", default=False,
"-i", "--ignore-case", action="store_true", default=False,
help="ignore case distinctions"
)
group.add_argument(
Expand Down Expand Up @@ -335,17 +337,18 @@ def has_void_args(argv):
Check if the command line has no arguments or only the --conf optional argument.
"""
n_args = len(argv)
return n_args == 1 or n_args == 2 and argv[1].startswith('--conf=') or n_args == 3 and argv[1] == '--conf'
return n_args == 1 or n_args == 2 and argv[1].startswith('--conf=') or \
n_args == 3 and argv[1] == '--conf'


def lograptor(files, patterns=None, matcher='ruled', cfgfiles=None, apps=None, hosts=None,
filters=None, time_period=None, time_range=None, case=False, invert=False,
word=False, files_with_match=None, count=False, quiet=False, max_count=0,
only_matching=False, line_number=False, with_filename=None,
ip_lookup=False, uid_lookup=False, anonymize=False, thread=False,
before_context=0, after_context=0, context=0):
def lograptor(files, patterns=None, matcher='ruled', cfgfiles=None, apps=None,
hosts=None, filters=None, time_period=None, time_range=None,
ignore_case=False, invert=False, word=False, files_with_match=None,
count=False, quiet=False, max_count=0, only_matching=False,
line_number=False, with_filename=None, ip_lookup=False, uid_lookup=False,
anonymize=False, thread=False, before_context=0, after_context=0, context=0):
"""
Run lograptor with arguments. Experimental feature to use the log processor into
Run lograptor with arguments. Experimental feature for use the log processor into
generic Python scripts. This part is still under development, do not use.
:param files: Input files. Each argument can be a file path or a glob pathname.
Expand All @@ -357,7 +360,7 @@ def lograptor(files, patterns=None, matcher='ruled', cfgfiles=None, apps=None, h
:param filters: process the log lines that match all the conditions for rule's field values.
:param time_range: process the log lines related to a time range.
:param time_period: restrict the search scope to a date or a date interval.
:param case: ignore case distinctions, defaults to `False`.
:param ignore_case: ignore case distinctions, defaults to `False`.
:param invert: invert the sense of patterns regexp matching.
:param word: force PATTERN to match only whole words.
:param files_with_match: get only names of FILEs containing matches, defaults is `False`.
Expand All @@ -383,7 +386,7 @@ def lograptor(files, patterns=None, matcher='ruled', cfgfiles=None, apps=None, h
args.cfgfiles = cfgfiles
args.time_period = time_period
args.time_range = time_range
args.case = case
args.ignore_case = ignore_case
args.invert = invert
args.word = word
args.files_with_match = files_with_match
Expand Down Expand Up @@ -414,8 +417,8 @@ def lograptor(files, patterns=None, matcher='ruled', cfgfiles=None, apps=None, h


def main():
if sys.version_info < (2, 7, 0):
sys.stderr.write("You need python 2.7 or later to run this program\n")
if sys.version_info < (3, 5, 0):
sys.stderr.write("You need Python 3.5+ to run this program\n")
sys.exit(1)

cli_parser = create_argument_parser()
Expand Down
Loading

0 comments on commit c15867b

Please sign in to comment.