logstash-filter-ipam 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dba543e9a08f3a88aabe5ef8aec5ec42223fb6f80a06f2e83504b8c1c2ae734c
4
- data.tar.gz: 42923057db032ad34494a648eb2c236eb74f05843b1e59a32b950765f7b8578a
3
+ metadata.gz: c955d04a7374c6098811d3e6057b26a1bef34da67597fcc574fa8b0d5e6004db
4
+ data.tar.gz: ee1b6a5c5a1b4f13ed3bc6b7e01ac84cc1345dbc1b14e5e9062cad3355543f79
5
5
  SHA512:
6
- metadata.gz: fdfccb1ed0f67a23420689a4be764df6c5270c87ff679ce14207b0ab1c55b5ddb6f003887f50b4e121f73a2c6fbd7f0418c0f59ae5b82241bf7e45a0dbe52536
7
- data.tar.gz: 9ed4e350f9f821da3dcca4a33490d5e2a33cb0977b2ec10dd71235f83f755eb876736a9a2d8e61d0231a8afe5a878a7631fa896ebec5dc9373486ef7d1600129
6
+ metadata.gz: c98a7ce2512389c315eeb307010ce576f401d6a53c24e084005860f98b909509ed8d45049d5fda9b7d53136caa1e740cd049b50299f6701c2c5e614f16ccee9a
7
+ data.tar.gz: 386d69da57968abc09924476c0b9289286deef2fb57208e0e2a1f93f68f4601ed77766a88ea5fb241b31e9dee2d37a8c15546c6628903a9575951e58e2fb4efd
@@ -23,7 +23,7 @@ class LogStash::Filters::Ipam < LogStash::Filters::Base
23
23
 
24
24
  # Mysql connection options.
25
25
  config :mysql_host, :validate => :string, :required => true
26
- #config :mysql_port, :validate => :number, :default => 3306
26
+ config :mysql_port, :validate => :number, :default => 3306
27
27
  config :mysql_user, :validate => :string, :required => true
28
28
  config :mysql_pass, :validate => :string, :required => true
29
29
  config :mysql_db, :validate => :string, :default => "phpipam"
@@ -59,24 +59,20 @@ class LogStash::Filters::Ipam < LogStash::Filters::Base
59
59
  # Get all the subnets from the Table
60
60
  subnets = ActiveRecord::Base.connection.exec_query("SELECT id, subnet, mask, description FROM subnets")
61
61
 
62
- # Parse result to create a JSON string
63
- json = '{"subnets":['
62
+ # Set subnets into IPv4 address format
64
63
  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
64
+ isub = Integer(sub['subnet'])
65
+ if isub >= 0 && isub <= 4294967295
66
+ sub['subnet'] = IPAddr.new(isub, Socket::AF_INET).to_s
67
+ sub['ipv4'] = true
73
68
  else
74
- json += ', "netmask": 0'
69
+ sub['ipv4'] = false
70
+ @logger.warn("Logger : Not compatible with IPv4.", :address => sub['subnet'], :event => event)
75
71
  end
76
- json += ', "description": "' + sub['description'] + '"},'
77
72
  end
78
- json = json[0...-1]
79
- json += ']}'
73
+
74
+ # Parse result to create a JSON string
75
+ return subnets.to_json
80
76
  rescue
81
77
  @logger.warn("Impossible to retrieve data from MySQL.", :address => @mysql_host, :event => event)
82
78
  end
@@ -88,8 +84,7 @@ class LogStash::Filters::Ipam < LogStash::Filters::Base
88
84
  # Reading files
89
85
  begin
90
86
  file = File.read(@file)
91
- json JSON.parse(file)
92
- return json["subnets"]
87
+ return JSON.parse(file)
93
88
  rescue
94
89
  @logger.warn("Impossible to read into file.", :address => @file, :event => event)
95
90
  end
@@ -99,6 +94,9 @@ class LogStash::Filters::Ipam < LogStash::Filters::Base
99
94
  def checkIpSubnets(ip, subnets)
100
95
  results = Array.new
101
96
  subnets.each do |sub|
97
+ if !sub['ipv4']
98
+ next
99
+ end
102
100
  if !@gateway && sub['subnet'] == "0.0.0.0"
103
101
  next
104
102
  end
@@ -128,10 +126,14 @@ class LogStash::Filters::Ipam < LogStash::Filters::Base
128
126
  # if need reset => update content.
129
127
  checkFile(event)
130
128
 
131
- # Get Subnets Checking the IP
129
+ # Get Subnets from updated file
132
130
  # if can't read => Warning
133
- # if gateway is false => won't register "0.0.0.0" subnets
134
131
  ipamSubnets = getIpamSubnets(event)
132
+
133
+ # Get Subnets that contains IP
134
+ # if @gateway => Get 0.0.0.0 subnets
135
+ # else => Don't get those subnets
136
+ # if !ipv4 => Don't handle those subnets
135
137
  subnets = checkIpSubnets(@ip, subnets)
136
138
 
137
139
  # Set field only if there is some subnets checked.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-filter-ipam'
3
- s.version = '0.1.4'
3
+ s.version = '0.1.5'
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.'
@@ -13,9 +13,12 @@ describe LogStash::Filters::Ipam do
13
13
  CONFIG
14
14
  end
15
15
 
16
- sample("ip" => "212.24.215.123") do
17
- expect(subject).to include("subnets")
18
- #expect(subject.get('subnets')).to eq('Hello World')
16
+ sample("ip" => "212.24.215.123",
17
+ "mysql_host" => "172.19.0.19",
18
+ "mysql_user" => "kibana",
19
+ "mysql_pass" => "QZQxf4XQGni6",) do
20
+ #expect(subject).to include("subnets")
21
+ #expect(subject.get('subnets')).to !eq('')
19
22
  end
20
23
  end
21
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-ipam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corentin Dekimpe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-21 00:00:00.000000000 Z
11
+ date: 2017-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement