Class: LogStash::Inputs::GitHub

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/inputs/github.rb

Overview

Read events from github webhooks

Instance Method Summary collapse

Instance Method Details

#registerObject



26
27
28
# File 'lib/logstash/inputs/github.rb', line 26

def register
  require "ftw"
end

#run(output_queue) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/logstash/inputs/github.rb', line 31

def run(output_queue)
  @server = FTW::WebServer.new(@ip, @port) do |request, response|
      body = request.read_body
      begin
        event = LogStash::Event.new(JSON.parse(body))
      rescue JSON::ParserError => e
        @logger.info("JSON parse failure. Falling back to plain-text", :error => e, :data => body)
        event = LogStash::Event.new("message" => body, "tags" => "_invalidjson")
      end
      event['headers'] = request.headers.to_hash
      if defined? @secret_token and event['headers']['x-hub-signature']
          event['hash'] = 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), @secret_token, body)
          if not Rack::Utils.secure_compare(event['hash'], event['headers']['x-hub-signature'])
              if not @drop_invalid
                  event['tags'] = "_Invalid_Github_Message"
              else
                  @logger.info("Dropping invalid Github message")
                  drop = true
              end
          end
      end
      if not drop
          decorate(event)
          output_queue << event
      end
      response.status = 200
      response.body = "Accepted!"
  end
  @server.run
end

#teardownObject

def run



62
63
64
# File 'lib/logstash/inputs/github.rb', line 62

def teardown
  @server.stop
end