#
# Cookbook:: irrigate-fluentd
# Recipe:: cloudwatch
#
# Copyright: The Orchard
#

if node['fluentd']['cloudwatch_logs'] && !node['fluentd']['cloudwatch_logs'].empty?
  node['fluentd']['cloudwatch_logs'].each_pair do |group, info|
    td_agent_source group.tr('/', '_') do
      type 'cloudwatch_logs'
      tag "cloudwatch.#{info['tag']}"
      parameters(
        log_group_name: group,
        log_stream_name: info['log_stream'],
        state_file: "#{node['fluentd']['state_path']}/#{group.tr('/', '_')}.state",
        use_log_stream_name_prefix: info['log_stream_as_prefix'],
        region: node['fluentd']['aws_region'],
        format: '/(?<message>.+)/'
      )
    end

    td_agent_filter group.tr('/', '_') do
      type 'record_transformer'
      tag "cloudwatch.#{info['tag']}"
      parameters(
        record:
        [
          {
            log_type: 'cloudwatch',
            app_name: info['tag'],
          },
        ]
      )
    end
  end
end

# vim: ts=2 sw=2 sts=2 et
