Class: Dogapi::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/dogapi/event.rb

Overview

Metadata class for storing the details of an event

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg_text, options = {}) ⇒ Event

Optional arguments:

:date_happened => time in seconds since the epoch (defaults to now)
:msg_title     => String
:priority      => String
:parent        => event ID (integer)
:tags          => array of Strings
:event_object  => String
:alert_type    => 'success', 'error'
:event_type    => String
:source_type_name => String
:aggregation_key => String

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/dogapi/event.rb', line 29

def initialize(msg_text, options = {})
  defaults = {
    :date_happened => Time.now.to_i,
    :msg_title => '',
    :priority => "normal",
    :parent => nil,
    :tags => [],
    :aggregation_key => nil
  }
  options = defaults.merge(options)

  @msg_text = msg_text
  @date_happened = options[:date_happened]
  @msg_title = options[:msg_title]
  @priority = options[:priority]
  @parent = options[:parent]
  @tags = options[:tags]
  @aggregation_key = options[:event_object] || options[:aggregation_key]
  @alert_type = options[:alert_type]
  @event_type = options[:event_type]
  @source_type_name = options[:source_type_name]
end

Instance Attribute Details

#aggregation_keyObject (readonly)

Returns the value of attribute aggregation_key


10
11
12
# File 'lib/dogapi/event.rb', line 10

def aggregation_key
  @aggregation_key
end

#date_happenedObject (readonly)

Returns the value of attribute date_happened


10
11
12
# File 'lib/dogapi/event.rb', line 10

def date_happened
  @date_happened
end

#msg_textObject (readonly)

Returns the value of attribute msg_text


10
11
12
# File 'lib/dogapi/event.rb', line 10

def msg_text
  @msg_text
end

#msg_titleObject (readonly)

Returns the value of attribute msg_title


10
11
12
# File 'lib/dogapi/event.rb', line 10

def msg_title
  @msg_title
end

#parentObject (readonly)

Returns the value of attribute parent


10
11
12
# File 'lib/dogapi/event.rb', line 10

def parent
  @parent
end

#priorityObject (readonly)

Returns the value of attribute priority


10
11
12
# File 'lib/dogapi/event.rb', line 10

def priority
  @priority
end

#tagsObject (readonly)

Returns the value of attribute tags


10
11
12
# File 'lib/dogapi/event.rb', line 10

def tags
  @tags
end

Instance Method Details

#to_hashObject

Copy and pasted from the internets stackoverflow.com/a/5031637/25276


54
55
56
57
58
# File 'lib/dogapi/event.rb', line 54

def to_hash
  hash = {}
  instance_variables.each { |var| hash[var.to_s[1..-1].to_sym] = instance_variable_get(var) }
  hash
end