forked from wavefrontHQ/go-wavefront-management-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloud_integrations_example_test.go
68 lines (55 loc) · 1.48 KB
/
cloud_integrations_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
package wavefront_test
import (
"log"
"github.com/WavefrontHQ/go-wavefront-management-api"
)
func ExampleCloudIntegrations() {
config := &wavefront.Config{
Address: "test.wavefront.com",
Token: "xxxx-xxxx-xxxx-xxxx-xxxx",
}
client, err := wavefront.NewClient(config)
if err != nil {
log.Fatal(err)
}
cloudIntegrations := client.CloudIntegrations()
// Create a new AWS CloudWatch Integration
externalId, err := cloudIntegrations.CreateAwsExternalID()
if err != nil {
log.Fatal(err)
}
cloudWatchIntegration := wavefront.CloudIntegration{
Name: "example-cloud-watch-integration",
Service: "CLOUDWATCH",
CloudWatch: &wavefront.CloudWatchConfiguration{
MetricFilterRegex: "^(ec2|elb).*$",
BaseCredentials: &wavefront.AWSBaseCredentials{
RoleARN: "arn:aws:iam:1234567890:role/example-cloud-watch-integration",
ExternalID: externalId,
},
},
}
err = cloudIntegrations.Create(&cloudWatchIntegration)
if err != nil {
log.Fatal(err)
}
// Get an integration by id
err = cloudIntegrations.Get(&cloudWatchIntegration)
if err != nil {
log.Fatal(err)
}
// Update an existing integration
cloudWatchIntegration.CloudWatch.InstanceSelectionTags = map[string]string{
"env": "prod",
"role": "app",
}
err = cloudIntegrations.Update(&cloudWatchIntegration)
if err != nil {
log.Fatal(err)
}
// Delete an existing integration and bypass the trashcan
err = cloudIntegrations.Delete(&cloudWatchIntegration, true)
if err != nil {
log.Fatal(err)
}
}