Class: Fluent::Plugin::CloudwatchLogsInput

Inherits:
Input
  • Object
show all
Defined in:
lib/fluent/plugin/in_cloudwatch_logs.rb

Constant Summary collapse

DEFAULT_STORAGE_TYPE =
'local'

Instance Method Summary collapse

Constructor Details

#initializeCloudwatchLogsInput

Returns a new instance of CloudwatchLogsInput.



57
58
59
60
61
62
# File 'lib/fluent/plugin/in_cloudwatch_logs.rb', line 57

def initialize
  super

  @parser = nil
  require 'aws-sdk-cloudwatchlogs'
end

Instance Method Details

#configure(conf) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/fluent/plugin/in_cloudwatch_logs.rb', line 64

def configure(conf)
  compat_parameters_convert(conf, :parser)
  super
  configure_parser(conf)

  @start_time = (Time.strptime(@start_time, @time_range_format).to_f * 1000).floor if @start_time
  @end_time = (Time.strptime(@end_time, @time_range_format).to_f * 1000).floor if @end_time
  if @start_time && @end_time && (@end_time < @start_time)
    raise Fluent::ConfigError, "end_time(#{@end_time}) should be greater than start_time(#{@start_time})."
  end
  @next_token_storage = storage_create(usage: 'store_next_tokens', conf: config, default_type: DEFAULT_STORAGE_TYPE)
end

#shutdownObject



126
127
128
129
# File 'lib/fluent/plugin/in_cloudwatch_logs.rb', line 126

def shutdown
  @finished = true
  super
end

#startObject



77
78
79
80
81
82
83
84
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
124
# File 'lib/fluent/plugin/in_cloudwatch_logs.rb', line 77

def start
  super
  options = {}
  options[:region] = @region if @region
  options[:endpoint] = @endpoint if @endpoint
  options[:http_proxy] = @http_proxy if @http_proxy

  if @aws_use_sts
    Aws.config[:region] = options[:region]
    credentials_options = {
      role_arn: @aws_sts_role_arn,
      role_session_name: @aws_sts_session_name
    }
    credentials_options[:sts_endpoint_url] = @aws_sts_endpoint_url if @aws_sts_endpoint_url
    if @region and @aws_sts_endpoint_url
      credentials_options[:client] = Aws::STS::Client.new(:region => @region, endpoint: @aws_sts_endpoint_url)
    elsif @region
      credentials_options[:client] = Aws::STS::Client.new(:region => @region)
    end
    options[:credentials] = Aws::AssumeRoleCredentials.new(credentials_options)
  elsif @web_identity_credentials
    c = @web_identity_credentials
    credentials_options = {}
    credentials_options[:role_arn] = c.role_arn
    credentials_options[:role_session_name] = c.role_session_name
    credentials_options[:web_identity_token_file] = c.web_identity_token_file
    credentials_options[:policy] = c.policy if c.policy
    credentials_options[:duration_seconds] = c.duration_seconds if c.duration_seconds
    if @region
      credentials_options[:client] = Aws::STS::Client.new(:region => @region)
    end
    options[:credentials] = Aws::AssumeRoleWebIdentityCredentials.new(credentials_options)
  else
    options[:credentials] = Aws::Credentials.new(@aws_key_id, @aws_sec_key) if @aws_key_id && @aws_sec_key
  end

  @logs = Aws::CloudWatchLogs::Client.new(options)

  @finished = false
  thread_create(:in_cloudwatch_logs_runner, &method(:run))

  @json_handler = case @json_handler
                  when :yajl
                    Yajl
                  when :json
                    JSON
                  end
end