@@ -88,50 +88,54 @@ func (d *SampleDatasource) CheckHealth(_ context.Context, req *backend.CheckHeal
8888 }
8989
9090 if push == "true" {
91+ gitApi := NewGitApi (pushGitURL , privateKeyFilePath )
92+ repository , err := gitApi .CloneRepo ()
93+ if err != nil {
94+ return nil , err
95+ }
96+ gitApi .FetchRepo (* repository )
97+
9198 dashboards , err := grafanaApi .SearchDashboardsWithTag (dashboardTag )
9299 if err != nil {
93100 log .DefaultLogger .Error ("search dashboard" , "error" , err .Error ())
94101 }
95102 for _ , dashboard := range dashboards {
96- // get raw Json
97- dashboardJson , boardProperties , err := grafanaApi .GetRawDashboardByID (dashboard .UID )
98- if err != nil {
99- log .DefaultLogger .Error ("get raw dashboard" , "error" , err .Error ())
100- }
101-
102- // get folder name and id, needed for update processes and git folder structure
103- folderName := boardProperties .FolderTitle
104- folderId := boardProperties .FolderID
105-
106- // get dashboard Object TODO: Verify if raw Json manipulation is faster
107- dashboardObject , _ , err := grafanaApi .GetDashboardObjectByID (dashboard .UID )
103+ // get dashboard Object and Properties
104+ dashboardObject , boardProperties , err := grafanaApi .GetDashboardObjectByID (dashboard .UID )
108105 if err != nil {
109106 log .DefaultLogger .Error ("get dashboard" , "error" , err .Error ())
110107 }
111108
112- // delete Tag from dashboard
109+ // delete Tag from dashboard Object
113110 dashboardWithDeletedTag := grafanaApi .DeleteTagFromDashboardObjectByID (dashboardObject , dashboardTag )
114111
115- // update dashboard with deleted Tag
112+ // get folder name and id, required for update processes and git folder structure
113+ folderName := boardProperties .FolderTitle
114+ folderId := boardProperties .FolderID
115+
116+ // update dashboard with deleted Tag in Grafana
116117 _ , err = grafanaApi .UpdateDashboardObjectByID (dashboardWithDeletedTag , folderId )
117118 if err != nil {
118119 log .DefaultLogger .Error ("update dashboard" , "error" , err .Error ())
119120 }
120- log .DefaultLogger .Debug ("Dashboard preparation successfully " )
121121
122- // Todo: If dashboard found, else skip git workflow
123- gitApi := NewGitApi (pushGitURL , privateKeyFilePath )
124- repository , err := gitApi .CloneRepo ()
122+ // get raw Json Dashboard, required for import and export
123+ dashboardJson , _ , err := grafanaApi .GetRawDashboardByID (dashboard .UID )
125124 if err != nil {
126- return nil , err
125+ log . DefaultLogger . Error ( "get raw dashboard" , "error" , err . Error ())
127126 }
128- gitApi .FetchRepo (* repository )
127+
128+ log .DefaultLogger .Debug ("Dashboard preparation successfully " )
129129 gitApi .AddFileWithContent (folderName + "/" + dashboardObject .Title + ".json" , string (dashboardJson ))
130+ log .DefaultLogger .Debug ("Dashboard added to in memory file system" )
131+ }
132+
133+ if len (dashboards ) > 0 {
130134 gitApi .CommitWorktree (* repository , dashboardTag )
131135 gitApi .PushRepo (* repository )
132-
133- log .DefaultLogger .Info ("Dashboard pushed successfully " )
134136 }
137+
138+ log .DefaultLogger .Info ("Dashboard pushed successfully" )
135139 }
136140
137141 return & backend.CheckHealthResult {
0 commit comments