Class: Garrison::Api::Alert

Inherits:
Object
  • Object
show all
Defined in:
lib/garrison/api/alert.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAlert

Returns a new instance of Alert.



50
# File 'lib/garrison/api/alert.rb', line 50

def initialize; end

Instance Attribute Details

#countObject

Returns the value of attribute count.



48
49
50
# File 'lib/garrison/api/alert.rb', line 48

def count
  @count
end

#departmentsObject

Returns the value of attribute departments.



46
47
48
# File 'lib/garrison/api/alert.rb', line 46

def departments
  @departments
end

#detailObject

Returns the value of attribute detail.



38
39
40
# File 'lib/garrison/api/alert.rb', line 38

def detail
  @detail
end

#familyObject

Returns the value of attribute family.



34
35
36
# File 'lib/garrison/api/alert.rb', line 34

def family
  @family
end

#findingObject

Returns the value of attribute finding.



40
41
42
# File 'lib/garrison/api/alert.rb', line 40

def finding
  @finding
end

#finding_idObject

Returns the value of attribute finding_id.



41
42
43
# File 'lib/garrison/api/alert.rb', line 41

def finding_id
  @finding_id
end

#first_detected_atObject

Returns the value of attribute first_detected_at.



42
43
44
# File 'lib/garrison/api/alert.rb', line 42

def first_detected_at
  @first_detected_at
end

#key_valuesObject

Returns the value of attribute key_values.



44
45
46
# File 'lib/garrison/api/alert.rb', line 44

def key_values
  @key_values
end

#last_detected_atObject

Returns the value of attribute last_detected_at.



43
44
45
# File 'lib/garrison/api/alert.rb', line 43

def last_detected_at
  @last_detected_at
end

#nameObject

Returns the value of attribute name.



36
37
38
# File 'lib/garrison/api/alert.rb', line 36

def name
  @name
end

#no_repeatObject

Returns the value of attribute no_repeat.



47
48
49
# File 'lib/garrison/api/alert.rb', line 47

def no_repeat
  @no_repeat
end

#run_uuidObject

Returns the value of attribute run_uuid.



32
33
34
# File 'lib/garrison/api/alert.rb', line 32

def run_uuid
  @run_uuid
end

#severityObject

Returns the value of attribute severity.



39
40
41
# File 'lib/garrison/api/alert.rb', line 39

def severity
  @severity
end

#sourceObject

Returns the value of attribute source.



35
36
37
# File 'lib/garrison/api/alert.rb', line 35

def source
  @source
end

#targetObject

Returns the value of attribute target.



37
38
39
# File 'lib/garrison/api/alert.rb', line 37

def target
  @target
end

#typeObject

Returns the value of attribute type.



33
34
35
# File 'lib/garrison/api/alert.rb', line 33

def type
  @type
end

#urlsObject

Returns the value of attribute urls.



45
46
47
# File 'lib/garrison/api/alert.rb', line 45

def urls
  @urls
end

Class Method Details

.obsolete_previous_runs(check) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/garrison/api/alert.rb', line 6

def obsolete_previous_runs(check)
  raise ArgumentError, "No source defined" unless check.source
  url = File.join(Api.configuration.url, 'api', 'v1', 'alerts', 'obsolete')

  party_params = {
    body: {
      source: check.source,
      agent_id: Api.configuration.uuid,
      run_id: check.run_uuid,
    }.to_json,
    headers: { 'Content-Type' => 'application/json' },
    logger: Logging.logger,
    log_level: :debug,
    raise_on: (400..599).to_a
  }

  Logging.debug "Alert::obsolete_previous_runs - #{party_params[:body]}"
  HTTParty.post(url, party_params)

rescue Errno::ECONNREFUSED => e
  Logging.error "#{e.class} to the Garrison API during Alert::obsolete_previous_runs - #{e.message}"
rescue HTTParty::ResponseError => e
  Logging.error "#{e.class} #{e.message.split(" - ")[0]} - When calling the Garrison API during Alert::obsolete_previous_runs"
end

Instance Method Details

#saveObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/garrison/api/alert.rb', line 52

def save
  url = File.join(Api.configuration.url, 'api', 'v1', 'alerts')

  party_params = {
    body: {
      name: name,
      target: target,
      detail: detail,
      finding: finding,
      finding_id: finding_id,
      first_detected_at: first_detected_at,
      last_detected_at: last_detected_at,
      kind: type,
      family: family,
      source: source,
      severity: severity,
      key_values: key_values,
      urls: urls,
      departments: departments,
      no_repeat: no_repeat,
      count: count,
      agent_id: Api.configuration.uuid,
      run_id: run_uuid,
    }.to_json,
    headers: { 'Content-Type' => 'application/json' },
    logger: Logging.logger,
    log_level: :debug,
    raise_on: (400..599).to_a
  }

  Logging.debug "Alert::save - #{party_params[:body]}"
  HTTParty.post(url, party_params)

rescue Errno::ECONNREFUSED => e
  Logging.error "#{e.class} to the Garrison API during Alert::save - #{e.message}"
rescue HTTParty::ResponseError => e
  Logging.error "#{e.class} #{e.message.split(" - ")[0]} - When calling the Garrison API during Alert::save"
end