Module: Capistrano::Datadog

Defined in:
lib/capistrano/datadog.rb,
lib/capistrano/datadog/v2.rb,
lib/capistrano/datadog/v3.rb

Defined Under Namespace

Classes: CaptureIO, LogCapture, Reporter

Class Method Summary collapse

Class Method Details

.cap_versionObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/capistrano/datadog.rb', line 18

def self.cap_version()
  if @cap_version.nil? then
    if !defined? Configuration
      @cap_version = ''
    elsif Configuration.respond_to? :instance
      @cap_version = :v2
    else
      @cap_version = :v3
    end
  end
  @cap_version
end

.reporterObject

Singleton method for Reporter



14
15
16
# File 'lib/capistrano/datadog.rb', line 14

def self.reporter()
  @reporter || @reporter = Reporter.new
end

.submit(api_key, use_getlogin = true, endpoint = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/capistrano/datadog.rb', line 31

def self.submit(api_key, use_getlogin=true, endpoint=nil)
  begin
    if api_key
      dog = Dogapi::Client.new(api_key, nil, nil, nil, true, nil, endpoint, false)
      reporter.report(use_getlogin).each do |event, hosts|
        if hosts.size > 0
          hosts.each do |host|
            dog.emit_event event, host: host
          end
        else
          dog.emit_event event
        end
      end
    else
      puts 'No api key set, not submitting to Datadog'
    end
  rescue Timeout::Error => e
    puts 'Could not submit to Datadog, request timed out.'
  rescue => e
    puts "Could not submit to Datadog: #{e.inspect}\n#{e.backtrace.join("\n")}"
  end
end