Class: Mihari::Emitters::TheHive

Inherits:
Base
  • Object
show all
Defined in:
lib/mihari/emitters/the_hive.rb

Constant Summary

Constants included from Mixins::Retriable

Mixins::Retriable::DEFAULT_ON

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

inherited, #run

Methods included from Mixins::Retriable

#retry_on_error

Methods included from Mixins::Configurable

#configuration_values, #configured?

Constructor Details

#initialize(*args, **kwargs) ⇒ TheHive

Returns a new instance of TheHive.



17
18
19
20
21
22
23
# File 'lib/mihari/emitters/the_hive.rb', line 17

def initialize(*args, **kwargs)
  super(*args, **kwargs)

  @api_endpoint = kwargs[:api_endpoint] || Mihari.config.thehive_api_endpoint
  @api_key = kwargs[:api_key] || Mihari.config.thehive_api_key
  @api_version = kwargs[:api_version] || Mihari.config.thehive_api_version
end

Instance Attribute Details

#api_endpointString? (readonly)

Returns:

  • (String, nil)


9
10
11
# File 'lib/mihari/emitters/the_hive.rb', line 9

def api_endpoint
  @api_endpoint
end

#api_keyString? (readonly)

Returns:

  • (String, nil)


12
13
14
# File 'lib/mihari/emitters/the_hive.rb', line 12

def api_key
  @api_key
end

#api_versionString? (readonly)

Returns:

  • (String, nil)


15
16
17
# File 'lib/mihari/emitters/the_hive.rb', line 15

def api_version
  @api_version
end

Instance Method Details

#emit(title:, description:, artifacts:, tags: [], **_options) ⇒ Object



30
31
32
33
34
35
# File 'lib/mihari/emitters/the_hive.rb', line 30

def emit(title:, description:, artifacts:, tags: [], **_options)
  return if artifacts.empty?

  payload = payload(title: title, description: description, artifacts: artifacts, tags: tags)
  api.alert.create(**payload)
end

#normalized_api_versionString?

Normalize API version for API client

Parameters:

  • version (String)

Returns:

  • (String, nil)


44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/mihari/emitters/the_hive.rb', line 44

def normalized_api_version
  @normalized_api_version ||= [].tap do |out|
    # v4 does not have version prefix in path (/api/)
    # v5 has version prefix in path (/api/v1/)
    table = {
      "" => nil,
      "v4" => nil,
      "v5" => "v1"
    }
    out << table[api_version.to_s.downcase]
  end.first
end

#valid?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/mihari/emitters/the_hive.rb', line 26

def valid?
  api_endpont? && api_key? && ping?
end