Class: Threatstack::Events::BaseEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/events/models/base_event.rb

Overview

Base event model containing the common attributes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ BaseEvent

Returns a new instance of BaseEvent.

Parameters:

  • args (Hash)
    String

    args.event_id

    String

    args.event_type

    String

    args.timestamp



21
22
23
24
25
26
# File 'lib/events/models/base_event.rb', line 21

def initialize(args)
  @event_id = args[:event_id].nil? ? SecureRandom.uuid : args[:event_id]
  @timestamp = args[:timestamp].nil? ? Time.now.utc.strftime('%FT%T.%3NZ') : args[:timestamp]
  @event_type = args[:event_type]
  @agent_type = Threatstack::Constants::RUBY
end

Instance Attribute Details

#agent_typeObject (readonly)

Returns the value of attribute agent_type.



15
16
17
# File 'lib/events/models/base_event.rb', line 15

def agent_type
  @agent_type
end

#event_idObject

Returns the value of attribute event_id.



12
13
14
# File 'lib/events/models/base_event.rb', line 12

def event_id
  @event_id
end

#event_typeObject

Returns the value of attribute event_type.



13
14
15
# File 'lib/events/models/base_event.rb', line 13

def event_type
  @event_type
end

#timestampObject

Returns the value of attribute timestamp.



14
15
16
# File 'lib/events/models/base_event.rb', line 14

def timestamp
  @timestamp
end

Instance Method Details

#to_core_hashObject



32
33
34
# File 'lib/events/models/base_event.rb', line 32

def to_core_hash
  { :event_id => @event_id, :event_type => @event_type, :agent_type => @agent_type, :timestamp => @timestamp }
end

#to_hashObject



28
29
30
# File 'lib/events/models/base_event.rb', line 28

def to_hash
  Hash[instance_variables.map { |name| [name[1..-1], instance_variable_get(name)] }]
end

#to_json_stringObject



36
37
38
# File 'lib/events/models/base_event.rb', line 36

def to_json_string
  to_hash.to_json
end