Allow users to tell telegraf Agent not to include host tag

closes #848
This commit is contained in:
Cameron Sparr
2016-03-21 15:33:19 -06:00
parent 5917a42997
commit f543dbb42f
4 changed files with 25 additions and 10 deletions

View File

@@ -27,17 +27,19 @@ func NewAgent(config *config.Config) (*Agent, error) {
Config: config,
}
if a.Config.Agent.Hostname == "" {
hostname, err := os.Hostname()
if err != nil {
return nil, err
if !a.Config.Agent.OmitHostname {
if a.Config.Agent.Hostname == "" {
hostname, err := os.Hostname()
if err != nil {
return nil, err
}
a.Config.Agent.Hostname = hostname
}
a.Config.Agent.Hostname = hostname
config.Tags["host"] = a.Config.Agent.Hostname
}
config.Tags["host"] = a.Config.Agent.Hostname
return a, nil
}

View File

@@ -1,7 +1,6 @@
package agent
import (
"github.com/stretchr/testify/assert"
"testing"
"time"
@@ -11,8 +10,18 @@ import (
_ "github.com/influxdata/telegraf/plugins/inputs/all"
// needing to load the outputs
_ "github.com/influxdata/telegraf/plugins/outputs/all"
"github.com/stretchr/testify/assert"
)
func TestAgent_OmitHostname(t *testing.T) {
c := config.NewConfig()
c.Agent.OmitHostname = true
_, err := NewAgent(c)
assert.NoError(t, err)
assert.NotContains(t, c.Tags, "host")
}
func TestAgent_LoadPlugin(t *testing.T) {
c := config.NewConfig()
c.InputFilters = []string{"mysql"}