-
Notifications
You must be signed in to change notification settings - Fork 4
/
zeek-client
executable file
·58 lines (42 loc) · 1.66 KB
/
zeek-client
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#! /usr/bin/env python3
"""
This is a prototypical implementation of a Zeek management client, as sketched
in the following architecture design doc:
https://docs.google.com/document/d/1r0wXnihx4yESOpLJ87Wh2g1V-aHOFUkbgiFe8RHJpZo/edit
Work on this client is currently in progress and maturing over the course of
the Zeek 5.x series. Feedback is welcome. This implementation adopts many of
the idioms and primitives also used by the zkg package manager.
"""
# https://pypi.org/project/argcomplete/#global-completion
# PYTHON_ARGCOMPLETE_OK
import sys
import zeekclient
def main():
# Preliminary configuration update: environment variables can already take
# hold. This allows autocompleted settings to show values more accurately
# than our hardwired defaults.
zeekclient.CONFIG.update_from_env()
parser = zeekclient.cli.create_parser()
args = parser.parse_args()
# Finalize config settings in expected hierarchical order:
zeekclient.CONFIG.update_from_file(args.configfile)
zeekclient.CONFIG.update_from_env()
zeekclient.CONFIG.update_from_args(args)
if args.version:
print(zeekclient.__version__)
return 0
# Establish logging as per requested verbosity and formatting
if not args.quiet:
zeekclient.logs.configure(
zeekclient.CONFIG.getint("client", "verbosity"),
zeekclient.CONFIG.getboolean("client", "rich_logging_format"),
)
if not args.command:
zeekclient.LOG.error("please provide a command to execute.")
return 1
try:
return args.run_cmd(args)
except KeyboardInterrupt:
return 0
if __name__ == "__main__":
sys.exit(main())