Class: Hachi::Models::Alert

Inherits:
Base
  • Object
show all
Defined in:
lib/hachi/models/alert.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title:, description:, severity: nil, date: nil, tags: nil, tlp: nil, status: nil, type:, source:, source_ref: nil, artifacts: nil, follow: nil) ⇒ Alert

Returns a new instance of Alert.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/hachi/models/alert.rb', line 22

def initialize(title:, description:, severity: nil, date: nil, tags: nil, tlp: nil, status: nil, type:, source:, source_ref: nil, artifacts: nil, follow: nil)
  @title = title
  @description = description
  @severity = severity
  @date = date
  @tags = tags
  @tlp = tlp
  @status = status
  @type = type
  @source = source
  @source_ref = source_ref || SecureRandom.hex(10)
  @artifacts = artifacts.nil? ? nil : artifacts.map { |a| Artifact.new(**a) }
  @follow = follow

  validate_date if date
  validate_severity if severity
  validate_status if status
  validate_tlp if tlp
  validate_artifacts if artifacts
end

Instance Attribute Details

#artifactsObject (readonly)

Returns the value of attribute artifacts.



19
20
21
# File 'lib/hachi/models/alert.rb', line 19

def artifacts
  @artifacts
end

#dateObject (readonly)

Returns the value of attribute date.



12
13
14
# File 'lib/hachi/models/alert.rb', line 12

def date
  @date
end

#descriptionObject (readonly)

Returns the value of attribute description.



10
11
12
# File 'lib/hachi/models/alert.rb', line 10

def description
  @description
end

#followObject (readonly)

Returns the value of attribute follow.



20
21
22
# File 'lib/hachi/models/alert.rb', line 20

def follow
  @follow
end

#severityObject (readonly)

Returns the value of attribute severity.



11
12
13
# File 'lib/hachi/models/alert.rb', line 11

def severity
  @severity
end

#sourceObject (readonly)

Returns the value of attribute source.



17
18
19
# File 'lib/hachi/models/alert.rb', line 17

def source
  @source
end

#source_refObject (readonly)

Returns the value of attribute source_ref.



18
19
20
# File 'lib/hachi/models/alert.rb', line 18

def source_ref
  @source_ref
end

#statusObject (readonly)

Returns the value of attribute status.



15
16
17
# File 'lib/hachi/models/alert.rb', line 15

def status
  @status
end

#tagsObject (readonly)

Returns the value of attribute tags.



13
14
15
# File 'lib/hachi/models/alert.rb', line 13

def tags
  @tags
end

#titleObject (readonly)

Returns the value of attribute title.



9
10
11
# File 'lib/hachi/models/alert.rb', line 9

def title
  @title
end

#tlpObject (readonly)

Returns the value of attribute tlp.



14
15
16
# File 'lib/hachi/models/alert.rb', line 14

def tlp
  @tlp
end

#typeObject (readonly)

Returns the value of attribute type.



16
17
18
# File 'lib/hachi/models/alert.rb', line 16

def type
  @type
end

Instance Method Details

#payloadObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/hachi/models/alert.rb', line 43

def payload
  {
    title: title,
    description: description,
    severity: severity,
    date: date,
    tags: tags,
    tlp: tlp,
    status: status,
    type: type,
    source: source,
    sourceRef: source_ref,
    artifacts: artifacts&.map(&:payload),
    follow: follow
  }.compact
end