def write_dashboard(get_path, parent_folder, isHome=False): dat = EasyDict() com = RecursiveFormatter(dat, BACKUP_INFO) raw_dbdi = json.loads(run("curl " + get_path)) the_db = raw_dbdi["dashboard"] the_db.pop("version", None) the_db.pop("id", None) good_from = {} good_from["dashboard"] = the_db good_from["overwrite"] = True dat.grafana_type_export = "dashboard" dat.file_month = datetime.datetime.now().month dat.file_year = datetime.datetime.now().year dat.datasource_name = raw_dbdi["meta"]["slug"] # db_fn = (str(raw_dbdi["meta"]["slug"]) + "_dashboard.json") if isHome == True: # db_fn = "HOME-dashboard.json" dat.datasource_name = "_HOME_" good_from["meta"] = {"isHome": True} datasource_bk_path = com.raw_( pjoin(parent_folder, BACKUP_INFO.grafana_export_file)) with open(datasource_bk_path, "w") as dbo: json.dump(good_from, dbo)
def grafana_retrive_datasources(parent_local_folder): grafana_url = "localhost:3000" dat = EasyDict() com = RecursiveFormatter(dat, BACKUP_INFO) dat.grafana_type_export = "datasource" dat.file_month = datetime.datetime.now().month dat.file_year = datetime.datetime.now().year with quiet(): # TODO in case values are not found, prompt user for them !!!!, Maybe # generalize the procedure dash_json = run("curl http://{}:{}@{}/api/datasources/ ".format( odb.var.GRAFANA_ADMIN_NAME, odb.var.GRAFANA_ADMIN_PASS, grafana_url)).strip() print(dash_json) dasource = json.loads(dash_json) local("mkdir -p " + parent_local_folder) for datas_dict in dasource: dat.datasource_name = datas_dict["name"] datasource_bk_path = com.raw_( pjoin(parent_local_folder, BACKUP_INFO.grafana_export_file)) datas_dict.pop("id", None) with open(datasource_bk_path, "w") as das: json.dump(datas_dict, das)