]> git.ipfire.org Git - thirdparty/systemd.git/blame - tools/catalog-report.py
tree-wide: drop 'This file is part of systemd' blurb
[thirdparty/systemd.git] / tools / catalog-report.py
CommitLineData
3e67e5c9 1#!/usr/bin/env python3
ba953453 2# -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
35df7443 3# SPDX-License-Identifier: MIT
ba953453 4#
818bf546 5# This file is distributed under the MIT license, see below.
ba953453
ZJS
6#
7# Copyright 2016 Zbigniew Jędrzejewski-Szmek
8#
9# The MIT License (MIT)
10#
11# Permission is hereby granted, free of charge, to any person obtaining a copy
12# of this software and associated documentation files (the "Software"), to deal
13# in the Software without restriction, including without limitation the rights
14# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15# copies of the Software, and to permit persons to whom the Software is
16# furnished to do so, subject to the following conditions:
17#
18# The above copyright notice and this permission notice shall be included in
19# all copies or substantial portions of the Software.
20#
21# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27# SOFTWARE.
28
29"""
30Prints out journal entries with no or bad catalog explanations.
31"""
32
33import re
34from systemd import journal, id128
35
36j = journal.Reader()
37
38logged = set()
39pattern = re.compile('@[A-Z0-9_]+@')
40
41mids = {v:k for k,v in id128.__dict__.items()
42 if k.startswith('SD_MESSAGE')}
43
44freq = 1000
45
46def log_entry(x):
47 if 'CODE_FILE' in x:
48 # some of our code was using 'CODE_FUNCTION' instead of 'CODE_FUNC'
49 print('{}:{} {}'.format(x.get('CODE_FILE', '???'),
50 x.get('CODE_LINE', '???'),
51 x.get('CODE_FUNC', None) or x.get('CODE_FUNCTION', '???')))
52 print(' {}'.format(x.get('MESSAGE', 'no message!')))
53 for k, v in x.items():
54 if k.startswith('CODE_') or k in {'MESSAGE_ID', 'MESSAGE'}:
55 continue
56 print(' {}={}'.format(k, v))
57 print()
58
59for i, x in enumerate(j):
60 if i % freq == 0:
61 print(i, end='\r')
62
63 try:
64 mid = x['MESSAGE_ID']
65 except KeyError:
66 continue
67 name = mids.get(mid, 'unknown')
68
69 try:
70 desc = journal.get_catalog(mid)
71 except FileNotFoundError:
72 if mid in logged:
73 continue
74
75 print('{} {.hex}: no catalog entry'.format(name, mid))
76 log_entry(x)
77 logged.add(mid)
78 continue
79
80 fields = [field[1:-1] for field in pattern.findall(desc)]
81 for field in fields:
82 index = (mid, field)
83 if field in x or index in logged:
84 continue
85 print('{} {.hex}: no field {}'.format(name, mid, field))
86 log_entry(x)
87 logged.add(index)