Skip to content

Commit

Permalink
Cleanup the structure for the fields that identify a beat
Browse files Browse the repository at this point in the history
* The `shipper` field is renamed to `beat.name`
* A `beat.hostname` field is added that contains the hostname
* A `beat.version` field is added that contains the version

Closes elastic#281.
  • Loading branch information
Tudor Golubenco committed Nov 10, 2015
1 parent a63f98a commit 1037d59
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ All notable changes to this project will be documented in this file based on the

### Backward Compatibility Breaks

### Bugfixes
* The `shipper` output field is renamed to `beat.name`. #285

### Bugfixes

### Added

* Added `beat.hostname` to contain the hostname where the Beat is running on as
returned by the operating system. #285
* Added `beat.version` to contain the version of the Beat. #285

### Deprecated

## [1.0.0-rc1](https://github.com/elastic/libbeat/compare/1.0.0-beta4...1.0.0-rc1)
Expand Down
2 changes: 1 addition & 1 deletion beat/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (b *Beat) LoadConfig() {

logp.Debug("beat", "Initializing output plugins")

if err := publisher.Publisher.Init(b.Name, b.Config.Output, b.Config.Shipper); err != nil {
if err := publisher.Publisher.Init(b.Name, b.Version, b.Config.Output, b.Config.Shipper); err != nil {
logp.Critical(err.Error())
os.Exit(1)
}
Expand Down
8 changes: 6 additions & 2 deletions publisher/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ func (p *preprocessor) onMessage(m message) {
continue
}

// add additional meta data
event["shipper"] = publisher.name
// add additional Beat meta data
event["beat"] = common.MapStr{
"name": publisher.name,
"hostname": publisher.hostname,
"version": publisher.version,
}
if len(publisher.tags) > 0 {
event["tags"] = publisher.tags
}
Expand Down
30 changes: 18 additions & 12 deletions publisher/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ type TransactionalEventPublisher interface {
}

type PublisherType struct {
name string
shipperName string // Shipper name as set in the configuration file
hostname string // Host name as returned by the operation system
name string // The shipperName if configured, the hostname otherwise
version string // The Beat version to include in the output docs
ipaddrs []string
tags []string
disabled bool
Expand Down Expand Up @@ -164,7 +167,8 @@ func (publisher *PublisherType) PublishTopology(params ...string) error {
}

func (publisher *PublisherType) Init(
beat string,
beatName string,
version string,
configs map[string]outputs.MothershipConfig,
shipper ShipperConfig,
) error {
Expand All @@ -180,9 +184,10 @@ func (publisher *PublisherType) Init(

publisher.wsOutput.Init()
publisher.wsPublisher.Init()
publisher.version = version

if !publisher.disabled {
plugins, err := outputs.InitOutputs(beat, configs, shipper.Topology_expire)
plugins, err := outputs.InitOutputs(beatName, configs, shipper.Topology_expire)
if err != nil {
return err
}
Expand Down Expand Up @@ -234,16 +239,17 @@ func (publisher *PublisherType) Init(
}
}

publisher.name = shipper.Name
if len(publisher.name) == 0 {
// use the hostname
publisher.name, err = os.Hostname()
if err != nil {
return err
}

logp.Info("No shipper name configured, using hostname '%s'", publisher.name)
publisher.shipperName = shipper.Name
publisher.hostname, err = os.Hostname()
if err != nil {
return err
}
if len(publisher.shipperName) > 0 {
publisher.name = publisher.shipperName
} else {
publisher.name = publisher.hostname
}
logp.Info("Publisher name: %s", publisher.name)

publisher.tags = shipper.Tags

Expand Down

0 comments on commit 1037d59

Please sign in to comment.