/
resource_visibility_packet_capture_object_templates_fw_server_port_tmpl.go
233 lines (221 loc) · 10 KB
/
resource_visibility_packet_capture_object_templates_fw_server_port_tmpl.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
package thunder
import (
"context"
edpt "github.com/a10networks/terraform-provider-thunder/thunder/axapi/endpoint"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func resourceVisibilityPacketCaptureObjectTemplatesFwServerPortTmpl() *schema.Resource {
return &schema.Resource{
Description: "`thunder_visibility_packet_capture_object_templates_fw_server_port_tmpl`: Configure template for fw.server.port\n\n__PLACEHOLDER__",
CreateContext: resourceVisibilityPacketCaptureObjectTemplatesFwServerPortTmplCreate,
UpdateContext: resourceVisibilityPacketCaptureObjectTemplatesFwServerPortTmplUpdate,
ReadContext: resourceVisibilityPacketCaptureObjectTemplatesFwServerPortTmplRead,
DeleteContext: resourceVisibilityPacketCaptureObjectTemplatesFwServerPortTmplDelete,
Schema: map[string]*schema.Schema{
"capture_config": {
Type: schema.TypeString, Optional: true, Description: "Specify name of the capture-config to use with this template",
},
"name": {
Type: schema.TypeString, Required: true, Description: "Packet Capture Template Name",
},
"trigger_stats_inc": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"es_resp_400": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable automatic packet-capture for Response status 400",
},
"es_resp_500": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable automatic packet-capture for Response status 500",
},
"es_resp_invalid_http": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable automatic packet-capture for Total non-http response",
},
"uuid": {
Type: schema.TypeString, Optional: true, Computed: true, Description: "uuid of the object",
},
},
},
},
"trigger_stats_rate": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"threshold_exceeded_by": {
Type: schema.TypeInt, Optional: true, Default: 5, Description: "Set the threshold to the number of times greater than the previous duration to start the capture, default is 5",
},
"duration": {
Type: schema.TypeInt, Optional: true, Default: 60, Description: "Time in seconds to look for the anomaly, default is 60",
},
"es_resp_400": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable automatic packet-capture for Response status 400",
},
"es_resp_500": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable automatic packet-capture for Response status 500",
},
"es_resp_invalid_http": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable automatic packet-capture for Total non-http response",
},
"uuid": {
Type: schema.TypeString, Optional: true, Computed: true, Description: "uuid of the object",
},
},
},
},
"trigger_stats_severity": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"error": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable packet capture on all error counters (Default disabled)",
},
"error_alert": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable packet capture on all alert error counters (Default disabled)",
},
"error_warning": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable packet capture on all warning error counters (Default disabled)",
},
"error_critical": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable packet capture on all critical error counters (Default disabled)",
},
"drop": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable packet capture on all drop counters (Default disabled)",
},
"drop_alert": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable packet capture on all alert drop counters (Default disabled)",
},
"drop_warning": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable packet capture on all warning drop counters (Default disabled)",
},
"drop_critical": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable packet capture on all critical drop counters (Default disabled)",
},
"uuid": {
Type: schema.TypeString, Optional: true, Computed: true, Description: "uuid of the object",
},
},
},
},
"user_tag": {
Type: schema.TypeString, Optional: true, Description: "Customized tag",
},
"uuid": {
Type: schema.TypeString, Optional: true, Computed: true, Description: "uuid of the object",
},
},
}
}
func resourceVisibilityPacketCaptureObjectTemplatesFwServerPortTmplCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceVisibilityPacketCaptureObjectTemplatesFwServerPortTmplCreate()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointVisibilityPacketCaptureObjectTemplatesFwServerPortTmpl(d)
d.SetId(obj.GetId())
err := obj.Post(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceVisibilityPacketCaptureObjectTemplatesFwServerPortTmplRead(ctx, d, meta)
}
return diags
}
func resourceVisibilityPacketCaptureObjectTemplatesFwServerPortTmplUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceVisibilityPacketCaptureObjectTemplatesFwServerPortTmplUpdate()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointVisibilityPacketCaptureObjectTemplatesFwServerPortTmpl(d)
err := obj.Put(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceVisibilityPacketCaptureObjectTemplatesFwServerPortTmplRead(ctx, d, meta)
}
return diags
}
func resourceVisibilityPacketCaptureObjectTemplatesFwServerPortTmplDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceVisibilityPacketCaptureObjectTemplatesFwServerPortTmplDelete()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointVisibilityPacketCaptureObjectTemplatesFwServerPortTmpl(d)
err := obj.Delete(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func resourceVisibilityPacketCaptureObjectTemplatesFwServerPortTmplRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceVisibilityPacketCaptureObjectTemplatesFwServerPortTmplRead()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointVisibilityPacketCaptureObjectTemplatesFwServerPortTmpl(d)
err := obj.Get(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func getObjectVisibilityPacketCaptureObjectTemplatesFwServerPortTmplTriggerStatsInc2681(d []interface{}) edpt.VisibilityPacketCaptureObjectTemplatesFwServerPortTmplTriggerStatsInc2681 {
count1 := len(d)
var ret edpt.VisibilityPacketCaptureObjectTemplatesFwServerPortTmplTriggerStatsInc2681
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.Es_resp_400 = in["es_resp_400"].(int)
ret.Es_resp_500 = in["es_resp_500"].(int)
ret.Es_resp_invalid_http = in["es_resp_invalid_http"].(int)
//omit uuid
}
return ret
}
func getObjectVisibilityPacketCaptureObjectTemplatesFwServerPortTmplTriggerStatsRate2682(d []interface{}) edpt.VisibilityPacketCaptureObjectTemplatesFwServerPortTmplTriggerStatsRate2682 {
count1 := len(d)
var ret edpt.VisibilityPacketCaptureObjectTemplatesFwServerPortTmplTriggerStatsRate2682
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.ThresholdExceededBy = in["threshold_exceeded_by"].(int)
ret.Duration = in["duration"].(int)
ret.Es_resp_400 = in["es_resp_400"].(int)
ret.Es_resp_500 = in["es_resp_500"].(int)
ret.Es_resp_invalid_http = in["es_resp_invalid_http"].(int)
//omit uuid
}
return ret
}
func getObjectVisibilityPacketCaptureObjectTemplatesFwServerPortTmplTriggerStatsSeverity2683(d []interface{}) edpt.VisibilityPacketCaptureObjectTemplatesFwServerPortTmplTriggerStatsSeverity2683 {
count1 := len(d)
var ret edpt.VisibilityPacketCaptureObjectTemplatesFwServerPortTmplTriggerStatsSeverity2683
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.Error = in["error"].(int)
ret.ErrorAlert = in["error_alert"].(int)
ret.ErrorWarning = in["error_warning"].(int)
ret.ErrorCritical = in["error_critical"].(int)
ret.Drop = in["drop"].(int)
ret.DropAlert = in["drop_alert"].(int)
ret.DropWarning = in["drop_warning"].(int)
ret.DropCritical = in["drop_critical"].(int)
//omit uuid
}
return ret
}
func dataToEndpointVisibilityPacketCaptureObjectTemplatesFwServerPortTmpl(d *schema.ResourceData) edpt.VisibilityPacketCaptureObjectTemplatesFwServerPortTmpl {
var ret edpt.VisibilityPacketCaptureObjectTemplatesFwServerPortTmpl
ret.Inst.CaptureConfig = d.Get("capture_config").(string)
ret.Inst.Name = d.Get("name").(string)
ret.Inst.TriggerStatsInc = getObjectVisibilityPacketCaptureObjectTemplatesFwServerPortTmplTriggerStatsInc2681(d.Get("trigger_stats_inc").([]interface{}))
ret.Inst.TriggerStatsRate = getObjectVisibilityPacketCaptureObjectTemplatesFwServerPortTmplTriggerStatsRate2682(d.Get("trigger_stats_rate").([]interface{}))
ret.Inst.TriggerStatsSeverity = getObjectVisibilityPacketCaptureObjectTemplatesFwServerPortTmplTriggerStatsSeverity2683(d.Get("trigger_stats_severity").([]interface{}))
ret.Inst.UserTag = d.Get("user_tag").(string)
//omit uuid
return ret
}