probe_dump.py 1.44 KB
Newer Older
Daniel Salzman's avatar
Daniel Salzman committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
#
# A simple Knot DNS probe client
#

import argparse
import libknot
import libknot.probe
import sys


def probe_loop(args):
    try:
        libknot.Knot(args.libknot_path)
    except:
        print("Cannot find shared library libknot.so")
        sys.exit(1)

    probe = libknot.probe.KnotProbe(args.probe_dir, args.channel)
    data = libknot.probe.KnotProbeDataArray(8)

    try:
        while (True):
            if probe.consume(data, 1000) > 0:
                for item in data:
                    print(item.str(color=not args.no_color, timestamp=not args.no_timestamp))
    except KeyboardInterrupt:
        sys.exit(0)


if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        formatter_class = argparse.ArgumentDefaultsHelpFormatter,
    )
    parser.add_argument(
36
        "-l", "--libknot-path",
Daniel Salzman's avatar
Daniel Salzman committed
37
38
39
        help="path to the libknot shared library"
    )
    parser.add_argument(
40
        "-d", "--probe-dir",
Daniel Salzman's avatar
Daniel Salzman committed
41
42
43
44
        default="/run/knot",
        help="path to the probe directory"
    )
    parser.add_argument(
45
        "-c", "--channel",
Daniel Salzman's avatar
Daniel Salzman committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
        type=int,
        default=1,
        help="the probe channel"
    )
    parser.add_argument(
        "--no-color",
        action='store_true',
        help="don't colorize the output"
    )
    parser.add_argument(
        "--no-timestamp",
        action='store_true',
        help="don't print the current timestamp"
    )
    args = parser.parse_args()

    probe_loop(args)