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