@@ -94,23 +94,30 @@ func (d *SampleDatasource) CheckHealth(_ context.Context, req *backend.CheckHeal
9494 }
9595 for _ , dashboard := range dashboards {
9696 // get raw Json
97- dashboardJson , _ , err := grafanaApi .GetRawDashboardByID (dashboard .UID )
97+ dashboardJson , boardProperties , err := grafanaApi .GetRawDashboardByID (dashboard .UID )
9898 if err != nil {
9999 log .DefaultLogger .Error ("get raw dashboard" , "error" , err .Error ())
100100 }
101+
102+ // get folder name and id, needed for update processes and git folder structure
103+ folderName := boardProperties .FolderTitle
104+ folderId := boardProperties .FolderID
105+
101106 // get dashboard Object TODO: Verify if raw Json manipulation is faster
102107 dashboardObject , _ , err := grafanaApi .GetDashboardObjectByID (dashboard .UID )
103108 if err != nil {
104109 log .DefaultLogger .Error ("get dashboard" , "error" , err .Error ())
105110 }
111+
106112 // delete Tag from dashboard
107113 dashboardWithDeletedTag := grafanaApi .DeleteTagFromDashboardObjectByID (dashboardObject , dashboardTag )
114+
108115 // update dashboard with deleted Tag
109- _ , err = grafanaApi .UpdateDashboardObjectByID (dashboardWithDeletedTag )
116+ _ , err = grafanaApi .UpdateDashboardObjectByID (dashboardWithDeletedTag , folderId )
110117 if err != nil {
111118 log .DefaultLogger .Error ("update dashboard" , "error" , err .Error ())
112119 }
113- log .DefaultLogger .Info ("Dashboard preparation successfully " )
120+ log .DefaultLogger .Debug ("Dashboard preparation successfully " )
114121
115122 // Todo: If dashboard found, else skip git workflow
116123 gitApi := NewGitApi (pushGitURL , privateKeyFilePath )
@@ -119,9 +126,11 @@ func (d *SampleDatasource) CheckHealth(_ context.Context, req *backend.CheckHeal
119126 return nil , err
120127 }
121128 gitApi .FetchRepo (* repository )
122- gitApi .AddFileWithContent (dashboardObject .Title + ".json" , string (dashboardJson ))
123- gitApi .CommitWorktree (* repository )
129+ gitApi .AddFileWithContent (folderName + "/" + dashboardObject .Title + ".json" , string (dashboardJson ))
130+ gitApi .CommitWorktree (* repository , dashboardTag )
124131 gitApi .PushRepo (* repository )
132+
133+ log .DefaultLogger .Info ("Dashboard pushed successfully " )
125134 }
126135 }
127136
0 commit comments