/
resource_ddos_table_stats.go
308 lines (299 loc) · 15.9 KB
/
resource_ddos_table_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
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
303
304
305
306
307
308
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 resourceDdosTableStats() *schema.Resource {
return &schema.Resource{
Description: "`thunder_ddos_table_stats`: Statistics for the object table\n\n__PLACEHOLDER__",
ReadContext: resourceDdosTableStatsRead,
Schema: map[string]*schema.Schema{
"stats": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"dst_learn": {
Type: schema.TypeInt, Optional: true, Description: "Dst Entry Learned",
},
"dst_hit": {
Type: schema.TypeInt, Optional: true, Description: "Dst Entry Hit",
},
"dst_miss": {
Type: schema.TypeInt, Optional: true, Description: "Dst Entry Missed",
},
"dst_entry_aged": {
Type: schema.TypeInt, Optional: true, Description: "Dst Entry Aged",
},
"src_learn": {
Type: schema.TypeInt, Optional: true, Description: "Src Entry Learned",
},
"src_hit": {
Type: schema.TypeInt, Optional: true, Description: "Src Entry Hit",
},
"src_miss": {
Type: schema.TypeInt, Optional: true, Description: "Src Entry Missed",
},
"src_entry_aged": {
Type: schema.TypeInt, Optional: true, Description: "Src Entry Aged",
},
"src_dst_learn": {
Type: schema.TypeInt, Optional: true, Description: "SrcDst Entry Learned",
},
"src_dst_hit": {
Type: schema.TypeInt, Optional: true, Description: "SrcDst Entry Hit",
},
"src_dst_miss": {
Type: schema.TypeInt, Optional: true, Description: "SrcDst Entry Missed",
},
"src_dst_entry_aged": {
Type: schema.TypeInt, Optional: true, Description: "SrcDst Entry Aged",
},
"telem_err_misc": {
Type: schema.TypeInt, Optional: true, Description: "From-l3-peer: Misc Error",
},
"telem_route_add_rcvd": {
Type: schema.TypeInt, Optional: true, Description: "From-l3-peer: Route-add Received",
},
"telem_route_del_rcvd": {
Type: schema.TypeInt, Optional: true, Description: "From-l3-peer: Route-del Received",
},
"telem_entry_created": {
Type: schema.TypeInt, Optional: true, Description: "From-l3-peer: Zone Entry Created",
},
"telem_entry_cleared": {
Type: schema.TypeInt, Optional: true, Description: "From-l3-peer: Zone Entry Deleted",
},
"telem_err_telem_entry_pre_exist": {
Type: schema.TypeInt, Optional: true, Description: "From-l3-peer: Zone Entry Pre-exist",
},
"telem_err_conflict_with_static": {
Type: schema.TypeInt, Optional: true, Description: "From-l3-peer: Conflict with Static Entry",
},
"telem_err_fail_to_create": {
Type: schema.TypeInt, Optional: true, Description: "From-l3-peer: Zone Entry Create Fail",
},
"telem_err_fail_to_delete": {
Type: schema.TypeInt, Optional: true, Description: "From-l3-peer: Zone Entry Delete Fail",
},
"src_zone_service_learn": {
Type: schema.TypeInt, Optional: true, Description: "SrcZoneService Entry Learned",
},
"src_zone_service_hit": {
Type: schema.TypeInt, Optional: true, Description: "SrcZoneService Entry Hit",
},
"src_zone_service_miss": {
Type: schema.TypeInt, Optional: true, Description: "SrcZoneService Entry Missed",
},
"src_zone_service_entry_aged": {
Type: schema.TypeInt, Optional: true, Description: "SrcZoneService Entry Aged",
},
"dst_white_list": {
Type: schema.TypeInt, Optional: true, Description: "Dst Entry Whitelisted",
},
"src_white_list": {
Type: schema.TypeInt, Optional: true, Description: "Src Entry Whitelisted",
},
"src_dst_white_list": {
Type: schema.TypeInt, Optional: true, Description: "SrcDst Entry Whitelisted",
},
"src_zone_service_white_list": {
Type: schema.TypeInt, Optional: true, Description: "SrcZoneService Entry Whitelisted",
},
"dst_black_list": {
Type: schema.TypeInt, Optional: true, Description: "Dst Entry Blacklisted",
},
"src_black_list": {
Type: schema.TypeInt, Optional: true, Description: "Src Entry Blacklisted",
},
"src_dst_black_list": {
Type: schema.TypeInt, Optional: true, Description: "SrcDst Entry Blacklisted",
},
"src_zone_service_black_list": {
Type: schema.TypeInt, Optional: true, Description: "SrcZoneService Entry Blacklisted",
},
"dst_learning_thre_exceed": {
Type: schema.TypeInt, Optional: true, Description: "Dst Dynamic Entry Count Overflow",
},
"dst_over_thre_policy_at_learning": {
Type: schema.TypeInt, Optional: true, Description: "Dst Overflow Policy Hit At Learning Stage",
},
"src_learning_thre_exceed": {
Type: schema.TypeInt, Optional: true, Description: "Src Dynamic Entry Count Overflow",
},
"src_over_thre_policy_at_lookup": {
Type: schema.TypeInt, Optional: true, Description: "Src Overflow Policy Hit At Lookup Stage",
},
"src_over_thre_policy_at_learning": {
Type: schema.TypeInt, Optional: true, Description: "Src Overflow Policy Hit At Learning Stage",
},
"src_dst_learning_thre_exceed": {
Type: schema.TypeInt, Optional: true, Description: "SrcDst Dynamic Entry Count Overflow",
},
"src_dst_over_thre_policy_at_lookup": {
Type: schema.TypeInt, Optional: true, Description: "SrcDst Overflow Policy Hit At Lookup Stage",
},
"src_dst_over_thre_policy_at_learning": {
Type: schema.TypeInt, Optional: true, Description: "SrcDst Overflow Policy Hit At Learning Stage",
},
"src_zone_service_learning_thre_exceed": {
Type: schema.TypeInt, Optional: true, Description: "SrcZoneService Dynamic Entry Count Overflow",
},
"src_zone_service_over_thre_policy_at_lookup": {
Type: schema.TypeInt, Optional: true, Description: "SrcZoneService Overflow Policy Lookup Hit",
},
"src_zone_service_over_thre_policy_at_learning": {
Type: schema.TypeInt, Optional: true, Description: "SrcZoneService Overflow Policy Learning Hit",
},
"entry_oom": {
Type: schema.TypeInt, Optional: true, Description: "Out of Entry Memory",
},
"entry_ext_oom": {
Type: schema.TypeInt, Optional: true, Description: "Out of Entry Extension Memory",
},
"src_dst_classlist_overflow_policy_at_learning": {
Type: schema.TypeInt, Optional: true, Description: "SrcDst Class-List Overflow Policy Hit",
},
"src_zone_service_classlist_overflow_policy_at_learning": {
Type: schema.TypeInt, Optional: true, Description: "SrcZoneService Class-List Overflow Policy Hit",
},
},
},
},
},
}
}
func resourceDdosTableStatsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceDdosTableStatsRead()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointDdosTableStats(d)
res, err := obj.Get(client.Token, client.Host, d.Id(), logger)
d.SetId(obj.GetId())
logger.Println(res)
DdosTableStatsStats := setObjectDdosTableStatsStats(res)
d.Set("stats", DdosTableStatsStats)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func setObjectDdosTableStatsStats(ret edpt.DataDdosTableStats) []interface{} {
return []interface{}{
map[string]interface{}{
"dst_learn": ret.DtDdosTableStats.Stats.Dst_learn,
"dst_hit": ret.DtDdosTableStats.Stats.Dst_hit,
"dst_miss": ret.DtDdosTableStats.Stats.Dst_miss,
"dst_entry_aged": ret.DtDdosTableStats.Stats.Dst_entry_aged,
"src_learn": ret.DtDdosTableStats.Stats.Src_learn,
"src_hit": ret.DtDdosTableStats.Stats.Src_hit,
"src_miss": ret.DtDdosTableStats.Stats.Src_miss,
"src_entry_aged": ret.DtDdosTableStats.Stats.Src_entry_aged,
"src_dst_learn": ret.DtDdosTableStats.Stats.Src_dst_learn,
"src_dst_hit": ret.DtDdosTableStats.Stats.Src_dst_hit,
"src_dst_miss": ret.DtDdosTableStats.Stats.Src_dst_miss,
"src_dst_entry_aged": ret.DtDdosTableStats.Stats.Src_dst_entry_aged,
"telem_err_misc": ret.DtDdosTableStats.Stats.Telem_err_misc,
"telem_route_add_rcvd": ret.DtDdosTableStats.Stats.Telem_route_add_rcvd,
"telem_route_del_rcvd": ret.DtDdosTableStats.Stats.Telem_route_del_rcvd,
"telem_entry_created": ret.DtDdosTableStats.Stats.Telem_entry_created,
"telem_entry_cleared": ret.DtDdosTableStats.Stats.Telem_entry_cleared,
"telem_err_telem_entry_pre_exist": ret.DtDdosTableStats.Stats.Telem_err_telem_entry_pre_exist,
"telem_err_conflict_with_static": ret.DtDdosTableStats.Stats.Telem_err_conflict_with_static,
"telem_err_fail_to_create": ret.DtDdosTableStats.Stats.Telem_err_fail_to_create,
"telem_err_fail_to_delete": ret.DtDdosTableStats.Stats.Telem_err_fail_to_delete,
"src_zone_service_learn": ret.DtDdosTableStats.Stats.Src_zone_service_learn,
"src_zone_service_hit": ret.DtDdosTableStats.Stats.Src_zone_service_hit,
"src_zone_service_miss": ret.DtDdosTableStats.Stats.Src_zone_service_miss,
"src_zone_service_entry_aged": ret.DtDdosTableStats.Stats.Src_zone_service_entry_aged,
"dst_white_list": ret.DtDdosTableStats.Stats.Dst_white_list,
"src_white_list": ret.DtDdosTableStats.Stats.Src_white_list,
"src_dst_white_list": ret.DtDdosTableStats.Stats.Src_dst_white_list,
"src_zone_service_white_list": ret.DtDdosTableStats.Stats.Src_zone_service_white_list,
"dst_black_list": ret.DtDdosTableStats.Stats.Dst_black_list,
"src_black_list": ret.DtDdosTableStats.Stats.Src_black_list,
"src_dst_black_list": ret.DtDdosTableStats.Stats.Src_dst_black_list,
"src_zone_service_black_list": ret.DtDdosTableStats.Stats.Src_zone_service_black_list,
"dst_learning_thre_exceed": ret.DtDdosTableStats.Stats.Dst_learning_thre_exceed,
"dst_over_thre_policy_at_learning": ret.DtDdosTableStats.Stats.Dst_over_thre_policy_at_learning,
"src_learning_thre_exceed": ret.DtDdosTableStats.Stats.Src_learning_thre_exceed,
"src_over_thre_policy_at_lookup": ret.DtDdosTableStats.Stats.Src_over_thre_policy_at_lookup,
"src_over_thre_policy_at_learning": ret.DtDdosTableStats.Stats.Src_over_thre_policy_at_learning,
"src_dst_learning_thre_exceed": ret.DtDdosTableStats.Stats.Src_dst_learning_thre_exceed,
"src_dst_over_thre_policy_at_lookup": ret.DtDdosTableStats.Stats.Src_dst_over_thre_policy_at_lookup,
"src_dst_over_thre_policy_at_learning": ret.DtDdosTableStats.Stats.Src_dst_over_thre_policy_at_learning,
"src_zone_service_learning_thre_exceed": ret.DtDdosTableStats.Stats.Src_zone_service_learning_thre_exceed,
"src_zone_service_over_thre_policy_at_lookup": ret.DtDdosTableStats.Stats.Src_zone_service_over_thre_policy_at_lookup,
"src_zone_service_over_thre_policy_at_learning": ret.DtDdosTableStats.Stats.Src_zone_service_over_thre_policy_at_learning,
"entry_oom": ret.DtDdosTableStats.Stats.Entry_oom,
"entry_ext_oom": ret.DtDdosTableStats.Stats.Entry_ext_oom,
"src_dst_classlist_overflow_policy_at_learning": ret.DtDdosTableStats.Stats.Src_dst_classlist_overflow_policy_at_learning,
"src_zone_service_classlist_overflow_policy_at_learning": ret.DtDdosTableStats.Stats.Src_zone_service_classlist_overflow_policy_at_learning,
},
}
}
func getObjectDdosTableStatsStats(d []interface{}) edpt.DdosTableStatsStats {
count1 := len(d)
var ret edpt.DdosTableStatsStats
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.Dst_learn = in["dst_learn"].(int)
ret.Dst_hit = in["dst_hit"].(int)
ret.Dst_miss = in["dst_miss"].(int)
ret.Dst_entry_aged = in["dst_entry_aged"].(int)
ret.Src_learn = in["src_learn"].(int)
ret.Src_hit = in["src_hit"].(int)
ret.Src_miss = in["src_miss"].(int)
ret.Src_entry_aged = in["src_entry_aged"].(int)
ret.Src_dst_learn = in["src_dst_learn"].(int)
ret.Src_dst_hit = in["src_dst_hit"].(int)
ret.Src_dst_miss = in["src_dst_miss"].(int)
ret.Src_dst_entry_aged = in["src_dst_entry_aged"].(int)
ret.Telem_err_misc = in["telem_err_misc"].(int)
ret.Telem_route_add_rcvd = in["telem_route_add_rcvd"].(int)
ret.Telem_route_del_rcvd = in["telem_route_del_rcvd"].(int)
ret.Telem_entry_created = in["telem_entry_created"].(int)
ret.Telem_entry_cleared = in["telem_entry_cleared"].(int)
ret.Telem_err_telem_entry_pre_exist = in["telem_err_telem_entry_pre_exist"].(int)
ret.Telem_err_conflict_with_static = in["telem_err_conflict_with_static"].(int)
ret.Telem_err_fail_to_create = in["telem_err_fail_to_create"].(int)
ret.Telem_err_fail_to_delete = in["telem_err_fail_to_delete"].(int)
ret.Src_zone_service_learn = in["src_zone_service_learn"].(int)
ret.Src_zone_service_hit = in["src_zone_service_hit"].(int)
ret.Src_zone_service_miss = in["src_zone_service_miss"].(int)
ret.Src_zone_service_entry_aged = in["src_zone_service_entry_aged"].(int)
ret.Dst_white_list = in["dst_white_list"].(int)
ret.Src_white_list = in["src_white_list"].(int)
ret.Src_dst_white_list = in["src_dst_white_list"].(int)
ret.Src_zone_service_white_list = in["src_zone_service_white_list"].(int)
ret.Dst_black_list = in["dst_black_list"].(int)
ret.Src_black_list = in["src_black_list"].(int)
ret.Src_dst_black_list = in["src_dst_black_list"].(int)
ret.Src_zone_service_black_list = in["src_zone_service_black_list"].(int)
ret.Dst_learning_thre_exceed = in["dst_learning_thre_exceed"].(int)
ret.Dst_over_thre_policy_at_learning = in["dst_over_thre_policy_at_learning"].(int)
ret.Src_learning_thre_exceed = in["src_learning_thre_exceed"].(int)
ret.Src_over_thre_policy_at_lookup = in["src_over_thre_policy_at_lookup"].(int)
ret.Src_over_thre_policy_at_learning = in["src_over_thre_policy_at_learning"].(int)
ret.Src_dst_learning_thre_exceed = in["src_dst_learning_thre_exceed"].(int)
ret.Src_dst_over_thre_policy_at_lookup = in["src_dst_over_thre_policy_at_lookup"].(int)
ret.Src_dst_over_thre_policy_at_learning = in["src_dst_over_thre_policy_at_learning"].(int)
ret.Src_zone_service_learning_thre_exceed = in["src_zone_service_learning_thre_exceed"].(int)
ret.Src_zone_service_over_thre_policy_at_lookup = in["src_zone_service_over_thre_policy_at_lookup"].(int)
ret.Src_zone_service_over_thre_policy_at_learning = in["src_zone_service_over_thre_policy_at_learning"].(int)
ret.Entry_oom = in["entry_oom"].(int)
ret.Entry_ext_oom = in["entry_ext_oom"].(int)
ret.Src_dst_classlist_overflow_policy_at_learning = in["src_dst_classlist_overflow_policy_at_learning"].(int)
ret.Src_zone_service_classlist_overflow_policy_at_learning = in["src_zone_service_classlist_overflow_policy_at_learning"].(int)
}
return ret
}
func dataToEndpointDdosTableStats(d *schema.ResourceData) edpt.DdosTableStats {
var ret edpt.DdosTableStats
ret.Stats = getObjectDdosTableStatsStats(d.Get("stats").([]interface{}))
return ret
}