forked from spaceapegames/go-wavefront
-
Notifications
You must be signed in to change notification settings - Fork 12
/
targets_example_test.go
64 lines (51 loc) · 1.22 KB
/
targets_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
package wavefront_test
import (
"log"
"os"
"github.com/WavefrontHQ/go-wavefront-management-api/v2"
)
func ExampleTargets() {
config := &wavefront.Config{
Address: "test.wavefront.com",
Token: "xxxx-xxxx-xxxx-xxxx-xxxx",
}
client, err := wavefront.NewClient(config)
if err != nil {
log.Fatal(err)
}
client.Debug(true)
targets := client.Targets()
tmpl, _ := os.ReadFile("./target-template.tmpl")
target := wavefront.Target{
Title: "test target",
Description: "testing something",
Method: "WEBHOOK",
Recipient: "https://hooks.slack.com/services/test/me",
ContentType: "application/json",
CustomHeaders: map[string]string{
"Testing": "true",
},
Triggers: []string{"ALERT_OPENED", "ALERT_RESOLVED"},
Template: string(tmpl),
}
// Create the target on Wavefront
err = targets.Create(&target)
if err != nil {
log.Fatal(err)
}
// Get an target by ID
err = targets.Get(&wavefront.Target{ID: target.ID})
if err != nil {
log.Fatal(err)
}
// The ID field is now set, so we can update or delete the Target
target.Description = "new description"
err = targets.Update(&target)
if err != nil {
log.Fatal(err)
}
err = targets.Delete(&target)
if err != nil {
log.Fatal(err)
}
}