Class: SoarAuditingProvider::AuditingProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/soar_auditing_provider/auditing_provider.rb

Constant Summary collapse

DEFAULT_NFRS =
{}
DEFAULT_FLOW_ID_GENERATOR =
-> { SoarFlow::ID::generate_flow_id }
DEFAULT_LEVEL =
:info
DEFAULT_QUEUE_WORKER_CONFIG =
{
  "queue_size" => 1000,
  "initial_back_off_in_seconds" => 1,
  "back_off_multiplier" => 2,
  "back_off_attempts" => 5
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ AuditingProvider

Returns a new instance of AuditingProvider.

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/soar_auditing_provider/auditing_provider.rb', line 24

def initialize(configuration)
  @configuration = configuration

  @auditors = create_auditors(configuration)
  raise ArgumentError.new("Invalid auditors provided") if not @auditors.is_a?(Hash)
  raise ArgumentError.new("No auditors provided") if @auditors.nil? or @auditors.empty?

  select_auditor(configuration['default_nfrs'])
  @flow_id_generator = @configuration["flow_id_generator"] || DEFAULT_FLOW_ID_GENERATOR
  create_auditing_worker
  @buffer_overflow_count = 0
  install_at_exit_handler
  initialize_metrics
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



21
22
23
# File 'lib/soar_auditing_provider/auditing_provider.rb', line 21

def configuration
  @configuration
end

#service_identifierObject

Returns the value of attribute service_identifier.



20
21
22
# File 'lib/soar_auditing_provider/auditing_provider.rb', line 20

def service_identifier
  @service_identifier
end

#startup_flow_idObject



39
40
41
# File 'lib/soar_auditing_provider/auditing_provider.rb', line 39

def startup_flow_id
  @startup_flow_id ||= @flow_id_generator.call
end

Instance Method Details

#audit_exception(exception:, level: :error, flow_id: nil, message: nil) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/soar_auditing_provider/auditing_provider.rb', line 89

def audit_exception(exception:, level: :error, flow_id: nil, message: nil)
  exception_message = "#{exception.class}: #{exception.message}"
  exception_message = "#{message} - #{exception_message}" if message
  exception_message = exception_message + ":\n\t" + exception.backtrace.join("\n\t")
  level = :error if not is_valid_audit_level?(level)
  send(level,exception_message,flow_id)
end

#debug(data, flow_identifier = nil) ⇒ Object



55
56
57
# File 'lib/soar_auditing_provider/auditing_provider.rb', line 55

def debug(data, flow_identifier = nil)
  audit(:debug, data, flow_identifier)
end

#detailed_statusObject



77
78
79
80
81
# File 'lib/soar_auditing_provider/auditing_provider.rb', line 77

def detailed_status
  detail = basic_status_detail
  detail = detail.merge(verbose_status_detail) if @configuration['verbose_detail']
  detail
end

#error(data, flow_identifier = nil) ⇒ Object



69
70
71
# File 'lib/soar_auditing_provider/auditing_provider.rb', line 69

def error(data, flow_identifier = nil)
  audit(:error, data, flow_identifier)
end

#fatal(data, flow_identifier = nil) ⇒ Object



73
74
75
# File 'lib/soar_auditing_provider/auditing_provider.rb', line 73

def fatal(data, flow_identifier = nil)
  audit(:fatal, data, flow_identifier)
end

#flush(timeout: 1) ⇒ Object



83
84
85
86
87
# File 'lib/soar_auditing_provider/auditing_provider.rb', line 83

def flush(timeout: 1)
  if @worker
    @worker.flush(timeout: timeout)
  end
end

#info(data, flow_identifier = nil) ⇒ Object Also known as: <<



59
60
61
# File 'lib/soar_auditing_provider/auditing_provider.rb', line 59

def info(data, flow_identifier = nil)
  audit(:info, data, flow_identifier)
end

#select(nfrs = DEFAULT) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/soar_auditing_provider/auditing_provider.rb', line 97

def select(nfrs = DEFAULT)
  if nfrs.nil? or nfrs.empty?
    auditor_selected = @auditors.keys.first
  else
    auditor_selected = nil
    @auditors.each do |auditor, configuration|
      auditor_nfrs = configuration['nfrs']
      nfrs_matched = true
      nfrs.each do |nfr, value|
        nfrs_matched = false if not auditor_nfrs[nfr] or (auditor_nfrs[nfr] != value)
      end
      if nfrs_matched
        auditor_selected = auditor
        break
      end
    end
    raise NFRMatchError.new("Could not match NFRs to an auditor") if auditor_selected.nil?
  end
  configuration = @auditors[auditor_selected]
  @auditor = auditor_selected
  return @auditor, configuration
end

#select_auditor(nfrs) ⇒ Object



43
44
45
46
# File 'lib/soar_auditing_provider/auditing_provider.rb', line 43

def select_auditor(nfrs)
  select(nfrs)
  set_audit_level(configured_audit_level)
end

#set_audit_level(level) ⇒ Object



48
49
50
51
52
53
# File 'lib/soar_auditing_provider/auditing_provider.rb', line 48

def set_audit_level(level)
  @auditor.set_audit_level(level)
rescue ArgumentError
  $stderr.puts 'Invalid auditing level'
  raise
end

#warn(data, flow_identifier = nil) ⇒ Object



65
66
67
# File 'lib/soar_auditing_provider/auditing_provider.rb', line 65

def warn(data, flow_identifier = nil)
  audit(:warn, data, flow_identifier)
end