Created
July 3, 2020 14:32
-
-
Save tsg/23534eb1822d1e84947731c38194be1f to your computer and use it in GitHub Desktop.
Split Kibana ndjson into search/visualization/dashboard as expected by the package registry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import sys | |
import os | |
# create dest directories | |
def ensure_directories(dest_dir): | |
def ensure_dir(dir): | |
if not os.path.exists(dir): | |
os.makedirs(dir) | |
ensure_dir(os.path.join(dest_dir, "dashboard")) | |
ensure_dir(os.path.join(dest_dir, "search")) | |
ensure_dir(os.path.join(dest_dir, "visualization")) | |
if __name__ == "__main__": | |
source_file = sys.argv[1] | |
dest_dir = sys.argv[2] | |
ensure_directories(dest_dir) | |
with open(source_file, "r") as fread: | |
for line in fread: | |
saved_object = json.loads(line) | |
type_ = saved_object.get("type") | |
id_ = saved_object.get("id") | |
if type_ == "dashboard": | |
fname = os.path.join(dest_dir, "dashboard", id_ + ".json") | |
elif type_ == "search": | |
fname = os.path.join(dest_dir, "search", id_ + ".json") | |
elif type_ == "visualization": | |
fname = os.path.join(dest_dir, "visualization", id_ + ".json") | |
else: | |
continue | |
with open(fname, "w") as fwrite: | |
json.dump(saved_object, fwrite, indent=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment