|
@@ -10,6 +10,11 @@ import (
|
10
|
10
|
"github.com/sirupsen/logrus"
|
11
|
11
|
)
|
12
|
12
|
|
|
13
|
+// FilterIgnored takes a map mapping files' names to their contents and remove
|
|
14
|
+// all the files that are supposed to be ignored by the dashboard manager.
|
|
15
|
+// An ignored file is either named "versions.json" or describing a dashboard
|
|
16
|
+// which slug starts with a given prefix.
|
|
17
|
+// Returns an error if the slug couldn't be tested against the prefix.
|
13
|
18
|
func FilterIgnored(
|
14
|
19
|
filesToPush *map[string][]byte, cfg *config.Config,
|
15
|
20
|
) (err error) {
|
|
@@ -34,6 +39,12 @@ func FilterIgnored(
|
34
|
39
|
return
|
35
|
40
|
}
|
36
|
41
|
|
|
42
|
+// PushFiles takes a slice of files' names and a map mapping a file's name to its
|
|
43
|
+// content, and iterates over the first slice. For each file name, it will push
|
|
44
|
+// to Grafana the content from the map that matches the name, as a creation or
|
|
45
|
+// an update of an existing dashboard.
|
|
46
|
+// Logs any errors encountered during an iteration, but doesn't return until all
|
|
47
|
+// creation and/or update requests have been performed.
|
37
|
48
|
func PushFiles(filenames []string, contents map[string][]byte, client *grafana.Client) {
|
38
|
49
|
// Push all files to the Grafana API
|
39
|
50
|
for _, filename := range filenames {
|
|
@@ -46,6 +57,12 @@ func PushFiles(filenames []string, contents map[string][]byte, client *grafana.C
|
46
|
57
|
}
|
47
|
58
|
}
|
48
|
59
|
|
|
60
|
+// DeleteDashboards takes a slice of files' names and a map mapping a file's name
|
|
61
|
+// to its content, and iterates over the first slice. For each file name, extract
|
|
62
|
+// a dashboard's slug from the content, in the map, that matches the name, and
|
|
63
|
+// will use it to send a deletion request to the Grafana API.
|
|
64
|
+// Logs any errors encountered during an iteration, but doesn't return until all
|
|
65
|
+// deletion requests have been performed.
|
49
|
66
|
func DeleteDashboards(filenames []string, contents map[string][]byte, client *grafana.Client) {
|
50
|
67
|
for _, filename := range filenames {
|
51
|
68
|
// Retrieve dashboard slug because we need it in the deletion request.
|