Class: Threatinator::Plugins::Output::Json

Inherits:
Output
  • Object
show all
Defined in:
lib/threatinator/plugins/output/json.rb,
lib/threatinator/plugins/output/json/config.rb

Defined Under Namespace

Classes: Config

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Json

Returns a new instance of Json.



12
13
14
15
16
# File 'lib/threatinator/plugins/output/json.rb', line 12

def initialize(config)
  @output_file = config.file
  @first = true
  puts "{"
end

Instance Method Details

#finishObject



44
45
46
# File 'lib/threatinator/plugins/output/json.rb', line 44

def finish
  puts "]}"
end

#handle_event(event) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/threatinator/plugins/output/json.rb', line 18

def handle_event(event)
  if @first
    puts "\"header\" : #{MultiJson.dump(event.header.to_h)}"
    puts ",\"items\" : ["
    puts "{"
    @first = false
  else
    puts ",{"
  end
  delim = ""
  if event.ipv4s.size > 0
    puts "#{delim}\"ipv4s\" : #{MultiJson.dump(event.ipv4s.list)}"
    delim = ","
  end
  if event.fqdns.size > 0
    puts "#{delim}\"fqdns\" : #{MultiJson.dump(event.fqdns.list)}"
    delim = ","
  end
  if event.urls.size > 0
    puts "#{delim}\"urls\" : #{MultiJson.dump(event.urls.list)}"
    delim = ","
  end
  puts "}"

end