65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/new_backup/datadog.rb', line 65
def dogger(msg, options={})
return if msg.nil? || msg.empty?
if options[:type] == :error
error msg
else
info msg
end
debug "#{self.class}##{__method__}@#{File.basename(__FILE__)}:#{__LINE__}: $dogger exists? #{$dogger.inspect}"
debug "#{self.class}##{__method__}@#{File.basename(__FILE__)}:#{__LINE__}: $dogger.api_key: #{$dogger.api_key}"
return if $dogger.api_key.nil? || $dogger.api_key.empty?
$dogger.client ||= Dogapi::Client.new($dogger.api_key)
debug "#{self.class}##{__method__}@#{File.basename(__FILE__)}:#{__LINE__}: $dogger.client: #{$dogger.client.inspect}"
$dogger.environment ||= (ENV['RAILS_ENV'].nil? || ENV['RAILS_ENV'].empty?) ? 'development' : ENV['RAILS_ENV']
hostname = `hostname`.chomp
emit_options = {
:msg_title => msg,
:alert_type => (options[:type] == :error) ? 'error' : 'success',
:tags => [ "host:#{hostname}", "env:#{$dogger.environment}", "new_backup" ],
:priority => 'normal',
:host => hostname,
:source => 'MyApps'}
body = options[:body] ||= msg
this_event = Dogapi::Event.new(body, emit_options)
debug "#{self.class}##{__method__}@#{File.basename(__FILE__)}:#{__LINE__}: emit_options: #{emit_options.to_yaml}\nbody: #{body}\nthis_event: #{this_event.inspect}"
$dogger.client.emit_event(this_event)
end
|