-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add Cloud Foundry Processor (#16621) * Add the cloudfoundry metadata processor. * Fix testing and documentation. * Add changelog entry. * Run mage fmt. * Fix docs. * Update asciidoc to set role=xpack and experimental. * Switch from cf to cloudfoundry for event key. Improve some event fields. Fix changelog, and update asciidoc to reference the field that is read for application ID. * Update fields.yml from cf to cloudfoundry. (cherry picked from commit 1e0c818) * Fix changelog.
- Loading branch information
1 parent
17b1cb3
commit a621de1
Showing
9 changed files
with
382 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
39 changes: 39 additions & 0 deletions
39
x-pack/libbeat/processors/add_cloudfoundry_metadata/_meta/fields.yml
This file contains 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,39 @@ | ||
- key: cloudfoundry | ||
title: Cloud Foundry | ||
description: > | ||
Cloud Foundry information collected from Cloud Foundry. | ||
short_config: false | ||
anchor: cloudfoundry-processor | ||
fields: | ||
- name: cloudfoundry | ||
type: group | ||
fields: | ||
- name: app.id | ||
type: keyword | ||
description: > | ||
Cloud Foundry application ID | ||
- name: app.name | ||
type: keyword | ||
description: > | ||
Cloud Foundry application name | ||
- name: space.id | ||
type: keyword | ||
description: > | ||
Cloud Foundry space name | ||
- name: space.name | ||
type: keyword | ||
description: > | ||
Cloud Foundry space name | ||
- name: org.id | ||
type: keyword | ||
description: > | ||
Cloud Foundry organization ID | ||
- name: org.name | ||
type: keyword | ||
description: > | ||
Cloud Foundry organization name |
99 changes: 99 additions & 0 deletions
99
x-pack/libbeat/processors/add_cloudfoundry_metadata/add_cloudfoundry_metadata.go
This file contains 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,99 @@ | ||
// 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. | ||
|
||
// +build linux darwin windows | ||
|
||
package add_cloudfoundry_metadata | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/elastic/beats/x-pack/libbeat/common/cloudfoundry" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/elastic/beats/libbeat/beat" | ||
"github.com/elastic/beats/libbeat/common" | ||
"github.com/elastic/beats/libbeat/logp" | ||
"github.com/elastic/beats/libbeat/processors" | ||
) | ||
|
||
const ( | ||
processorName = "add_cloudfoundry_metadata" | ||
) | ||
|
||
func init() { | ||
processors.RegisterPlugin(processorName, New) | ||
} | ||
|
||
type addCloudFoundryMetadata struct { | ||
log *logp.Logger | ||
client cloudfoundry.Client | ||
} | ||
|
||
const selector = "add_cloudfoundry_metadata" | ||
|
||
// New constructs a new add_cloudfoundry_metadata processor. | ||
func New(cfg *common.Config) (processors.Processor, error) { | ||
var config cloudfoundry.Config | ||
if err := cfg.Unpack(&config); err != nil { | ||
return nil, errors.Wrapf(err, "fail to unpack the %v configuration", processorName) | ||
} | ||
|
||
log := logp.NewLogger(selector) | ||
hub := cloudfoundry.NewHub(&config, "add_cloudfoundry_metadata", log) | ||
client, err := hub.Client() | ||
if err != nil { | ||
log.Debugf("%s: failed to created cloudfoundry client: %+v", processorName, err) | ||
} | ||
|
||
// Janitor run every 5 minutes to clean up the client cache. | ||
client.StartJanitor(5 * time.Minute) | ||
|
||
return &addCloudFoundryMetadata{ | ||
log: log, | ||
client: client, | ||
}, nil | ||
} | ||
|
||
func (d *addCloudFoundryMetadata) Run(event *beat.Event) (*beat.Event, error) { | ||
if d.client == nil { | ||
return event, nil | ||
} | ||
valI, err := event.GetValue("cloudfoundry.app.id") | ||
if err != nil { | ||
// doesn't have the required cf.app.id value to add more information | ||
return event, nil | ||
} | ||
val, _ := valI.(string) | ||
if val == "" { | ||
// wrong type or not set | ||
return event, nil | ||
} | ||
app, err := d.client.GetAppByGuid(val) | ||
if err != nil { | ||
d.log.Warnf("failed to get application info for GUID(%s): %v", val, err) | ||
return event, nil | ||
} | ||
event.Fields.DeepUpdate(common.MapStr{ | ||
"cloudfoundry": common.MapStr{ | ||
"app": common.MapStr{ | ||
"name": app.Name, | ||
}, | ||
"space": common.MapStr{ | ||
"id": app.SpaceData.Meta.Guid, | ||
"name": app.SpaceData.Entity.Name, | ||
}, | ||
"org": common.MapStr{ | ||
"id": app.SpaceData.Entity.OrgData.Meta.Guid, | ||
"name": app.SpaceData.Entity.OrgData.Entity.Name, | ||
}, | ||
}, | ||
}) | ||
return event, nil | ||
} | ||
|
||
func (d *addCloudFoundryMetadata) String() string { | ||
return processorName | ||
} |
Oops, something went wrong.