/
resource_visibility_flow_collector_netflow_stats.go
189 lines (171 loc) · 7.69 KB
/
resource_visibility_flow_collector_netflow_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
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 resourceVisibilityFlowCollectorNetflowStats() *schema.Resource {
return &schema.Resource{
Description: "`thunder_visibility_flow_collector_netflow_stats`: Statistics for the object netflow\n\n__PLACEHOLDER__",
ReadContext: resourceVisibilityFlowCollectorNetflowStatsRead,
Schema: map[string]*schema.Schema{
"stats": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"pkts_rcvd": {
Type: schema.TypeInt, Optional: true, Description: "Total nflow packets received",
},
"v9_templates_created": {
Type: schema.TypeInt, Optional: true, Description: "Total v9 templates created",
},
"v9_templates_deleted": {
Type: schema.TypeInt, Optional: true, Description: "Total v9 templates deleted",
},
"v10_templates_created": {
Type: schema.TypeInt, Optional: true, Description: "Total v10(IPFIX) templates created",
},
"v10_templates_deleted": {
Type: schema.TypeInt, Optional: true, Description: "Total v10(IPFIX) templates deleted",
},
"template_drop_exceeded": {
Type: schema.TypeInt, Optional: true, Description: "Total templates dropped because of maximum limit",
},
"template_drop_out_of_memory": {
Type: schema.TypeInt, Optional: true, Description: "Total templates dropped becuase of out of memory",
},
"frag_dropped": {
Type: schema.TypeInt, Optional: true, Description: "Total nflow fragment packets dropped",
},
"agent_not_found": {
Type: schema.TypeInt, Optional: true, Description: "nflow pkts from not configured agents",
},
"version_not_supported": {
Type: schema.TypeInt, Optional: true, Description: "nflow version not supported",
},
"unknown_dir": {
Type: schema.TypeInt, Optional: true, Description: "nflow sample direction is unknown",
},
},
},
},
"template": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"stats": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"templates_added_to_delq": {
Type: schema.TypeInt, Optional: true, Description: "Netflow templates added to the delete queue",
},
"templates_removed_from_delq": {
Type: schema.TypeInt, Optional: true, Description: "Netflow templates removed from the delete queue",
},
},
},
},
},
},
},
},
}
}
func resourceVisibilityFlowCollectorNetflowStatsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceVisibilityFlowCollectorNetflowStatsRead()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointVisibilityFlowCollectorNetflowStats(d)
res, err := obj.Get(client.Token, client.Host, d.Id(), logger)
d.SetId(obj.GetId())
logger.Println(res)
VisibilityFlowCollectorNetflowStatsStats := setObjectVisibilityFlowCollectorNetflowStatsStats(res)
d.Set("stats", VisibilityFlowCollectorNetflowStatsStats)
VisibilityFlowCollectorNetflowStatsTemplate := setObjectVisibilityFlowCollectorNetflowStatsTemplate(res)
d.Set("template", VisibilityFlowCollectorNetflowStatsTemplate)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func setObjectVisibilityFlowCollectorNetflowStatsStats(ret edpt.DataVisibilityFlowCollectorNetflowStats) []interface{} {
return []interface{}{
map[string]interface{}{
"pkts_rcvd": ret.DtVisibilityFlowCollectorNetflowStats.Stats.PktsRcvd,
"v9_templates_created": ret.DtVisibilityFlowCollectorNetflowStats.Stats.V9TemplatesCreated,
"v9_templates_deleted": ret.DtVisibilityFlowCollectorNetflowStats.Stats.V9TemplatesDeleted,
"v10_templates_created": ret.DtVisibilityFlowCollectorNetflowStats.Stats.V10TemplatesCreated,
"v10_templates_deleted": ret.DtVisibilityFlowCollectorNetflowStats.Stats.V10TemplatesDeleted,
"template_drop_exceeded": ret.DtVisibilityFlowCollectorNetflowStats.Stats.TemplateDropExceeded,
"template_drop_out_of_memory": ret.DtVisibilityFlowCollectorNetflowStats.Stats.TemplateDropOutOfMemory,
"frag_dropped": ret.DtVisibilityFlowCollectorNetflowStats.Stats.FragDropped,
"agent_not_found": ret.DtVisibilityFlowCollectorNetflowStats.Stats.AgentNotFound,
"version_not_supported": ret.DtVisibilityFlowCollectorNetflowStats.Stats.VersionNotSupported,
"unknown_dir": ret.DtVisibilityFlowCollectorNetflowStats.Stats.UnknownDir,
},
}
}
func setObjectVisibilityFlowCollectorNetflowStatsTemplate(ret edpt.DataVisibilityFlowCollectorNetflowStats) []interface{} {
return []interface{}{
map[string]interface{}{
"stats": setObjectVisibilityFlowCollectorNetflowStatsTemplateStats(ret.DtVisibilityFlowCollectorNetflowStats.Template.Stats),
},
}
}
func setObjectVisibilityFlowCollectorNetflowStatsTemplateStats(d edpt.VisibilityFlowCollectorNetflowStatsTemplateStats) []map[string]interface{} {
result := []map[string]interface{}{}
in := make(map[string]interface{})
in["templates_added_to_delq"] = d.TemplatesAddedToDelq
in["templates_removed_from_delq"] = d.TemplatesRemovedFromDelq
result = append(result, in)
return result
}
func getObjectVisibilityFlowCollectorNetflowStatsStats(d []interface{}) edpt.VisibilityFlowCollectorNetflowStatsStats {
count1 := len(d)
var ret edpt.VisibilityFlowCollectorNetflowStatsStats
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.PktsRcvd = in["pkts_rcvd"].(int)
ret.V9TemplatesCreated = in["v9_templates_created"].(int)
ret.V9TemplatesDeleted = in["v9_templates_deleted"].(int)
ret.V10TemplatesCreated = in["v10_templates_created"].(int)
ret.V10TemplatesDeleted = in["v10_templates_deleted"].(int)
ret.TemplateDropExceeded = in["template_drop_exceeded"].(int)
ret.TemplateDropOutOfMemory = in["template_drop_out_of_memory"].(int)
ret.FragDropped = in["frag_dropped"].(int)
ret.AgentNotFound = in["agent_not_found"].(int)
ret.VersionNotSupported = in["version_not_supported"].(int)
ret.UnknownDir = in["unknown_dir"].(int)
}
return ret
}
func getObjectVisibilityFlowCollectorNetflowStatsTemplate(d []interface{}) edpt.VisibilityFlowCollectorNetflowStatsTemplate {
count1 := len(d)
var ret edpt.VisibilityFlowCollectorNetflowStatsTemplate
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.Stats = getObjectVisibilityFlowCollectorNetflowStatsTemplateStats(in["stats"].([]interface{}))
}
return ret
}
func getObjectVisibilityFlowCollectorNetflowStatsTemplateStats(d []interface{}) edpt.VisibilityFlowCollectorNetflowStatsTemplateStats {
count1 := len(d)
var ret edpt.VisibilityFlowCollectorNetflowStatsTemplateStats
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.TemplatesAddedToDelq = in["templates_added_to_delq"].(int)
ret.TemplatesRemovedFromDelq = in["templates_removed_from_delq"].(int)
}
return ret
}
func dataToEndpointVisibilityFlowCollectorNetflowStats(d *schema.ResourceData) edpt.VisibilityFlowCollectorNetflowStats {
var ret edpt.VisibilityFlowCollectorNetflowStats
ret.Stats = getObjectVisibilityFlowCollectorNetflowStatsStats(d.Get("stats").([]interface{}))
ret.Template = getObjectVisibilityFlowCollectorNetflowStatsTemplate(d.Get("template").([]interface{}))
return ret
}