Commit Graph

49 Commits

Author SHA1 Message Date
Miguel Angel Ajo 6b87af03cd Add functional test for var log messages and enhance functional script
This test adds testing for var log messages format. In this commit we
also enhance the functional.sh script to:

1) make sed usage more compatible with other systems (--expression -> -e)
2) Add color to output PASSED / FAILED
3) Generate template files for non existing outputs
4) Generate failed outputs for manual verification

Change-Id: I1146b96fe9c91473c0127d0c47f890db1ddfb7b5
2018-10-15 09:50:13 +00:00
Miguel Angel Ajo 222bb2a984 Create and enable funcional testing
The funcional testing will include, per case, input files
and output files, plus a simple bash script which makes
sure the output stays as it should, and otherwise shows
a diff and fails the case.

Change-Id: I4c5f1143188f49c6a1448ca8918ab8b30710b865
2018-10-15 08:10:16 +00:00
Miguel Angel Ajo 20645e4f9a Making sure we're ready for python3
Adds py37 to the env list and switches pep8 python to
python3, including necessary changes to make pylint
and pep8 checks happy in python3:

* Unpins pylint, as 1.4.5 explodes (exception) when trying
  to check our code.

* Unpins flake8-import-order from an old version.

* Stops making use of the builtin cmp function, and replaces
  it with the recommended (a > b) - (a < b).

* Disables one py3 specific warning, since it's still necessary
  for python2 (useless-object-inheritance)

* Removes a non existing argument in netprobe parser (version).

* Inserts an additional blank line between __future__ imports
  and stdlib imports.

Change-Id: If4a45108fe93080f9967e2ac26d681b8dd5c7fc2
2018-10-03 15:10:59 +02:00
Zuul 352a5ab8f2 Merge "Add Apache license headers to the .py files" 2018-09-27 10:26:32 +00:00
Zuul 546fee53dc Merge "Stop setting version manually" 2018-09-27 09:09:41 +00:00
Miguel Angel Ajo e518ac9bc7 Add Apache license headers to the .py files
The purpose of this change is to help the licensecheck tool
identifying the license of the sourcecode.

Change-Id: I3cc325e825fefe3c124329d8ab4b10821c9b1676
2018-09-27 10:15:53 +02:00
Monty Taylor 44d81d873e
Stop setting version manually
One of the reasons that pbr exists is to have versions be driven by
signed git tags instead of by content in the source repository. This has
the benefit of being both easier and preventing people from forgetting
to push a git tag when they cut a release.

Additionally, this code is doesn't work for sdist jobs in Zuul upstream
because it requires the project to be importable to run setup.py, but
sdist/wheel generation does not otherwise need to install dependencies.

Remove the override of version in setup.py and replace the hard-coded
version string in oslogmerger.py with the appropriate pbr code.

Change-Id: Ifdbb649b02d7e2fde6e8682e138c81817543fb08
2018-07-05 17:01:26 -05:00
Matthew Booth 9dd538d2e8 Parse message logs containining timestamps with microseconds
Change-Id: I9ffb52dccf3c18dac5cf5dfe8c957a95301d72be
2018-04-20 11:33:51 +01:00
Miguel Angel Ajo e08b086914 Enable py27 and py35 unit testing
This also includes a couple of basic unit tests as proof
that this is working.

Change-Id: Iff8241b4bdfd3c97319198873527911e8ed318e1
2018-03-01 17:14:45 +00:00
Miguel Angel Ajo 5193d0010e Setup tox.ini for unit and pep8 testing
This patch includes fixes to all the pep8 warnings.

Change-Id: I4f87e1428258824509d2d83879312a1f0dff0a8a
2018-02-28 23:19:52 +00:00
Miguel Angel Ajo 809bb6add3 Python 3.x compatibility
Now the code is python2 and python3 compatible, and they both
generate the same output regardless of subtle differences.

