diff --git a/plugins/outputs/appdynamics/README.md b/plugins/outputs/appdynamics/README.md index e55eb0a07..14f8d479e 100644 --- a/plugins/outputs/appdynamics/README.md +++ b/plugins/outputs/appdynamics/README.md @@ -6,7 +6,7 @@ via raw TCP. ## Configuration: ```toml - ## controller information tor connect and retrieve tier-id value + ## controller information to connect and retrieve tier-id value controllerTierURL = "https://foo.saas.appdynamics.com/controller/rest/applications/bar/tiers/baz?output=JSON" controllerUserName = "apiuser" controllerPassword = "apipass" @@ -14,4 +14,4 @@ via raw TCP. ## |Component:%d| gets transformed into |Component:id| during initialization - where 'id' is a tier-id for ## this controller application/tier combination agentURL = "http://localhost:8293/machineagent/metrics?name=Server|Component:%d|Custom+Metrics|" -``` \ No newline at end of file +``` diff --git a/plugins/outputs/appdynamics/appdynamics.go b/plugins/outputs/appdynamics/appdynamics.go index 85d811785..3f292e31b 100644 --- a/plugins/outputs/appdynamics/appdynamics.go +++ b/plugins/outputs/appdynamics/appdynamics.go @@ -1,13 +1,13 @@ -package influxdb +package appdynamics import ( "encoding/json" "fmt" "github.com/influxdata/telegraf" + "github.com/influxdata/telegraf/plugins/outputs" "io/ioutil" "log" "net/http" - "github.com/influxdata/telegraf/plugins/outputs" ) var sampleConfig = ` @@ -23,9 +23,9 @@ var sampleConfig = ` type Appdynamics struct { // Controller values for retrieving tier-id from the controller - ControllerTierURL string - ControllerUserName string - ControllerPassword string + ControllerTierURL string + ControllerUserName string + ControllerPassword string // Machine agent URL format string AgentURL string @@ -35,7 +35,7 @@ type Appdynamics struct { } // Close - There is nothing to close here, but need to comply with output interface -func (a *Appdynamics) Close() error{ +func (a *Appdynamics) Close() error { return nil } @@ -85,7 +85,7 @@ func (a *Appdynamics) getTierId() (int64, error) { return 0, err } if len(tiers) != 1 { - fmt.Println("Invalid reply: ", tiers) + return 0, fmt.Errorf("Invalid reply: %v", tiers) } return tiers[0].Id, nil @@ -105,10 +105,9 @@ func (a *Appdynamics) Write(metrics []telegraf.Metric) error { default: appdType = "sum" } - url := a.AgentURL + metric.Name() + fmt.Sprintf("&value=%v&type=%s", metric.Fields()["value"], appdType) - fmt.Printf("Calling %s ...\n", url) - _, err := http.Get(url) - if err != nil { + url := fmt.Sprintf("%s%s&value=%v&type=%s", a.AgentURL, metric.Name(), metric.Fields()["value"], appdType) + log.Printf("Calling %s ...\n", url) + if _, err := http.Post(url, "", nil); err != nil { log.Println("ERROR: " + err.Error()) } } diff --git a/plugins/outputs/appdynamics/appdynamics_test.go b/plugins/outputs/appdynamics/appdynamics_test.go index 90ef9384e..c8a4fbe42 100644 --- a/plugins/outputs/appdynamics/appdynamics_test.go +++ b/plugins/outputs/appdynamics/appdynamics_test.go @@ -1,4 +1,4 @@ -package influxdb +package appdynamics import ( "fmt" @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/assert" ) -// TestAppdynamicsError - attemp to initialize Appdynamics with invalid controller user name value +// TestAppdynamicsError - attempt to initialize Appdynamics with invalid controller user name value func TestAppdynamicsError(t *testing.T) { a := Appdynamics{ ControllerTierURL: "https://foo.saas.appdynamics.com/controller/rest/applications/bar/tiers/baz?output=JSON", @@ -18,6 +18,7 @@ func TestAppdynamicsError(t *testing.T) { ControllerPassword: "pass123", AgentURL: "http://localhost:8293/machineagent/metrics?name=Server|Component:%d|Custom+Metrics|", } + assert.Error(t, a.Connect()) } @@ -41,18 +42,20 @@ func TestAppdynamicsOK(t *testing.T) { ControllerPassword: "pass123", AgentURL: "http://localhost:8293/machineagent/metrics?name=Server|Component:%d|Custom+Metrics|", } + // this error is expected since we are not connecting to actual controller assert.Error(t, a.Connect()) // reset agent url value with '123' tier id a.AgentURL = fmt.Sprintf(a.AgentURL, 123) assert.Equal(t, a.AgentURL, "http://localhost:8293/machineagent/metrics?name=Server|Component:123|Custom+Metrics|") + tm := time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC) // counter type - appd-type: sum m, _ := telegraf.NewMetric( "foo", - map[string]string{"metrcic_type": "counter"}, + map[string]string{"metric_type": "counter"}, map[string]interface{}{"value": float64(1.23)}, - time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC), + tm, ) metrics := []telegraf.Metric{m} assert.NoError(t, a.Write(metrics)) @@ -64,7 +67,7 @@ func TestAppdynamicsOK(t *testing.T) { "foo", map[string]string{"metric_type": "gauge"}, map[string]interface{}{"value": float64(4.56)}, - time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC), + tm, ) metrics = []telegraf.Metric{m} assert.NoError(t, a.Write(metrics)) @@ -74,9 +77,9 @@ func TestAppdynamicsOK(t *testing.T) { // other type - defaults to appd-type: sum m, _ = telegraf.NewMetric( "foo", - map[string]string{"metric_type": "bar"}, + map[string]string{"metric_type": "other"}, map[string]interface{}{"value": float64(7.89)}, - time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC), + tm, ) metrics = []telegraf.Metric{m} assert.NoError(t, a.Write(metrics))