Skip to content

Commit

Permalink
Add configurable path for Graylog
Browse files Browse the repository at this point in the history
  • Loading branch information
tomtrafford committed Oct 9, 2023
1 parent 006c101 commit 6470e1c
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion malcolm/imalcolm.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,36 @@ def parse_args():
return args


def graylog_from_yaml(yaml_path):
from ruamel.yaml import YAML

assert yaml_path.endswith(
".yaml"
), f"Expected a/path/to/<yamlname>.yaml, got {yaml_path!r}"
with open(yaml_path) as f:
text = f.read()
# First separate them into their relevant sections
yaml = YAML(typ="rt")
ds = yaml.load(text)
graylog = "graylog2.diamond.ac.uk"
for d in ds:
assert len(d) == 1, f"Expected section length 1, got {len(d)}"
name = list(d)[0]
if name == "builtin.defines.string":
if d[name]["name"] == "graylog_path":
graylog = d[name]["value"]
print(graylog)
f.close()
return graylog


def make_logging_config(args):
from ruamel import yaml

graylog = "graylog2.diamond.ac.uk"
if args.yaml:
graylog = graylog_from_yaml(args.yaml)
print(graylog)
log_config = {
"version": 1,
"disable_existing_loggers": False,
Expand Down Expand Up @@ -99,7 +126,7 @@ def make_logging_config(args):
"class": "pygelf.GelfTcpHandler",
# Obviously a DLS-specific configuration: the graylog server
# address and port
"host": "graylog2.diamond.ac.uk",
"host": graylog,
"port": 12202,
"debug": True,
"level": "DEBUG",
Expand Down

0 comments on commit 6470e1c

Please sign in to comment.