class Hachi::Models::Alert

Attributes

artifacts[R]
date[R]
description[R]
follow[R]
severity[R]
source[R]
source_ref[R]
status[R]
tags[R]
title[R]
tlp[R]
type[R]

Public Class Methods

new(title:, description:, type:, source:, severity: nil, date: nil, tags: nil, tlp: nil, status: nil, source_ref: nil, artifacts: nil, follow: nil) click to toggle source
# File lib/hachi/models/alert.rb, line 11
def initialize(title:, description:, type:, source:, severity: nil, date: nil, tags: nil, tlp: nil, status: nil, 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

Public Instance Methods

payload() click to toggle source
# File lib/hachi/models/alert.rb, line 32
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

Private Instance Methods

validate_artifacts() click to toggle source
# File lib/hachi/models/alert.rb, line 58
def validate_artifacts
  artifacts.each(&:validate_for_creation)
end
validate_date() click to toggle source
# File lib/hachi/models/alert.rb, line 51
def validate_date
  DateTime.parse(date)
  true
rescue ArgumentError => _e
  raise ArgumentError, "date should be Date format"
end