fdellwing
(Fabian Dellwing)
September 25, 2018, 7:08am
1
Da ich nirgends etwas gefunden habe, habe ich versucht mein eigenes Regex dafür zu schreiben:
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET.
Leider funktioniert dies nicht so wirklich und ich sehe aktuell nicht warum, hat noch jemand eine Idee?
[09:05 root@drupal-cms ~] > /var/www/piwik/misc/log-analytics/import_logs.py --recorders=4 --url=https://stats.promato.de --idsite=16 --log-format-regex='.*:\ (?P<ip>[\w*.]+).*\[(?P<date>.*)\].*\ (?P<status>\b\d{3}\b)\ (?P<length>\d+)\ -.*\"(?P<method>\S+)\ (?P<path>[\S]+).*' --dry-run /tmp/krberlin.log.1
0 lines parsed, 0 lines recorded, 0 records/sec (avg), 0 records/sec (current)
Parsing log /tmp/krberlin.log.1...
Logs import summary
-------------------
0 requests imported successfully
22 requests were downloads
4562 requests ignored:
101 HTTP errors
38 HTTP redirects
2179 invalid log lines
0 filtered log lines
0 requests did not match any known site
0 requests did not match any --hostname
0 requests done by bots, search engines...
2244 requests to static resources (css, js, images, ico, ttf...)
0 requests to file downloads did not match any --download-extensions
Website import summary
----------------------
0 requests imported to 1 sites
1 sites already existed
0 sites were created:
0 distinct hostnames did not match any existing site:
Performance summary
-------------------
Total time: 0 seconds
Requests imported per second: 0.0 requests per second
Leider scheint es auch keine Methode zu geben mir sagen zu lassen welche Lines ihm nicht passen.
fdellwing
(Fabian Dellwing)
September 26, 2018, 9:17am
2
@Lukas Irgendeine Idee? Das zu debuggen ist echt frustrierend.
Alle diese 10 Zeilen sind angeblich ungültig, matchen aber das Regex:
Sep 25 05:55:57 dktig-proxy haproxy[6801]: 157.55.39.209:33372 [25/Sep/2018:05:55:57.211] ft_https~ bk_krberlin/dkv 0/0/0/208/208 200 8325 - - ---- 15/12/0/1/0 0/0 "GET /de/suche/search/berlin/bezirk/12.jsf HTTP/1.1"
Sep 25 06:02:55 dktig-proxy haproxy[6801]: 157.55.39.209:28324 [25/Sep/2018:06:02:55.349] ft_https~ bk_krberlin/dkv 0/0/0/277/277 200 7433 - - ---- 7/6/0/1/0 0/0 "GET /en/search/search/hospital/show.jsf HTTP/1.1"
Sep 25 06:05:01 dktig-proxy haproxy[6801]: 189.59.5.81:58370 [25/Sep/2018:06:05:01.688] ft_https~ bk_krberlin/dkv 0/0/1/103/104 200 7316 - - ---- 5/4/0/1/0 0/0 "GET /user/ HTTP/1.1"
Sep 25 06:05:27 dktig-proxy haproxy[6801]: 176.62.229.88:55008 [25/Sep/2018:06:05:27.584] ft_https~ bk_krberlin/dkv 0/0/0/72/72 200 7456 - - ---- 5/4/0/1/0 0/0 "POST /user/ HTTP/1.1"
Sep 25 06:21:59 dktig-proxy haproxy[6801]: 66.249.76.104:60671 [25/Sep/2018:06:21:58.960] ft_https~ bk_krberlin/dkv 0/0/0/277/277 200 7532 - - ---- 9/8/0/1/0 0/0 "GET /en/search/hospital/show/formular/2.1/261100310/00.jsf HTTP/1.1"
Sep 25 06:22:30 dktig-proxy haproxy[6801]: 157.55.39.114:11032 [25/Sep/2018:06:22:30.443] ft_https~ bk_krberlin/dkv 0/0/0/128/128 200 8643 - - ---- 7/6/0/1/0 0/0 "GET /de/hilfe/merkliste HTTP/1.1"
Sep 25 06:22:31 dktig-proxy haproxy[6801]: 157.55.39.114:11032 [25/Sep/2018:06:22:30.740] ft_https~ bk_krberlin/dkv 0/0/0/446/453 200 39206 - - ---- 7/6/0/1/0 0/0 "GET /de/suche/Struktur.html HTTP/1.1"
Sep 25 06:22:35 dktig-proxy haproxy[6801]: 157.55.39.197:7732 [25/Sep/2018:06:22:35.793] ft_https~ bk_krberlin/dkv 0/0/1/91/92 200 8052 - - ---- 7/6/0/1/0 0/0 "GET /de/hilfe/qualitaet HTTP/1.1"
Sep 25 06:23:18 dktig-proxy haproxy[6801]: 66.249.76.102:54478 [25/Sep/2018:06:23:17.934] ft_https~ bk_krberlin/dkv 0/0/0/509/509 200 8629 - - ---- 5/4/0/1/0 0/0 "GET /en/search/hospital/show/formular/2.1/261100310/00/314475953.jsf;jsessionid=8A79BAEFBBB2DC550D4ED403A98F7191 HTTP/1.1"
Sep 25 06:23:52 dktig-proxy haproxy[6801]: 66.249.76.102:54478 [25/Sep/2018:06:23:51.824] ft_https~ bk_krberlin/dkv 0/0/0/426/426 200 9763 - - ---- 6/5/0/1/0 0/0 "GET /en/search/hospital/show/formular/2.2/261110027/02/314429390/B-3:table1/3.html;jsessionid=86C4FDD3FB60F6677F05C8E8A4A73D03 HTTP/1.1"
fdellwing
(Fabian Dellwing)
September 26, 2018, 10:03am
3
Ok, habe es gelöst. Ich habe gelernt (Invalid log lines with common_complete log format · Issue #197 · matomo-org/matomo-log-analytics · GitHub ), dass man 2x --debug
angeben kann um angezeigt zu bekommen was ihn genau stört (Ist das irgendwo dokumentiert?). Danach war es recht einfach, man muss einfach ein Datumsformat angeben welches die Millisekunden enthält
Um erfolgreich haproxy Logs zu importieren benötigt man also folgende 2 Optionen:
--log-format-regex='.*:\ (?P<ip>[\w*.]+).*\[(?P<date>.*)\].*\ (?P<status>\b\d{3}\b)\ (?P<length>\d+)\ -.*\"(?P<method>\S+)\ (?P<path>[\S]+).*' --log-date-format='%d/%b/%Y:%H:%M:%S.%f'
1 Like
Lukas
(Lukas Winkler)
September 26, 2018, 4:53pm
4
Hallo,
Schön, dass du die Lösung gefunden hast. Ich habe LogAnalytics noch nie verwendet und kenne mich daher nicht so gut aus.
Es wäre wirklich nett, wenn du einen Pull Request mit dem Regex machen könntet:
Das mit --debug --debug
ist definitiv nicht intuitiv und kommt auf meine Dokumentations-TODO.
fdellwing
(Fabian Dellwing)
September 27, 2018, 7:31am
5
Puh, mein Python ist echt nicht so gut. Ich schaue mal ob ich das hinbekomme…
Lukas
(Lukas Winkler)
September 27, 2018, 7:33am
6
Ich glaube, du musst einfach nur hier einen Eintrag hinzufügen.
'ncsa_extended': RegexFormat('ncsa_extended', _NCSA_EXTENDED_LOG_FORMAT),
'common_complete': RegexFormat('common_complete', _HOST_PREFIX + _NCSA_EXTENDED_LOG_FORMAT),
'w3c_extended': W3cExtendedFormat(),
'amazon_cloudfront': AmazonCloudFrontFormat(),
'iis': IisFormat(),
'shoutcast': ShoutcastFormat(),
's3': RegexFormat('s3', _S3_LOG_FORMAT),
'icecast2': RegexFormat('icecast2', _ICECAST2_LOG_FORMAT),
'elb': RegexFormat('elb', _ELB_LOG_FORMAT, '%Y-%m-%dT%H:%M:%S'),
'nginx_json': JsonFormat('nginx_json'),
'ovh': RegexFormat('ovh', _OVH_FORMAT)
}
##
## Code.
##
class Configuration(object):
"""
Stores all the configuration options by reading sys.argv and parsing,
if needed, the config.inc.php.
fdellwing
(Fabian Dellwing)
September 27, 2018, 7:45am
7
Tja, leider isses nicht so einfach. Wenn ich den Regex fest einbaue matcht plötzlich keine einzige Zeile mehr. Ich gucke mal ob ich was rausfinde.
1 Like
Lukas
(Lukas Winkler)
September 27, 2018, 7:47am
8
Vermutlich brauchst du in Python die ganzen \
zum Escapen der Sonderzeichen (wie [
) nicht mehr.
fdellwing
(Fabian Dellwing)
September 27, 2018, 7:47am
9
Der Regex Editor ist auf Python eingestellt UND natürlich wurde das Regex auch vorher mit Python gematched wenn ich über die CLI übergebe
fdellwing
(Fabian Dellwing)
September 27, 2018, 7:56am
10
Ok, habe das Problem gefunden in dem ich mir mal hab ausgeben lassen, was er an re.compile()
übergibt. Es sieht so aus, also müsste ich \b
doppelt escapen, also \\b
dann kommt es korrekt als \b
beim compile an.
1 Like