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

#closeObject

def run



60
61
62
# File 'lib/logstash/inputs/github.rb', line 60

def close
  @server.stop
end

#registerObject



24
25
26
# File 'lib/logstash/inputs/github.rb', line 24

def register
  require "ftw"
end

#run(output_queue) ⇒ Object



29
30
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
# File 'lib/logstash/inputs/github.rb', line 29

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