Class: Rnotifier::EventData

Inherits:
Object
  • Object
show all
Defined in:
lib/rnotifier/event_data.rb

Constant Summary collapse

EVENT =
0
ALERT =
1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, data = {}, tags = nil) ⇒ EventData

Returns a new instance of EventData.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rnotifier/event_data.rb', line 8

def initialize(name, type, data = {}, tags = nil)
  @data = {
    :name => name, 
    :data => data,
    :app_env => EventData.app_env,
    :occurred_at => Time.now.to_i,
    :rnotifier_client => Config::CLIENT,
    :type => type,
  }

  @data[:tags] = tags if tags
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/rnotifier/event_data.rb', line 3

def data
  @data
end

Class Method Details

.app_envObject



33
34
35
36
37
38
39
40
41
# File 'lib/rnotifier/event_data.rb', line 33

def self.app_env
  @app_env ||= {
    :env => Config.current_env,
    :pid => $$,
    :host => (Socket.gethostname rescue ''),
    :language => 'ruby',
    :timezone => (Time.now.zone rescue nil)
  }
end

Instance Method Details

#notifyObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rnotifier/event_data.rb', line 21

def notify
  return false unless Config.valid?

  begin
    Notifier.send(data, Config.event_path)
  rescue Exception => e
    Rlogger.error("[EVENT NOTIFY] #{e.message}")
    Rlogger.error("[EVENT NOTIFY] #{e.backtrace}")
    false
  end
end