// Stream implements the router.LogAdapter interface.
func (a *LogstashAdapter) Stream(logstream chan *router.Message) {
	AwsAvailabilityZone := aws.AvailabilityZone()
	AwsRegion := aws.InstanceRegion()
	AwsInstanceId := aws.InstanceId()
	AwsInstanceType := aws.InstanceType()

	for m := range logstream {
		msg := LogstashMessage{
			Message:          m.Data,
			Name:             m.Container.Name,
			ID:               m.Container.ID,
			Image:            m.Container.Config.Image,
			Hostname:         m.Container.Config.Hostname,
			Env:              m.Container.Config.Env,
			Labels:           m.Container.Config.Labels,
			AvailabilityZone: AwsAvailabilityZone,
			InstanceId:       AwsInstanceId,
			InstanceType:     AwsInstanceType,
			Region:           AwsRegion,
		}
		js, err := json.Marshal(msg)
		if err != nil {
			log.Println("logstash:", err)
			continue
		}
		_, err = a.conn.Write(js)
		if err != nil {
			log.Println("logstash:", err)
			continue
		}
	}
}
Exemple #2
0
func (e EC2Tags) Get() (map[string]string, error) {
	tags := make(map[string]string)

	// Passing blank values here instructs the AWS library to look at the
	// current instances meta data for the security credentials.
	auth, err := aws.GetAuth("", "", "", time.Time{})
	if err != nil {
		return tags, errors.New(fmt.Sprintf("Error creating AWS authentication: %s", err.Error()))
	}

	// Find the current region and create a new EC2 connection
	region := aws.GetRegion(aws.InstanceRegion())
	ec2Client := ec2.New(auth, region)

	// Filter by the current machines instance-id
	filter := ec2.NewFilter()
	filter.Add("resource-id", aws.InstanceId())

	// Describe the tags for the current instance
	resp, err := ec2Client.DescribeTags(filter)
	if err != nil {
		return tags, errors.New(fmt.Sprintf("Error downloading tags: %s", err.Error()))
	}

	// Collect the tags
	for _, tag := range resp.Tags {
		tags[tag.Key] = tag.Value
	}

	return tags, nil
}