-
Notifications
You must be signed in to change notification settings - Fork 32
/
custom_filter_config.go
360 lines (347 loc) · 11.8 KB
/
custom_filter_config.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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/**
* @license
* Copyright 2020 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dashboards
import (
"encoding/json"
"github.com/dynatrace-oss/terraform-provider-dynatrace/terraform/hcl"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/xjson"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
// CustomFilterConfig Configuration of the custom filter of a tile
type CustomFilterConfig struct {
Type CustomFilterConfigType `json:"type"` // The type of the filter
CustomName string `json:"customName"` // The name of the tile, set by user
DefaultName string `json:"defaultName"` // The default name of the tile
ChartConfig *CustomFilterChartConfig `json:"chartConfig"` // Config Configuration of a custom chart
FiltersPerEntityType map[string]map[string][]string `json:"filtersPerEntityType"` // A list of filters, applied to specific entity types
Unknowns map[string]json.RawMessage `json:"-"`
}
func (me *CustomFilterConfig) Schema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Description: "The type of the filter. Possible values are `ALB`, `APPLICATION`, `APPLICATION_METHOD`, `APPMON`, `ASG`, `AWS_CREDENTIALS`, `AWS_CUSTOM_SERVICE`, `AWS_LAMBDA_FUNCTION`, `CLOUD_APPLICATION`, `CLOUD_APPLICATION_INSTANCE`, `CLOUD_APPLICATION_NAMESPACE`, `CONTAINER_GROUP_INSTANCE`, `CUSTOM_APPLICATION`, `CUSTOM_DEVICES`, `CUSTOM_SERVICES`, `DATABASE`, `DATABASE_KEY_REQUEST`, `DCRUM_APPLICATION`, `DCRUM_ENTITY`, `DYNAMO_DB`, `EBS`, `EC2`, `ELB`, `ENVIRONMENT`, `ESXI`, `EXTERNAL_SYNTHETIC_TEST`, `GLOBAL_BACKGROUND_ACTIVITY`, `HOST`, `IOT`, `KUBERNETES_CLUSTER`, `KUBERNETES_NODE`, `MDA_SERVICE`, `MIXED`, `MOBILE_APPLICATION`, `MONITORED_ENTITY`, `NLB`, `PG_BACKGROUND_ACTIVITY`, `PROBLEM`, `PROCESS_GROUP_INSTANCE`, `RDS`, `REMOTE_PLUGIN`, `SERVICE`, `SERVICE_KEY_REQUEST`, `SYNTHETIC_BROWSER_MONITOR`, `SYNTHETIC_HTTPCHECK`, `SYNTHETIC_HTTPCHECK_STEP`, `SYNTHETIC_LOCATION`, `SYNTHETIC_TEST`, `SYNTHETIC_TEST_STEP`, `UI_ENTITY`, `VIRTUAL_MACHINE`, `WEB_CHECK`.",
Required: true,
},
"custom_name": {
Type: schema.TypeString,
Description: "The name of the tile, set by user",
Required: true,
},
"default_name": {
Type: schema.TypeString,
Description: "The default name of the tile",
Required: true,
},
"chart_config": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "Configuration of a custom chart",
Elem: &schema.Resource{
Schema: new(CustomFilterChartConfig).Schema(),
},
},
"filters": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "Configuration of a custom chart",
Elem: &schema.Resource{
Schema: new(FiltersPerEntityType).Schema(),
},
},
"unknowns": {
Type: schema.TypeString,
Description: "allows for configuring properties that are not explicitly supported by the current version of this provider",
Optional: true,
},
}
}
func (me *CustomFilterConfig) MarshalHCL(properties hcl.Properties) error {
if err := properties.Unknowns(me.Unknowns); err != nil {
return err
}
if err := properties.Encode("type", string(me.Type)); err != nil {
return err
}
if err := properties.Encode("custom_name", me.CustomName); err != nil {
return err
}
if err := properties.Encode("default_name", me.DefaultName); err != nil {
return err
}
if err := properties.Encode("chart_config", me.ChartConfig); err != nil {
return err
}
if len(me.FiltersPerEntityType) > 0 {
filtersPerEntityType := &FiltersPerEntityType{Filters: []*FilterForEntityType{}}
for k, v := range me.FiltersPerEntityType {
filterForEntityType := &FilterForEntityType{
EntityType: "",
Filters: []*FilterMatch{},
}
filterForEntityType.EntityType = k
for mk, mv := range v {
filterForEntityType.Filters = append(filterForEntityType.Filters, &FilterMatch{
Key: mk,
Values: mv,
})
}
filtersPerEntityType.Filters = append(filtersPerEntityType.Filters, filterForEntityType)
}
if err := properties.Encode("filters", filtersPerEntityType); err != nil {
return err
}
}
return nil
}
func (me *CustomFilterConfig) UnmarshalHCL(decoder hcl.Decoder) error {
if value, ok := decoder.GetOk("unknowns"); ok {
if err := json.Unmarshal([]byte(value.(string)), me); err != nil {
return err
}
if err := json.Unmarshal([]byte(value.(string)), &me.Unknowns); err != nil {
return err
}
delete(me.Unknowns, "type")
delete(me.Unknowns, "custom_name")
delete(me.Unknowns, "default_name")
delete(me.Unknowns, "chart_config")
delete(me.Unknowns, "filters")
if len(me.Unknowns) == 0 {
me.Unknowns = nil
}
}
if value, ok := decoder.GetOk("type"); ok {
me.Type = CustomFilterConfigType(value.(string))
}
if value, ok := decoder.GetOk("custom_name"); ok {
me.CustomName = value.(string)
}
if value, ok := decoder.GetOk("default_name"); ok {
me.DefaultName = value.(string)
}
if _, ok := decoder.GetOk("chart_config.#"); ok {
me.ChartConfig = new(CustomFilterChartConfig)
if err := me.ChartConfig.UnmarshalHCL(hcl.NewDecoder(decoder, "chart_config", 0)); err != nil {
return err
}
}
if _, ok := decoder.GetOk("filters.#"); ok {
filtersPerEntityType := new(FiltersPerEntityType)
if err := filtersPerEntityType.UnmarshalHCL(hcl.NewDecoder(decoder, "filters", 0)); err != nil {
return err
}
me.FiltersPerEntityType = map[string]map[string][]string{}
if len(filtersPerEntityType.Filters) > 0 {
for _, filterForEntityType := range filtersPerEntityType.Filters {
filterMatches := map[string][]string{}
for _, filterMatch := range filterForEntityType.Filters {
filterMatches[filterMatch.Key] = filterMatch.Values
}
if len(filterMatches) > 0 {
me.FiltersPerEntityType[filterForEntityType.EntityType] = filterMatches
}
}
}
}
return nil
}
func (me *CustomFilterConfig) MarshalJSON() ([]byte, error) {
m := map[string]json.RawMessage{}
if len(me.Unknowns) > 0 {
for k, v := range me.Unknowns {
m[k] = v
}
}
{
rawMessage, err := json.Marshal(me.Type)
if err != nil {
return nil, err
}
m["type"] = rawMessage
}
{
rawMessage, err := json.Marshal(me.CustomName)
if err != nil {
return nil, err
}
m["customName"] = rawMessage
}
{
rawMessage, err := json.Marshal(me.DefaultName)
if err != nil {
return nil, err
}
m["defaultName"] = rawMessage
}
if me.ChartConfig != nil {
rawMessage, err := json.Marshal(me.ChartConfig)
if err != nil {
return nil, err
}
m["chartConfig"] = rawMessage
}
filtersPerEntityType := me.FiltersPerEntityType
if filtersPerEntityType == nil {
filtersPerEntityType = map[string]map[string][]string{}
}
{
rawMessage, err := json.Marshal(filtersPerEntityType)
if err != nil {
return nil, err
}
m["filtersPerEntityType"] = rawMessage
}
return json.Marshal(m)
}
func (me *CustomFilterConfig) UnmarshalJSON(data []byte) error {
m := xjson.Properties{}
if err := json.Unmarshal(data, &m); err != nil {
return err
}
if err := m.Unmarshal("type", &me.Type); err != nil {
return err
}
if err := m.Unmarshal("customName", &me.CustomName); err != nil {
return err
}
if err := m.Unmarshal("defaultName", &me.DefaultName); err != nil {
return err
}
if err := m.Unmarshal("chartConfig", &me.ChartConfig); err != nil {
return err
}
if err := m.Unmarshal("filtersPerEntityType", &me.FiltersPerEntityType); err != nil {
return err
}
if len(m) > 0 {
me.Unknowns = m
}
return nil
}
// CustomFilterConfigType has no documentation
type CustomFilterConfigType string
// CustomFilterConfigTypes offers the known enum values
var CustomFilterConfigTypes = struct {
Alb CustomFilterConfigType
Application CustomFilterConfigType
ApplicationMethod CustomFilterConfigType
Appmon CustomFilterConfigType
Asg CustomFilterConfigType
AwsCredentials CustomFilterConfigType
AwsCustomService CustomFilterConfigType
AwsLambdaFunction CustomFilterConfigType
CloudApplication CustomFilterConfigType
CloudApplicationInstance CustomFilterConfigType
CloudApplicationNamespace CustomFilterConfigType
ContainerGroupInstance CustomFilterConfigType
CustomApplication CustomFilterConfigType
CustomDevices CustomFilterConfigType
CustomServices CustomFilterConfigType
Database CustomFilterConfigType
DatabaseKeyRequest CustomFilterConfigType
DcrumApplication CustomFilterConfigType
DcrumEntity CustomFilterConfigType
DynamoDb CustomFilterConfigType
Ebs CustomFilterConfigType
Ec2 CustomFilterConfigType
Elb CustomFilterConfigType
Environment CustomFilterConfigType
Esxi CustomFilterConfigType
ExternalSyntheticTest CustomFilterConfigType
GlobalBackgroundActivity CustomFilterConfigType
Host CustomFilterConfigType
Iot CustomFilterConfigType
KubernetesCluster CustomFilterConfigType
KubernetesNode CustomFilterConfigType
MdaService CustomFilterConfigType
Mixed CustomFilterConfigType
MobileApplication CustomFilterConfigType
MonitoredEntity CustomFilterConfigType
Nlb CustomFilterConfigType
PgBackgroundActivity CustomFilterConfigType
Problem CustomFilterConfigType
ProcessGroupInstance CustomFilterConfigType
Rds CustomFilterConfigType
RemotePlugin CustomFilterConfigType
Service CustomFilterConfigType
ServiceKeyRequest CustomFilterConfigType
SyntheticBrowserMonitor CustomFilterConfigType
SyntheticHTTPcheck CustomFilterConfigType
SyntheticHTTPcheckStep CustomFilterConfigType
SyntheticLocation CustomFilterConfigType
SyntheticTest CustomFilterConfigType
SyntheticTestStep CustomFilterConfigType
UUEntity CustomFilterConfigType
VirtualMachine CustomFilterConfigType
WebCheck CustomFilterConfigType
}{
"ALB",
"APPLICATION",
"APPLICATION_METHOD",
"APPMON",
"ASG",
"AWS_CREDENTIALS",
"AWS_CUSTOM_SERVICE",
"AWS_LAMBDA_FUNCTION",
"CLOUD_APPLICATION",
"CLOUD_APPLICATION_INSTANCE",
"CLOUD_APPLICATION_NAMESPACE",
"CONTAINER_GROUP_INSTANCE",
"CUSTOM_APPLICATION",
"CUSTOM_DEVICES",
"CUSTOM_SERVICES",
"DATABASE",
"DATABASE_KEY_REQUEST",
"DCRUM_APPLICATION",
"DCRUM_ENTITY",
"DYNAMO_DB",
"EBS",
"EC2",
"ELB",
"ENVIRONMENT",
"ESXI",
"EXTERNAL_SYNTHETIC_TEST",
"GLOBAL_BACKGROUND_ACTIVITY",
"HOST",
"IOT",
"KUBERNETES_CLUSTER",
"KUBERNETES_NODE",
"MDA_SERVICE",
"MIXED",
"MOBILE_APPLICATION",
"MONITORED_ENTITY",
"NLB",
"PG_BACKGROUND_ACTIVITY",
"PROBLEM",
"PROCESS_GROUP_INSTANCE",
"RDS",
"REMOTE_PLUGIN",
"SERVICE",
"SERVICE_KEY_REQUEST",
"SYNTHETIC_BROWSER_MONITOR",
"SYNTHETIC_HTTPCHECK",
"SYNTHETIC_HTTPCHECK_STEP",
"SYNTHETIC_LOCATION",
"SYNTHETIC_TEST",
"SYNTHETIC_TEST_STEP",
"UI_ENTITY",
"VIRTUAL_MACHINE",
"WEB_CHECK",
}