logstash-filter-cidr 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZmQ1MGUyNGEwYjAzOTYwYmRlMDlmNjRhNTUzNzkzNmExYWU2YTdlZg==
5
+ data.tar.gz: !binary |-
6
+ NDEwNTllZTczYzNiZThjZTYzYWNlMmMzZmM3ZmYzNmM0MTFmZDg1Mg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MzMxMzBiZmFjMWFkM2EzYTliOGM3ZjlmN2Y0Y2RkZTFjNWEzODc1ZThjYWY2
10
+ NGIzNTI5MGY5MTllOGQ0MjM2Y2UyY2Y5NDFhYTJiZTIwYjg4MzEzOTdjZDRm
11
+ Yjk1YTA1MzQ4NzBhNGY1OTVkMmIwMDZjZmFlYWVhZGRlN2Q4NmY=
12
+ data.tar.gz: !binary |-
13
+ ODU0NTRjMzgwYTljYzhlNjBiYWEwNDk2YjlkM2NiNmU3MTQzNjg5MDc4Yzkw
14
+ N2ZjMjg4NmRjNmNiOGJhNzNmZmFiMGM2MzA5ODk3M2VlNWYzMmM5ZTMxN2E1
15
+ ZjI4Mzk2Njg1MTY3OTJjODkyNzE0ZjlkODMwMzFkNTE5NGY4NjI=
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ Gemfile.lock
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+ gem 'rake'
3
+ gem 'gem_publisher'
@@ -0,0 +1,12 @@
1
+ require "gem_publisher"
2
+
3
+ desc "Publish gem to RubyGems.org"
4
+ task :publish_gem do |t|
5
+ gem = GemPublisher.publish_if_updated("logstash-filter-cidr.gemspec", :rubygems)
6
+ puts "Published #{gem}" if gem
7
+ end
8
+
9
+ task :default do
10
+ system("rake -T")
11
+ end
12
+
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require "logstash/namespace"
4
+ require "ipaddr"
5
+
6
+
7
+ # The CIDR filter is for checking IP addresses in events against a list of
8
+ # network blocks that might contain it. Multiple addresses can be checked
9
+ # against multiple networks, any match succeeds. Upon success additional tags
10
+ # and/or fields can be added to the event.
11
+
12
+ class LogStash::Filters::CIDR < LogStash::Filters::Base
13
+
14
+ config_name "cidr"
15
+ milestone 1
16
+
17
+ # The IP address(es) to check with. Example:
18
+ #
19
+ # filter {
20
+ # %PLUGIN% {
21
+ # add_tag => [ "testnet" ]
22
+ # address => [ "%{src_ip}", "%{dst_ip}" ]
23
+ # network => [ "192.0.2.0/24" ]
24
+ # }
25
+ # }
26
+ config :address, :validate => :array, :default => []
27
+
28
+ # The IP network(s) to check against. Example:
29
+ #
30
+ # filter {
31
+ # %PLUGIN% {
32
+ # add_tag => [ "linklocal" ]
33
+ # address => [ "%{clientip}" ]
34
+ # network => [ "169.254.0.0/16", "fe80::/64" ]
35
+ # }
36
+ # }
37
+ config :network, :validate => :array, :default => []
38
+
39
+ public
40
+ def register
41
+ # Nothing
42
+ end # def register
43
+
44
+ public
45
+ def filter(event)
46
+ return unless filter?(event)
47
+
48
+ address = @address.collect do |a|
49
+ begin
50
+ IPAddr.new(event.sprintf(a))
51
+ rescue ArgumentError => e
52
+ @logger.warn("Invalid IP address, skipping", :address => a, :event => event)
53
+ nil
54
+ end
55
+ end
56
+ address.compact!
57
+
58
+ network = @network.collect do |n|
59
+ begin
60
+ IPAddr.new(event.sprintf(n))
61
+ rescue ArgumentError => e
62
+ @logger.warn("Invalid IP network, skipping", :network => n, :event => event)
63
+ nil
64
+ end
65
+ end
66
+ network.compact!
67
+
68
+ # Try every combination of address and network, first match wins
69
+ address.product(network).each do |a, n|
70
+ @logger.debug("Checking IP inclusion", :address => a, :network => n)
71
+ if n.include?(a)
72
+ filter_matched(event)
73
+ return
74
+ end
75
+ end
76
+ end # def filter
77
+ end # class LogStash::Filters::CIDR
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'logstash-filter-cidr'
4
+ s.version = '0.1.0'
5
+ s.licenses = ['Apache License (2.0)']
6
+ s.summary = "The CIDR filter is for checking IP addresses in events against a list of network blocks that might contain it."
7
+ s.description = "The CIDR filter is for checking IP addresses in events against a list of network blocks that might contain it. Multiple addresses can be checked against multiple networks, any match succeeds. Upon success additional tags and/or fields can be added to the event."
8
+ s.authors = ["Elasticsearch"]
9
+ s.email = 'richard.pijnenburg@elasticsearch.com'
10
+ s.homepage = "http://logstash.net/"
11
+ s.require_paths = ["lib"]
12
+
13
+ # Files
14
+ s.files = `git ls-files`.split($\)
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", "group" => "filter" }
21
+
22
+ # Gem dependencies
23
+ s.add_runtime_dependency 'logstash', '>= 1.4.0', '< 2.0.0'
24
+
25
+ end
26
+
@@ -0,0 +1,71 @@
1
+ require "test_utils"
2
+ require "logstash/filters/cidr"
3
+
4
+ describe LogStash::Filters::CIDR do
5
+ extend LogStash::RSpec
6
+
7
+ describe "IPV4 match test" do
8
+ config <<-CONFIG
9
+ filter {
10
+ cidr {
11
+ address => [ "%{clientip}" ]
12
+ network => [ "192.168.0.0/24" ]
13
+ add_tag => [ "matched" ]
14
+ }
15
+ }
16
+ CONFIG
17
+
18
+ sample("clientip" => "192.168.0.30") do
19
+ insist { subject["tags"] }.include?("matched")
20
+ end
21
+ end
22
+
23
+ describe "IPV4 non match" do
24
+ config <<-CONFIG
25
+ filter {
26
+ cidr {
27
+ address => [ "%{clientip}" ]
28
+ network => [ "192.168.0.0/24" ]
29
+ add_tag => [ "matched" ]
30
+ }
31
+ }
32
+ CONFIG
33
+
34
+ sample("clientip" => "123.52.122.33") do
35
+ insist { subject["tags"] }.nil?
36
+ end
37
+ end
38
+
39
+ describe "IPV6 match test" do
40
+ config <<-CONFIG
41
+ filter {
42
+ cidr {
43
+ address => [ "%{clientip}" ]
44
+ network => [ "fe80::/64" ]
45
+ add_tag => [ "matched" ]
46
+ }
47
+ }
48
+ CONFIG
49
+
50
+ sample("clientip" => "fe80:0:0:0:0:0:0:1") do
51
+ insist { subject["tags"] }.include?("matched")
52
+ end
53
+ end
54
+
55
+ describe "IPV6 non match" do
56
+ config <<-CONFIG
57
+ filter {
58
+ cidr {
59
+ address => [ "%{clientip}" ]
60
+ network => [ "fe80::/64" ]
61
+ add_tag => [ "matched" ]
62
+ }
63
+ }
64
+ CONFIG
65
+
66
+ sample("clientip" => "fd82:0:0:0:0:0:0:1") do
67
+ insist { subject["tags"] }.nil?
68
+ end
69
+ end
70
+
71
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-cidr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Elasticsearch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: !binary |-
20
+ MS40LjA=
21
+ - - <
22
+ - !ruby/object:Gem::Version
23
+ version: 2.0.0
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: !binary |-
31
+ MS40LjA=
32
+ - - <
33
+ - !ruby/object:Gem::Version
34
+ version: 2.0.0
35
+ description: The CIDR filter is for checking IP addresses in events against a list
36
+ of network blocks that might contain it. Multiple addresses can be checked against
37
+ multiple networks, any match succeeds. Upon success additional tags and/or fields
38
+ can be added to the event.
39
+ email: richard.pijnenburg@elasticsearch.com
40
+ executables: []
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - Rakefile
47
+ - lib/logstash/filters/cidr.rb
48
+ - logstash-filter-cidr.gemspec
49
+ - spec/filters/cidr.rb
50
+ homepage: http://logstash.net/
51
+ licenses:
52
+ - Apache License (2.0)
53
+ metadata:
54
+ logstash_plugin: 'true'
55
+ group: filter
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 2.4.1
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: The CIDR filter is for checking IP addresses in events against a list of
76
+ network blocks that might contain it.
77
+ test_files:
78
+ - spec/filters/cidr.rb