Class: Fluent::WebhookMackerelInput
- Inherits:
-
Input
- Object
- Input
- Fluent::WebhookMackerelInput
- Includes:
- DetachProcessMixin
- Defined in:
- lib/fluent/plugin/in_webhook_mackerel.rb
Instance Method Summary collapse
Instance Method Details
#process(payload) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/fluent/plugin/in_webhook_mackerel.rb', line 54 def process(payload) event = payload.delete "event" payload[:event] = event $log.info "tag: #{@tag.dup}.#{event}, payload:#{payload}" router.emit("#{@tag.dup}.#{event}", Engine.now, payload) end |
#run ⇒ 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 52 |
# File 'lib/fluent/plugin/in_webhook_mackerel.rb', line 28 def run @server = WEBrick::HTTPServer.new( :BindAddress => @bind, :Port => @port, ) $log.debug "Listen on http://#{@bind}:#{@port}#{@mount}" @server.mount_proc(@mount) do |req, res| begin $log.debug req.header if req.request_method != "POST" res.status = 405 else payload = JSON.parse(req.body) process(payload) res.status = 204 end rescue => e $log.error e.inspect $log.error e.backtrace.join("\n") res.status = 400 end end @server.start end |
#shutdown ⇒ Object
22 23 24 25 26 |
# File 'lib/fluent/plugin/in_webhook_mackerel.rb', line 22 def shutdown super @server.shutdown Thread.kill(@thread) end |
#start ⇒ Object
17 18 19 20 |
# File 'lib/fluent/plugin/in_webhook_mackerel.rb', line 17 def start super @thread = Thread.new(&method(:run)) end |