Commit fb2c36f0 authored by Michał Woźniak's avatar Michał Woźniak

Support Matomo 4.x and Python 3.x

parent 9840127d
__pycache__
FROM python:2-alpine
FROM python:3-alpine
MAINTAINER Michał "rysiek" Woźniak <rysiek@hackerspace.pl>
# we need git
RUN apk add --no-cache git
# add Matomo log analytics
RUN git clone --single-branch --branch 3.x-dev https://github.com/matomo-org/matomo-log-analytics.git /opt/matomo-log-analytics
RUN git clone --single-branch --branch 4.x-dev https://github.com/matomo-org/matomo-log-analytics.git /opt/matomo-log-analytics
WORKDIR /opt/matomo-log-analytics
RUN pip install inotify_simple
COPY ./logwatch.py /opt/matomo-log-analytics/
COPY ./matomnom.py /opt/matomo-log-analytics/
ENTRYPOINT ["python", "./logwatch.py"]
ENTRYPOINT ["python", "./matomnom.py"]
CMD ["--help"]
# Log MatomNom (for Matomo 3.x)
# Log MatomNom (for Matomo 4.x)
Matomo's [log analytics](https://matomo.org/log-analytics/), but automatically watching specified directories for logs to ingest. Any detected logfiles are ingested and moved out of the way or deleted.
......@@ -6,7 +6,7 @@ The script should be useful in situations where webserver logfiles are to be ing
## Requirements
The `logwatch.py` script requires Matomo's `import_logs.py` (branch `3-x.dev`) log analytics script to be available for import. Since that script only runs on Python 2.7, so does this. Obviously requirements of the `import_logs.py` script need to be satisfied, plus `inotify_simple` and `signal` modules need to be available.
The `matomnom.py` script requires Matomo's `import_logs.py` (branch `4-x.dev`) log analytics script to be available for import. Since that script only runs on Python 3.x, so does this. Obviously requirements of the `import_logs.py` script need to be satisfied, plus `inotify_simple` and `signal` modules need to be available.
## Operation
......@@ -22,7 +22,7 @@ While ingestion is in progress new files are *not* being added to the batch. Onc
## Usage
Run `./logwatch.py --help` to get help. All `import_logs.py` options are supported, plus these additional ones:
Run `./matomnom.py --help` to get help. All `import_logs.py` options are supported, plus these additional ones:
- `--logfiles-glob` (default: `"*.log"`)
Only files matching this shell glob expression will be ingested. It's
......@@ -77,13 +77,13 @@ Run `./logwatch.py --help` to get help. All `import_logs.py` options are support
## Docker usage
Run the image with log directories you want to watch volume-mounted. Specify the options and directories to watch directly as the command (`logwatch.py` is the entrypoint script, and default command is `--help`).
Run the image with log directories you want to watch volume-mounted. Specify the options and directories to watch directly as the command (`matomnom.py` is the entrypoint script, and default command is `--help`).
### Example docker-compose service
```yaml
logwatch:
build: https://git.rys.io/libre/log-matomnom.git#matomo-3.x
matomnom:
build: https://git.rys.io/libre/log-matomnom.git#matomo-4.x
volumes:
- "/var/log/old/nginx/:/logs/nginx/"
- "/var/log/old/apache/:/logs/apache/"
......
......@@ -3,7 +3,7 @@
from inotify_simple import INotify, flags
import import_logs
from optparse import OptionParser
from argparse import ArgumentParser
import sys
import os
import os.path
......@@ -15,6 +15,7 @@ import shutil
import logging
import threading
import signal
import textwrap
def signal_handler(signal, frame):
logging.info('Quitting...')
......@@ -82,7 +83,7 @@ By default, the script will try to produce clean reports and will exclude bots,
self.parser.epilog="""About Watchful Matomo Log Analytics: https://git.rys.io/libre/watchful-matomo-log-analytics/ ;
This script is based on Matomo Server Log Analytics: https://matomo.org/log-analytics/"""
self.parser.add_option(
self.parser.add_argument(
'--logfiles-glob',
dest='logfiles_glob',
default="*.log",
......@@ -91,10 +92,10 @@ This script is based on Matomo Server Log Analytics: https://matomo.org/log-anal
"prefix and suffix is applied! See --prefix-ingested and --suffix-ingested."
)
self.parser.add_option(
self.parser.add_argument(
'--ingestion-grace-period',
dest='ingestion_grace_period',
type='float',
type=float,
default=5,
help="Delay (in seconds; fractions are supported) between noticing a logfile to be "
"processed and starting ingesting it. This is part of the built-in heuristic for "
......@@ -102,7 +103,7 @@ This script is based on Matomo Server Log Analytics: https://matomo.org/log-anal
"safely ingested."
)
self.parser.add_option(
self.parser.add_argument(
'--delete-ingested',
dest='delete_ingested',
action='store_true',
......@@ -110,7 +111,7 @@ This script is based on Matomo Server Log Analytics: https://matomo.org/log-anal
help="Delete successfully ingested logfiles."
)
self.parser.add_option(
self.parser.add_argument(
'--prefix-ingested',
dest='prefix_ingested',
default="ingested/",
......@@ -122,7 +123,7 @@ This script is based on Matomo Server Log Analytics: https://matomo.org/log-anal
"is ignored if --delete-ingested is used."
)
self.parser.add_option(
self.parser.add_argument(
'--suffix-ingested',
dest='suffix_ingested',
default=".ingested",
......@@ -130,7 +131,7 @@ This script is based on Matomo Server Log Analytics: https://matomo.org/log-anal
"This option is ignored if --delete-ingested is used."
)
self.parser.add_option(
self.parser.add_argument(
'--exit-on-error',
dest='exit_on_error',
action='store_true',
......@@ -138,7 +139,7 @@ This script is based on Matomo Server Log Analytics: https://matomo.org/log-anal
help="Exit when ingestion errors are encountered."
)
self.parser.add_option(
self.parser.add_argument(
'--delete-failed',
dest='delete_failed',
action='store_true',
......@@ -147,7 +148,7 @@ This script is based on Matomo Server Log Analytics: https://matomo.org/log-anal
)
self.parser.add_option(
self.parser.add_argument(
'--prefix-failed',
dest='prefix_failed',
default="failed/",
......@@ -161,7 +162,7 @@ This script is based on Matomo Server Log Analytics: https://matomo.org/log-anal
"if --delete-failed is used."
)
self.parser.add_option(
self.parser.add_argument(
'--suffix-failed',
dest='suffix_failed',
default=".failed",
......@@ -169,7 +170,7 @@ This script is based on Matomo Server Log Analytics: https://matomo.org/log-anal
"contain any '/' characters. This option is ignored if --delete-failed is used."
)
self.parser.add_option(
self.parser.add_argument(
'--no-auto-archive',
dest='auto_archive',
action='store_false',
......@@ -366,10 +367,10 @@ config = Configuration()
import_logs.config = config
# this depends on the Configuration()
matomo = import_logs.Matomo()
matomo = import_logs.MatomoHttpUrllib()
import_logs.matomo = matomo
# this depends on Matomo()
# this depends on MatomoHttpUrllib()
config.init_token_auth()
# the rest of init
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment