Class: LogStash::Inputs::Twitter

Inherits:
Base show all
Defined in:
lib/logstash/inputs/twitter.rb

Overview

Read events from the twitter streaming api.

Constant Summary

Constants included from Config::Mixin

Config::Mixin::CONFIGSORT

Instance Attribute Summary

Attributes inherited from Base

#params, #threadable

Attributes included from Config::Mixin

#config, #original_params

Attributes inherited from Plugin

#logger, #params

Instance Method Summary collapse

Methods inherited from Base

#initialize, #tag

Methods included from Config::Mixin

#config_init, included

Methods inherited from Plugin

#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #teardown, #terminating?, #to_s

Constructor Details

This class inherits a constructor from LogStash::Inputs::Base

Instance Method Details

#registerObject



51
52
53
54
55
56
57
58
59
# File 'lib/logstash/inputs/twitter.rb', line 51

def register
  require "twitter"
  @client = Twitter::Streaming::Client.new do |c|
    c.consumer_key = @consumer_key
    c.consumer_secret = @consumer_secret.value
    c.access_token = @oauth_token
    c.access_token_secret = @oauth_token_secret.value
  end
end

#run(queue) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/logstash/inputs/twitter.rb', line 62

def run(queue)
  @logger.info("Starting twitter tracking", :keywords => @keywords)
  @client.filter(:track => @keywords.join(",")) do |tweet|
    @logger.info? && @logger.info("Got tweet", :user => tweet.user.screen_name, :text => tweet.text)
    event = LogStash::Event.new(
      "@timestamp" => tweet.created_at.gmtime,
      "message" => tweet.full_text,
      "user" => tweet.user.screen_name,
      "client" => tweet.source,
      "retweeted" => tweet.retweeted?,
      "source" => "http://twitter.com/#{tweet.user.screen_name}/status/#{tweet.id}"
    )
    decorate(event)
    event["in-reply-to"] = tweet.in_reply_to_status_id if tweet.reply?
    unless tweet.urls.empty?
      event["urls"] = tweet.urls.map(&:expanded_url).map(&:to_s)
    end
    queue << event
  end # client.filter
end