fluent-plugin-ec2-metadata 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 925b152c581833ade6515063ca0bb368ea020957
4
- data.tar.gz: e1debc52e316b0f0dcfdbdbf61a65319ba84ded4
3
+ metadata.gz: e72a76bfeb7db2cffcc55ef8125cbf727e39452c
4
+ data.tar.gz: 262dfff134c0f1c6e2c70f75f3952e44dfc0c07e
5
5
  SHA512:
6
- metadata.gz: 0d4e83b16d0836ed17b23aa66103dd333e960bab0e689db0383d81f9ff368ce33b66cf80cab357ee450b434acffd5f00a957a685d442bd9885b058d73d1009b7
7
- data.tar.gz: 8b9b4acf8189439c7c528d1aeb66d6ff0c8cccd387154059b6d1c1bd0ff59e0bb4f04562a6281f79271f3bea1642ca77eb52a2fa15b686f692e6e7cdbf7270ce
6
+ metadata.gz: 7707d4060fe19458ffda77ea95af0d65a9c7e01166f781d5c93cacb5e30641221c536da2edb0b60664090bdf24470d6f29d2374459250100dd6bab4e70935e0c
7
+ data.tar.gz: 52734d6d7fad767437c2b40ecad7664cb187997b4954d6e56bd5d010952ac7f89886fe8a26b8bab091c7a9d21e25b2878a262b6a43c82f520a922393cce7c372
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # fluent-plugin-ec2-metadata, a plugin for [Fluentd](http://fluentd.org)
1
+ # fluent-plugin-ec2-metadata
2
2
 
3
- Fluentd plugin to add ec2 metadata fields to a event record
3
+ [Fluentd](http://fluentd.org) plugin to add ec2 metadata fields to a event record
4
4
 
5
5
  ## Installation
6
6
  Use RubyGems:
@@ -56,11 +56,12 @@ The following placeholders are always available:
56
56
  * ${instance_type} instance type
57
57
  * ${availability_zone} availability zone
58
58
  * ${region} region
59
+ * ${mac} MAC address
60
+ * ${vpc_id} vpc id
61
+ * ${subnet_id} subnet id
59
62
 
60
63
  The followings are available when you define `aws_key_id` and `aws_sec_key`(or define IAM Policy):
61
64
 
62
- * ${vpc_id} vpc id
63
- * ${subnet_id} subnet id
64
65
  * ${tagset_xxx} EC2 tag (e.g. tagset_name is replaced by the value of Key = Name)
65
66
 
66
67
  The following is an example for a minimal IAM policy needed to ReadOnlyAccess to EC2.
@@ -97,8 +98,8 @@ The following is an example for a minimal IAM policy needed to ReadOnlyAccess to
97
98
  }
98
99
  ```
99
100
 
100
- Refer to the {AWS documentation}[http://docs.aws.amazon.com/IAM/latest/UserGuide/ExampleIAMPolicies.html] for example policies.
101
- Using {IAM roles}[http://docs.aws.amazon.com/IAM/latest/UserGuide/WorkingWithRoles.html] with a properly configured IAM policy are preferred over embedding access keys on EC2 instances.
101
+ Refer to the [AWS documentation](http://docs.aws.amazon.com/IAM/latest/UserGuide/ExampleIAMPolicies.html) for example policies.
102
+ Using [IAM roles](http://docs.aws.amazon.com/IAM/latest/UserGuide/WorkingWithRoles.html) with a properly configured IAM policy are preferred over embedding access keys on EC2 instances.
102
103
 
103
104
  ## Contributing
104
105
 
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fluent-plugin-ec2-metadata"
7
- spec.version = "0.0.5"
7
+ spec.version = "0.0.6"
8
8
  spec.authors = ["SAKAMOTO Takumi"]
9
9
  spec.email = ["takumi.saka@gmail.com"]
10
10
  spec.description = %q{Fluentd output plugin to add ec2 metadata fields to a event record}
@@ -5,7 +5,6 @@ module Fluent
5
5
  def initialize
6
6
  super
7
7
  require 'net/http'
8
- require 'aws-sdk-v1'
9
8
  end
10
9
 
11
10
  config_param :output_tag, :string
@@ -33,23 +32,28 @@ module Fluent
33
32
  @ec2_metadata['instance_type'] = get_metadata('instance-type')
34
33
  @ec2_metadata['availability_zone'] = get_metadata('placement/availability-zone')
35
34
  @ec2_metadata['region'] = @ec2_metadata['availability_zone'].chop
35
+ @ec2_metadata['mac'] = get_metadata('mac')
36
+ @ec2_metadata['vpc_id'] = get_metadata("network/interfaces/macs/#{@ec2_metadata['mac']}/vpc-id")
37
+ @ec2_metadata['subnet_id'] = get_metadata("network/interfaces/macs/#{@ec2_metadata['mac']}/subnet-id")
38
+
39
+ # get tags
40
+ if @map.values.any? { |v| v.match(/^\${tagset_/) }
41
+ require 'aws-sdk-v1'
42
+
43
+ if @aws_key_id and @aws_sec_key then
44
+ AWS.config(access_key_id: @aws_key_id, secret_access_key: @aws_sec_key, region: @ec2_metadata['region'])
45
+ else
46
+ AWS.config(region: @ec2_metadata['region'])
47
+ end
36
48
 
37
- if @aws_key_id and @aws_sec_key then
38
- #require 'aws-sdk'
39
- AWS.config(access_key_id: @aws_key_id, secret_access_key: @aws_sec_key, region: @ec2_metadata['region'])
40
- else
41
- AWS.config(region: @ec2_metadata['region'])
42
- end
43
49
  response = AWS.ec2.client.describe_instances( { :instance_ids => [ @ec2_metadata['instance_id'] ] })
44
50
  instance = response[:reservation_set].first[:instances_set].first
45
51
  raise Fluent::ConfigError, "ec2-metadata: failed to get instance data #{response.pretty_inspect}" if instance.nil?
46
52
 
47
- @ec2_metadata['vpc_id'] = instance[:vpc_id]
48
- @ec2_metadata['subnet_id'] = instance[:subnet_id]
49
-
50
53
  instance[:tag_set].each { |tag|
51
54
  @ec2_metadata["tagset_#{tag[:key].downcase}"] = tag[:value]
52
55
  }
56
+ end
53
57
  end
54
58
 
55
59
  def emit(tag, es, chain)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-ec2-metadata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - SAKAMOTO Takumi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-27 00:00:00.000000000 Z
11
+ date: 2015-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake