Class: Threatinator::Actions::Run::Action

Inherits:
Threatinator::Action show all
Includes:
Logging
Defined in:
lib/threatinator/actions/run/action.rb

Instance Attribute Summary

Attributes inherited from Threatinator::Action

#registry

Instance Method Summary collapse

Methods included from Logging

included, #logger

Constructor Details

#initialize(registry, config) ⇒ Action

Returns a new instance of Action.



14
15
16
17
# File 'lib/threatinator/actions/run/action.rb', line 14

def initialize(registry, config)
  super(registry)
  @config = config
end

Instance Method Details

#build_outputObject



19
20
21
# File 'lib/threatinator/actions/run/action.rb', line 19

def build_output
  @config.output.build_output
end

#execObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/threatinator/actions/run/action.rb', line 23

def exec
  opts = {}

  feed = registry.get(@config.feed_provider, @config.feed_name)
  if feed.nil?
    logger.error("Unknown feed: provider = #{@config.feed_provider}, name = #{@config.feed_name}")
    raise Threatinator::Exceptions::UnknownFeed.new(@config.feed_provider, @config.feed_name)
  end

  output = build_output

  feed_runner = Threatinator::FeedRunner.new(feed, output)
  status = StatusObserver.new
  feed_runner.add_observer(status)

  @config.observers.each do |observer|
    feed_runner.add_observer(observer)
  end

  feed_runner.run

  if status.missed?
    logger.error "#{status.missed} records were MISSED (neither parsed nor filtered). You may need to update your feed specification! Try increasing the logging level to DEBUG, or re-run with run.coverage_output='output.csv' to see which records were parsed/filtered/missed."
  end

  if status.errors?
    logger.error "#{status.errors} records had errors! You may have a bug in your feed specification! Try increasing the logging level to DEBUG, or re-run with run.coverage_output='output.csv' to see which records had errors."
  end

  logger.info "#{status.total} records processed. #{status.parsed} parsed, #{status.filtered} filtered, #{status.missed} missed, #{status.errors} errors"
end