module FeedImport
Public Class Methods
import_dump(file)
click to toggle source
Imports from hexdumps separated by “%” and merged by ‘,’
# File lib/rbkb/plug/feed_import.rb, line 53 def import_dump(file) ret = [] dat = File.read(file) dat.strip.split(/^%$/).each do |msg| ret << "" msg.strip.split(/^,$/).each do |chunk| ret[-1] << chunk.strip.dehexdump end end return ret end
import_pcap(file, filter=nil)
click to toggle source
Imports an array from pcap
# File lib/rbkb/plug/feed_import.rb, line 20 def import_pcap(file, filter=nil) ret = Array.new pcap = Pcap::Capture.open_offline(file) pcap.setfilter filter if filter pcap.each_packet do |pkt| if ( (pkt.udp? and dat=pkt.udp_data) or (pkt.tcp? and dat=pkt.tcp_data and not dat.empty?) ) ret << dat end end return ret end
import_rawfiles(glob_pat)
click to toggle source
Imports raw messages in files by a glob pattern (i.e. /tmp/foo/msgs.*) Manage filenames so that they’re in the right order on import. See Dir.glob for valid globbing patterns.
# File lib/rbkb/plug/feed_import.rb, line 69 def import_rawfiles(glob_pat) Dir.glob(glob_pat).map { |f| File.read(f) } end
import_yaml(file)
click to toggle source
Imports an array from yaml
# File lib/rbkb/plug/feed_import.rb, line 43 def import_yaml(file) unless ( ret = YAML.load_file(file) ).kind_of? Array raise "#{file.inspect} did not provide an array" end return ret end
Private Instance Methods
import_dump(file)
click to toggle source
Imports from hexdumps separated by “%” and merged by ‘,’
# File lib/rbkb/plug/feed_import.rb, line 53 def import_dump(file) ret = [] dat = File.read(file) dat.strip.split(/^%$/).each do |msg| ret << "" msg.strip.split(/^,$/).each do |chunk| ret[-1] << chunk.strip.dehexdump end end return ret end
import_pcap(file, filter=nil)
click to toggle source
Imports an array from pcap
# File lib/rbkb/plug/feed_import.rb, line 20 def import_pcap(file, filter=nil) ret = Array.new pcap = Pcap::Capture.open_offline(file) pcap.setfilter filter if filter pcap.each_packet do |pkt| if ( (pkt.udp? and dat=pkt.udp_data) or (pkt.tcp? and dat=pkt.tcp_data and not dat.empty?) ) ret << dat end end return ret end
import_rawfiles(glob_pat)
click to toggle source
Imports raw messages in files by a glob pattern (i.e. /tmp/foo/msgs.*) Manage filenames so that they’re in the right order on import. See Dir.glob for valid globbing patterns.
# File lib/rbkb/plug/feed_import.rb, line 69 def import_rawfiles(glob_pat) Dir.glob(glob_pat).map { |f| File.read(f) } end
import_yaml(file)
click to toggle source
Imports an array from yaml
# File lib/rbkb/plug/feed_import.rb, line 43 def import_yaml(file) unless ( ret = YAML.load_file(file) ).kind_of? Array raise "#{file.inspect} did not provide an array" end return ret end