Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(outputs.groundwork): Add default appType as config option #11300

Merged
merged 2 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions plugins/outputs/groundwork/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 7 additions & 2 deletions plugins/outputs/groundwork/groundwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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")
}
Expand All @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -200,6 +204,7 @@ func init() {
GroupTag: "group",
ResourceTag: "host",
DefaultHost: "telegraf",
DefaultAppType: "TELEGRAF",
DefaultServiceState: string(transit.ServiceOk),
}
})
Expand Down
27 changes: 17 additions & 10 deletions plugins/outputs/groundwork/groundwork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
const (
defaultTestAgentID = "ec1676cc-583d-48ee-b035-7fb5ed0fcf88"
defaultHost = "telegraf"
defaultAppType = "TELEGRAF"
customAppType = "SYSLOG"
)

func TestWriteWithDefaults(t *testing.T) {
Expand All @@ -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)
Expand All @@ -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,
},
Expand Down Expand Up @@ -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)
Expand All @@ -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,
},
Expand All @@ -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"`
Expand Down