forked from newrelic/nri-flex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurl_api.go
53 lines (52 loc) · 8.36 KB
/
url_api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//nolint:lll
package fixtures
var URLTests = []struct {
Name string
Endpoint string
Port string
Payload string
Config string
ExpectedStdout string
}{
{
Name: "ECS Task State Change",
Endpoint: "ecstask",
Port: "8000",
Payload: `{"version":"0","id":"f8a990c2-2f93-4713-8b5d-d5b96f35bfd7","detail-type":"ECSTaskStateChange","source":"aws.ecs","account":"123456789012","time":"2016-09-15T21:57:35Z","region":"us-east-1","resources":["arn:aws:ecs:us-east-1:123456789012:task/3102878e-4af2-4b3c-b9c1-2556b95b2bbf"],"detail":{"clusterArn":"arn:aws:ecs:us-east-1:123456789012:cluster/cluster1","containerInstanceArn":"arn:aws:ecs:us-east-1:123456789012:container-instance/04f8c17d-29e0-4711-aa74-852654e477ec","containers":[{"containerArn":"arn:aws:ecs:us-east-1:123456789012:container/40a3b4bd-79ae-4472-a0be-816e5e0044a0","lastStatus":"PENDING","name":"test","taskArn":"arn:aws:ecs:us-east-1:123456789012:task/3102878e-4af2-4b3c-b9c1-2556b95b2bbf"},{"containerArn":"arn:aws:ecs:us-east-1:123456789012:container/50a3b4bd-eqre-4472-a0be-qeqwe","lastStatus":"PENDING","name":"abc","taskArn":"arn:aws:ecs:us-east-1:123456789012:task/3102878e-adfa-32-b9c1-qwerqe"}],"createdAt":"2016-09-15T21:30:33.3Z","desiredStatus":"RUNNING","lastStatus":"PENDING","overrides":{"containerOverrides":[{"command":["command1","command2"],"environment":[{"name":"env1","value":"value1"},{"name":"env2","value":"value2"}],"name":"test"}]},"updatedAt":"2016-09-15T21:30:33.3Z","taskArn":"arn:aws:ecs:us-east-1:123456789012:task/3102878e-4af2-4b3c-b9c1-2556b95b2bbf","taskDefinitionArn":"arn:aws:ecs:us-east-1:123456789012:task-definition/testTD:1","version":1}}`,
Config: `
---
integrations:
- name: nri-flex
config:
name: EcsTaskChangeSample
custom_attributes: # applies to all apis
myCustAttr: myCustVal
apis:
- event_type: EcsTaskChangeSample
url: http://127.0.0.1:8000/ecstask
custom_attributes:
nestedCustAttr: nestedCustVal # nested custom attributes specific to each api
add_attribute:
newAttr: myNewAttr_${detail.desiredStatus}
`,
ExpectedStdout: `{"name":"com.newrelic.nri-flex","protocol_version":"3","integration_version":"1.4.4","data":[{"metrics":[{"account":123456789012,"api.StatusCode":200,"containerArn":"arn:aws:ecs:us-east-1:123456789012:container/40a3b4bd-79ae-4472-a0be-816e5e0044a0","detail-type":"ECS Task State Change","detail.clusterArn":"arn:aws:ecs:us-east-1:123456789012:cluster/cluster1","detail.containerInstanceArn":"arn:aws:ecs:us-east-1:123456789012:container-instance/04f8c17d-29e0-4711-aa74-852654e477ec","detail.createdAt":"2016-09-15T21:30:33.3Z","detail.desiredStatus":"RUNNING","detail.lastStatus":"PENDING","detail.taskArn":"arn:aws:ecs:us-east-1:123456789012:task/3102878e-4af2-4b3c-b9c1-2556b95b2bbf","detail.taskDefinitionArn":"arn:aws:ecs:us-east-1:123456789012:task-definition/testTD:1","detail.updatedAt":"2016-09-15T21:30:33.3Z","detail.version":1,"event_type":"EcsTaskChangeSample","id":"f8a990c2-2f93-4713-8b5d-d5b96f35bfd7","integration_name":"com.newrelic.nri-flex","integration_version":"1.4.4","lastStatus":"PENDING","myCustAttr":"myCustVal","name":"test","nestedCustAttr":"nestedCustVal","newAttr":"myNewAttr_RUNNING","region":"us-east-1","source":"aws.ecs","taskArn":"arn:aws:ecs:us-east-1:123456789012:task/3102878e-4af2-4b3c-b9c1-2556b95b2bbf","time":"2016-09-15T21:57:35Z","version":0},{"account":123456789012,"api.StatusCode":200,"containerArn":"arn:aws:ecs:us-east-1:123456789012:container/50a3b4bd-eqre-4472-a0be-qeqwe","detail-type":"ECS Task State Change","detail.clusterArn":"arn:aws:ecs:us-east-1:123456789012:cluster/cluster1","detail.containerInstanceArn":"arn:aws:ecs:us-east-1:123456789012:container-instance/04f8c17d-29e0-4711-aa74-852654e477ec","detail.createdAt":"2016-09-15T21:30:33.3Z","detail.desiredStatus":"RUNNING","detail.lastStatus":"PENDING","detail.taskArn":"arn:aws:ecs:us-east-1:123456789012:task/3102878e-4af2-4b3c-b9c1-2556b95b2bbf","detail.taskDefinitionArn":"arn:aws:ecs:us-east-1:123456789012:task-definition/testTD:1","detail.updatedAt":"2016-09-15T21:30:33.3Z","detail.version":1,"event_type":"EcsTaskChangeSample","id":"f8a990c2-2f93-4713-8b5d-d5b96f35bfd7","integration_name":"com.newrelic.nri-flex","integration_version":"1.4.4","lastStatus":"PENDING","myCustAttr":"myCustVal","name":"abc","nestedCustAttr":"nestedCustVal","newAttr":"myNewAttr_RUNNING","region":"us-east-1","source":"aws.ecs","taskArn":"arn:aws:ecs:us-east-1:123456789012:task/3102878e-adfa-32-b9c1-qwerqe","time":"2016-09-15T21:57:35Z","version":0},{"account":123456789012,"api.StatusCode":200,"commandSamples":"[map[:command1] map[:command2]]","detail-type":"ECS Task State Change","detail.clusterArn":"arn:aws:ecs:us-east-1:123456789012:cluster/cluster1","detail.containerInstanceArn":"arn:aws:ecs:us-east-1:123456789012:container-instance/04f8c17d-29e0-4711-aa74-852654e477ec","detail.createdAt":"2016-09-15T21:30:33.3Z","detail.desiredStatus":"RUNNING","detail.lastStatus":"PENDING","detail.taskArn":"arn:aws:ecs:us-east-1:123456789012:task/3102878e-4af2-4b3c-b9c1-2556b95b2bbf","detail.taskDefinitionArn":"arn:aws:ecs:us-east-1:123456789012:task-definition/testTD:1","detail.updatedAt":"2016-09-15T21:30:33.3Z","detail.version":1,"environmentSamples":"[map[name:env1 value:value1] map[name:env2 value:value2]]","event_type":"EcsTaskChangeSample","id":"f8a990c2-2f93-4713-8b5d-d5b96f35bfd7","integration_name":"com.newrelic.nri-flex","integration_version":"1.4.4","myCustAttr":"myCustVal","name":"test","nestedCustAttr":"nestedCustVal","newAttr":"myNewAttr_RUNNING","region":"us-east-1","source":"aws.ecs","time":"2016-09-15T21:57:35Z","version":0},{"":"arn:aws:ecs:us-east-1:123456789012:task/3102878e-4af2-4b3c-b9c1-2556b95b2bbf","account":123456789012,"api.StatusCode":200,"detail-type":"ECS Task State Change","detail.clusterArn":"arn:aws:ecs:us-east-1:123456789012:cluster/cluster1","detail.containerInstanceArn":"arn:aws:ecs:us-east-1:123456789012:container-instance/04f8c17d-29e0-4711-aa74-852654e477ec","detail.createdAt":"2016-09-15T21:30:33.3Z","detail.desiredStatus":"RUNNING","detail.lastStatus":"PENDING","detail.taskArn":"arn:aws:ecs:us-east-1:123456789012:task/3102878e-4af2-4b3c-b9c1-2556b95b2bbf","detail.taskDefinitionArn":"arn:aws:ecs:us-east-1:123456789012:task-definition/testTD:1","detail.updatedAt":"2016-09-15T21:30:33.3Z","detail.version":1,"event_type":"EcsTaskChangeSample","id":"f8a990c2-2f93-4713-8b5d-d5b96f35bfd7","integration_name":"com.newrelic.nri-flex","integration_version":"1.4.4","myCustAttr":"myCustVal","nestedCustAttr":"nestedCustVal","newAttr":"myNewAttr_RUNNING","region":"us-east-1","source":"aws.ecs","time":"2016-09-15T21:57:35Z","version":0},{"event_type":"flexStatusSample","flex.Hostname":"rocky","flex.IntegrationVersion":"1.4.4","flex.counter.ConfigsProcessed":1,"flex.counter.EcsTaskChangeSample":4,"flex.counter.EventCount":4,"flex.counter.EventDropCount":0,"flex.counter.HttpRequests":1,"flex.time.elapsedMs":48,"flex.time.endMs":1654079094326,"flex.time.startMs":1654079094278}],"inventory":{},"events":[]}]}`,
},
{
Name: "API and convert spaces",
Endpoint: "leaderinfo",
Port: "8001",
Payload: `{"id":"eca0338f4ea31566","leader info":{"leader":"8a69d5f6b7814500","start time":"2014-10-24T13:15:51.186620747-07:00","uptime":"10m59.322358947s","abc":{"def":123,"hij":234}},"name":"node3"}`,
Config: `
---
integrations:
- name: nri-flex
config:
name: TestURL
apis:
- event_type: TestURL
url: http://127.0.0.1:8001/leaderinfo
convert_space: "_"
`,
ExpectedStdout: `{"name":"com.newrelic.nri-flex","protocol_version":"3","integration_version":"Unknown-SNAPSHOT","data":[{"metrics":[{"api.StatusCode":200,"event_type":"TestURL","id":"eca0338f4ea31566","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT","leader_info.abc.def":123,"leader_info.abc.hij":234,"leader_info.leader":"8a69d5f6b7814500","leader_info.start_time":"2014-10-24T13:15:51.186620747-07:00","leader_info.uptime":"10m59.322358947s","name":"node3"},{"event_type":"flexStatusSample","flex.Hostname":"d43822b4a811","flex.IntegrationVersion":"Unknown-SNAPSHOT","flex.counter.ConfigsProcessed":1,"flex.counter.EventCount":1,"flex.counter.EventDropCount":0,"flex.counter.HttpRequests":1,"flex.counter.TestURL":1,"flex.time.elapsedMs":7,"flex.time.endMs":1654770857187,"flex.time.startMs":1654770857180}],"inventory":{},"events":[]}]}`,
},
}