Sha256: 64eaa78739bcad91115238f3c895c3545c954043a3bcab1bb7299b9f39b4e66a

Contents?: true

Size: 988 Bytes

Versions: 1

Compression:

Stored size: 988 Bytes

Contents

require 'docker'

module Fluent
  class Fluent::DockerHostname < Filter
    Fluent::Plugin.register_filter('docker_hostname', self)

    config_param :docker_url, :string,  :default => 'unix:///var/run/docker.sock'

    def configure(conf)
      super

      Docker.url = @docker_url
      @containerid_hash = Hash.new
    end

    def get_appname(container_id)
      Docker::Container.all.each do |obj|
        container_json = obj.json

        if container_id.to_s == container_json['Id'].to_s
          config = container_json['Config']

          return config['Hostname']
        end
      end

      return nil
    end

    def filter_stream(tag, es)
      new_es = MultiEventStream.new

      container_id = tag.match(/(\w{64})/)
      @containerid_hash[container_id] ||= get_appname(container_id)

      es.each {|time, record|
        record[:container_hostname] = @containerid_hash[container_id]
        new_es.add(time, record)
      }

      return new_es
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-docker_hostname-0.1.4 lib/fluent/plugin/filter_docker_hostname.rb