85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/logstash/inputs/twitter.rb', line 85
def run(queue)
@logger.info("Starting twitter tracking", :keywords => @keywords)
begin
@client.filter(:track => @keywords.join(",")) do ||
if .is_a?(Twitter::Tweet)
@logger.debug? && @logger.debug("Got tweet", :user => .user.screen_name, :text => .text)
if @full_tweet
event = LogStash::Event.new(LogStash::Util.stringify_symbols(.to_hash))
event.timestamp = LogStash::Timestamp.new(.created_at)
else
event = LogStash::Event.new(
LogStash::Event::TIMESTAMP => LogStash::Timestamp.new(.created_at),
"message" => .full_text,
"user" => .user.screen_name,
"client" => .source,
"retweeted" => .,
"source" => "http://twitter.com/#{.user.screen_name}/status/#{.id}"
)
event["in-reply-to"] = .in_reply_to_status_id if .reply?
unless .urls.empty?
event["urls"] = .urls.map(&:expanded_url).map(&:to_s)
end
end
decorate(event)
queue << event
end
end rescue LogStash::ShutdownSignal
return
rescue Twitter::Error::TooManyRequests => e
@logger.warn("Twitter too many requests error, sleeping for #{e.rate_limit.reset_in}s")
sleep(e.rate_limit.reset_in)
retry
rescue => e
@logger.warn("Twitter client error", :message => e.message, :exception => e, :backtrace => e.backtrace)
retry
end
end
|