-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_parser.star
executable file
·37 lines (31 loc) · 1015 Bytes
/
log_parser.star
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
load("json.star", "json")
load("time.star", "time")
#load("logging.star", "log")
def apply(metric):
#log.debug("soh value: {}".format(metric.fields.get("value")))
j = json.decode(metric.fields.get("value"))
new_metric = Metric("log")
new_metric.tags["level"] = j["level"]
new_metric.tags["location"] = j["location"]
level = "info"
location = "unknown"
if "level" in j:
level = j["level"]
if "location" in j:
location = j["location"]
new_metric.tags["level"] = level
new_metric.tags["location"] = location
new_metric.time = time.now().unix_nano
# Iterate over json keys
for key in j:
# Skip these since they are already dealt with
if key == "level" or key == "location":
continue
# Add other keys as fields
entry = j[key]
etype = type(entry)
if (etype != "string"):
# skip non-strings
continue
new_metric.fields[key] = entry
return new_metric