Class: Garrison::Checks::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/garrison/agents/check.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Check

Returns a new instance of Check.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/garrison/agents/check.rb', line 12

def initialize(options = {})
  @source      = ENV['GARRISON_ALERT_SOURCE']
  @severity    = ENV['GARRISON_ALERT_SEVERITY']
  @type        = ENV['GARRISON_ALERT_TYPE']
  @family      = ENV['GARRISON_ALERT_FAMILY']
  @departments = ENV['GARRISON_ALERT_DEPARTMENTS'] ? ENV['GARRISON_ALERT_DEPARTMENTS'].split(',') : []
  @options     = options

  Logging.info "Starting... #{self.class.name}"
  inherit_settings
  Logging.info "Agent Settings (source=#{self.source} severity=#{self.severity || 'dynamic'} type=#{self.type} family=#{self.family} departments=#{self.departments.join(',')})"

  options_log = options.map do |key, value|
    value = value.is_a?(Array) ? value.join(',') : value
    "#{key}=#{value}"
  end
  Logging.info "Check Settings (#{options_log.join(' ')})" if options.any?
end

Instance Attribute Details

#departmentsObject

Returns the value of attribute departments.



9
10
11
# File 'lib/garrison/agents/check.rb', line 9

def departments
  @departments
end

#familyObject

Returns the value of attribute family.



8
9
10
# File 'lib/garrison/agents/check.rb', line 8

def family
  @family
end

#optionsObject

Returns the value of attribute options.



10
11
12
# File 'lib/garrison/agents/check.rb', line 10

def options
  @options
end

#severityObject

Returns the value of attribute severity.



6
7
8
# File 'lib/garrison/agents/check.rb', line 6

def severity
  @severity
end

#sourceObject

Returns the value of attribute source.



5
6
7
# File 'lib/garrison/agents/check.rb', line 5

def source
  @source
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/garrison/agents/check.rb', line 7

def type
  @type
end

Instance Method Details

#alert(params = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/garrison/agents/check.rb', line 39

def alert(params = {})
  Logging.info "Raising alert for '#{params[:target]}'"
  utc_time_now = Time.now.utc

  alert = Api::Alert.new
  alert.type = type
  alert.family = family
  alert.source = source
  alert.departments = departments

  alert.name = params[:name]
  alert.target = params[:target]
  alert.detail = params[:detail]
  alert.severity = params[:external_severity] || severity
  alert.count = params[:count] || 1

  alert.finding = params[:finding]
  alert.finding_id = params[:finding_id]
  alert.first_detected_at = params[:first_detected_at] || utc_time_now
  alert.last_detected_at = params[:last_detected_at] || utc_time_now

  alert.urls = params[:urls]
  alert.key_values = (self.key_values + params[:key_values]).uniq { |h| h[:key] }

  alert.no_repeat = params[:no_repeat]

  alert.save
end

#key_valuesObject



35
36
37
# File 'lib/garrison/agents/check.rb', line 35

def key_values
  []
end

#performObject



31
32
33
# File 'lib/garrison/agents/check.rb', line 31

def perform
  raise 'You must provide a perform method in your check class'
end