debian-image-builder-frontend/devel/gen-dashboards
Gianluca Zuccarelli 53b5bdf72b devel: re-use existing dashboards
Rather than have duplicate copies of the dashboard in this repo,
I've added a python script to extract the dashboard configs from
the image-builder and osbuild-composer repos. The script is called
in the `setup.sh` script.`
2021-10-29 11:02:22 +01:00

32 lines
1 KiB
Python
Executable file

#!/usr/bin/env python
import argparse, sys, yaml
TEMPLATE_DIR="../../image-builder/templates/dashboards/grafana-dashboard-insights-image-builder-general.configmap.yml"
OUTPUT_DIR="config/grafana/dashboards/"
def load_config(config_filepath):
with open(config_filepath, "r") as stream:
try:
return yaml.safe_load(stream)['data']['grafana.json']
except yaml.YAMLError as e:
print("Error parsing configmap: {}\n".format(str(e)))
sys.exit(1)
def write_dashboard(dashboard, output_filepath):
with open(output_filepath, 'w') as f:
try:
f.write(dashboard)
f.close()
except Exception as e:
print("Error saving dashboard: {}\n".format(str(e)))
sys.exit(1)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--input", help="Path to the dashboard configmap", type=str)
parser.add_argument("-o", "--output", help="File path of the output", type=str)
args = parser.parse_args()
write_dashboard(load_config(args.input), args.output)
if __name__ == "__main__":
main()