-
Notifications
You must be signed in to change notification settings - Fork 31
/
service_now.go
165 lines (151 loc) · 7.62 KB
/
service_now.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
/**
* @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 notifications
import (
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/export/sensitive"
"github.com/dynatrace-oss/terraform-provider-dynatrace/terraform/hcl"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
type ServiceNow struct {
Enabled bool `json:"-"`
Name string `json:"-"`
ProfileID string `json:"-"`
FormatProblemDetailsAsText *bool `json:"formatProblemDetailsAsText,omitempty"` // Use text format for problem details instead of HTML.
InstanceName *string `json:"instanceName"` // The ServiceNow instance identifier. It refers to the first part of your own ServiceNow URL. \n\n This field is mutually exclusive with the **url** field. You can only use one of them
URL *string `json:"url"` // The URL of the on-premise ServiceNow installation. \n\n This field is mutually exclusive with the **instanceName** field. You can only use one of them
Username string `json:"username"` // The username of the ServiceNow account. \n\n Make sure that your user account has the `web_service_admin` and `x_dynat_ruxit.Integration` roles
Password string `json:"password"` // The password to the ServiceNow account
Message string `json:"message"` // The content of the ServiceNow description. Type '{' for placeholder suggestions
SendIncidents bool `json:"sendIncidents"` // Send incidents into ServiceNow ITSM
SendEvents bool `json:"sendEvents"` // Send events into ServiceNow ITOM
}
func (me *ServiceNow) PrepareMarshalHCL(decoder hcl.Decoder) error {
if password, ok := decoder.GetOk("password"); ok && len(password.(string)) > 0 {
me.Password = password.(string)
}
return nil
}
func (me *ServiceNow) FillDemoValues() []string {
me.Password = "#######"
return []string{"Please fill in the password"}
}
func (me *ServiceNow) Schema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"format_problem_details_as_text": {
Type: schema.TypeBool,
Description: "Use text format for problem details instead of HTML.",
Optional: true, // nullable
},
"name": {
Type: schema.TypeString,
Description: "The name of the notification configuration",
Required: true,
},
"active": {
Type: schema.TypeBool,
Description: "The configuration is enabled (`true`) or disabled (`false`)",
Required: true,
},
"profile": {
Type: schema.TypeString,
Description: "The ID of the associated alerting profile",
Required: true,
},
"events": {
Type: schema.TypeBool,
Description: "Send events into ServiceNow ITOM",
Optional: true,
},
"incidents": {
Type: schema.TypeBool,
Description: "Send incidents into ServiceNow ITSM",
Required: true,
},
"url": {
Type: schema.TypeString,
Description: "The URL of the on-premise ServiceNow installation. This field is mutually exclusive with the **instance** field. You can only use one of them",
Optional: true,
},
"username": {
Type: schema.TypeString,
Description: "The username of the ServiceNow account. Make sure that your user account has the `rest_service`, `web_request_admin`, and `x_dynat_ruxit.Integration` roles",
Required: true,
},
"instance": {
Type: schema.TypeString,
Description: "The ServiceNow instance identifier. It refers to the first part of your own ServiceNow URL. This field is mutually exclusive with the **url** field. You can only use one of them",
Optional: true,
},
"message": {
Type: schema.TypeString,
Description: "The content of the ServiceNow description. You can use the following placeholders: * `{ImpactedEntity}`: The entity impacted by the problem or *X* impacted entities. * `{PID}`: The ID of the reported problem. * `{ProblemDetailsHTML}`: All problem event details, including root cause, as an HTML-formatted string. * `{ProblemID}`: The display number of the reported problem. * `{ProblemImpact}`: The [impact level](https://www.dynatrace.com/support/help/shortlink/impact-analysis) of the problem. Possible values are `APPLICATION`, `SERVICE`, and `INFRASTRUCTURE`. * `{ProblemSeverity}`: The [severity level](https://www.dynatrace.com/support/help/shortlink/event-types) of the problem. Possible values are `AVAILABILITY`, `ERROR`, `PERFORMANCE`, `RESOURCE_CONTENTION`, and `CUSTOM_ALERT`. * `{ProblemTitle}`: A short description of the problem. * `{ProblemURL}`: The URL of the problem within Dynatrace. * `{State}`: The state of the problem. Possible values are `OPEN` and `RESOLVED`. * `{Tags}`: The list of tags that are defined for all impacted entities, separated by commas",
Required: true,
},
"password": {
Type: schema.TypeString,
Description: "The password to the ServiceNow account",
Sensitive: true,
Optional: true,
},
"legacy_id": {
Type: schema.TypeString,
Description: "The ID of these settings when referred to from resources requiring the REST API V1 keys",
Computed: true,
Optional: true,
},
}
}
func (me *ServiceNow) MarshalHCL(properties hcl.Properties) error { // The password field MUST NOT get serialized into HCL here
// The Dynatrace Settings 2.0 API delivers a scrambled version of any previously stored password here
// Evaluation at this point would lead to that scrambled version to make it into the Terraform State
// As a result any plans would be non-empty
return properties.EncodeAll(sensitive.ConditionalIgnoreChangesMap(
me.Schema(),
map[string]any{
"name": me.Name,
"active": me.Enabled,
"profile": me.ProfileID,
"format_problem_details_as_text": me.FormatProblemDetailsAsText,
"events": me.SendEvents,
"incidents": me.SendIncidents,
"url": me.URL,
"username": me.Username,
"instance": me.InstanceName,
"message": me.Message,
"password": me.Password,
},
))
}
func (me *ServiceNow) HandlePreconditions() error {
// ---- InstanceName *string -> {"preconditions":[{"property":"url","type":"NULL"},{"expectedValue":"","property":"url","type":"EQUALS"}],"type":"OR"}
return nil
}
func (me *ServiceNow) UnmarshalHCL(decoder hcl.Decoder) error {
return decoder.DecodeAll(map[string]any{
"name": &me.Name,
"active": &me.Enabled,
"profile": &me.ProfileID,
"format_problem_details_as_text": &me.FormatProblemDetailsAsText,
"events": &me.SendEvents,
"incidents": &me.SendIncidents,
"url": &me.URL,
"username": &me.Username,
"instance": &me.InstanceName,
"message": &me.Message,
"password": &me.Password,
})
}