Class: Binnacle::Event

Inherits:
Resource show all
Defined in:
lib/binnacle/resources/event.rb

Direct Known Subclasses

Trap::ExceptionEvent

Instance Attribute Summary collapse

Attributes inherited from Resource

#connection

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

get, #post, #post_asynch

Instance Attribute Details

#channel_idObject

Returns the value of attribute channel_id.



4
5
6
# File 'lib/binnacle/resources/event.rb', line 4

def channel_id
  @channel_id
end

#client_event_timeObject

Returns the value of attribute client_event_time.



8
9
10
# File 'lib/binnacle/resources/event.rb', line 8

def client_event_time
  @client_event_time
end

#client_idObject

Returns the value of attribute client_id.



6
7
8
# File 'lib/binnacle/resources/event.rb', line 6

def client_id
  @client_id
end

#environmentObject

Returns the value of attribute environment.



14
15
16
# File 'lib/binnacle/resources/event.rb', line 14

def environment
  @environment
end

#event_nameObject

Returns the value of attribute event_name.



5
6
7
# File 'lib/binnacle/resources/event.rb', line 5

def event_name
  @event_name
end

#event_timeObject

Returns the value of attribute event_time.



13
14
15
# File 'lib/binnacle/resources/event.rb', line 13

def event_time
  @event_time
end

#ip_addressObject

Returns the value of attribute ip_address.



9
10
11
# File 'lib/binnacle/resources/event.rb', line 9

def ip_address
  @ip_address
end

#jsonObject

Returns the value of attribute json.



12
13
14
# File 'lib/binnacle/resources/event.rb', line 12

def json
  @json
end

#log_levelObject

Returns the value of attribute log_level.



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

def log_level
  @log_level
end

#session_idObject

Returns the value of attribute session_id.



7
8
9
# File 'lib/binnacle/resources/event.rb', line 7

def session_id
  @session_id
end

#tagsObject

Returns the value of attribute tags.



11
12
13
# File 'lib/binnacle/resources/event.rb', line 11

def tags
  @tags
end

Class Method Details

.events(connection, channel, date, start_hour, end_hour, lines, environment = rails_env) ⇒ Object



101
102
103
104
105
# File 'lib/binnacle/resources/event.rb', line 101

def self.events(connection, channel, date, start_hour, end_hour, lines, environment = rails_env)
  path = [route(channel), environment, date].compact.join('/')

  get(connection, path, {'start_hour' => start_hour, 'end_hour' => end_hour, 'limit' => lines})
end

.from_hash(h) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/binnacle/resources/event.rb', line 57

def self.from_hash(h)
  event = self.new()
  event.channel_id = h['channelId']
  event.event_name = h['eventName']
  event.client_id = h['clientId']
  event.session_id = h['sessionId']
  event.ip_address = h['ipAddress']
  event.log_level = h['logLevel']
  event.event_time = Time.at(h['eventTime']/1000)
  event.tags = h['tags']
  event.json = h['json']
  event.environment = h['environment']

  event
end

.recents(connection, lines, since, channel, environment = rails_env) ⇒ Object



95
96
97
98
99
# File 'lib/binnacle/resources/event.rb', line 95

def self.recents(connection, lines, since, channel, environment = rails_env)
  path = [route(channel), environment, 'recents'].compact.join('/')

  get(connection, path, {'limit' => lines, 'since' => since})
end

.route(channel) ⇒ Object



91
92
93
# File 'lib/binnacle/resources/event.rb', line 91

def self.route(channel)
  "/api/events/#{channel}"
end

Instance Method Details

#configure(channel_id, event_name, client_id, session_id, log_level, environment = Event.rails_env, ts = Time.now, tags = [], json = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/binnacle/resources/event.rb', line 16

def configure(channel_id, event_name, client_id, session_id, log_level, environment = Event.rails_env, ts = Time.now, tags = [], json = {})
  self.channel_id = channel_id
  self.event_name = event_name
  self.client_id = client_id
  self.session_id = session_id
  self.timestamp = ts ? ts : Time.now
  self.log_level = log_level
  self.tags = tags
  self.json = json
  self.environment = environment || Event.rails_env
end

#configure_from_logging_progname(progname, channel_id, client_id, session_id, log_level, environment = Event.rails_env, ts = Time.now, tags = [], json = {}) ⇒ Object



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

def configure_from_logging_progname(progname, channel_id, client_id, session_id, log_level, environment =  Event.rails_env, ts = Time.now, tags = [], json = {})
  if progname.is_a?(Hash)
    self.client_id = progname[:client_id] || client_id
    self.session_id = progname[:session_id] || session_id
    self.channel_id = progname[:channel_id] || channel_id
    self.event_name =  progname[:event_name]
    self.tags = progname[:tags] || tags
    self.json = json
    self.json.merge!(progname[:json]) if progname[:json]
    self.environment = environment || Event.rails_env
  elsif progname.is_a?(String)
    self.client_id = client_id
    self.session_id = session_id
    self.channel_id = channel_id
    self.event_name = progname
    self.tags = tags
    self.json = json
    self.environment = environment || Event.rails_env
  end

  self.timestamp = ts ? ts : Time.now
  self.log_level = log_level
  self.environment = environment || Event.rails_env
end

#routeObject



87
88
89
# File 'lib/binnacle/resources/event.rb', line 87

def route
  "/api/events/#{channel_id}"
end

#timestamp=(ts) ⇒ Object



53
54
55
# File 'lib/binnacle/resources/event.rb', line 53

def timestamp=(ts)
  self.client_event_time = ts.strftime("%Y-%m-%dT%H:%M:%S%z")
end

#to_jsonObject



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/binnacle/resources/event.rb', line 73

def to_json
  {
    "channelId" => channel_id,
    "sessionId" => session_id,
    "clientEventTime" => client_event_time,
    "eventName" => event_name,
    "clientId" => client_id,
    "logLevel" => log_level,
    "tags" => tags,
    "environment" => environment,
    "json" => json
  }.to_json
end