/
resource_fw_service_group_stats.go
277 lines (239 loc) · 9.5 KB
/
resource_fw_service_group_stats.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
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 resourceFwServiceGroupStats() *schema.Resource {
return &schema.Resource{
Description: "`thunder_fw_service_group_stats`: Statistics for the object service-group\n\n__PLACEHOLDER__",
ReadContext: resourceFwServiceGroupStatsRead,
Schema: map[string]*schema.Schema{
"member_list": {
Type: schema.TypeList, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString, Required: true, Description: "Member name",
},
"port": {
Type: schema.TypeInt, Required: true, Description: "Port number",
},
"stats": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"curr_conn": {
Type: schema.TypeInt, Optional: true, Description: "Current connections",
},
"total_fwd_bytes": {
Type: schema.TypeInt, Optional: true, Description: "Total forward bytes",
},
"total_fwd_pkts": {
Type: schema.TypeInt, Optional: true, Description: "Total forward packets",
},
"total_rev_bytes": {
Type: schema.TypeInt, Optional: true, Description: "Total reverse bytes",
},
"total_rev_pkts": {
Type: schema.TypeInt, Optional: true, Description: "Total reverse packets",
},
"total_conn": {
Type: schema.TypeInt, Optional: true, Description: "Total connections",
},
"total_rev_pkts_inspected": {
Type: schema.TypeInt, Optional: true, Description: "Total reverse packets inspected",
},
"total_rev_pkts_inspected_status_code_2xx": {
Type: schema.TypeInt, Optional: true, Description: "Total reverse packets inspected status code 2xx",
},
"total_rev_pkts_inspected_status_code_non_5xx": {
Type: schema.TypeInt, Optional: true, Description: "Total reverse packets inspected status code non 5xx",
},
"curr_req": {
Type: schema.TypeInt, Optional: true, Description: "Current requests",
},
"total_req": {
Type: schema.TypeInt, Optional: true, Description: "Total requests",
},
"total_req_succ": {
Type: schema.TypeInt, Optional: true, Description: "Total requests success",
},
"peak_conn": {
Type: schema.TypeInt, Optional: true, Description: "Peak connections",
},
"response_time": {
Type: schema.TypeInt, Optional: true, Description: "Response time",
},
"fastest_rsp_time": {
Type: schema.TypeInt, Optional: true, Description: "Fastest response time",
},
"slowest_rsp_time": {
Type: schema.TypeInt, Optional: true, Description: "Slowest response time",
},
"curr_ssl_conn": {
Type: schema.TypeInt, Optional: true, Description: "Current SSL connections",
},
"total_ssl_conn": {
Type: schema.TypeInt, Optional: true, Description: "Total SSL connections",
},
"curr_conn_overflow": {
Type: schema.TypeInt, Optional: true, Description: "Current connection counter overflow count",
},
"state_flaps": {
Type: schema.TypeInt, Optional: true, Description: "State flaps count",
},
},
},
},
},
},
},
"name": {
Type: schema.TypeString, Required: true, Description: "FW Service Name",
},
"stats": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"server_selection_fail_drop": {
Type: schema.TypeInt, Optional: true, Description: "Service selection fail drop",
},
"server_selection_fail_reset": {
Type: schema.TypeInt, Optional: true, Description: "Service selection fail reset",
},
"service_peak_conn": {
Type: schema.TypeInt, Optional: true, Description: "Service peak connection",
},
},
},
},
},
}
}
func resourceFwServiceGroupStatsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceFwServiceGroupStatsRead()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointFwServiceGroupStats(d)
res, err := obj.Get(client.Token, client.Host, d.Id(), logger)
d.SetId(obj.GetId())
logger.Println(res)
FwServiceGroupStatsMemberList := setSliceFwServiceGroupStatsMemberList(res)
d.Set("member_list", FwServiceGroupStatsMemberList)
FwServiceGroupStatsStats := setObjectFwServiceGroupStatsStats(res)
d.Set("stats", FwServiceGroupStatsStats)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func setSliceFwServiceGroupStatsMemberList(d edpt.DataFwServiceGroupStats) []map[string]interface{} {
result := []map[string]interface{}{}
for _, item := range d.DtFwServiceGroupStats.MemberList {
in := make(map[string]interface{})
in["name"] = item.Name
in["port"] = item.Port
in["stats"] = setObjectFwServiceGroupStatsMemberListStats(item.Stats)
result = append(result, in)
}
return result
}
func setObjectFwServiceGroupStatsMemberListStats(d edpt.FwServiceGroupStatsMemberListStats) []map[string]interface{} {
result := []map[string]interface{}{}
in := make(map[string]interface{})
in["curr_conn"] = d.Curr_conn
in["total_fwd_bytes"] = d.Total_fwd_bytes
in["total_fwd_pkts"] = d.Total_fwd_pkts
in["total_rev_bytes"] = d.Total_rev_bytes
in["total_rev_pkts"] = d.Total_rev_pkts
in["total_conn"] = d.Total_conn
in["total_rev_pkts_inspected"] = d.Total_rev_pkts_inspected
in["total_rev_pkts_inspected_status_code_2xx"] = d.Total_rev_pkts_inspected_status_code_2xx
in["total_rev_pkts_inspected_status_code_non_5xx"] = d.Total_rev_pkts_inspected_status_code_non_5xx
in["curr_req"] = d.Curr_req
in["total_req"] = d.Total_req
in["total_req_succ"] = d.Total_req_succ
in["peak_conn"] = d.Peak_conn
in["response_time"] = d.Response_time
in["fastest_rsp_time"] = d.Fastest_rsp_time
in["slowest_rsp_time"] = d.Slowest_rsp_time
in["curr_ssl_conn"] = d.Curr_ssl_conn
in["total_ssl_conn"] = d.Total_ssl_conn
in["curr_conn_overflow"] = d.Curr_conn_overflow
in["state_flaps"] = d.State_flaps
result = append(result, in)
return result
}
func setObjectFwServiceGroupStatsStats(ret edpt.DataFwServiceGroupStats) []interface{} {
return []interface{}{
map[string]interface{}{
"server_selection_fail_drop": ret.DtFwServiceGroupStats.Stats.Server_selection_fail_drop,
"server_selection_fail_reset": ret.DtFwServiceGroupStats.Stats.Server_selection_fail_reset,
"service_peak_conn": ret.DtFwServiceGroupStats.Stats.Service_peak_conn,
},
}
}
func getSliceFwServiceGroupStatsMemberList(d []interface{}) []edpt.FwServiceGroupStatsMemberList {
count1 := len(d)
ret := make([]edpt.FwServiceGroupStatsMemberList, 0, count1)
for _, item := range d {
in := item.(map[string]interface{})
var oi edpt.FwServiceGroupStatsMemberList
oi.Name = in["name"].(string)
oi.Port = in["port"].(int)
oi.Stats = getObjectFwServiceGroupStatsMemberListStats(in["stats"].([]interface{}))
ret = append(ret, oi)
}
return ret
}
func getObjectFwServiceGroupStatsMemberListStats(d []interface{}) edpt.FwServiceGroupStatsMemberListStats {
count1 := len(d)
var ret edpt.FwServiceGroupStatsMemberListStats
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.Curr_conn = in["curr_conn"].(int)
ret.Total_fwd_bytes = in["total_fwd_bytes"].(int)
ret.Total_fwd_pkts = in["total_fwd_pkts"].(int)
ret.Total_rev_bytes = in["total_rev_bytes"].(int)
ret.Total_rev_pkts = in["total_rev_pkts"].(int)
ret.Total_conn = in["total_conn"].(int)
ret.Total_rev_pkts_inspected = in["total_rev_pkts_inspected"].(int)
ret.Total_rev_pkts_inspected_status_code_2xx = in["total_rev_pkts_inspected_status_code_2xx"].(int)
ret.Total_rev_pkts_inspected_status_code_non_5xx = in["total_rev_pkts_inspected_status_code_non_5xx"].(int)
ret.Curr_req = in["curr_req"].(int)
ret.Total_req = in["total_req"].(int)
ret.Total_req_succ = in["total_req_succ"].(int)
ret.Peak_conn = in["peak_conn"].(int)
ret.Response_time = in["response_time"].(int)
ret.Fastest_rsp_time = in["fastest_rsp_time"].(int)
ret.Slowest_rsp_time = in["slowest_rsp_time"].(int)
ret.Curr_ssl_conn = in["curr_ssl_conn"].(int)
ret.Total_ssl_conn = in["total_ssl_conn"].(int)
ret.Curr_conn_overflow = in["curr_conn_overflow"].(int)
ret.State_flaps = in["state_flaps"].(int)
}
return ret
}
func getObjectFwServiceGroupStatsStats(d []interface{}) edpt.FwServiceGroupStatsStats {
count1 := len(d)
var ret edpt.FwServiceGroupStatsStats
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.Server_selection_fail_drop = in["server_selection_fail_drop"].(int)
ret.Server_selection_fail_reset = in["server_selection_fail_reset"].(int)
ret.Service_peak_conn = in["service_peak_conn"].(int)
}
return ret
}
func dataToEndpointFwServiceGroupStats(d *schema.ResourceData) edpt.FwServiceGroupStats {
var ret edpt.FwServiceGroupStats
ret.MemberList = getSliceFwServiceGroupStatsMemberList(d.Get("member_list").([]interface{}))
ret.Name = d.Get("name").(string)
ret.Stats = getObjectFwServiceGroupStatsStats(d.Get("stats").([]interface{}))
return ret
}