fluent-plugin-netflowipfix 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,346 @@
1
+ ---
2
+ option:
3
+ 1:
4
+ - 4
5
+ - :in_bytes
6
+ 2:
7
+ - 4
8
+ - :in_pkts
9
+ 3:
10
+ - 4
11
+ - :flows
12
+ 4:
13
+ - :uint8
14
+ - :protocol
15
+ 5:
16
+ - :uint8
17
+ - :src_tos
18
+ 6:
19
+ - :uint8
20
+ - :tcp_flags
21
+ 7:
22
+ - :uint16
23
+ - :l4_src_port
24
+ 8:
25
+ - :ip4_addr
26
+ - :ipv4_src_addr
27
+ 9:
28
+ - :uint8
29
+ - :src_mask
30
+ 10:
31
+ - 2
32
+ - :input_snmp
33
+ 11:
34
+ - :uint16
35
+ - :l4_dst_port
36
+ 12:
37
+ - :ip4_addr
38
+ - :ipv4_dst_addr
39
+ 13:
40
+ - :uint8
41
+ - :dst_mask
42
+ 14:
43
+ - 2
44
+ - :output_snmp
45
+ 15:
46
+ - :ip4_addr
47
+ - :ipv4_next_hop
48
+ 16:
49
+ - 2
50
+ - :src_as
51
+ 17:
52
+ - 2
53
+ - :dst_as
54
+ 18:
55
+ - :ip4_addr
56
+ - :bgp_ipv4_next_hop
57
+ 19:
58
+ - 4
59
+ - :mul_dst_pkts
60
+ 20:
61
+ - 4
62
+ - :mul_dst_bytes
63
+ 21:
64
+ - :uint32
65
+ - :last_switched
66
+ 22:
67
+ - :uint32
68
+ - :first_switched
69
+ 23:
70
+ - 4
71
+ - :out_bytes
72
+ 24:
73
+ - 4
74
+ - :out_pkts
75
+ 25:
76
+ - :uint16
77
+ - :min_pkt_length
78
+ 26:
79
+ - :uint16
80
+ - :max_pkt_length
81
+ 27:
82
+ - :ip6_addr
83
+ - :ipv6_src_addr
84
+ 28:
85
+ - :ip6_addr
86
+ - :ipv6_dst_addr
87
+ 29:
88
+ - :uint8
89
+ - :ipv6_src_mask
90
+ 30:
91
+ - :uint8
92
+ - :ipv6_dst_mask
93
+ 31:
94
+ - 3
95
+ - :ipv6_flow_label
96
+ 32:
97
+ - :uint16
98
+ - :icmp_type
99
+ 33:
100
+ - :uint8
101
+ - :mul_igmp_type
102
+ 34:
103
+ - :uint32
104
+ - :sampling_interval
105
+ 35:
106
+ - :uint8
107
+ - :sampling_algorithm
108
+ 36:
109
+ - :uint16
110
+ - :flow_active_timeout
111
+ 37:
112
+ - :uint16
113
+ - :flow_inactive_timeout
114
+ 38:
115
+ - :uint8
116
+ - :engine_type
117
+ 39:
118
+ - :uint8
119
+ - :engine_id
120
+ 40:
121
+ - 4
122
+ - :total_bytes_exp
123
+ 41:
124
+ - 4
125
+ - :total_pkts_exp
126
+ 42:
127
+ - 4
128
+ - :total_flows_exp
129
+ 43:
130
+ - 4
131
+ - :skip43
132
+ 44:
133
+ - :ip4_addr
134
+ - :ipv4_src_prefix
135
+ 45:
136
+ - :ip4_addr
137
+ - :ipv4_dst_prefix
138
+ 46:
139
+ - :uint8
140
+ - :mpls_top_label_type
141
+ 47:
142
+ - :uint32
143
+ - :mpls_top_label_ip_addr
144
+ 48:
145
+ - 1
146
+ - :flow_sampler_id
147
+ 49:
148
+ - :uint8
149
+ - :flow_sampler_mode
150
+ 50:
151
+ - :uint32
152
+ - :flow_sampler_random_interval
153
+ 51:
154
+ - 1
155
+ - :skip51
156
+ 52:
157
+ - :uint8
158
+ - :min_ttl
159
+ 53:
160
+ - :uint8
161
+ - :max_ttl
162
+ 54:
163
+ - :uint16
164
+ - :ipv4_ident
165
+ 55:
166
+ - :uint8
167
+ - :dst_tos
168
+ 56:
169
+ - :mac_addr
170
+ - :in_src_mac
171
+ 57:
172
+ - :mac_addr
173
+ - :out_dst_mac
174
+ 58:
175
+ - :uint16
176
+ - :src_vlan
177
+ 59:
178
+ - :uint16
179
+ - :dst_vlan
180
+ 60:
181
+ - :uint8
182
+ - :ip_protocol_version
183
+ 61:
184
+ - :uint8
185
+ - :direction
186
+ 62:
187
+ - :ip6_addr
188
+ - :ipv6_next_hop
189
+ 63:
190
+ - :ip6_addr
191
+ - :bgp_ipv6_next_hop
192
+ 64:
193
+ - :uint32
194
+ - :ipv6_option_headers
195
+ 65:
196
+ - 1
197
+ - :skip65
198
+ 66:
199
+ - 1
200
+ - :skip66
201
+ 67:
202
+ - 1
203
+ - :skip67
204
+ 68:
205
+ - 1
206
+ - :skip68
207
+ 69:
208
+ - 1
209
+ - :skip69
210
+ 70:
211
+ - :mpls_label
212
+ - :mpls_label_1
213
+ 71:
214
+ - :mpls_label
215
+ - :mpls_label_2
216
+ 72:
217
+ - :mpls_label
218
+ - :mpls_label_3
219
+ 73:
220
+ - :mpls_label
221
+ - :mpls_label_4
222
+ 74:
223
+ - :mpls_label
224
+ - :mpls_label_5
225
+ 75:
226
+ - :mpls_label
227
+ - :mpls_label_6
228
+ 76:
229
+ - :mpls_label
230
+ - :mpls_label_7
231
+ 77:
232
+ - :mpls_label
233
+ - :mpls_label_8
234
+ 78:
235
+ - :mpls_label
236
+ - :mpls_label_9
237
+ 79:
238
+ - :mpls_label
239
+ - :mpls_label_10
240
+ 80:
241
+ - :mac_addr
242
+ - :in_dst_mac
243
+ 81:
244
+ - :mac_addr
245
+ - :out_src_mac
246
+ 82:
247
+ - :string
248
+ - :if_name
249
+ 83:
250
+ - :string
251
+ - :if_desc
252
+ 84:
253
+ - :string
254
+ - :sampler_name
255
+ 89:
256
+ - :uint8
257
+ - :forwarding_status
258
+ 91:
259
+ - :uint8
260
+ - :mpls_prefix_len
261
+ 234:
262
+ - :uint32
263
+ - :ingress_vrf_id
264
+ 235:
265
+ - :uint32
266
+ - :egress_vrf_id
267
+ 236:
268
+ - :string
269
+ - :vrf_name
270
+ 148:
271
+ - 4
272
+ - :NF_F_CONN_ID
273
+ 176:
274
+ - 1
275
+ - :NF_F_ICMP_TYPE
276
+ 177:
277
+ - 1
278
+ - :NF_F_ICMP_CODE
279
+ 152:
280
+ - 8
281
+ - :NF_F_FLOW_CREATE_TIME_MSEC
282
+ 233:
283
+ - 1
284
+ - :NF_F_FW_EVENT
285
+ 323:
286
+ - 8
287
+ - :NF_F_EVENT_TIME_MSEC
288
+ 33000:
289
+ - 12
290
+ - :NF_F_INGRESS_ACL_ID
291
+ 33001:
292
+ - 12
293
+ - :NF_F_EGRESS_ACL_ID
294
+ 33002:
295
+ - 2
296
+ - :NF_F_FW_EXT_EVENT
297
+ 40000:
298
+ - 20
299
+ - :NF_F_USERNAME
300
+ 40001:
301
+ - 4
302
+ - skip40001
303
+ 40002:
304
+ - 4
305
+ - skip40002
306
+ 40003:
307
+ - 2
308
+ - skip40003
309
+ 40004:
310
+ - 2
311
+ - skip40004
312
+ 40005:
313
+ - 1
314
+ - skip40005
315
+ 85:
316
+ - 4
317
+ - skip85
318
+ 178:
319
+ - 1
320
+ - skip178
321
+ 179:
322
+ - 1
323
+ - skip179
324
+ 231:
325
+ - 4
326
+ - skip231
327
+ # 232:
328
+ # - 4
329
+ # - skip232
330
+
331
+ scope:
332
+ 1:
333
+ - :ip4_addr
334
+ - :system
335
+ 2:
336
+ - 1
337
+ - :skip2
338
+ 3:
339
+ - 1
340
+ - :skip3
341
+ 4:
342
+ - 1
343
+ - :skip4
344
+ 5:
345
+ - 1
346
+ - :skip5
@@ -0,0 +1,243 @@
1
+ require "bindata"
2
+
3
+ module Fluent
4
+ module Plugin
5
+ class NetflowipfixInput < Fluent::Plugin::Input
6
+
7
+
8
+ class IP4Addr < BinData::Primitive
9
+ endian :big
10
+ uint32 :storage
11
+
12
+ def set(val)
13
+ ip = IPAddr.new(val)
14
+ if ! ip.ipv4?
15
+ raise ArgumentError, "invalid IPv4 address '#{val}'"
16
+ end
17
+ self.storage = ip.to_i
18
+ end # set
19
+
20
+ def get
21
+ IPAddr.new_ntoh([self.storage].pack('N')).to_s
22
+ end # get
23
+ end # class
24
+
25
+
26
+ class IP6Addr < BinData::Primitive
27
+ endian :big
28
+ uint128 :storage
29
+
30
+ def set(val)
31
+ ip = IPAddr.new(val)
32
+ if ! ip.ipv6?
33
+ raise ArgumentError, "invalid IPv6 address `#{val}'"
34
+ end
35
+ self.storage = ip.to_i
36
+ end
37
+
38
+ def get
39
+ IPAddr.new_ntoh((0..7).map { |i|
40
+ (self.storage >> (112 - 16 * i)) & 0xffff
41
+ }.pack('n8')).to_s
42
+ end
43
+ end
44
+
45
+
46
+ class MacAddr < BinData::Primitive
47
+ endian :big
48
+ array :bytes, type: :uint8, initial_length: 6
49
+
50
+ def set(val)
51
+ ints = val.split(/:/).collect { |int| int.to_i(16) }
52
+ self.bytes = ints
53
+ end
54
+
55
+ def get
56
+ self.bytes.collect { |byte| byte.value.to_s(16).rjust(2,'0') }.join(":")
57
+ end
58
+ end
59
+
60
+ class MplsLabel < BinData::Primitive
61
+ endian :big
62
+ bit20 :label
63
+ bit3 :exp
64
+ bit1 :bottom
65
+ def set(val)
66
+ self.label = val >> 4
67
+ self.exp = (val & 0b1111) >> 1
68
+ self.bottom = val & 0b1
69
+ end
70
+ def get
71
+ self.label
72
+ end
73
+ end
74
+
75
+ class Header < BinData::Record
76
+ endian :big
77
+ uint16 :version
78
+ end
79
+
80
+ class Netflow5Packet < BinData::Record
81
+ endian :big
82
+ uint16 :version
83
+ uint16 :flow_records
84
+ uint32 :uptime
85
+ uint32 :unix_sec
86
+ uint32 :unix_nsec
87
+ uint32 :flow_seq_num
88
+ uint8 :engine_type
89
+ uint8 :engine_id
90
+ bit2 :sampling_algorithm
91
+ bit14 :sampling_interval
92
+ array :records, initial_length: :flow_records do
93
+ ip4_addr :ipv4_src_addr
94
+ ip4_addr :ipv4_dst_addr
95
+ ip4_addr :ipv4_next_hop
96
+ uint16 :input_snmp
97
+ uint16 :output_snmp
98
+ uint32 :in_pkts
99
+ uint32 :in_bytes
100
+ uint32 :first_switched
101
+ uint32 :last_switched
102
+ uint16 :l4_src_port
103
+ uint16 :l4_dst_port
104
+ skip length: 1
105
+ uint8 :tcp_flags # Split up the TCP flags maybe?
106
+ uint8 :protocol
107
+ uint8 :src_tos
108
+ uint16 :src_as
109
+ uint16 :dst_as
110
+ uint8 :src_mask
111
+ uint8 :dst_mask
112
+ skip length: 2
113
+ end
114
+ end
115
+
116
+ # Template format for v9 and v10 - shared field must use same name to simplify code
117
+ class Template9 < BinData::Record
118
+ endian :big
119
+ array :templates, read_until: lambda { array.num_bytes == flowset_length - 4 } do
120
+ uint16 :template_id
121
+ uint16 :field_count
122
+ array :template_fields, initial_length: :field_count do
123
+ uint16 :field_type
124
+ uint16 :field_length
125
+ end # array fields
126
+ end # array templates
127
+ end #class
128
+
129
+ class Template10 < BinData::Record
130
+ endian :big
131
+ array :templates, read_until: lambda { array.num_bytes == flowset_length - 4 } do
132
+ uint16 :template_id
133
+ uint16 :field_count
134
+ array :template_fields, initial_length: :field_count do
135
+ uint16 :field_type
136
+ uint16 :field_length
137
+ # TODO: if upperbit (enterprise_bit) is set, then we have an enterprise # of 4 bytes (uint32)
138
+ uint32 :enterpriseNumber, :onlyif => lambda { field_type >= 0x8000 }
139
+ end # array fields
140
+ end # array templates
141
+ end #class
142
+
143
+ class Option9 < BinData::Record
144
+ endian :big
145
+ array :templates, read_until: lambda { flowset_length - 4 - array.num_bytes <= 2 } do
146
+ uint16 :template_id
147
+ uint16 :scope_length
148
+ uint16 :option_length
149
+ array :scope_fields, initial_length: lambda { scope_length / 4 } do
150
+ uint16 :field_type
151
+ uint16 :field_length
152
+ end # array scope_fields
153
+ array :option_fields, initial_length: lambda { option_length / 4 } do
154
+ uint16 :field_type
155
+ uint16 :field_length
156
+ end # array option_fields
157
+ end # array templates
158
+ skip length: lambda { templates.length.odd? ? 2 : 0 }
159
+ end #class
160
+
161
+ class Option10 < BinData::Record
162
+ endian :big
163
+ array :templates, read_until: lambda { flowset_length - 4 - array.num_bytes <= 2 } do
164
+ uint16 :template_id
165
+ uint16 :field_count
166
+ uint16 :scope_field_count
167
+ array :scope_fields, initial_length: :scope_field_count do
168
+ uint16 :field_type
169
+ uint16 :field_length
170
+ # TODO: if upperbit (enterprise_bit) is set, then we have an enterprise # of 4 bytes (uint32)
171
+ uint32 :enterpriseNumber, :onlyif => lambda { field_type >= 0x8000 }
172
+ end # array scope_fields
173
+ array :option_fields, initial_length: lambda { field_count - scope_field_count } do
174
+ uint16 :field_type
175
+ uint16 :field_length
176
+ # TODO: if upperbit (enterprise_bit) is set, then we have an enterprise # of 4 bytes (uint32)
177
+ uint32 :enterpriseNumber, :onlyif => lambda { field_type >= 0x8000 }
178
+ end # array option_fields
179
+ end # array templates
180
+ end #class
181
+
182
+ class Netflow9Packet < BinData::Record
183
+ endian :big
184
+ uint16 :version
185
+ uint16 :flow_records
186
+ uint32 :uptime
187
+ uint32 :unix_sec
188
+ uint32 :flow_seq_num
189
+ uint32 :source_id
190
+ array :records, read_until: :eof do
191
+ uint16 :flowset_id
192
+ uint16 :flowset_length
193
+ choice :flowset_data, selection: :flowset_id do
194
+ template9 0
195
+ option9 1
196
+ string :default, read_length: lambda { flowset_length - 4 }
197
+ end # choice
198
+ end # array records
199
+ end #class
200
+
201
+ class Netflow10Packet < BinData::Record
202
+ endian :big
203
+ uint16 :version
204
+ uint16 :ipfix_length #flow_records
205
+ uint32 :unix_sec #export_time #uptime
206
+ # uint32 :
207
+ uint32 :flow_seq_num # seq_num
208
+ uint32 :source_id # observation_domain_id
209
+ array :records, read_until: :eof do
210
+ # set header
211
+ uint16 :flowset_id # 2 = template, 3 = options, >= 256 = data sets
212
+ uint16 :flowset_length # in octets
213
+ # record
214
+ choice :flowset_data, selection: :flowset_id do
215
+ template10 2
216
+ option10 3
217
+ string :default, read_length: lambda { flowset_length - 4 }
218
+ end # choice
219
+ end # array
220
+ end # class
221
+
222
+
223
+ class OctetArray1 < BinData::Array
224
+ endian :big
225
+ uint8 :storage
226
+ end
227
+
228
+ class OctetArray2 < BinData::Primitive
229
+ array :bytes, type: :uint8, initial_length: 2
230
+
231
+ def set(val)
232
+ ints = val.split(/:/).collect { |int| int.to_i(16) }
233
+ self.bytes = ints
234
+ end
235
+
236
+ def get
237
+ self.bytes.collect { |byte| byte.value.to_s(16).rjust(2,'0') }.join(":")
238
+ end
239
+ end
240
+
241
+ end # class NetflowipfixInput
242
+ end # module Plugin
243
+ end # module Fluent