-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
migraterule.py
executable file
·40 lines (27 loc) · 992 Bytes
/
migraterule.py
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
#!/usr/bin/env python
import json
import sys
if __name__ == "__main__":
failed = []
for line in sys.stdin.readlines():
line = line.strip("\n")
rule = json.loads(line)
new_meta = {}
old_meta = rule["Meta"]
# cannot migrate rules with more than one channel
# because we don't know which event id matches to
# which channel (drawback of old rules)
if len(rule["Meta"]["Channels"]) > 1:
failed.append(rule["Name"])
continue
new_meta["Events"] = { rule["Meta"]["Channels"][0]: rule["Meta"]["EventIDs"] }
for k in old_meta:
if k not in ["Traces", "Channels", "EventIDs"]:
new_meta[k] = old_meta[k]
new_meta["Schema"] = "2.0.0"
rule["Meta"] = new_meta
json.dump(rule, sys.stdout, indent=2)
print()
print()
for f in failed:
print(f"Failed at migrating {f}", file=sys.stderr)