Class: Threatinator::Plugins::Output::Csv

Inherits:
FileBasedOutput show all
Defined in:
lib/threatinator/plugins/output/csv.rb

Defined Under Namespace

Classes: Config

Instance Method Summary collapse

Methods inherited from FileBasedOutput

#finish

Methods inherited from Output

#finish

Constructor Details

#initialize(config) ⇒ Csv

Returns a new instance of Csv.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/threatinator/plugins/output/csv.rb', line 10

def initialize(config)
  super(config)
  @csv = ::CSV.new(self.output_io, 
                   :write_headers => true,
                   :headers => [
                     :provider,
                     :feed_name,
                     :type,
                     :ipv4_1,
                     :ipv4_2,
                     :ipv4_3,
                     :ipv4_4,
                     :fqdn_1,
                     :fqdn_2,
                     :fqdn_3,
                     :fqdn_4,
                     :url_1,
                     :url_2,
                     :url_3,
                     :url_4
                   ])
end

Instance Method Details

#handle_event(event) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/threatinator/plugins/output/csv.rb', line 33

def handle_event(event)
  ipv4s = event.ipv4s.to_a[0..3].map { |o| o.nil? ? nil : o.ipv4.to_addr }
  fqdns = event.fqdns.to_a[0..3]
  urls  = event.urls.to_a[0..3].map {|x| x.to_s }
  @csv.add_row([
    event.feed_provider,
    event.feed_name,
    event.type,
    ipv4s[0],
    ipv4s[1],
    ipv4s[2],
    ipv4s[3],
    fqdns[0],
    fqdns[1],
    fqdns[2],
    fqdns[3],
    urls[0],
    urls[1],
    urls[2],
    urls[3],
  ])
end