Change-Id: Ic6b908387becf4d0de5d9da72ce6915d3f7c3b1c
2018-02-28 12:18:37 +00:00
Matthew Booth c9e5f14026 Make iter(LogFile) return an independent generator
This is a simplification of the previous code which used global state.
It was prompted by a bug: iterating over a log file containing 3
lines, we were returning lines 1 and 3, and omitting line 2.

Change-Id: Ic7388f96a6201f30e16662ff4a5f3c081ac2c4bd
2017-09-29 18:27:13 +01:00
Matthew Booth 4583d5c340 Add --default-tz
Change-Id: I4b827b257879eae396852e7464236fb86ff0f57d
2017-09-29 18:27:12 +01:00
Matthew Booth e73a2a35b2 Fix incorrect auto-detection as timestamp log
TSLogParser was searching for any instance of [<number>] in a log
line, which was incorrectly matching on, eg:

  Sep 15 18:09:46 clgrabguye21.localdomain su[160015]: ...

With this change we assert that the timestamp occurs at the beginning
of the line.

Change-Id: I04da2f1fa661bccfd3b046dfc22e5a10f6cb37f8
2017-09-29 18:26:51 +01:00
Matthew Booth 1c6d22503d Delete some dead code
Change-Id: I92c05a7520541b937badbbd87308daf12a76baf5
2017-09-29 18:26:51 +01:00
Matthew Booth 1a31f79327 Add auto-detect parser for raw syslog
Change-Id: Iba7e80d97cffc809defdfdd87f88a8b698f28019
2017-09-29 18:26:51 +01:00
Matthew Booth 1be8b23dfc Add auto-detect parser for libvirt domain logs
Change-Id: I7d98327bebf20b01e41525b56ef59c68cbb8bbd3
2017-09-29 18:26:49 +01:00
Matthew Booth 11e139a706 Allow zero positional arguments
Allow all log files to have their formats given explicitly, with no
auto-detection.

Change-Id: I0a0a614642bc543f03d394b5e8822a445e7bde5b
2017-09-21 11:30:48 +01:00
Matthew Booth 06de0ba054 Implement format auto-detection
Add a new option --os-logs/-ol to explicitly specify OpenStack format
logs. Logs whose format is not given explicitly are auto-detected.

Change-Id: Ie97127f24f34ab386138db28b626abf4c259ac24
2017-09-21 11:30:48 +01:00
Matthew Booth 27599915cb Refactor log parsing into separate parser classes
All log entries are now the lighter weight LogEntry class, which is
also responsible for its own output. Parsing is simplified and
separated into independent parser classes.

Change-Id: I264cf20933e8af007556efd7a36639f854460f49
2017-09-20 16:53:05 +01:00
Matthew Booth f2be96fe6a Always merge sort input files with heapq.merge
heapq.merge does an extremely efficient merge sort. Being a merge sort
it has constant memory overhead, and is very fast. It also starts
producing output immediately. It obsoletes both previous sorting
methods, so we deprecate the --min-memory option.

Change-Id: I8384b7214ba54dffa61d1c2195f3b4c238ba253a
2017-05-25 10:18:10 +01:00
Miguel Angel Ajo 5b9c82746b Bump version to 1.1.0 for release
Change-Id: I0461a7bf6ef78ff2afeb2c38ea4478b4b3cda46c
2017-03-15 11:18:33 +01:00
Jenkins 27b28c12f2 Merge "Guard against all exceptions when processing a line" 2017-03-15 09:27:22 +00:00
Ihar Hrachyshka 881b6fd359 Guard against all exceptions when processing a line
You never know what's in the input string, so catch all possible
failures without crashing the tool.

Related-Bug: #1672921
Change-Id: I3a518be2e6087d0a096fa3c36aa40dcad8aecb98
2017-03-15 04:37:58 +00:00
Ihar Hrachyshka 733b98a8ec Guard against null-strings in lines
Without that patch, the tool chokes on lines with null-bytes in the
middle, which as it turned out sometimes happens in neutron logs.

