Class: Fluent::ZoomdataOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_zoomdata.rb

Instance Method Summary collapse

Constructor Details

#initializeZoomdataOutput

Returns a new instance of ZoomdataOutput.



6
7
8
9
10
# File 'lib/fluent/plugin/out_zoomdata.rb', line 6

def initialize
  super
  require 'net/http'
  require 'uri'
end

Instance Method Details

#configure(conf) ⇒ Object



24
25
26
# File 'lib/fluent/plugin/out_zoomdata.rb', line 24

def configure(conf)
  super
end

#emit(tag, es, chain) ⇒ Object



71
72
73
74
75
76
# File 'lib/fluent/plugin/out_zoomdata.rb', line 71

def emit(tag, es, chain)
  es.each do |time, record|
    post(tag, time, record)
  end
  chain.next
end

#format_url(tag) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/fluent/plugin/out_zoomdata.rb', line 36

def format_url(tag)
  if @sourcename
    @endpoint_url + URI.escape('?source='+@sourcename)
  else
    @endpoint_url + URI.escape('?source='+tag)
  end
end

#post(tag, time, record) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/fluent/plugin/out_zoomdata.rb', line 44

def post(tag, time, record)
  url = format_url(tag)
  res = nil
  begin
    uri = URI.parse(url)
    req = Net::HTTP::Post.new(url)
    req.basic_auth(@username, @password)
    req['Content-Type'] = 'application/json'
    req.body = JSON.dump(record)
    http = Net::HTTP.new(uri.host, uri.port)
    if @ssl
      http.use_ssl = true
      unless @verify_ssl
        http.verify_mode = OpenSSL::SSL::VERIFY_NONE
      end
    end
    res = http.start {|http| http.request(req)}
  rescue IOError, EOFError, SystemCallError
    # server didn't respond
    $log.warn "Net::HTTP.post_form raises exception: #{$!.class}, '#{$!.message}'"
  end
  unless res and res.is_a?(Net::HTTPSuccess)
    $log.warn "failed to post to zoomdata: #{url}, json: #{record}, code: #{res && res.code}"
  end

end

#shutdownObject



32
33
34
# File 'lib/fluent/plugin/out_zoomdata.rb', line 32

def shutdown
  super
end

#startObject



28
29
30
# File 'lib/fluent/plugin/out_zoomdata.rb', line 28

def start
  super
end