logide-parsimine/raport/main2.py

52 lines
1.5 KiB
Python

#!/usr/bin/python
# encoding: utf-8
import GeoIP
import re
import sys
from collections import Counter
from log_parsers import JavaLogParser
sys.stderr.write("Loen standardsisendist...\n")
errors = Counter()
for timestamp, log_entry, stack_trace, byte_count, line_count, event_count in JavaLogParser(sys.stdin, errors_only=True):
errors[stack_trace] += 1
from jinja2 import Template
import codecs
HTML_TEMPLATE = u"""<!DOCTYPE>
<html>
<head>
<title>Apache logide raport</title>
<meta charset="utf-8"/>
<link href="https://getbootstrap.com/docs/4.1/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" crossorigin="anonymous"></script>
<script src="https://getbootstrap.com/docs/4.1/dist/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
{% for stack_trace, count in errors.items() %}
<div class="row mt-3">
<div class="md-12">
{{ count }} korda esinenud viga
<button class="btn btn-primary" type="button" data-toggle="collapse"
data-target="#stack-{{ loop.index }}">Stack trace</button>
</div>
</div>
<div class="row">
<div class="md-12">
<div id="stack-{{ loop.index }}" class="collapse">
<pre>{{ stack_trace }}</pre>
</div>
</div>
</div>
{% endfor %}
</div>
</body>
</html>
"""
template = Template(HTML_TEMPLATE)
print template.render(locals())