Related-Bug: #1672921
Change-Id: I2ec2c637dc03008f4d964f88a788af0d69abe282
2017-03-15 04:37:46 +00:00
Miguel Angel Ajo f39e434d99 Fix variable size timestamp for OS LogEntry 2016-04-26 14:46:59 -05:00
Miguel Angel Ajo 6086787765 Remove README.rst from datafiles to avoid warnings in pip
This will also fix an issue with pip install on OSX.
2016-04-26 10:59:43 -05:00
Miguel Angel Ajo e901627f16 Updated netprobe, and added netprobe.log to auto alias 2016-04-26 10:50:19 -05:00
Miguel Angel Ajo 7eb4f383db Added a new probe: netprobe
This is an standalone .py file that can be uploaded to remote
servers and used to log network packets over network interfaces.

It will discover new interfaces automatically, in the root or
inside network namespaces.

Interfaces and namespaces are filtered via regular expressions.

usage: netprobe [-h] [-v] [--netns-re NETNS_REGEX]
                [--netdev-re NETDEV_REGEX]
                [--tcpdump-filter TCPDUMP_FILTER]
                [--check-interval CHECK_INTERVAL]

This tool will track system network devices as they appear in a host,
and start tcpdump processes for each of them, while the output of all
the tcpdumps goes in a single openstack-like log.

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  --netns-re NETNS_REGEX, -n NETNS_REGEX
  --netdev-re NETDEV_REGEX, -d NETDEV_REGEX
  --tcpdump-filter TCPDUMP_FILTER, -t TCPDUMP_FILTER
  --check-interval CHECK_INTERVAL, -i CHECK_INTERVAL
                        The interval between interface checks
2016-04-23 18:53:37 +02:00
Miguel Ángel Ajo 561b4310f7 Merge pull request #25 from Akrog/issue7/other_log_formats
Add support for other log formats
2016-03-29 12:21:01 +02:00
Miguel Ángel Ajo a202c68891 Merge pull request #24 from Akrog/fix/autoalias
Fix/autoalias
2016-03-29 12:20:54 +02:00
Gorka Eguileor ef9b9bd54f Fix #7: Add support for timestamped logs
This patch adds support for timestamped log files with the format
"[    0.003036]".

Since timestamp many times will not take epoc time as the source of the
timestamp but the time the system started, the initial datetime will be
calculated by substracting from the file modified datetime the last
timestamp in the file.

Option added is --timestamp-logs or -tl, and it also supports ALIAS and
globs, and is also affected by base directory and postfix options.
2016-03-25 15:14:45 +01:00
Gorka Eguileor 8c3ae25c17 Add Support /var/log/messages type of logs
This patch adds support for log files that use the same datetime format
as /var/log/messages, which is in the for of Oct 15 14:11:19.

Year will from last modification to the file will be used to complete
missing year.

In the process of refactoring the read of the logs the OpenStack log
reading has been simplified to not require the presence of PID or LEVEL,
thus providing more compatibility with custom log formats (as long as
default datetime format is being used).

With this refactoring it is now easier to add new datetime formats to
the script.

Option added is --msg-logs or -ml and it also supports ALIAS and globs,
and is also affected by base directory and postfix options.

TODO: If year of file creation and file last modification are different
we should start with the cration year and then change to the next year
once the months go back.
2016-03-25 15:14:25 +01:00
Gorka Eguileor 8ec77f229d Fix #23: auto alias with absolute paths
When using an absolute path an auto alias generation level 3 we would
get IndexError: pop from empty list.

This patch fixes this issue by removing the empty string generated from
splitting the path by "/" and adding a lead "/" to the first directory.
2016-03-25 15:09:23 +01:00
Gorka Eguileor 610c23d389 Fix #22: duplicated auto generated aliases
During auto alias generation with levels 2 and 3, when we are removing
unnecessary directories we were not taking into consideration existing
files in parent directory, so we could end up with duplicated aliases.

