diff --git a/plugins/outputs/groundwork/README.md b/plugins/outputs/groundwork/README.md index e11febc6b0d49..b75bc83603c56 100644 --- a/plugins/outputs/groundwork/README.md +++ b/plugins/outputs/groundwork/README.md @@ -19,6 +19,9 @@ GW8+ ## Username and password to access GroundWork API. username = "" password = "" + + ## Default application type to use in GroundWork client + # default_app_type = "TELEGRAF" ## Default display name for the host with services(metrics). # default_host = "telegraf" diff --git a/plugins/outputs/groundwork/groundwork.go b/plugins/outputs/groundwork/groundwork.go index ede4dbd5aa726..28a62353d5ecf 100644 --- a/plugins/outputs/groundwork/groundwork.go +++ b/plugins/outputs/groundwork/groundwork.go @@ -33,6 +33,7 @@ type Groundwork struct { AgentID string `toml:"agent_id"` Username string `toml:"username"` Password string `toml:"password"` + DefaultAppType string `toml:"default_app_type"` DefaultHost string `toml:"default_host"` DefaultServiceState string `toml:"default_service_state"` GroupTag string `toml:"group_tag"` @@ -58,6 +59,9 @@ func (g *Groundwork) Init() error { if g.Password == "" { return errors.New("no 'password' provided") } + if g.DefaultAppType == "" { + return errors.New("no 'default_app_type' provided") + } if g.DefaultHost == "" { return errors.New("no 'default_host' provided") } @@ -70,7 +74,7 @@ func (g *Groundwork) Init() error { g.client = clients.GWClient{ AppName: "telegraf", - AppType: "TELEGRAF", + AppType: g.DefaultAppType, GWConnection: &clients.GWConnection{ HostName: g.Server, UserName: g.Username, @@ -172,7 +176,7 @@ func (g *Groundwork) Write(metrics []telegraf.Metric) error { } requestJSON, err := json.Marshal(transit.ResourcesWithServicesRequest{ Context: &transit.TracerContext{ - AppType: "TELEGRAF", + AppType: g.DefaultAppType, AgentID: g.AgentID, TraceToken: traceToken, TimeStamp: transit.NewTimestamp(), @@ -200,6 +204,7 @@ func init() { GroupTag: "group", ResourceTag: "host", DefaultHost: "telegraf", + DefaultAppType: "TELEGRAF", DefaultServiceState: string(transit.ServiceOk), } }) diff --git a/plugins/outputs/groundwork/groundwork_test.go b/plugins/outputs/groundwork/groundwork_test.go index 28d5766da2195..86b0870e17a11 100644 --- a/plugins/outputs/groundwork/groundwork_test.go +++ b/plugins/outputs/groundwork/groundwork_test.go @@ -18,6 +18,8 @@ import ( const ( defaultTestAgentID = "ec1676cc-583d-48ee-b035-7fb5ed0fcf88" defaultHost = "telegraf" + defaultAppType = "TELEGRAF" + customAppType = "SYSLOG" ) func TestWriteWithDefaults(t *testing.T) { @@ -36,6 +38,7 @@ func TestWriteWithDefaults(t *testing.T) { // Check if server gets valid metrics object require.Equal(t, defaultTestAgentID, obj.Context.AgentID) + require.Equal(t, customAppType, obj.Context.AppType) require.Equal(t, defaultHost, obj.Resources[0].Name) require.Equal(t, "IntMetric", obj.Resources[0].Services[0].Name) require.Equal(t, int64(42), obj.Resources[0].Services[0].Metrics[0].Value.IntegerValue) @@ -46,12 +49,13 @@ func TestWriteWithDefaults(t *testing.T) { })) i := Groundwork{ - Server: server.URL, - AgentID: defaultTestAgentID, - DefaultHost: defaultHost, + Server: server.URL, + AgentID: defaultTestAgentID, + DefaultHost: defaultHost, + DefaultAppType: customAppType, client: clients.GWClient{ AppName: "telegraf", - AppType: "TELEGRAF", + AppType: customAppType, GWConnection: &clients.GWConnection{ HostName: server.URL, }, @@ -82,6 +86,7 @@ func TestWriteWithTags(t *testing.T) { // Check if server gets valid metrics object require.Equal(t, defaultTestAgentID, obj.Context.AgentID) + require.Equal(t, defaultAppType, obj.Context.AppType) require.Equal(t, "Host01", obj.Resources[0].Name) require.Equal(t, "FloatMetric", obj.Resources[0].Services[0].Name) require.Equal(t, 1.0, obj.Resources[0].Services[0].Metrics[0].Value.DoubleValue) @@ -93,14 +98,15 @@ func TestWriteWithTags(t *testing.T) { })) i := Groundwork{ - Server: server.URL, - AgentID: defaultTestAgentID, - DefaultHost: defaultHost, - GroupTag: "group", - ResourceTag: "host", + Server: server.URL, + AgentID: defaultTestAgentID, + DefaultHost: defaultHost, + DefaultAppType: defaultAppType, + GroupTag: "group", + ResourceTag: "host", client: clients.GWClient{ AppName: "telegraf", - AppType: "TELEGRAF", + AppType: defaultAppType, GWConnection: &clients.GWConnection{ HostName: server.URL, }, @@ -116,6 +122,7 @@ func TestWriteWithTags(t *testing.T) { type groundworkObject struct { Context struct { AgentID string `json:"agentId"` + AppType string `json:"appType"` } `json:"context"` Resources []struct { Name string `json:"name"`