logstash-codec-sflow 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +4 -0
- data/DEVELOPER.md +2 -0
- data/Gemfile +2 -0
- data/LICENSE +13 -0
- data/NOTICE.TXT +5 -0
- data/README.md +100 -0
- data/lib/logstash/codecs/sflow/counter_record.rb +122 -0
- data/lib/logstash/codecs/sflow/datagram.rb +29 -0
- data/lib/logstash/codecs/sflow/flow_record.rb +64 -0
- data/lib/logstash/codecs/sflow/sample.rb +56 -0
- data/lib/logstash/codecs/sflow/util.rb +54 -0
- data/lib/logstash/codecs/sflow.rb +89 -0
- data/logstash-codec-sflow.gemspec +27 -0
- data/spec/codecs/sflow_counters_sample.dat +0 -0
- data/spec/codecs/sflow_flow_sample.dat +0 -0
- data/spec/codecs/sflow_spec.rb +20 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7734945c0489502693b7f17044c6f96bae64637b
|
4
|
+
data.tar.gz: 9b353b730c693c2397f5edb013c3b0811a5f133c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5767825ecfb36ad9a4738cf770fb0718f9a785264b7e87fabbf6e292afaa058ff49fa6761cc5e456ffbcec4f4875cc7cfd48a19597d74a8fb0ac0d3f133fada6
|
7
|
+
data.tar.gz: 90e4aa370af0b55f121aa7b922e577d6153b166724048fdb3eaee630366214360b8dc0d3088a01d56a6d1ed8e98fb2475fc0036f1acbb4bc27faeeb918cfd4b0
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
## 2.0.0
|
2
|
+
- Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
|
3
|
+
instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
|
4
|
+
- Dependency on logstash-core update to 2.0
|
data/DEVELOPER.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2012–2015 Elasticsearch <http://www.elastic.co>
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/NOTICE.TXT
ADDED
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# Logstash Codec SFlow Plugin
|
2
|
+
## Description
|
3
|
+
Logstash codec plugin to decrypt sflow
|
4
|
+
|
5
|
+
[![Build
|
6
|
+
Status](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Codecs/job/logstash-plugin-codec-example-unit/badge/icon)](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Codecs/job/logstash-plugin-codec-example-unit/)
|
7
|
+
|
8
|
+
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
9
|
+
|
10
|
+
It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
|
11
|
+
|
12
|
+
## Documentation
|
13
|
+
|
14
|
+
Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
|
15
|
+
|
16
|
+
- For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
|
17
|
+
- For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
|
18
|
+
|
19
|
+
## Need Help?
|
20
|
+
|
21
|
+
Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
|
22
|
+
|
23
|
+
## Developing
|
24
|
+
|
25
|
+
### 1. Plugin Developement and Testing
|
26
|
+
|
27
|
+
#### Code
|
28
|
+
- To get started, you'll need JRuby with the Bundler gem installed.
|
29
|
+
|
30
|
+
- Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization.
|
31
|
+
|
32
|
+
- Install dependencies
|
33
|
+
```sh
|
34
|
+
bundle install
|
35
|
+
```
|
36
|
+
|
37
|
+
#### Test
|
38
|
+
|
39
|
+
```sh
|
40
|
+
bundle exec rspec
|
41
|
+
```
|
42
|
+
|
43
|
+
The Logstash code required to run the tests/specs is specified in the `Gemfile` by the line similar to:
|
44
|
+
```ruby
|
45
|
+
gem "logstash", :github => "elasticsearch/logstash", :branch => "1.5"
|
46
|
+
```
|
47
|
+
To test against another version or a local Logstash, edit the `Gemfile` to specify an alternative location, for example:
|
48
|
+
```ruby
|
49
|
+
gem "logstash", :github => "elasticsearch/logstash", :ref => "master"
|
50
|
+
```
|
51
|
+
```ruby
|
52
|
+
gem "logstash", :path => "/your/local/logstash"
|
53
|
+
```
|
54
|
+
|
55
|
+
Then update your dependencies and run your tests:
|
56
|
+
|
57
|
+
```sh
|
58
|
+
bundle install
|
59
|
+
bundle exec rspec
|
60
|
+
```
|
61
|
+
|
62
|
+
### 2. Running your unpublished Plugin in Logstash
|
63
|
+
|
64
|
+
#### 2.1 Run in a local Logstash clone
|
65
|
+
|
66
|
+
- Edit Logstash `tools/Gemfile` and add the local plugin path, for example:
|
67
|
+
```ruby
|
68
|
+
gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
|
69
|
+
```
|
70
|
+
- Update Logstash dependencies
|
71
|
+
```sh
|
72
|
+
rake vendor:gems
|
73
|
+
```
|
74
|
+
- Run Logstash with your plugin
|
75
|
+
```sh
|
76
|
+
bin/logstash -e 'filter {awesome {}}'
|
77
|
+
```
|
78
|
+
At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
|
79
|
+
|
80
|
+
#### 2.2 Run in an installed Logstash
|
81
|
+
|
82
|
+
- Build your plugin gem
|
83
|
+
```sh
|
84
|
+
gem build logstash-filter-awesome.gemspec
|
85
|
+
```
|
86
|
+
- Install the plugin from the Logstash home
|
87
|
+
```sh
|
88
|
+
bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
|
89
|
+
```
|
90
|
+
- Start Logstash and proceed to test the plugin
|
91
|
+
|
92
|
+
## Contributing
|
93
|
+
|
94
|
+
All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
|
95
|
+
|
96
|
+
Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
|
97
|
+
|
98
|
+
It is more important to me that you are able to contribute.
|
99
|
+
|
100
|
+
For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'bindata'
|
4
|
+
|
5
|
+
class GenericInterface < BinData::Record
|
6
|
+
endian :big
|
7
|
+
uint32 :interface_index
|
8
|
+
uint32 :interface_type
|
9
|
+
uint64 :interface_speed
|
10
|
+
uint32 :interface_direction
|
11
|
+
uint32 :interface_status
|
12
|
+
uint64 :input_octets
|
13
|
+
uint32 :input_packets
|
14
|
+
uint32 :input_multicast_packets
|
15
|
+
uint32 :input_broadcast_packets
|
16
|
+
uint32 :input_discarded_packets
|
17
|
+
uint32 :input_errors
|
18
|
+
uint32 :input_unknown_protocol_packets
|
19
|
+
uint64 :output_octets
|
20
|
+
uint32 :output_packets
|
21
|
+
uint32 :output_multicast_packets
|
22
|
+
uint32 :output_broadcast_packets
|
23
|
+
uint32 :output_discarded_packets
|
24
|
+
uint32 :output_errors
|
25
|
+
uint32 :promiscous_mode
|
26
|
+
end
|
27
|
+
|
28
|
+
class EthernetInterfaces < BinData::Record
|
29
|
+
endian :big
|
30
|
+
uint32 :dot3StatsAlignmentErrors
|
31
|
+
uint32 :dot3StatsFCSErrors
|
32
|
+
uint32 :dot3StatsSingleCollisionFrames
|
33
|
+
uint32 :dot3StatsMultipleCollisionFrames
|
34
|
+
uint32 :dot3StatsSQETestErrors
|
35
|
+
uint32 :dot3StatsDeferredTransmissions
|
36
|
+
uint32 :dot3StatsLateCollisions
|
37
|
+
uint32 :dot3StatsExcessiveCollisions
|
38
|
+
uint32 :dot3StatsInternalMacTransmitErrors
|
39
|
+
uint32 :dot3StatsCarrierSenseErrors
|
40
|
+
uint32 :dot3StatsFrameTooLongs
|
41
|
+
uint32 :dot3StatsInternalMacReceiveErrors
|
42
|
+
uint32 :dot3StatsSymbolErrors
|
43
|
+
end
|
44
|
+
|
45
|
+
class TokenRing < BinData::Record
|
46
|
+
endian :big
|
47
|
+
uint32 :dot5StatsLineErrors
|
48
|
+
uint32 :dot5StatsBurstErrors
|
49
|
+
uint32 :dot5StatsACErrors
|
50
|
+
uint32 :dot5StatsAbortTransErrors
|
51
|
+
uint32 :dot5StatsInternalErrors
|
52
|
+
uint32 :dot5StatsLostFrameErrors
|
53
|
+
uint32 :dot5StatsReceiveCongestions
|
54
|
+
uint32 :dot5StatsFrameCopiedErrors
|
55
|
+
uint32 :dot5StatsTokenErrors
|
56
|
+
uint32 :dot5StatsSoftErrors
|
57
|
+
uint32 :dot5StatsHardErrors
|
58
|
+
uint32 :dot5StatsSignalLoss
|
59
|
+
uint32 :dot5StatsTransmitBeacons
|
60
|
+
uint32 :dot5StatsRecoverys
|
61
|
+
uint32 :dot5StatsLobeWires
|
62
|
+
uint32 :dot5StatsRemoves
|
63
|
+
uint32 :dot5StatsSingles
|
64
|
+
uint32 :dot5StatsFreqErrors
|
65
|
+
end
|
66
|
+
|
67
|
+
class HundredBaseVG < BinData::Record
|
68
|
+
endian :big
|
69
|
+
uint32 :dot12InHighPriorityFrames
|
70
|
+
uint64 :dot12InHighPriorityOctets
|
71
|
+
uint32 :dot12InNormPriorityFrames
|
72
|
+
uint64 :dot12InNormPriorityOctets
|
73
|
+
uint32 :dot12InIPMErrors
|
74
|
+
uint32 :dot12InOversizeFrameErrors
|
75
|
+
uint32 :dot12InDataErrors
|
76
|
+
uint32 :dot12InNullAddressedFrames
|
77
|
+
uint32 :dot12OutHighPriorityFrames
|
78
|
+
uint64 :dot12OutHighPriorityOctets
|
79
|
+
uint32 :dot12TransitionIntoTrainings
|
80
|
+
uint64 :dot12HCInHighPriorityOctets
|
81
|
+
uint64 :dot12HCInNormPriorityOctets
|
82
|
+
uint64 :dot12HCOutHighPriorityOctets
|
83
|
+
end
|
84
|
+
|
85
|
+
class Vlan < BinData::Record
|
86
|
+
endian :big
|
87
|
+
uint32 :vlan_id
|
88
|
+
uint64 :octets
|
89
|
+
uint32 :ucastPkts
|
90
|
+
uint32 :multicastPkts
|
91
|
+
uint32 :broadcastPkts
|
92
|
+
uint32 :discards
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
class ProcessorInformation < BinData::Record
|
97
|
+
endian :big
|
98
|
+
uint32 :five_sec_cpu_percent
|
99
|
+
uint32 :one_min_cpu_percent
|
100
|
+
uint32 :five_min_cpu_percent
|
101
|
+
uint64 :total_memory
|
102
|
+
uint64 :free_memory
|
103
|
+
end
|
104
|
+
|
105
|
+
class HttpCounters < BinData::Record
|
106
|
+
endian :big
|
107
|
+
uint32 :method_option_count
|
108
|
+
uint32 :method_get_count
|
109
|
+
uint32 :method_head_count
|
110
|
+
uint32 :method_post_count
|
111
|
+
uint32 :method_put_count
|
112
|
+
uint32 :method_delete_count
|
113
|
+
uint32 :method_trace_count
|
114
|
+
uint32 :method_connect_count
|
115
|
+
uint32 :method_other_count
|
116
|
+
uint32 :status_1XX_count
|
117
|
+
uint32 :status_2XX_count
|
118
|
+
uint32 :status_3XX_count
|
119
|
+
uint32 :status_4XX_count
|
120
|
+
uint32 :status_5XX_count
|
121
|
+
uint32 :status_other_count
|
122
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'bindata'
|
4
|
+
require 'logstash/codecs/sflow/util'
|
5
|
+
require 'logstash/codecs/sflow/sample'
|
6
|
+
|
7
|
+
class SFlow < BinData::Record
|
8
|
+
endian :big
|
9
|
+
uint32 :sflow_version
|
10
|
+
uint32 :ip_version
|
11
|
+
choice :agent_ip, :selection => :ip_version do
|
12
|
+
ip4_addr 1
|
13
|
+
ip6_addr 2
|
14
|
+
end
|
15
|
+
uint32 :sub_agent_id
|
16
|
+
uint32 :sequence_number
|
17
|
+
uint32 :uptime_in_ms
|
18
|
+
uint32 :sample_count
|
19
|
+
array :samples, :initial_length => :sample_count do
|
20
|
+
bit20 :sample_entreprise
|
21
|
+
bit12 :sample_format
|
22
|
+
uint32 :sample_length
|
23
|
+
choice :sample_data, :selection => lambda { "#{sample_entreprise}-#{sample_format}" } do
|
24
|
+
flow_sample "0-1"
|
25
|
+
counter_sample "0-2"
|
26
|
+
skip :default, :length => :sample_length
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'bindata'
|
4
|
+
require 'logstash/codecs/sflow/util'
|
5
|
+
|
6
|
+
class RawPacketHeader < BinData::Record
|
7
|
+
endian :big
|
8
|
+
uint32 :protocol
|
9
|
+
uint32 :frame_length
|
10
|
+
uint32 :stripped
|
11
|
+
uint32 :header_size
|
12
|
+
skip :length => :header_size
|
13
|
+
end
|
14
|
+
|
15
|
+
class EthernetFrameData < BinData::Record
|
16
|
+
endian :big
|
17
|
+
uint32 :packet_length
|
18
|
+
mac_address :src_mac
|
19
|
+
mac_address :dst_mac
|
20
|
+
uint32 :type
|
21
|
+
end
|
22
|
+
|
23
|
+
class IP4Data < BinData::Record
|
24
|
+
endian :big
|
25
|
+
uint32 :ip_packet_length
|
26
|
+
uint32 :ip_protocol
|
27
|
+
ip4_addr :src_ip
|
28
|
+
ip4_addr :dst_ip
|
29
|
+
uint32 :src_port
|
30
|
+
uint32 :dst_port
|
31
|
+
uint32 :tcp_flags
|
32
|
+
uint32 :type
|
33
|
+
end
|
34
|
+
|
35
|
+
class IP6Data < BinData::Record
|
36
|
+
endian :big
|
37
|
+
uint32 :ip_packet_length
|
38
|
+
uint32 :ip_next_header
|
39
|
+
ip6_addr :src_ip
|
40
|
+
ip6_addr :dst_ip
|
41
|
+
uint32 :src_port
|
42
|
+
uint32 :dst_port
|
43
|
+
uint32 :tcp_flags
|
44
|
+
uint32 :ip_priority
|
45
|
+
end
|
46
|
+
|
47
|
+
class ExtendedSwitchData < BinData::Record
|
48
|
+
endian :big
|
49
|
+
uint32 :src_vlan
|
50
|
+
uint32 :src_priority
|
51
|
+
uint32 :dst_vlan
|
52
|
+
uint32 :dst_priority
|
53
|
+
end
|
54
|
+
|
55
|
+
class ExtendedRouterData < BinData::Record
|
56
|
+
endian :big
|
57
|
+
uint32 :ip_version
|
58
|
+
choice :ip_address_next_hop_router, :selection => :ip_version do
|
59
|
+
ip4_addr 1
|
60
|
+
ip6_addr 2
|
61
|
+
end
|
62
|
+
uint32 :src_mask_len
|
63
|
+
uint32 :dst_mask_len
|
64
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'bindata'
|
4
|
+
require 'logstash/codecs/sflow/flow_record'
|
5
|
+
require 'logstash/codecs/sflow/counter_record'
|
6
|
+
|
7
|
+
class FlowSample < BinData::Record
|
8
|
+
endian :big
|
9
|
+
uint32 :sequence_number
|
10
|
+
uint8 :source_id_type
|
11
|
+
uint24 :source_id_index
|
12
|
+
uint32 :sampling_rate
|
13
|
+
uint32 :sample_pool
|
14
|
+
uint32 :drops
|
15
|
+
uint32 :input_interface
|
16
|
+
uint32 :output_interface
|
17
|
+
uint32 :record_count
|
18
|
+
array :records, :initial_length => :record_count do
|
19
|
+
bit20 :record_entreprise
|
20
|
+
bit12 :record_format
|
21
|
+
uint32 :record_length
|
22
|
+
choice :record_data, :selection => :record_format do
|
23
|
+
raw_packet_header 1
|
24
|
+
ethernet_frame_data 2
|
25
|
+
ip4_data 3
|
26
|
+
ip6_data 4
|
27
|
+
extended_switch_data 1001
|
28
|
+
extended_router_data 1002
|
29
|
+
skip :default, :length => :record_length
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class CounterSample < BinData::Record
|
35
|
+
endian :big
|
36
|
+
uint32 :sample_seq_number
|
37
|
+
uint8 :source_id_type
|
38
|
+
uint24 :source_id_index
|
39
|
+
uint32 :record_count
|
40
|
+
array :records, :initial_length => :record_count do
|
41
|
+
bit20 :record_entreprise
|
42
|
+
bit12 :record_format
|
43
|
+
uint32 :record_length
|
44
|
+
choice :record_data, :selection => lambda { "#{record_entreprise}-#{record_format}" } do
|
45
|
+
generic_interface "0-1"
|
46
|
+
ethernet_interfaces "0-2"
|
47
|
+
token_ring "0-3"
|
48
|
+
hundred_base_vg "0-4"
|
49
|
+
vlan "0-5"
|
50
|
+
processor_information "0-1001"
|
51
|
+
http_counters "0-2201"
|
52
|
+
skip :default, :length => :record_length
|
53
|
+
end
|
54
|
+
#processor_information :record_data
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'bindata'
|
4
|
+
require 'ipaddr'
|
5
|
+
|
6
|
+
class MacAddress < BinData::Primitive
|
7
|
+
array :bytes, :type => :uint8, :initial_length => 6
|
8
|
+
bit16 :padbytes
|
9
|
+
|
10
|
+
def set(val)
|
11
|
+
ints = val.split(/:/).collect { |int| int.to_i(16) }
|
12
|
+
self.bytes = ints
|
13
|
+
end
|
14
|
+
|
15
|
+
def get
|
16
|
+
self.bytes.collect { |byte| byte.value.to_s(16).rjust(2, '0') }.join(":")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class IP4Addr < BinData::Primitive
|
21
|
+
endian :big
|
22
|
+
uint32 :storage
|
23
|
+
|
24
|
+
def set(val)
|
25
|
+
ip = IPAddr.new(val)
|
26
|
+
if !ip.ipv4?
|
27
|
+
raise ArgumentError, "invalid IPv4 address '#{val}'"
|
28
|
+
end
|
29
|
+
self.storage = ip.to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
def get
|
33
|
+
IPAddr.new_ntoh([self.storage].pack('N')).to_s
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class IP6Addr < BinData::Primitive
|
38
|
+
endian :big
|
39
|
+
uint128 :storage
|
40
|
+
|
41
|
+
def set(val)
|
42
|
+
ip = IPAddr.new(val)
|
43
|
+
if !ip.ipv6?
|
44
|
+
raise ArgumentError, "invalid IPv6 address `#{val}'"
|
45
|
+
end
|
46
|
+
self.storage = ip.to_i
|
47
|
+
end
|
48
|
+
|
49
|
+
def get
|
50
|
+
IPAddr.new_ntoh((0..7).map { |i|
|
51
|
+
(self.storage >> (112 - 16 * i)) & 0xffff
|
52
|
+
}.pack('n8')).to_s
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/codecs/base"
|
3
|
+
require "logstash/namespace"
|
4
|
+
|
5
|
+
# The "sflow" codec is for decoding sflow v5 flows.
|
6
|
+
class LogStash::Codecs::Sflow < LogStash::Codecs::Base
|
7
|
+
config_name "sflow"
|
8
|
+
|
9
|
+
# Specify which sflow must not be send in the event
|
10
|
+
config :removed_field, :validate => :array, :default => ['record_length', 'record_count', 'record_entreprise',
|
11
|
+
'record_format', 'sample_entreprise', 'sample_format',
|
12
|
+
'sample_length', 'sample_count', 'sflow_version',
|
13
|
+
'ip_version']
|
14
|
+
|
15
|
+
|
16
|
+
def initialize(params = {})
|
17
|
+
super(params)
|
18
|
+
@threadsafe = false
|
19
|
+
end
|
20
|
+
|
21
|
+
# def initialize
|
22
|
+
|
23
|
+
public
|
24
|
+
def register
|
25
|
+
require "logstash/codecs/sflow/datagram"
|
26
|
+
end
|
27
|
+
|
28
|
+
# def register
|
29
|
+
|
30
|
+
public
|
31
|
+
def decode(payload)
|
32
|
+
decoded = SFlow.read(payload)
|
33
|
+
|
34
|
+
events = []
|
35
|
+
|
36
|
+
decoded['samples'].each do |sample|
|
37
|
+
if sample['sample_data'].to_s.eql? ''
|
38
|
+
@logger.warn("Unknown sample entreprise #{sample['sample_entreprise'].to_s} - format #{sample['sample_format'].to_s}")
|
39
|
+
next
|
40
|
+
end
|
41
|
+
sample['sample_data']['records'].each do |record|
|
42
|
+
# Ensure that some data exist for the record
|
43
|
+
if record['record_data'].to_s.eql? ''
|
44
|
+
@logger.warn("Unknown record entreprise #{record['record_entreprise'].to_s}, format #{record['record_format'].to_s}")
|
45
|
+
next
|
46
|
+
end
|
47
|
+
|
48
|
+
# Create the logstash event
|
49
|
+
event = {
|
50
|
+
LogStash::Event::TIMESTAMP => LogStash::Timestamp.now
|
51
|
+
}
|
52
|
+
|
53
|
+
decoded.each_pair do |k, v|
|
54
|
+
unless k.to_s.eql? 'samples' or @removed_field.include? k.to_s
|
55
|
+
event["#{k}"] = v
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
sample.each_pair do |k, v|
|
60
|
+
unless k.to_s.eql? 'sample_data' or @removed_field.include? k.to_s
|
61
|
+
event["#{k}"] = v
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
sample['sample_data'].each_pair do |k, v|
|
66
|
+
unless k.to_s.eql? 'records' or @removed_field.include? k.to_s
|
67
|
+
event["#{k}"] = v
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
record.each_pair do |k, v|
|
72
|
+
unless k.to_s.eql? 'record_data' or @removed_field.include? k.to_s
|
73
|
+
event["#{k}"] = v
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
record['record_data'].each_pair do |k, v|
|
78
|
+
event["#{k}"] = v
|
79
|
+
end
|
80
|
+
|
81
|
+
events.push(event)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
events.each do |event|
|
86
|
+
yield event
|
87
|
+
end
|
88
|
+
end # def decode
|
89
|
+
end # class LogStash::Filters::Sflow
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
|
3
|
+
s.name = 'logstash-codec-sflow'
|
4
|
+
s.version = '0.1.0'
|
5
|
+
s.licenses = ['Apache License (2.0)']
|
6
|
+
s.summary = "The sflow codec is for decoding SFlow v5 flows."
|
7
|
+
s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
|
8
|
+
s.authors = ["Nicolas Fraison"]
|
9
|
+
s.email = ''
|
10
|
+
s.homepage = ""
|
11
|
+
s.require_paths = ["lib"]
|
12
|
+
|
13
|
+
# Files
|
14
|
+
s.files = Dir['lib/**/*', 'spec/**/*', 'vendor/**/*', '*.gemspec', '*.md', 'CONTRIBUTORS', 'Gemfile', 'LICENSE', 'NOTICE.TXT']
|
15
|
+
|
16
|
+
# Tests
|
17
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
18
|
+
|
19
|
+
# Special flag to let us know this is actually a logstash plugin
|
20
|
+
s.metadata = {"logstash_plugin" => "true", "logstash_group" => "codec"}
|
21
|
+
|
22
|
+
# Gem dependencies
|
23
|
+
s.add_runtime_dependency "logstash-core", ">= 1.4.0", "< 3.0.0"
|
24
|
+
s.add_runtime_dependency 'bindata', ['>= 2.1.0']
|
25
|
+
s.add_development_dependency 'logstash-devutils'
|
26
|
+
end
|
27
|
+
|
Binary file
|
Binary file
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "logstash/devutils/rspec/spec_helper"
|
4
|
+
require "logstash/codecs/sflow"
|
5
|
+
|
6
|
+
describe LogStash::Codecs::Sflow do
|
7
|
+
before :each do
|
8
|
+
@subject = LogStash::Codecs::Sflow.new
|
9
|
+
payload = IO.read(File.join(File.dirname(__FILE__), "sflow_counters_sample.dat"), :mode => "rb")
|
10
|
+
@subject.decode(payload)
|
11
|
+
payload = IO.read(File.join(File.dirname(__FILE__), "sflow_flow_sample.dat"), :mode => "rb")
|
12
|
+
@subject.decode(payload)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#new" do
|
16
|
+
it "LogStash::Codecs::Sflow" do
|
17
|
+
@subject.should be_an_instance_of LogStash::Codecs::Sflow
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-codec-sflow
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nicolas Fraison
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: 1.4.0
|
19
|
+
- - "<"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
name: logstash-core
|
23
|
+
prerelease: false
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.4.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.0.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 2.1.0
|
39
|
+
name: bindata
|
40
|
+
prerelease: false
|
41
|
+
type: :runtime
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.1.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
name: logstash-devutils
|
54
|
+
prerelease: false
|
55
|
+
type: :development
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
description: This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program
|
62
|
+
email: ''
|
63
|
+
executables: []
|
64
|
+
extensions: []
|
65
|
+
extra_rdoc_files: []
|
66
|
+
files:
|
67
|
+
- CHANGELOG.md
|
68
|
+
- DEVELOPER.md
|
69
|
+
- Gemfile
|
70
|
+
- LICENSE
|
71
|
+
- NOTICE.TXT
|
72
|
+
- README.md
|
73
|
+
- lib/logstash/codecs/sflow.rb
|
74
|
+
- lib/logstash/codecs/sflow/counter_record.rb
|
75
|
+
- lib/logstash/codecs/sflow/datagram.rb
|
76
|
+
- lib/logstash/codecs/sflow/flow_record.rb
|
77
|
+
- lib/logstash/codecs/sflow/sample.rb
|
78
|
+
- lib/logstash/codecs/sflow/util.rb
|
79
|
+
- logstash-codec-sflow.gemspec
|
80
|
+
- spec/codecs/sflow_counters_sample.dat
|
81
|
+
- spec/codecs/sflow_flow_sample.dat
|
82
|
+
- spec/codecs/sflow_spec.rb
|
83
|
+
homepage: ''
|
84
|
+
licenses:
|
85
|
+
- Apache License (2.0)
|
86
|
+
metadata:
|
87
|
+
logstash_plugin: 'true'
|
88
|
+
logstash_group: codec
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.4.8
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: The sflow codec is for decoding SFlow v5 flows.
|
109
|
+
test_files:
|
110
|
+
- spec/codecs/sflow_counters_sample.dat
|
111
|
+
- spec/codecs/sflow_flow_sample.dat
|
112
|
+
- spec/codecs/sflow_spec.rb
|