For example if we had cinder/vol.log and vol.log we would end up with 2
[vol] aliases.
2016-03-25 15:06:02 +01:00
Gorka Eguileor de87c7e08a Fix #21: KeyError with auto alias level >= 2
This patch fixes an error with auto alias generation levels 2 and 3 were
we would get a KeyError exception on certain cases.

For example with `os-log-merger -a2 2/cinder/vol.log 2/vol.log` we would
be getting KeyError: 'cinder'.

The reason for this was that we were overwriting subtrees so when we
added 2/vol.log we would be destroying the subtree generated when we
added 2/cinder/vol.log.
2016-03-25 15:03:36 +01:00
Gorka Eguileor 50f1564adb Fix #19: Empty output with -m option
When one of the log files is empty and we use `-m` option we will get no
output, unlike normal operation that would output contents of all other
files correctly.

This patch fixes this by removing from the files to read empty ones like
we do once we start processing the files.
2016-03-25 14:58:39 +01:00
Gorka Eguileor 546a34ff09 Fix #13: Don't modify datetime format on output
Current code would modify the datetime format on the output file adding
000 to the microseconds count, so an input of "2016-03-07 12:15:27.805"
would become "2016-03-07 12:15:27.805000".

This patch changes the way we output the datetime, and instead of using
the datetime object used for sorting we will output the original
datetime string.

This will probably be useful later when we support custom log formats or
other log sources.
2016-03-22 22:23:44 +01:00
Gorka Eguileor 93d7d89017 Fix pep8 errors
This patch removes a couple of pep8 errors from oslogmerger.py.
2016-03-22 22:03:38 +01:00
Gorka Eguileor 8459bad993 Optionally reduce memory footprint
This patch adds an option to reduce program's memory footprint during
runtime and updates README file accordingly.

Instead of loading all contents into memory and then sorting the
entries, it will go entry by entry saving the oldest one.

Memory reduced footprint operation increases time to merge logs by
approximately 25%.

Option is `-m` or `--min-memory`.
2016-03-20 23:37:45 +01:00
Gorka Eguileor f7289fb629 Fix #11: Add auto alias generation
This patch adds optional alias generation from filenames.

There are 4 generation levels:
- Level 0: means disabled and will return the full file.
- Level 1: use filename without base or postfix
- Level 2: like 1, change filenames, reduce directories.
- Level 3: like 2, plus reduce directory names

If an alias is given auto alias generation will be skipped for that
file.
2016-03-14 10:01:33 +01:00
Gorka Eguileor 97513f8c4e Fix #9: Remove dependency from oslo_config
This patch replaces the parsing done by oslo_config with arg_parse in
order to remove the dependency on the external library.
2016-03-10 22:56:20 +01:00
Miguel Angel Ajo Pelayo 8b914bd9e4 Do not append slash to logbase 2016-02-20 22:34:27 +01:00
Miguel Angel Ajo Pelayo 6b4d5f4aa5 Introduced log-base and log-postfix options 2016-02-20 16:43:03 +01:00
Miguel Angel Ajo 8771e03c13 Add missing example scripts from RDO day presentation 2016-02-09 09:44:59 +01:00
Miguel Angel Ajo db9527b3d4 Ignore initial non-dated lines
Initial lines, if non dated, generated an exception, this fixes
the issue by ignoring those lines.
2015-11-08 22:41:42 +01:00
Miguel Angel Ajo 183efe3b13 Support for URLS instead of local log files, simple caching. 2015-11-06 14:11:56 +01:00
Miguel Angel Ajo cda7f90f16 More robust processing of out of order log lines 2015-10-29 12:35:45 +01:00
Miguel Angel Ajo 3ea3ead668 Initial commit 2015-10-27 14:01:45 +01:00