@@ -99,6 +99,9 @@ def __init__(self, **kwargs):
99
99
# * allow to create new dashboard with same name in specified folder.
100
100
self .allow_new = kwargs .get ("allow_new" , False )
101
101
102
+ # * when importing dash, keep dashboard uid defined in the json file.
103
+ self .keep_uid = kwargs .get ("keep_uid" , False )
104
+
102
105
# * try to connect to the API
103
106
try :
104
107
res = self .grafana_api .health .check ()
@@ -305,18 +308,25 @@ def import_dashboard(self, dashboard: t.Dict[str, t.Any]) -> bool:
305
308
)
306
309
# ** case d) send a copy to existing dash : update existing
307
310
elif new_dash ["folderId" ] == old_dash ["folderId" ]:
308
- if "uid" not in new_dash ["dashboard" ] or new_dash ["dashboard" ]["uid" ] != old_dash ["uid" ]:
311
+ if (
312
+ "uid" not in new_dash ["dashboard" ]
313
+ or new_dash ["dashboard" ]["uid" ] != old_dash ["uid" ]
314
+ or new_dash ["dashboard" ]["id" ] != old_dash ["id" ]
315
+ ):
309
316
if self .overwrite :
310
- new_dash ["dashboard" ]["uid" ] = old_dash ["uid" ]
317
+ if not self .keep_uid :
318
+ new_dash ["dashboard" ]["uid" ] = old_dash ["uid" ]
311
319
new_dash ["dashboard" ]["id" ] = old_dash ["id" ]
312
320
else :
313
321
raise GrafanaClient .GrafanaBadInputError (
314
322
"Dashboard with the same title already exists in this folder with another uid. "
315
323
"Use `overwrite` to permit overwriting it."
316
324
)
317
325
else :
318
- # force the creation of a new dashboard
319
- new_dash ["dashboard" ]["uid" ] = None
326
+ if not self .keep_uid :
327
+ # force the creation of a new dashboard
328
+ new_dash ["dashboard" ]["uid" ] = None
329
+
320
330
new_dash ["dashboard" ]["id" ] = None
321
331
new_dash ["overwrite" ] = False
322
332
0 commit comments