forked from wavefrontHQ/go-wavefront-management-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboards_example_test.go
114 lines (94 loc) · 2.16 KB
/
dashboards_example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package wavefront_test
import (
"fmt"
"log"
"github.com/WavefrontHQ/go-wavefront-management-api"
)
func ExampleDashboards() {
config := &wavefront.Config{
Address: "test.wavefront.com",
Token: "xxxx-xxxx-xxxx-xxxx-xxxx",
}
client, err := wavefront.NewClient(config)
if err != nil {
log.Fatal(err)
}
dashboards := client.Dashboards()
// Create the components of the Dashboard (Sections, Rows, Charts and Sources).
sources := []wavefront.Source{
{
Name: "Source 1",
Query: "ts()",
},
}
charts := []wavefront.Chart{
{
Name: "Chart 1",
Description: "Chart 1 shows ...",
Sources: sources,
Units: "units per time",
},
}
rows := []wavefront.Row{
{
Name: "Row 1",
Charts: charts,
},
}
sections := []wavefront.Section{
{
Name: "Section 1",
Rows: rows,
},
}
params := map[string]wavefront.ParameterDetail{
"param": {
Label: "test",
DefaultValue: "Label",
HideFromView: false,
ParameterType: "SIMPLE",
ValuesToReadableStrings: map[string]string{"Label": "test"},
},
}
d := &wavefront.Dashboard{
Name: "My First Dashboard",
ID: "dashboard1",
Description: "A Dashboard to show things",
Url: "dashboard1",
Sections: sections,
Tags: []string{"dc1", "synergy"},
ParameterDetails: params,
}
// Create the dashboard on Wavefront
err = dashboards.Create(d)
if err != nil {
log.Fatal(err)
}
// We can update/delete the Dashboard
fmt.Println("dashboard ID is", d.ID)
// Alternatively we could search for the Dashboard
results, err := dashboards.Find(
[]*wavefront.SearchCondition{
{
Key: "name",
Value: "My First Dashboard",
MatchingMethod: "EXACT",
},
})
if err != nil {
log.Fatal(err)
}
fmt.Println("found dashboard with ID", results[0].ID)
// Update the Dashboard
d.Sections[0].Rows[0].Name = "Updated Chart Name"
err = dashboards.Update(d)
if err != nil {
log.Fatal(err)
}
// Delete the Dashboard
err = dashboards.Delete(d, true)
if err != nil {
log.Fatal(err)
}
fmt.Println("dashboard deleted")
}