logstash-filter-ipam 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/lib/logstash/filters/ipam.rb +37 -11
- data/logstash-filter-ipam.gemspec +3 -2
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dba543e9a08f3a88aabe5ef8aec5ec42223fb6f80a06f2e83504b8c1c2ae734c
|
4
|
+
data.tar.gz: 42923057db032ad34494a648eb2c236eb74f05843b1e59a32b950765f7b8578a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdfccb1ed0f67a23420689a4be764df6c5270c87ff679ce14207b0ab1c55b5ddb6f003887f50b4e121f73a2c6fbd7f0418c0f59ae5b82241bf7e45a0dbe52536
|
7
|
+
data.tar.gz: 9ed4e350f9f821da3dcca4a33490d5e2a33cb0977b2ec10dd71235f83f755eb876736a9a2d8e61d0231a8afe5a878a7631fa896ebec5dc9373486ef7d1600129
|
data/Gemfile
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
require "active_record"
|
3
|
+
require "activerecord-jdbcmysql-adapter"
|
2
4
|
require "logstash/filters/base"
|
3
5
|
require "logstash/namespace"
|
4
6
|
require "ipaddr"
|
5
|
-
require "mysql"
|
6
7
|
require "json"
|
7
8
|
|
8
9
|
# This filter will replace the contents of the default
|
@@ -22,6 +23,7 @@ class LogStash::Filters::Ipam < LogStash::Filters::Base
|
|
22
23
|
|
23
24
|
# Mysql connection options.
|
24
25
|
config :mysql_host, :validate => :string, :required => true
|
26
|
+
#config :mysql_port, :validate => :number, :default => 3306
|
25
27
|
config :mysql_user, :validate => :string, :required => true
|
26
28
|
config :mysql_pass, :validate => :string, :required => true
|
27
29
|
config :mysql_db, :validate => :string, :default => "phpipam"
|
@@ -45,16 +47,40 @@ class LogStash::Filters::Ipam < LogStash::Filters::Base
|
|
45
47
|
private
|
46
48
|
def downloadIpamSubnets(event)
|
47
49
|
begin
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
# Create connection to the MySQL Database
|
51
|
+
ActiveRecord::Base.establish_connection ({
|
52
|
+
:adapter => "mysql",
|
53
|
+
:host => @mysql_host,
|
54
|
+
:username => @mysql_user,
|
55
|
+
:password => @mysql_pass,
|
56
|
+
:database => @mysql_db
|
57
|
+
})
|
58
|
+
|
59
|
+
# Get all the subnets from the Table
|
60
|
+
subnets = ActiveRecord::Base.connection.exec_query("SELECT id, subnet, mask, description FROM subnets")
|
61
|
+
|
62
|
+
# Parse result to create a JSON string
|
63
|
+
json = '{"subnets":['
|
64
|
+
subnets.each do |sub|
|
65
|
+
json += '{"id":' + sub['id'].to_s
|
66
|
+
sub['subnet'] = Integer(sub['subnet'])
|
67
|
+
if sub['subnet'] >= 0 && sub['subnet'] <= 4294967295 # Check if the subnet is an IPv4 address
|
68
|
+
sub['subnet'] = IPAddr.new(sub['subnet'], Socket::AF_INET).to_s
|
69
|
+
end
|
70
|
+
json += ', "subnet": "' + sub['subnet'].to_s + '"'
|
71
|
+
if sub['mask'].to_s.length > 0
|
72
|
+
json += ', "netmask": ' + sub['mask'].to_s
|
73
|
+
else
|
74
|
+
json += ', "netmask": 0'
|
75
|
+
end
|
76
|
+
json += ', "description": "' + sub['description'] + '"},'
|
77
|
+
end
|
78
|
+
json = json[0...-1]
|
79
|
+
json += ']}'
|
55
80
|
rescue
|
56
|
-
@logger.warn("Impossible to retrieve data from
|
81
|
+
@logger.warn("Impossible to retrieve data from MySQL.", :address => @mysql_host, :event => event)
|
57
82
|
end
|
83
|
+
return json
|
58
84
|
end
|
59
85
|
|
60
86
|
private
|
@@ -103,8 +129,8 @@ class LogStash::Filters::Ipam < LogStash::Filters::Base
|
|
103
129
|
checkFile(event)
|
104
130
|
|
105
131
|
# Get Subnets Checking the IP
|
106
|
-
#
|
107
|
-
#
|
132
|
+
# if can't read => Warning
|
133
|
+
# if gateway is false => won't register "0.0.0.0" subnets
|
108
134
|
ipamSubnets = getIpamSubnets(event)
|
109
135
|
subnets = checkIpSubnets(@ip, subnets)
|
110
136
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-filter-ipam'
|
3
|
-
s.version = '0.1.
|
3
|
+
s.version = '0.1.4'
|
4
4
|
s.licenses = ['Apache-2.0']
|
5
5
|
s.summary = 'Correlation with IPAM.'
|
6
6
|
s.description = 'Filter that allows getting subnets from existing file extracted from IPAM for an IP address.'
|
@@ -19,5 +19,6 @@ Gem::Specification.new do |s|
|
|
19
19
|
|
20
20
|
# Gem dependencies
|
21
21
|
s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
|
22
|
+
s.add_runtime_dependency "activerecord", "~> 4.0.0"
|
22
23
|
s.add_development_dependency 'logstash-devutils'
|
23
|
-
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-filter-ipam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Corentin Dekimpe
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 4.0.0
|
33
|
+
name: activerecord
|
34
|
+
prerelease: false
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.0.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
requirement: !ruby/object:Gem::Requirement
|
29
43
|
requirements:
|