-
Notifications
You must be signed in to change notification settings - Fork 5k
Add autodiscover for aws_ec2 #14823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kaiyan-sheng
merged 29 commits into
elastic:master
from
kaiyan-sheng:autodiscover_aws_ec2
Feb 6, 2020
Merged
Add autodiscover for aws_ec2 #14823
Changes from 18 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
3506757
Add autodiscover for aws_ec2
kaiyan-sheng 07469cd
Add aws_ec2 autodiscover
kaiyan-sheng dfc6269
test with logp.Debug
kaiyan-sheng 4d350ea
Merge remote-tracking branch 'upstream/master' into autodiscover_aws_ec2
kaiyan-sheng e5899f8
Add comment to DefaultConfig function
kaiyan-sheng fcdba2f
Merge remote-tracking branch 'upstream/master' into autodiscover_aws_ec2
kaiyan-sheng c042a08
Change ec2 metadata mapping
kaiyan-sheng 5662544
Update changelog
kaiyan-sheng a4e7f4f
Update changelog
kaiyan-sheng 580c13a
change instanceId to instanceID
kaiyan-sheng f06521d
Collect from all regions if regions is not specified
kaiyan-sheng 3a5fa25
Add GetRegions into aws_elb provider
kaiyan-sheng fef6fde
Add aws_ec2 provider into autodiscover doc
kaiyan-sheng 543e18a
update autodiscover doc
kaiyan-sheng 4605f1f
try to fix doc
kaiyan-sheng 556830a
Add unit tests
kaiyan-sheng 0f7afa6
add comments
kaiyan-sheng 6af9ca2
Fix metricbeat doc
kaiyan-sheng 672c42b
Make houndci happy
kaiyan-sheng cd459b4
Merge remote-tracking branch 'upstream/master' into autodiscover_aws_ec2
kaiyan-sheng 397dd24
Merge remote-tracking branch 'upstream/master' into autodiscover_aws_ec2
kaiyan-sheng 6d13377
Merge remote-tracking branch 'upstream/master' into autodiscover_aws_ec2
kaiyan-sheng 780a34a
Merge remote-tracking branch 'upstream/master' into autodiscover_aws_ec2
kaiyan-sheng 8e70d89
update changelog
kaiyan-sheng eb0d83f
update changelog
kaiyan-sheng 6505d1a
Merge remote-tracking branch 'upstream/master' into autodiscover_aws_ec2
kaiyan-sheng 48f121c
Add aws prefix to meta ec2
kaiyan-sheng 656379e
update field names from ec2 to aws.ec2
kaiyan-sheng 286d2ad
Add aws.ec2.* to autodiscover template
kaiyan-sheng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| {beatname_uc} supports templates for modules: | ||
|
|
||
| ["source","yaml",subs="attributes"] | ||
| ------------------------------------------------------------------------------------- | ||
| metricbeat.autodiscover: | ||
| providers: | ||
| - type: aws_ec2 | ||
| period: 1m | ||
| credential_profile_name: elastic-beats | ||
| templates: | ||
| - condition: | ||
| equals: | ||
| meta.ec2.tags.service: "mysql" | ||
kaiyan-sheng marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| config: | ||
| - module: mysql | ||
| metricsets: ["status", "galera_status"] | ||
| period: 10s | ||
| hosts: ["root:password@tcp(${data.meta.ec2.public.ip}:3306)/"] | ||
| username: root | ||
| password: password | ||
| ------------------------------------------------------------------------------------- | ||
|
|
||
| This autodiscover provider takes our standard AWS credentials options. | ||
| With this configuration, `mysql` metricbeat module will be launched for all EC2 | ||
| instances that have `service: mysql` as a tag. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
x-pack/libbeat/autodiscover/providers/aws/ec2/_meta/fields.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| - key: ec2_listener | ||
| title: "EC2 Listener" | ||
| description: > | ||
| AWS EC2 Listeners | ||
| short_config: false | ||
| release: experimental | ||
| fields: | ||
| - name: ec2_listener | ||
| type: group | ||
| description: > | ||
| Represents an AWS EC2 Listener, e.g. state of an EC2. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| // or more contributor license agreements. Licensed under the Elastic License; | ||
| // you may not use this file except in compliance with the Elastic License. | ||
|
|
||
| package ec2 | ||
|
|
||
| import ( | ||
| "github.com/aws/aws-sdk-go-v2/service/ec2" | ||
| "github.com/pkg/errors" | ||
|
|
||
| "github.com/elastic/beats/libbeat/common" | ||
| "github.com/elastic/beats/libbeat/logp" | ||
| awsauto "github.com/elastic/beats/x-pack/libbeat/autodiscover/providers/aws" | ||
| ) | ||
|
|
||
| type ec2Instance struct { | ||
| ec2Instance ec2.Instance | ||
| } | ||
|
|
||
| // toMap converts this ec2Instance into the form consumed as metadata in the autodiscovery process. | ||
| func (i *ec2Instance) toMap() common.MapStr { | ||
| architecture, err := i.ec2Instance.Architecture.MarshalValue() | ||
| if err != nil { | ||
| logp.Error(errors.Wrap(err, "MarshalValue failed for architecture: ")) | ||
| } | ||
|
|
||
| m := common.MapStr{ | ||
| "image": i.toImage(), | ||
| "vpc": i.toVpc(), | ||
| "subnet": i.toSubnet(), | ||
| "private": i.toPrivate(), | ||
| "public": i.toPublic(), | ||
| "monitoring": i.toMonitoringState(), | ||
| "kernel": i.toKernel(), | ||
| "state": i.stateMap(), | ||
| "architecture": architecture, | ||
| "root_device_name": awsauto.SafeString(i.ec2Instance.RootDeviceName), | ||
| } | ||
|
|
||
| for _, tag := range i.ec2Instance.Tags { | ||
| m.Put("tags."+awsauto.SafeString(tag.Key), awsauto.SafeString(tag.Value)) | ||
| } | ||
| return m | ||
| } | ||
|
|
||
| func (i *ec2Instance) instanceID() string { | ||
| return awsauto.SafeString(i.ec2Instance.InstanceId) | ||
| } | ||
|
|
||
| func (i *ec2Instance) toImage() common.MapStr { | ||
| m := common.MapStr{} | ||
| m["id"] = awsauto.SafeString(i.ec2Instance.ImageId) | ||
| return m | ||
| } | ||
|
|
||
| func (i *ec2Instance) toMonitoringState() common.MapStr { | ||
| monitoringState, err := i.ec2Instance.Monitoring.State.MarshalValue() | ||
| if err != nil { | ||
| logp.Error(errors.Wrap(err, "MarshalValue failed for monitoring state: ")) | ||
kaiyan-sheng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| m := common.MapStr{} | ||
| m["state"] = monitoringState | ||
| return m | ||
| } | ||
|
|
||
| func (i *ec2Instance) toPrivate() common.MapStr { | ||
| m := common.MapStr{} | ||
| m["ip"] = awsauto.SafeString(i.ec2Instance.PrivateIpAddress) | ||
| m["dns_name"] = awsauto.SafeString(i.ec2Instance.PrivateDnsName) | ||
| return m | ||
| } | ||
|
|
||
| func (i *ec2Instance) toPublic() common.MapStr { | ||
| m := common.MapStr{} | ||
| m["ip"] = awsauto.SafeString(i.ec2Instance.PublicIpAddress) | ||
| m["dns_name"] = awsauto.SafeString(i.ec2Instance.PublicDnsName) | ||
| return m | ||
| } | ||
|
|
||
| func (i *ec2Instance) toVpc() common.MapStr { | ||
| m := common.MapStr{} | ||
| m["id"] = awsauto.SafeString(i.ec2Instance.VpcId) | ||
| return m | ||
| } | ||
|
|
||
| func (i *ec2Instance) toSubnet() common.MapStr { | ||
| m := common.MapStr{} | ||
| m["id"] = awsauto.SafeString(i.ec2Instance.SubnetId) | ||
| return m | ||
| } | ||
|
|
||
| func (i *ec2Instance) toKernel() common.MapStr { | ||
| m := common.MapStr{} | ||
| m["id"] = awsauto.SafeString(i.ec2Instance.KernelId) | ||
| return m | ||
| } | ||
|
|
||
| func (i *ec2Instance) toCloudMap() common.MapStr { | ||
| m := common.MapStr{} | ||
| availabilityZone := awsauto.SafeString(i.ec2Instance.Placement.AvailabilityZone) | ||
| m["availability_zone"] = availabilityZone | ||
| m["provider"] = "aws" | ||
|
|
||
| // The region is just an AZ with the last character removed | ||
| m["region"] = availabilityZone[:len(availabilityZone)-1] | ||
|
|
||
| instance := common.MapStr{} | ||
| instance["id"] = i.instanceID() | ||
| m["instance"] = instance | ||
|
|
||
| instanceType, err := i.ec2Instance.InstanceType.MarshalValue() | ||
| if err != nil { | ||
| logp.Error(errors.Wrap(err, "MarshalValue failed for instance type: ")) | ||
| } | ||
kaiyan-sheng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| machine := common.MapStr{} | ||
| machine["type"] = instanceType | ||
| m["machine"] = machine | ||
| return m | ||
| } | ||
|
|
||
| // stateMap converts the State part of the ec2 struct into a friendlier map with 'reason' and 'code' fields. | ||
| func (i *ec2Instance) stateMap() (stateMap common.MapStr) { | ||
| state := i.ec2Instance.State | ||
| stateMap = common.MapStr{} | ||
| nameString, err := state.Name.MarshalValue() | ||
| if err != nil { | ||
| logp.Error(errors.Wrap(err, "MarshalValue failed for instance state name: ")) | ||
| } | ||
|
|
||
| stateMap["name"] = nameString | ||
| stateMap["code"] = state.Code | ||
| return stateMap | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.