This commit is contained in:
parent
ba5b52b15d
commit
1ad8365bf2
2 changed files with 9 additions and 7 deletions
|
@ -7,9 +7,9 @@ pipeline:
|
||||||
group: test
|
group: test
|
||||||
commands:
|
commands:
|
||||||
- pip3 install -e .[test]
|
- pip3 install -e .[test]
|
||||||
- python3 -m unittest coverage run --rcfile=setup.cfg -m unittest discover tlsrpt_exporter
|
- python3 -m coverage run --rcfile=setup.cfg -m unittest discover tlsrpt_exporter
|
||||||
- python3 -m unittest coverage combine
|
- python3 -m coverage combine
|
||||||
- python3 -m unittest coverage report --rcfile=setup.cfg
|
- python3 -m coverage report --rcfile=setup.cfg
|
||||||
|
|
||||||
codestyle:
|
codestyle:
|
||||||
image: python:3.11-bookworm
|
image: python:3.11-bookworm
|
||||||
|
|
|
@ -39,7 +39,8 @@ class Reporter(bottle.Bottle):
|
||||||
prefix += f'{count_s},{count_f};'
|
prefix += f'{count_s},{count_f};'
|
||||||
if domain is None:
|
if domain is None:
|
||||||
return
|
return
|
||||||
with open(os.path.join(self.datadir, 'reports', prefix[:-1] + '+' + domain + '+' + data['report-id']), 'w') as f:
|
fname = os.path.join(self.datadir, 'reports', prefix[:-1] + '+' + domain + '+' + data['report-id'])
|
||||||
|
with open(fname, 'w') as f:
|
||||||
json.dump(data, f)
|
json.dump(data, f)
|
||||||
|
|
||||||
def report(self):
|
def report(self):
|
||||||
|
@ -47,7 +48,7 @@ class Reporter(bottle.Bottle):
|
||||||
bottle.response.add_header('Accept', 'application/tlsrpt+json')
|
bottle.response.add_header('Accept', 'application/tlsrpt+json')
|
||||||
if 'application/tlsrpt+gzip' in bottle.request.content_type:
|
if 'application/tlsrpt+gzip' in bottle.request.content_type:
|
||||||
self.handle(self.decompress(bottle.request.body))
|
self.handle(self.decompress(bottle.request.body))
|
||||||
elif 'application/tlsrpt+json' in bottle.request.content_type:
|
elif 'application/tlsrpt+json' in bottle.request.content_type:
|
||||||
self.handle(json.load(bottle.request.body))
|
self.handle(json.load(bottle.request.body))
|
||||||
else:
|
else:
|
||||||
bottle.response.status = 406
|
bottle.response.status = 406
|
||||||
|
@ -69,7 +70,7 @@ class Metrics(bottle.Bottle):
|
||||||
self.count_f[domain] = self.count_f.setdefault(domain, 0) + count_f
|
self.count_f[domain] = self.count_f.setdefault(domain, 0) + count_f
|
||||||
self.count[domain] = self.count.setdefault(domain, 0) + 1
|
self.count[domain] = self.count.setdefault(domain, 0) + 1
|
||||||
|
|
||||||
def load_reports(self):
|
def load_reports(self):
|
||||||
for report in os.listdir(os.path.join(self.datadir, 'reports')):
|
for report in os.listdir(os.path.join(self.datadir, 'reports')):
|
||||||
if report.startswith('.'):
|
if report.startswith('.'):
|
||||||
continue
|
continue
|
||||||
|
@ -163,7 +164,8 @@ def main():
|
||||||
ap.add_argument('--host', '-H', type=str, default='::', help='Address to bind to')
|
ap.add_argument('--host', '-H', type=str, default='::', help='Address to bind to')
|
||||||
ap.add_argument('--port', '-p', type=int, default=9123, help='Port to bind to')
|
ap.add_argument('--port', '-p', type=int, default=9123, help='Port to bind to')
|
||||||
ap.add_argument('--base-url', '-B', type=str, default=None, help='Base URL')
|
ap.add_argument('--base-url', '-B', type=str, default=None, help='Base URL')
|
||||||
ap.add_argument('--data-dir', '-d', type=str, default='/tmp/prometheus-tlsrpt-exporter', help='Directory to save reports to')
|
ap.add_argument('--data-dir', '-d', type=str,
|
||||||
|
default='/tmp/prometheus-tlsrpt-exporter', help='Directory to save reports to')
|
||||||
ap.add_argument('--template-dir', '-t', type=str, default='templates', help='Directory to load templates from')
|
ap.add_argument('--template-dir', '-t', type=str, default='templates', help='Directory to load templates from')
|
||||||
ns = ap.parse_args()
|
ns = ap.parse_args()
|
||||||
os.makedirs(os.path.join(ns.data_dir, 'reports'), exist_ok=True)
|
os.makedirs(os.path.join(ns.data_dir, 'reports'), exist_ok=True)
|
||||||
|
|
Loading…
Reference in a new issue