Logdissect is a CLI utility and Python library for analyzing log files and other data. It can parse, merge, filter, and export data (to log files, or JSON).
Installing
sudo pip install logdissect
or
git clone https://github.com/dogoncouch/logdissect.gitcd logdissectsudo make all
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
--verbose set verbose terminal output
-s silence terminal output
--list-parsers return a list of available parsers
-p PARSER select a parser (default: syslog)
-z, --unzip include files compressed with gzip
-t TZONE specify timezone offset to UTC (e.g. '+0500')
filter options:
--dhost DHOST match a destination host
--grep PATTERN match a pattern
--last LAST match a preceeding time period (e.g. 5m/3h/2d/etc)
--process PROCESS match a source process
--protocol PROTOCOL match a protocol
--range RANGE match a time range (YYYYMMDDhhmm-YYYYMMDDhhmm)
--utc use UTC for range matching
--rdhost DHOST filter out a destination host
--rgrep PATTERN filter out a pattern
--rprocess PROCESS filter out a source process
--rprotocol PROTOCOL filter out a protocol
--rshost SHOST filter out a source host
--rsource SOURCE filter out a log source
--shost SHOST match a source host
--source SOURCE match a log source
output options:
--linejson LINEJSON set the output file for line by line JSON output
--outlog OUTLOG set the output file for standard log output
--label LABEL set label type for OUTLOG (fname|fpath)
--sojson SOJSON set the output file for single object JSON output
--pretty use pretty formatting for sojson output
metadata: logdissect uses file modification times to assign years to syslog date stamps. This allows it to parse logs that span more than one year without a problem. If you are copying log files, always use cp -p (or cp –preserve=timestamps) and scp -p to preserve original mtimes and other file metadata.
Re-parsing: If you are planning on parsing an output file back into logdissect at some point, using JSON is highly recommended. The JSON output modules use date stamps that include a year. Re-parsing a standard log output file will cause problems if the file has a different mtime than the original logs.
–range shortcuts: The range module will fill in your ranges with zeroes if they are shorter than 14 characters. If you want to get a range of 20170204120000 to 20170204130000, you can save time and use 2017020412 and 2017020413.
–last options: The last option should be a number followed by either ‘s’ for seconds, ‘m’ for minutes, ‘h’ for hours, or ‘d’ for days (e.g. –last=20m).
Multiple options: All non-time-based filters can be used more than once.
logdissect 2.0 and above provides a stable API for parsing log lines and files. For more information on library usage, see the API documentation.