forked from spaceapegames/go-wavefront
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcloud_integration.go
343 lines (274 loc) · 12.7 KB
/
cloud_integration.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
package wavefront
import (
"fmt"
"strconv"
)
type CloudIntegration struct {
ForceSave bool `json:"forceSave,omitempty"`
Id string `json:"id,omitempty"`
// The human-readable name of this integration
Name string `json:"name"`
// A value denoting which cloud service this integration integrates with
Service string `json:"service"`
// A value denoting whether or not this cloud integration is in the trashcan
InTrash bool `json:"inTrash,omitempty"`
// The creator of the cloud integration
CreatorId string `json:"creatorId,omitempty"`
// The user of the last person to update this integration
UpdaterId string `json:"updaterId,omitempty"`
// Event of the last error encountered by Wavefront servers when fetching data using this integration
LastErrorEvent *Event `json:"lastErrorEvent,omitempty"`
// A list of point tag key-values to add to every point ingested using this integration
AdditionalTags map[string]string `json:"additionalTags,omitempty"`
// Time that this integration last received a data point, in epoch millis
LastReceivedDataPointMs int `json:"lastReceivedDataPointMs,omitempty"`
// Number of metrics / events ingested by this integration the last time it ran
LastMetricCount int `json:"lastMetricCount,omitempty"`
CloudWatch *CloudWatchConfiguration `json:"cloudWatch,omitempty"`
CloudTrail *CloudTrailConfiguration `json:"cloudTrail,omitempty"`
EC2 *EC2Configuration `json:"ec2,omitempty"`
GCP *GCPConfiguration `json:"gcp,omitempty"`
GCPBilling *GCPBillingConfiguration `json:"gcpBilling,omitempty"`
NewRelic *NewRelicConfiguration `json:"newRelic,omitempty"`
AppDynamics *AppDynamicsConfiguration `json:"appDynamics,omitempty"`
Tesla *TeslaConfiguration `json:"tesla,omitempty"`
Azure *AzureConfiguration `json:"azure,omitempty"`
AzureActivityLog *AzureActivityLogConfiguration `json:"azureActivityLog,omitempty"`
// Time, in epoch millis, of the last error encountered by Wavefront servers when fetching data using this integration.
LastErrorMs int `json:"lastErrorMs,omitempty"`
// True when an aws credential failed to authenticate
Disabled bool `json:"disabled,omitempty"`
// Opaque Id of the last Wavefront Integrations service to act on this integration
LastProcessorId string `json:"lastProcessorId,omitempty"`
// Time, in epoch millis, that this integration was last processed
LastProcessingTimestamp int `json:"lastProcessingTimestamp,omitempty"`
CreatedEpochMillis int `json:"createdEpochMillis,omitempty"`
UpdatedEpochMillis int `json:"updatedEpochMillis,omitempty"`
// Service refresh rate in minutes
ServiceRefreshRateInMins int `json:"serviceRefreshRateInMins,omitempty"`
Deleted bool `json:"deleted,omitempty"`
}
type CloudWatchConfiguration struct {
// A regular expression that a CloudWatch metric name must match (case-insensitively) in order to be ingested
MetricFilterRegex string `json:"metricFilterRegex,omitempty"`
// A list of namespace that limit what we query from cloudwatch
Namespaces []string `json:"namespaces,omitempty"`
BaseCredentials *AWSBaseCredentials `json:"baseCredentials,omitempty"`
// A string->string map of white list of AWS instance tag-value pairs (in AWS).
// If the instance's AWS tags match this whitelist, CloudWatch data about this instance is ingested.
// Multiple entries are OR'ed
InstanceSelectionTags map[string]string `json:"instanceSelectionTags,omitempty"`
// A string->string map of white list of AWS volume tag-value pairs (in AWS).
// If the volume's AWS tags match this whitelist, CloudWatch data about this volume is ingested.
// Multiple entries are OR'ed
VolumeSelectionTags map[string]string `json:"volumeSelectionTags,omitempty"`
// A regular expression that AWS tag key name must match (case-insensitively) in order to be ingested
PointTagFilterRegex string `json:"pointTagFilterRegex,omitempty"`
}
type CloudTrailConfiguration struct {
// The AWS Region of the S3 bucket where CloudTrail logs are stored
Region string `json:"region"`
// The common prefix, if any, appended to all CloudTrail log files
Prefix string `json:"prefix,omitempty"`
BaseCredentials *AWSBaseCredentials `json:"baseCredentials,omitempty"`
// Name of the S3 bucket where CloudTrail logs are stored
BucketName string `json:"bucketName"`
// Rule to filter cloud trail log event
FilterRule string `json:"filterRule,omitempty"`
}
type EC2Configuration struct {
BaseCredentials *AWSBaseCredentials `json:"baseCredentials,omitempty"`
// A list of AWS instance tags that, when found, will be used as the "source" name in a series.
// Default: hostname, host, name
// If no tag in this list is found, the series source is set to the instance id.
HostNameTags []string `json:"hostNameTags"`
}
type GCPConfiguration struct {
// A regular expression that a CloudWatch metric name must match (case-insensitively) in order to be ingested
MetricFilterRegex string `json:"metricFilterRegex,omitempty"`
// The Google Cloud Platform (GCP) project id.
ProjectId string `json:"projectId"`
// Private key for a Google Cloud Platform (GCP) service account within your project. The account must at least be
// granted Monitoring Viewer permissions. This key must be in the JSON format generated by GCP.
// Use `{"project_id":"%s"}' to retain the existing key when updating
GcpJSONKey string `json:"gcpJsonKey"`
// A list of Google Cloud Platform (GCP) services (Such as ComputeEngine, PUbSub...etc) from which to pull metrics.
CategoriesToFetch []string `json:"categoriesToFetch,omitempty"`
}
type GCPBillingConfiguration struct {
// The Google Cloud Platform (GCP) project id.
ProjectId string `json:"projectId"`
// API key for Google Cloud Platform (GCP). Use 'saved_api_key' to retain existing API key when updating
GcpApiKey string `json:"gcpApiKey"`
// Private key for a Google Cloud Platform (GCP) service account within your project. The account must at least be
// granted Monitoring Viewer permissions. This key must be in the JSON format generated by GCP.
// Use `{"project_id":"%s"}' to retain the existing key when updating
GcpJSONKey string `json:"gcpJsonKey"`
}
type NewRelicConfiguration struct {
// New Relic REST API Key
ApiKey string `json:"apiKey"`
// A regular expression that a application name must match (case-insensitively) in order to collect metrics
AppFilterRegex string `json:"appFilterRegex,omitempty"`
// A regular expression that a host name must match (case-insensitively) in order to collect metrics
HostFilterRegex string `json:"hostFilterRegex,omitempty"`
NewRelicMetricFilters []*NewRelicMetricFilters `json:"newRelicMetricFilters,omitempty"`
}
type AppDynamicsConfiguration struct {
// Username is a combination of username and the account name
UserName string `json:"userName"`
// Name of the SaaS controller
ControllerName string `json:"controllerName"`
// Password for the AppDynamics user
EncryptedPassword string `json:"encryptedPassword"`
// Set this to 'false' to get separate results for all values with in the time range, by default it is true
EnableRollup bool `json:"enableRollup,omitempty"`
// Flag to control Error metric injections
EnableErrorMetrics bool `json:"enableErrorMetrics,omitempty"`
// Flag to control Business Transaction Metric injection
EnableBusinessTrxMetrics bool `json:"enableBusinessTrxMetrics,omitempty"`
// flag to control Backend metric injection
EnableBackendMetrics bool `json:"enableBackendMetrics,omitempty"`
// Flag to control Overall Performance metric injection
EnableOverallPerfMetrics bool `json:"enableOverallPerfMetrics,omitempty"`
// Flag to control individual Node metric injection
EnableIndividualNodeMetrics bool `json:"enableIndividualNodeMetrics,omitempty"`
// Flag to control Application Infrastructure metric injection
EnableAppInfraMetrics bool `json:"enableAppInfraMetrics,omitempty"`
// Flag to control Service End point metric injection
EnableServiceEndpointMetrics bool `json:"enableServiceEndpointMetrics,omitempty"`
// List of regular expressions that a application name must match (case-insensitively) in order to be ingested
AppFilterRegex []string `json:"appFilterRegex"`
}
type TeslaConfiguration struct {
// Email address for the Tesla account login
Email string `json:"email"`
Password string `json:"password"`
}
type AzureConfiguration struct {
// A regular expression that a CloudWatch metric name must match (case-insensitively) in order to be ingested
MetricFilterRegex string `json:"metricFilterRegex,omitempty"`
BaseCredentials *AzureBaseCredentials `json:"baseCredentials,omitempty"`
// A list of Azure services (such as Microsoft.Compute/virtualMachines,Microsoft.Cache/redis etc) from which to pull
// metrics
CategoryFilter []string `json:"categoryFilter,omitempty"`
// A list of Azure resource groups from which to pull metrics
ResourceGroupFilter []string `json:"resourceGroupFilter,omitempty"`
}
type AzureActivityLogConfiguration struct {
BaseCredentials *AzureBaseCredentials `json:"baseCredentials,omitempty"`
// A list of Azure ActivityLog categories to pull events for
CategoryFilter []string `json:"categoryFilter,omitempty"`
}
type AWSBaseCredentials struct {
// The Role ARN that the customer has created in AWS IAM to allow access to Wavefront
RoleARN string `json:"roleArn"`
// The external id corresponding to the Role ARN
ExternalID string `json:"externalId"`
}
type NewRelicMetricFilters struct {
AppName string `json:"appName"`
MetricFilterRegex string `json:"metricFilterRegex"`
}
type AzureBaseCredentials struct {
// Client Id for an Azure service account within your project
ClientID string `json:"clientId"`
// Client Secret for an Azure service account within your project. use `saved_secret` to retain the client secret
// when updating
ClientSecret string `json:"clientSecret"`
// Tenant Id for an Azure service account within your project
Tenant string `json:"tenant"`
}
const baseCloudIntegrationPath = "/api/v2/cloudintegration"
type CloudIntegrations struct {
client Wavefronter
}
func (c *Client) CloudIntegrations() *CloudIntegrations {
return &CloudIntegrations{client: c}
}
func (ci CloudIntegrations) Find(filter []*SearchCondition) (
results []*CloudIntegration, err error) {
err = doSearch(filter, "cloudintegration", ci.client, &results)
return
}
// Get a CloudIntegration for a given ID
// ID must be specified
func (ci CloudIntegrations) Get(cloudIntegration *CloudIntegration) error {
if cloudIntegration.Id == "" {
return fmt.Errorf("cloud integration id must be specified")
}
return doRest(
"GET",
fmt.Sprintf("%s/%s", baseCloudIntegrationPath, cloudIntegration.Id),
ci.client,
doResponse(cloudIntegration))
}
// Deletes a given CloudIntegration and sets the ID of the object to ""
// ID must be specified
func (ci CloudIntegrations) Delete(cloudIntegration *CloudIntegration, skipTrash bool) error {
if cloudIntegration.Id == "" {
return fmt.Errorf("cloud integration id must be specified")
}
params := map[string]string{
"skipTrash": strconv.FormatBool(skipTrash),
}
err := doRest(
"DELETE",
fmt.Sprintf("%s/%s", baseCloudIntegrationPath, cloudIntegration.Id),
ci.client,
doParams(params))
if err == nil {
cloudIntegration.Id = ""
}
return err
}
// Updates a given CloudIntegration in Wavefront
func (ci CloudIntegrations) Update(cloudIntegration *CloudIntegration) error {
if cloudIntegration.Id == "" {
return fmt.Errorf("cloud integration id must be specified")
}
return doRest(
"PUT",
fmt.Sprintf("%s/%s", baseCloudIntegrationPath, cloudIntegration.Id),
ci.client,
doPayload(cloudIntegration),
doResponse(cloudIntegration))
}
// Creates a CloudIntegration in Wavefront
// If successful, the ID field will be populated
func (ci CloudIntegrations) Create(cloudIntegration *CloudIntegration) error {
return doRest(
"POST",
baseCloudIntegrationPath,
ci.client,
doPayload(cloudIntegration),
doResponse(cloudIntegration))
}
// Creates an AWS ExternalID for use in AWS IAM Roles
func (ci CloudIntegrations) CreateAwsExternalID() (string, error) {
externalId := ""
err := doRest(
"POST",
fmt.Sprintf("%s/awsExternalId", baseCloudIntegrationPath),
ci.client,
doResponse(&externalId))
return externalId, err
}
// Deletes an AWS ExternalID
func (ci CloudIntegrations) DeleteAwsExternalID(externalId *string) error {
err := doRest(
"DELETE",
fmt.Sprintf("%s/awsExternalId/%s", baseCloudIntegrationPath, *externalId),
ci.client)
if err == nil {
*externalId = ""
}
return err
}
// Verifies an AWS ExternalID exists
func (ci CloudIntegrations) VerifyAwsExternalID(externalId string) error {
return doRest(
"GET",
fmt.Sprintf("%s/awsExternalId/%s", baseCloudIntegrationPath, externalId),
ci.client)
}