class Fluent::Plugin::ZulipOutput
Constants
- ZULIP_CONTENT_MAX_SIZE
- ZULIP_SUBJECT_MAX_SIZE
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_zulip.rb, line 55 def configure(conf) super case @message_type when :private raise Fluent::ConfigError, "recipients are required when private message" if @recipients.empty? when :stream raise Fluent::ConfigError, "stream_name is required when stream message" unless @stream_name end if @subject && @subject_key raise Fluent::ConfigError, "subject and subject_key are exclusive with each other" end if @subject && @subject.bytesize > ZULIP_SUBJECT_MAX_SIZE raise Fluent::ConfigError, "subject max length is #{ZULIP_SUBJECT_MAX_SIZE}" end @client = Zulip::Client.new(site: @site, username: @bot_email_address, api_key: @bot_api_key, ssl: { verify: @verify_ssl }) end
multi_workers_ready?()
click to toggle source
# File lib/fluent/plugin/out_zulip.rb, line 51 def multi_workers_ready? true end
process(tag, es)
click to toggle source
# File lib/fluent/plugin/out_zulip.rb, line 79 def process(tag, es) es.each do |time, record| process_record(tag, time, record) end end
process_record(tag, time, record)
click to toggle source
# File lib/fluent/plugin/out_zulip.rb, line 92 def process_record(tag, time, record) loop do response = send_message(tag, time, record) case when response.success? log.trace(response.body) when response.status == 429 interval = response.headers["X-RateLimit-Reset"].to_i - Time.now.to_i log.info("Sleeping: #{interval} sec") sleep(interval) next else log.error(status: response.status, message: response.reason_phrase, body: response.body) end log.debug(response) break end end
send_message(tag, time, record)
click to toggle source
# File lib/fluent/plugin/out_zulip.rb, line 113 def send_message(tag, time, record) case @message_type when :stream to = @stream_name subject = @subject || record[@subject_key] @client.send_public_message(to: to, subject: subject, content: record[@content_key]) when :private to = @recipients @client.send_private_message(to: to, content: record[@content_key]) end end
write(chunk)
click to toggle source
# File lib/fluent/plugin/out_zulip.rb, line 85 def write(chunk) tag = chunk.metadata.tag chunk.each do |time, record| process_record(tag, time, record) end end