-
Notifications
You must be signed in to change notification settings - Fork 133
/
data_source_tc_dbbrain_diag_event.go
200 lines (161 loc) · 4.95 KB
/
data_source_tc_dbbrain_diag_event.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
package dbbrain
import (
"context"
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
dbbrain "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dbbrain/v20210527"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)
func DataSourceTencentCloudDbbrainDiagEvent() *schema.Resource {
return &schema.Resource{
Read: dataSourceTencentCloudDbbrainDiagEventRead,
Schema: map[string]*schema.Schema{
"instance_id": {
Required: true,
Type: schema.TypeString,
Description: "isntance id.",
},
"event_id": {
Optional: true,
Computed: true,
Type: schema.TypeInt,
Description: "Event ID. Obtain it through `Get Instance Diagnosis History DescribeDBDiagHistory`.",
},
"product": {
Optional: true,
Type: schema.TypeString,
Description: "Service product type, supported values include: `mysql` - cloud database MySQL, `cynosdb` - cloud database CynosDB for MySQL, the default is `mysql`.",
},
"diag_item": {
Computed: true,
Type: schema.TypeString,
Description: "diagnostic item.",
},
"diag_type": {
Computed: true,
Type: schema.TypeString,
Description: "Diagnostic type.",
},
"explanation": {
Computed: true,
Type: schema.TypeString,
Description: "Diagnostic event details, output is empty if there is no additional explanatory information.",
},
"outline": {
Computed: true,
Type: schema.TypeString,
Description: "Diagnostic summary.",
},
"problem": {
Computed: true,
Type: schema.TypeString,
Description: "Diagnosed problem.",
},
"severity": {
Computed: true,
Type: schema.TypeInt,
Description: "severity. The severity is divided into 5 levels, according to the degree of impact from high to low: 1: Fatal, 2: Serious, 3: Warning, 4: Prompt, 5: Healthy.",
},
"start_time": {
Computed: true,
Type: schema.TypeString,
Description: "Starting time.",
},
"suggestions": {
Computed: true,
Type: schema.TypeString,
Description: "A diagnostic suggestion, or empty if there is no suggestion.",
},
"metric": {
Computed: true,
Type: schema.TypeString,
Description: "reserved text. Note: This field may return null, indicating that no valid value can be obtained.",
},
"end_time": {
Computed: true,
Type: schema.TypeString,
Description: "End Time.",
},
"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},
},
}
}
func dataSourceTencentCloudDbbrainDiagEventRead(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("data_source.tencentcloud_dbbrain_diag_event.read")()
defer tccommon.InconsistentCheck(d, meta)()
logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
var id string
paramMap := make(map[string]interface{})
if v, ok := d.GetOk("instance_id"); ok {
paramMap["instance_id"] = helper.String(v.(string))
id = v.(string)
}
if v, _ := d.GetOk("event_id"); v != nil {
paramMap["event_id"] = helper.IntInt64(v.(int))
}
if v, ok := d.GetOk("product"); ok {
paramMap["product"] = helper.String(v.(string))
}
var result *dbbrain.DescribeDBDiagEventResponseParams
service := DbbrainService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
var e error
result, e = service.DescribeDbbrainDiagEventByFilter(ctx, paramMap)
if e != nil {
return tccommon.RetryError(e)
}
return nil
})
if err != nil {
return err
}
if result != nil {
if result.DiagItem != nil {
_ = d.Set("diag_item", result.DiagItem)
}
if result.DiagType != nil {
_ = d.Set("diag_type", result.DiagType)
}
if result.EventId != nil {
_ = d.Set("event_id", result.EventId)
}
if result.Explanation != nil {
_ = d.Set("explanation", result.Explanation)
}
if result.Outline != nil {
_ = d.Set("outline", result.Outline)
}
if result.Problem != nil {
_ = d.Set("problem", result.Problem)
}
if result.Severity != nil {
_ = d.Set("severity", result.Severity)
}
if result.StartTime != nil {
_ = d.Set("start_time", result.StartTime)
}
if result.Suggestions != nil {
_ = d.Set("suggestions", result.Suggestions)
}
if result.Metric != nil {
_ = d.Set("metric", result.Metric)
}
if result.EndTime != nil {
_ = d.Set("end_time", result.EndTime)
}
}
d.SetId(id)
output, ok := d.GetOk("result_output_file")
if ok && output.(string) != "" {
if e := tccommon.WriteToFile(output.(string), result); e != nil {
return e
}
}
return nil
}