Class: LogStash::Filters::Ipam
- Inherits:
-
Base
- Object
- Base
- LogStash::Filters::Ipam
- Defined in:
- lib/logstash/filters/ipam.rb
Overview
This filter will replace the contents of the default message field with whatever you specify in the configuration.
It is only intended to be used as an .
Instance Method Summary collapse
Instance Method Details
#filter(event) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/logstash/filters/ipam.rb', line 36 def filter(event) results = Array.new file = File.read(@file) json = JSON.parse(file) subnets = json["subnets"] begin ip = IPAddr.new(@ip) rescue ArgumentError => e @logger.warn("Invalid IP address, skipping", :address => @ip, :event => event) nil end subnets.each do |sub| if IPAddr.new(sub['subnet'] + "/" + sub['netmask'].to_s) === ip results.push(sub) end end # Set field only if there is some subnets checked. if results.length > 0 event.set(@field, results) # filter_matched should go in the last line of our successful code filter_matched(event) end end |
#register ⇒ Object
31 32 33 |
# File 'lib/logstash/filters/ipam.rb', line 31 def register # Add instance variables end |