-
Notifications
You must be signed in to change notification settings - Fork 32
/
condition.go
302 lines (288 loc) · 11.2 KB
/
condition.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
/**
* @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 service
import (
"encoding/json"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/v1/config/metrics/calculated/service/settings/comparisoninfo"
"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"
)
// Condition A condition of a rule usage.
type Condition struct {
Attribute Attribute `json:"attribute"` // The attribute to be matched. Note that for a service property attribute you must use the comparison of the `FAST_STRING` type.
ComparisonInfo comparisoninfo.ComparisonInfo `json:"comparisonInfo"` // Type-specific comparison for attributes. The actual set of fields depends on the `type` of the comparison. See the [Service metrics API - JSON models](https://dt-url.net/9803svb) help topic for example models of every notification type.
Unknowns map[string]json.RawMessage `json:"-"`
}
func (me *Condition) Schema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"attribute": {
Type: schema.TypeString,
Required: true,
Description: "The attribute to be matched. Note that for a service property attribute you must use the comparison of the `FAST_STRING` type. Possible values are `ACTOR_SYSTEM`, `AKKA_ACTOR_CLASS_NAME`, `AKKA_ACTOR_MESSAGE_TYPE`, `AKKA_ACTOR_PATH`, `APPLICATION_BUILD_VERSION`, `APPLICATION_RELEASE_VERSION`, `AZURE_FUNCTIONS_FUNCTION_NAME`, `AZURE_FUNCTIONS_SITE_NAME`, `CICS_PROGRAM_NAME`, `CICS_SYSTEM_ID`, `CICS_TASK_ID`, `CICS_TRANSACTION_ID`, `CICS_USER_ID`, `CPU_TIME`, `CTG_GATEWAY_URL`, `CTG_PROGRAM`, `CTG_SERVER_NAME`, `CTG_TRANSACTION_ID`, `CUSTOMSERVICE_CLASS`, `CUSTOMSERVICE_METHOD`, `DATABASE_CHILD_CALL_COUNT`, `DATABASE_CHILD_CALL_TIME`, `DATABASE_HOST`, `DATABASE_NAME`, `DATABASE_TYPE`, `DATABASE_URL`, `DISK_IO_TIME`, `ERROR_COUNT`, `ESB_APPLICATION_NAME`, `ESB_INPUT_TYPE`, `ESB_LIBRARY_NAME`, `ESB_MESSAGE_FLOW_NAME`, `EXCEPTION_CLASS`, `EXCEPTION_MESSAGE`, `FAILED_STATE`, `FAILURE_REASON`, `FLAW_STATE`, `HTTP_REQUEST_METHOD`, `HTTP_STATUS`, `HTTP_STATUS_CLASS`, `IMS_PROGRAM_NAME`, `IMS_TRANSACTION_ID`, `IMS_USER_ID`, `IO_TIME`, `IS_KEY_REQUEST`, `LAMBDA_COLDSTART`, `LOCK_TIME`, `MESSAGING_DESTINATION_TYPE`, `MESSAGING_IS_TEMPORARY_QUEUE`, `MESSAGING_QUEUE_NAME`, `MESSAGING_QUEUE_VENDOR`, `NETWORK_IO_TIME`, `NON_DATABASE_CHILD_CALL_COUNT`, `NON_DATABASE_CHILD_CALL_TIME`, `PROCESS_GROUP_NAME`, `PROCESS_GROUP_TAG`, `REMOTE_ENDPOINT`, `REMOTE_METHOD`, `REMOTE_SERVICE_NAME`, `REQUEST_NAME`, `REQUEST_TYPE`, `RESPONSE_TIME`, `RESPONSE_TIME_CLIENT`, `RMI_CLASS`, `RMI_METHOD`, `SERVICE_DISPLAY_NAME`, `SERVICE_NAME`, `SERVICE_PORT`, `SERVICE_PUBLIC_DOMAIN_NAME`, `SERVICE_REQUEST_ATTRIBUTE`, `SERVICE_TAG`, `SERVICE_TYPE`, `SERVICE_WEB_APPLICATION_ID`, `SERVICE_WEB_CONTEXT_ROOT`, `SERVICE_WEB_SERVER_NAME`, `SERVICE_WEB_SERVICE_NAME`, `SERVICE_WEB_SERVICE_NAMESPACE`, `SUSPENSION_TIME`, `TOTAL_PROCESSING_TIME`, `WAIT_TIME`, `WEBREQUEST_QUERY`, `WEBREQUEST_RELATIVE_URL`, `WEBREQUEST_URL`, `WEBREQUEST_URL_HOST`, `WEBREQUEST_URL_PATH`, `WEBREQUEST_URL_PORT`, `WEBSERVICE_ENDPOINT`, `WEBSERVICE_METHOD` and `ZOS_CALL_TYPE`",
},
"comparison": {
Type: schema.TypeList,
Required: true,
MaxItems: 1,
MinItems: 1,
Description: "Type-specific comparison for attributes",
Elem: &schema.Resource{Schema: new(comparisoninfo.Wrapper).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 *Condition) MarshalHCL(properties hcl.Properties) error {
if err := properties.Unknowns(me.Unknowns); err != nil {
return err
}
return properties.EncodeAll(map[string]any{
"attribute": me.Attribute,
"comparison": &comparisoninfo.Wrapper{Comparison: me.ComparisonInfo},
"unknowns": me.Unknowns,
})
}
func (me *Condition) UnmarshalHCL(decoder hcl.Decoder) error {
compWrap := comparisoninfo.Wrapper{Comparison: me.ComparisonInfo}
if err := decoder.DecodeAll(map[string]any{
"attribute": &me.Attribute,
"comparison": &compWrap,
"unknowns": &me.Unknowns,
}); err != nil {
return err
}
me.ComparisonInfo = compWrap.Comparison
return nil
}
func (me *Condition) MarshalJSON() ([]byte, error) {
properties := xjson.NewProperties(me.Unknowns)
if err := properties.MarshalAll(map[string]any{
"attribute": me.Attribute,
"comparisonInfo": me.ComparisonInfo,
}); err != nil {
return nil, err
}
return json.Marshal(properties)
}
func (me *Condition) UnmarshalJSON(data []byte) error {
properties := xjson.NewProperties(me.Unknowns)
if err := json.Unmarshal(data, &properties); err != nil {
return err
}
compWrap := comparisoninfo.Wrapper{Comparison: me.ComparisonInfo}
if err := properties.UnmarshalAll(map[string]any{
"attribute": &me.Attribute,
"comparisonInfo": &compWrap,
}); err != nil {
return err
}
me.ComparisonInfo = compWrap.Comparison
return nil
}
// Attribute The attribute to extract from. You can only use attributes of the **string** type.
type Attribute string
// Attributes offers the known enum values
var Attributes = struct {
ActorSystem Attribute
AkkaActorClassName Attribute
AkkaActorMessageType Attribute
AkkaActorPath Attribute
ApplicationBuildVersion Attribute
ApplicationEnvironment Attribute
ApplicationName Attribute
ApplicationReleaseVersion Attribute
AzureFunctionsFunctionName Attribute
AzureFunctionsSiteName Attribute
CICSProgramName Attribute
CICSSystemID Attribute
CICSTaskID Attribute
CICSTransactionID Attribute
CICSUserID Attribute
CPUTime Attribute
CTGGatewayURL Attribute
CTGProgram Attribute
CTGServerName Attribute
CTGTransactionID Attribute
CustomserviceClass Attribute
CustomserviceMethod Attribute
DatabaseChildCallCount Attribute
DatabaseChildCallTime Attribute
DatabaseHost Attribute
DatabaseName Attribute
DatabaseStatemnent Attribute
DatabaseType Attribute
DatabaseURL Attribute
DiskIoTime Attribute
ErrorCount Attribute
EsbApplicationName Attribute
EsbInputType Attribute
EsbLibraryName Attribute
EsbMessageFlowName Attribute
ExceptionClass Attribute
ExceptionMessage Attribute
FailedState Attribute
FailureReason Attribute
FlawState Attribute
HTTPRequestMethod Attribute
HTTPStatus Attribute
HTTPStatusClass Attribute
IMSProgramName Attribute
IMSTransactionID Attribute
IMSUserID Attribute
IoTime Attribute
IsKeyRequest Attribute
LambdaColdstart Attribute
LockTime Attribute
MessagingDestinationType Attribute
MessagingIsTemporaryQueue Attribute
MessagingQueueName Attribute
MessagingQueueVendor Attribute
NetworkIoTime Attribute
NonDatabaseChildCallCount Attribute
NonDatabaseChildCallTime Attribute
ProcessGroupName Attribute
ProcessGroupTag Attribute
RemoteEndpoint Attribute
RemoteMethod Attribute
RemoteServiceName Attribute
RequestName Attribute
RequestType Attribute
ResponseTime Attribute
ResponseTimeClient Attribute
RMIClass Attribute
RMIMethod Attribute
ServiceDisplayName Attribute
ServiceName Attribute
ServicePort Attribute
ServicePublicDomainName Attribute
ServiceRequestAttribute Attribute
ServiceTag Attribute
ServiceType Attribute
ServiceWebApplicationID Attribute
ServiceWebContextRoot Attribute
ServiceWebServerName Attribute
ServiceWebServiceName Attribute
ServiceWebServiceNamespace Attribute
SuspensionTime Attribute
TotalProcessingTime Attribute
WaitTime Attribute
WebrequestQuery Attribute
WebrequestRelativeURL Attribute
WebrequestURL Attribute
WebrequestURLHost Attribute
WebrequestURLPath Attribute
WebrequestURLPort Attribute
WebserviceEndpoint Attribute
WebserviceMethod Attribute
ZosCallType Attribute
}{
"ACTOR_SYSTEM",
"AKKA_ACTOR_CLASS_NAME",
"AKKA_ACTOR_MESSAGE_TYPE",
"AKKA_ACTOR_PATH",
"APPLICATION_BUILD_VERSION",
"APPLICATION_ENVIRONMENT",
"APPLICATION_NAME",
"APPLICATION_RELEASE_VERSION",
"AZURE_FUNCTIONS_FUNCTION_NAME",
"AZURE_FUNCTIONS_SITE_NAME",
"CICS_PROGRAM_NAME",
"CICS_SYSTEM_ID",
"CICS_TASK_ID",
"CICS_TRANSACTION_ID",
"CICS_USER_ID",
"CPU_TIME",
"CTG_GATEWAY_URL",
"CTG_PROGRAM",
"CTG_SERVER_NAME",
"CTG_TRANSACTION_ID",
"CUSTOMSERVICE_CLASS",
"CUSTOMSERVICE_METHOD",
"DATABASE_CHILD_CALL_COUNT",
"DATABASE_CHILD_CALL_TIME",
"DATABASE_HOST",
"DATABASE_NAME",
"DATABASE_STATEMENT",
"DATABASE_TYPE",
"DATABASE_URL",
"DISK_IO_TIME",
"ERROR_COUNT",
"ESB_APPLICATION_NAME",
"ESB_INPUT_TYPE",
"ESB_LIBRARY_NAME",
"ESB_MESSAGE_FLOW_NAME",
"EXCEPTION_CLASS",
"EXCEPTION_MESSAGE",
"FAILED_STATE",
"FAILURE_REASON",
"FLAW_STATE",
"HTTP_REQUEST_METHOD",
"HTTP_STATUS",
"HTTP_STATUS_CLASS",
"IMS_PROGRAM_NAME",
"IMS_TRANSACTION_ID",
"IMS_USER_ID",
"IO_TIME",
"IS_KEY_REQUEST",
"LAMBDA_COLDSTART",
"LOCK_TIME",
"MESSAGING_DESTINATION_TYPE",
"MESSAGING_IS_TEMPORARY_QUEUE",
"MESSAGING_QUEUE_NAME",
"MESSAGING_QUEUE_VENDOR",
"NETWORK_IO_TIME",
"NON_DATABASE_CHILD_CALL_COUNT",
"NON_DATABASE_CHILD_CALL_TIME",
"PROCESS_GROUP_NAME",
"PROCESS_GROUP_TAG",
"REMOTE_ENDPOINT",
"REMOTE_METHOD",
"REMOTE_SERVICE_NAME",
"REQUEST_NAME",
"REQUEST_TYPE",
"RESPONSE_TIME",
"RESPONSE_TIME_CLIENT",
"RMI_CLASS",
"RMI_METHOD",
"SERVICE_DISPLAY_NAME",
"SERVICE_NAME",
"SERVICE_PORT",
"SERVICE_PUBLIC_DOMAIN_NAME",
"SERVICE_REQUEST_ATTRIBUTE",
"SERVICE_TAG",
"SERVICE_TYPE",
"SERVICE_WEB_APPLICATION_ID",
"SERVICE_WEB_CONTEXT_ROOT",
"SERVICE_WEB_SERVER_NAME",
"SERVICE_WEB_SERVICE_NAME",
"SERVICE_WEB_SERVICE_NAMESPACE",
"SUSPENSION_TIME",
"TOTAL_PROCESSING_TIME",
"WAIT_TIME",
"WEBREQUEST_QUERY",
"WEBREQUEST_RELATIVE_URL",
"WEBREQUEST_URL",
"WEBREQUEST_URL_HOST",
"WEBREQUEST_URL_PATH",
"WEBREQUEST_URL_PORT",
"WEBSERVICE_ENDPOINT",
"WEBSERVICE_METHOD",
"ZOS_CALL_TYPE",
}