fixtures

package
v1.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2023 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CommandTests = []struct {
	Name           string
	Config         string
	ExpectedStdout string
}{

	{
		Name: "Linux file list of the /etc/apt directory with specified shell",
		Config: `
---
integrations:
  - name: nri-flex
    interval: 300s
    config:
      name: LinuxFileList
      apis:
        - event_type: LinuxFileList
          commands:
            - run: ls -1 /etc/apt/
              shell: sh
              split: horizontal
              set_header: [FileName]
              regex_match: true
              split_by: (\S+)
`,
		ExpectedStdout: `{"name":"com.newrelic.nri-flex","protocol_version":"3","integration_version":"Unknown-SNAPSHOT","data":[{"metrics":[{"FileName":"apt.conf.d","event_type":"LinuxFileList","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"FileName":"auth.conf.d","event_type":"LinuxFileList","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"FileName":"keyrings","event_type":"LinuxFileList","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"FileName":"preferences.d","event_type":"LinuxFileList","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"FileName":"sources.list","event_type":"LinuxFileList","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"FileName":"sources.list.d","event_type":"LinuxFileList","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"FileName":"trusted.gpg.d","event_type":"LinuxFileList","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"event_type":"flexStatusSample","flex.Hostname":"551daa101010","flex.IntegrationVersion":"Unknown-SNAPSHOT","flex.counter.ConfigsProcessed":1,"flex.counter.EventCount":7,"flex.counter.EventDropCount":0,"flex.counter.LinuxFileList":7,"flex.time.elapsedMs":50,"flex.time.endMs":1654007859822,"flex.time.startMs":1654007859772}],"inventory":{},"events":[]}]}`,
	},
	{
		Name: "Linux file list of the /etc/apt directory removing header",
		Config: `
---
integrations:
  - name: nri-flex
    interval: 300s
    config:
      name: LinuxFileList
      apis:
        - event_type: LinuxFileList
          commands:
            - run: ls -l --time-style="+%Y" /etc/apt/
              split: horizontal
              set_header: [Permissions,Type,Owner,Group,Size,Year,FileName]
              row_start: 1
              regex_match: false
              split_by: \s+
`,
		ExpectedStdout: `{"name":"com.newrelic.nri-flex","protocol_version":"3","integration_version":"Unknown-SNAPSHOT","data":[{"metrics":[{"FileName":"apt.conf.d","Group":"root","Owner":"root","Permissions":"drwxr-xr-x","Size":4096,"Type":2,"Year":2022,"event_type":"LinuxFileList","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"FileName":"auth.conf.d","Group":"root","Owner":"root","Permissions":"drwxr-xr-x","Size":4096,"Type":2,"Year":2022,"event_type":"LinuxFileList","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"FileName":"keyrings","Group":"root","Owner":"root","Permissions":"drwxr-xr-x","Size":4096,"Type":2,"Year":2022,"event_type":"LinuxFileList","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"FileName":"preferences.d","Group":"root","Owner":"root","Permissions":"drwxr-xr-x","Size":4096,"Type":2,"Year":2022,"event_type":"LinuxFileList","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"FileName":"sources.list","Group":"root","Owner":"root","Permissions":"-rw-r--r--","Size":2477,"Type":1,"Year":2022,"event_type":"LinuxFileList","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"FileName":"sources.list.d","Group":"root","Owner":"root","Permissions":"drwxr-xr-x","Size":4096,"Type":2,"Year":2022,"event_type":"LinuxFileList","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"FileName":"trusted.gpg.d","Group":"root","Owner":"root","Permissions":"drwxr-xr-x","Size":4096,"Type":2,"Year":2022,"event_type":"LinuxFileList","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"event_type":"flexStatusSample","flex.Hostname":"192a822e9207","flex.IntegrationVersion":"Unknown-SNAPSHOT","flex.counter.ConfigsProcessed":1,"flex.counter.EventCount":7,"flex.counter.EventDropCount":0,"flex.counter.LinuxFileList":7,"flex.time.elapsedMs":49,"flex.time.endMs":1668597855728,"flex.time.startMs":1908597855679}],"inventory":{},"events":[]}]}`,
	},
	{
		Name: "Linux file list of the /etc/apt directory filtering lines",
		Config: `
---
integrations:
  - name: nri-flex
    interval: 300s
    config:
      name: LinuxFileList
      apis:
        - event_type: LinuxFileList
          commands:
            - run: ls -l --time-style="+%Y" /etc/apt/
              split: horizontal
              set_header: [Permissions,Type,Owner,Group,Size,Year,FileName]
              line_start: 1
              line_end: 3
              regex_match: false
              split_by: \s+
`,
		ExpectedStdout: `{"name":"com.newrelic.nri-flex","protocol_version":"3","integration_version":"Unknown-SNAPSHOT","data":[{"metrics":[{"FileName":"apt.conf.d","Group":"root","Owner":"root","Permissions":"drwxr-xr-x","Size":4096,"Type":2,"Year":2022,"event_type":"LinuxFileList","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"FileName":"auth.conf.d","Group":"root","Owner":"root","Permissions":"drwxr-xr-x","Size":4096,"Type":2,"Year":2022,"event_type":"LinuxFileList","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"event_type":"flexStatusSample","flex.Hostname":"952eb193a212","flex.IntegrationVersion":"Unknown-SNAPSHOT","flex.counter.ConfigsProcessed":1,"flex.counter.EventCount":2,"flex.counter.EventDropCount":0,"flex.counter.LinuxFileList":2,"flex.time.elapsedMs":50,"flex.time.endMs":1666020132212,"flex.time.startMs":1666020132162}],"inventory":{},"events":[]}]}`,
	},
	{
		Name: "Linux filesystem usage",
		Config: `
---
integrations:
  - name: nri-flex
    # interval: 30s
    config:
      name: linuxFilesystem
      apis:
        - name: linuxFilesystem
          commands:
            - run: df -PT -B1 -x tmpfs -x xfs -x vxfs -x btrfs -x ext -x ext2 -x ext3 -x ext4 -x hfs
              split: horizontal
              set_header:
                [
                  fs,
                  fsType,
                  capacityBytes,
                  usedBytes,
                  availableBytes,
                  usedPerc,
                  mountedOn,
                ]
              regex_match: true
              split_by: (\S+.\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)
          perc_to_decimal: true
`,
		ExpectedStdout: `{"name":"com.newrelic.nri-flex","protocol_version":"3","integration_version":"Unknown-SNAPSHOT","data":[{"metrics":[{"availableBytes":"Available","capacityBytes":"1-blocks","event_type":"linuxFilesystemSample","fs":"Filesystem","fsType":"Type","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT","mountedOn":"Mounted on","usedBytes":"Used","usedPerc":"Capacity"},{"availableBytes":3847839744,"capacityBytes":41921515520,"event_type":"linuxFilesystemSample","fs":"overlay","fsType":"overlay","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT","mountedOn":"/","usedBytes":38073675776,"usedPerc":91},{"event_type":"flexStatusSample","flex.Hostname":"0a8c4028be4f","flex.IntegrationVersion":"Unknown-SNAPSHOT","flex.counter.ConfigsProcessed":1,"flex.counter.EventCount":2,"flex.counter.EventDropCount":0,"flex.counter.linuxFilesystemSample":2,"flex.time.elapsedMs":57,"flex.time.endMs":1654009494052,"flex.time.startMs":1654009493995}],"inventory":{},"events":[]}]}`,
	},
	{
		Name: "Linux filesystem usage mock using printf and splitting header",
		Config: `
---
name: linuxFilesystem
apis:
  - name: linuxFilesystem
    commands:
      - run: printf "Filesystem     Type                1K-blocks     Used Available Use Mounted\nfuse-overlayfs fuse.fuse-overlayfs  40938980 37779284   3159696  93 /\n"
        split: horizontal
        header_split_by: \s+
        row_header: 0
        row_start: 1
        regex_match: false
        split_by: \s+
    perc_to_decimal: true
`,
		ExpectedStdout: `{"name":"com.newrelic.nri-flex","protocol_version":"3","integration_version":"Unknown-SNAPSHOT","data":[{"metrics":[{"1K-blocks":40938980,"Available":3159696,"Filesystem":"fuse-overlayfs","Mounted":"/","Type":"fuse.fuse-overlayfs","Use":93,"Used":37779284,"event_type":"linuxFilesystemSample","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"event_type":"flexStatusSample","flex.Hostname":"0e0a965295ba","flex.IntegrationVersion":"Unknown-SNAPSHOT","flex.counter.ConfigsProcessed":1,"flex.counter.EventCount":1,"flex.counter.EventDropCount":0,"flex.counter.linuxFilesystemSample":1,"flex.time.elapsedMs":49,"flex.time.endMs":1654698466033,"flex.time.startMs":1654698465984}],"inventory":{},"events":[]}]}`,
	},
	{
		Name: "Echo message with assert pattern",
		Config: `
---
integrations:
  - name: nri-flex
    config:
      name: EchoHi
      apis:
        - name: echoHi
          event_type: echoMessage
          commands:
            - run: "echo hi:bye"
              split_by: ":"
              assert:
                match: hi
                not_match: foo
`,
		ExpectedStdout: `{"name":"com.newrelic.nri-flex","protocol_version":"3","integration_version":"Unknown-SNAPSHOT","data":[{"metrics":[{"event_type":"echoMessage","flex.commandTimeMs":3,"hi":"bye","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"event_type":"flexStatusSample","flex.Hostname":"0e0a965295ba","flex.IntegrationVersion":"Unknown-SNAPSHOT","flex.counter.ConfigsProcessed":1,"flex.counter.EventCount":1,"flex.counter.EventDropCount":0,"flex.counter.echoMessage":1,"flex.time.elapsedMs":40,"flex.time.endMs":1654696788571,"flex.time.startMs":1654696788531}],"inventory":{},"events":[]}]}`,
	},
	{
		Name: "Print message, store_variable and store_lookups",
		Config: `
---
integrations:
  - name: nri-flex
    config:
      name: jsonIntegrationTest
      apis:
        - name: post
          commands:
           - run: printf '{"id":123,"node":456}\n'
          store_variables:
            Id: id
          store_lookups:
            nodeId: node
        - name: readIDInfo2
          commands:
            - run: printf '{"different_id":${var:Id}}\n'
        - name: readIDInfo3
          commands:
            - run: printf '{"different_node":${lookup:nodeId}}\n'
`,
		ExpectedStdout: `{"name":"com.newrelic.nri-flex","protocol_version":"3","integration_version":"Unknown-SNAPSHOT","data":[{"metrics":[{"event_type":"postSample","id":123,"integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT","node":456},{"different_id":123,"event_type":"readIDInfo2Sample","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"different_node":456,"event_type":"readIDInfo3Sample","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"event_type":"flexStatusSample","flex.Hostname":"0e0a965295ba","flex.IntegrationVersion":"Unknown-SNAPSHOT","flex.counter.ConfigsProcessed":1,"flex.counter.EventCount":3,"flex.counter.EventDropCount":0,"flex.counter.postSample":1,"flex.counter.readIDInfo2Sample":1,"flex.counter.readIDInfo3Sample":1,"flex.time.elapsedMs":165,"flex.time.endMs":1654776136702,"flex.time.startMs":1654776136537}],"inventory":{},"events":[]}]}`,
	},
	{
		Name: "Print message and lookup",
		Config: `
---
integrations:
  - name: nri-flex
    config:
      name: jsonIntegrationTest
      apis:
        - name: post
          commands:
           - run: printf '[{"id":123},{"id":456}]\n'
        - name: readIDInfo2
          commands:
            - run: printf '{"different_id":${lookup.postSample:id}}\n'
`,
		ExpectedStdout: `{"name":"com.newrelic.nri-flex","protocol_version":"3","integration_version":"Unknown-SNAPSHOT","data":[{"metrics":[{"event_type":"postSample","id":123,"integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"event_type":"postSample","id":456,"integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"different_id":123,"event_type":"readIDInfo2Sample","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"different_id":456,"event_type":"readIDInfo2Sample","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"event_type":"flexStatusSample","flex.Hostname":"0e0a965295ba","flex.IntegrationVersion":"Unknown-SNAPSHOT","flex.counter.ConfigsProcessed":1,"flex.counter.EventCount":4,"flex.counter.EventDropCount":0,"flex.counter.postSample":2,"flex.counter.readIDInfo2Sample":2,"flex.time.elapsedMs":52,"flex.time.endMs":1654775074784,"flex.time.startMs":1654775074732}],"inventory":{},"events":[]}]}`,
	},
	{
		Name: "Print message, lookup and dedupe_lookups",
		Config: `
---
integrations:
  - name: nri-flex
    config:
      name: jsonIntegrationTest
      apis:
        - name: post
          commands:
           - run: printf '[{"id":123},{"id":123}]\n'
        - name: readIDInfo2
          commands:
            - run: printf '{"different_id":${lookup.postSample:id}}\n'
          dedupe_lookups:
            - id
`,
		ExpectedStdout: `{"name":"com.newrelic.nri-flex","protocol_version":"3","integration_version":"Unknown-SNAPSHOT","data":[{"metrics":[{"event_type":"postSample","id":123,"integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"event_type":"postSample","id":123,"integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"different_id":123,"event_type":"readIDInfo2Sample","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"event_type":"flexStatusSample","flex.Hostname":"0e0a965295ba","flex.IntegrationVersion":"Unknown-SNAPSHOT","flex.counter.ConfigsProcessed":1,"flex.counter.EventCount":3,"flex.counter.EventDropCount":0,"flex.counter.postSample":2,"flex.counter.readIDInfo2Sample":1,"flex.time.elapsedMs":144,"flex.time.endMs":1654775565835,"flex.time.startMs":1654775565691}],"inventory":{},"events":[]}]}`,
	},
}
View Source
var FileTests = []struct {
	Name           string
	FileContent    string
	Config         string
	ExpectedStdout string
}{
	{
		Name:        "Use ignore_output",
		FileContent: `{"id": "ec8f4ea31566","leaderInfo": {"leader": "8a67814500","startTime": 1588232295,"uptime": 3600},"name": "node3","sendAppendRequestCnt": 0,"state": "StateFollower"}`,
		Config: `
name: jsonIntegrationTest
apis:
  - name: readEtcdSelfLeaderInfo
    file: FILE_PATH
    ignore_output: true
    custom_attributes:
      env: production
`,
		ExpectedStdout: `{"name":"com.newrelic.nri-flex","protocol_version":"3","integration_version":"Unknown-SNAPSHOT","data":[{"metrics":[{"event_type":"flexStatusSample","flex.Hostname":"0e0a965295ba","flex.IntegrationVersion":"Unknown-SNAPSHOT","flex.counter.ConfigsProcessed":1,"flex.counter.EventCount":0,"flex.counter.EventDropCount":0,"flex.time.elapsedMs":45,"flex.time.endMs":1654704471027,"flex.time.startMs":1654704470982}],"inventory":{},"events":[]}]}`,
	},
	{
		Name:        "Use sample_filter to skip metrics",
		FileContent: `{"id": "ec8f4ea31566","leaderInfo": {"leader": "8a67814500","startTime": 1588232295,"uptime": 3600},"name": "node3","sendAppendRequestCnt": 0,"state": "StateFollower"}`,
		Config: `
name: jsonIntegrationTest
apis:
  - name: readEtcdSelfLeaderInfo
    file: FILE_PATH
    sample_filter:
      - name: node3
    custom_attributes:
      env: production
`,
		ExpectedStdout: `{"name":"com.newrelic.nri-flex","protocol_version":"3","integration_version":"Unknown-SNAPSHOT","data":[{"metrics":[{"event_type":"flexStatusSample","flex.Hostname":"0e0a965295ba","flex.IntegrationVersion":"Unknown-SNAPSHOT","flex.counter.ConfigsProcessed":1,"flex.counter.EventCount":0,"flex.counter.EventDropCount":0,"flex.time.elapsedMs":47,"flex.time.endMs":1654705788545,"flex.time.startMs":1654705788498}],"inventory":{},"events":[]}]}`,
	},
	{
		Name:        "Use sample_include_filter to get key",
		FileContent: `{"usageInfo": [{"quantities": 10,"customerId": "abc"},{"quantities": 20,"customerId": "xyz"}]}`,
		Config: `
name: jsonIntegrationTest
apis:
  - name: readEtcdSelfLeaderInfo
    file: FILE_PATH
    sample_include_filter:
      - customerId: abc
    custom_attributes:
      env: production
`,
		ExpectedStdout: `{"name":"com.newrelic.nri-flex","protocol_version":"3","integration_version":"Unknown-SNAPSHOT","data":[{"metrics":[{"customerId":"abc","env":"production","event_type":"usageInfoSample","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT","quantities":10},{"event_type":"flexStatusSample","flex.Hostname":"0e0a965295ba","flex.IntegrationVersion":"Unknown-SNAPSHOT","flex.counter.ConfigsProcessed":1,"flex.counter.EventCount":1,"flex.counter.EventDropCount":0,"flex.counter.usageInfoSample":1,"flex.time.elapsedMs":8,"flex.time.endMs":1654706477610,"flex.time.startMs":1654706477602}],"inventory":{},"events":[]}]}`,
	},
	{
		Name:        "Use sample_exclude_filter to exclude key",
		FileContent: `{"usageInfo": [{"quantities": 10,"customerId": "abc"},{"quantities": 20,"customerId": "xyz"}]}`,
		Config: `
name: jsonIntegrationTest
apis:
  - name: readEtcdSelfLeaderInfo
    file: FILE_PATH
    sample_include_filter:
      - customerId: abc
    custom_attributes:
      env: production
`,
		ExpectedStdout: `{"name":"com.newrelic.nri-flex","protocol_version":"3","integration_version":"Unknown-SNAPSHOT","data":[{"metrics":[{"customerId":"xyz","env":"production","event_type":"usageInfoSample","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT","quantities":20},{"event_type":"flexStatusSample","flex.Hostname":"0e0a965295ba","flex.IntegrationVersion":"Unknown-SNAPSHOT","flex.counter.ConfigsProcessed":1,"flex.counter.EventCount":1,"flex.counter.EventDropCount":0,"flex.counter.usageInfoSample":1,"flex.time.elapsedMs":49,"flex.time.endMs":1654706661615,"flex.time.startMs":1654706661566}],"inventory":{},"events":[]}]}`,
	},
	{
		Name:        "Provide start_key and rename_key of json",
		FileContent: `{"id": "ec8f4ea31566","leaderInfo": {"leader": "8a67814500","startTime": 1588232295,"uptime": 3600},"name": "node3","sendAppendRequestCnt": 0,"state": "StateFollower"}`,
		Config: `
name: jsonIntegrationTest
apis:
  - name: readEtcdSelfLeaderInfo
    file: FILE_PATH
    start_key:
      - leaderInfo
    rename_keys:
      startTime: timestamp
    custom_attributes:
      env: production
`,
		ExpectedStdout: `{"name":"com.newrelic.nri-flex","protocol_version":"3","integration_version":"Unknown-SNAPSHOT","data":[{"metrics":[{"env":"production","event_type":"readEtcdSelfLeaderInfoSample","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT","leader":"8a67814500","timestamp":1588232295,"uptime":3600},{"event_type":"flexStatusSample","flex.Hostname":"0e0a965295ba","flex.IntegrationVersion":"Unknown-SNAPSHOT","flex.counter.ConfigsProcessed":1,"flex.counter.EventCount":1,"flex.counter.EventDropCount":0,"flex.counter.readEtcdSelfLeaderInfoSample":1,"flex.time.elapsedMs":8,"flex.time.endMs":1654699825870,"flex.time.startMs":1654699825862}],"inventory":{},"events":[]}]}`,
	},
	{
		Name:        "Use keep_keys with jq",
		FileContent: `{"id": "ec8f4ea31566","leaderInfo": {"leader": "8a67814500","startTime": 1588232295,"uptime": 3600},"name": "node3","sendAppendRequestCnt": 0,"state": "StateFollower"}`,
		Config: `
name: jsonIntegrationTest
apis:
  - name: readEtcdSelfLeaderInfo
    file: FILE_PATH
    keep_keys:
      - leader
    jq: ".leaderInfo"
    custom_attributes:
      env: production
`,
		ExpectedStdout: `{"name":"com.newrelic.nri-flex","protocol_version":"3","integration_version":"Unknown-SNAPSHOT","data":[{"metrics":[{"event_type":"readEtcdSelfLeaderInfoSample","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT","leader":"8a67814500"},{"event_type":"flexStatusSample","flex.Hostname":"0e0a965295ba","flex.IntegrationVersion":"Unknown-SNAPSHOT","flex.counter.ConfigsProcessed":1,"flex.counter.EventCount":1,"flex.counter.EventDropCount":0,"flex.counter.readEtcdSelfLeaderInfoSample":1,"flex.time.elapsedMs":9,"flex.time.endMs":1654703090744,"flex.time.startMs":1654703090735}],"inventory":{},"events":[]}]}`,
	},
	{
		Name:        "Use lazy_flatten with math and remove_key",
		FileContent: `{"contacts": [{"name": "batman","number": 911},{"name": "robin","number": 112}]}`,
		Config: `
name: jsonIntegrationTest
apis:
  - name: readEtcdSelfLeaderInfo
    file: FILE_PATH
    lazy_flatten:
      - contacts
    math:
      sum: ${contacts.flat.0.number} + ${contacts.flat.1.number} + 200
    remove_keys:
      - contacts.flat.1.name
    custom_attributes:
      env: production
`,
		ExpectedStdout: `{"name":"com.newrelic.nri-flex","protocol_version":"3","integration_version":"Unknown-SNAPSHOT","data":[{"metrics":[{"contacts.flat.0.name":"batman","contacts.flat.0.number":911,"contacts.flat.1.number":112,"env":"production","event_type":"readEtcdSelfLeaderInfoSample","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT","sum":1223},{"event_type":"flexStatusSample","flex.Hostname":"0e0a965295ba","flex.IntegrationVersion":"Unknown-SNAPSHOT","flex.counter.ConfigsProcessed":1,"flex.counter.EventCount":1,"flex.counter.EventDropCount":0,"flex.counter.readEtcdSelfLeaderInfoSample":1,"flex.time.elapsedMs":57,"flex.time.endMs":1654705302291,"flex.time.startMs":1654705302234}],"inventory":{},"events":[]}]}`,
	},
	{
		Name:        "Use snake_to_camel and split_objects",
		FileContent: `{"first":{"id":"eca01566","leader_Info":{"up_time":"10m59.322358947s","abc":{"def":123,"hij":234}},"name":"node1"},"second":{"id":"eca04ea31566","leader_Info":{"up_time":"10m59.322358947s","abc":{"def":123,"hij":234}},"name":"node2"}}`,
		Config: `
name: jsonIntegrationTest
apis:
  - name: readEtcdSelfLeaderInfo
    file: FILE_PATH
    snake_to_camel: true
    split_objects: true
`,
		ExpectedStdout: `{"name":"com.newrelic.nri-flex","protocol_version":"3","integration_version":"Unknown-SNAPSHOT","data":[{"metrics":[{"event_type":"Sample","id":"eca01566","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT","leaderInfo.abc.def":123,"leaderInfo.abc.hij":234,"leaderInfo.upTime":"10m59.322358947s","name":"node1","split.id":"first"},{"event_type":"Sample","id":"eca04ea31566","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT","leaderInfo.abc.def":123,"leaderInfo.abc.hij":234,"leaderInfo.upTime":"10m59.322358947s","name":"node2","split.id":"second"},{"event_type":"flexStatusSample","flex.Hostname":"0e0a965295ba","flex.IntegrationVersion":"Unknown-SNAPSHOT","flex.counter.ConfigsProcessed":1,"flex.counter.EventCount":2,"flex.counter.EventDropCount":0,"flex.counter.Sample":2,"flex.time.elapsedMs":45,"flex.time.endMs":1654761239572,"flex.time.startMs":1654761239527}],"inventory":{},"events":[]}]}`,
	},
	{
		Name:        "Use to_lower, strip_keys, value_parser and value_transformer",
		FileContent: `{"id":"eca0338f4ea31566","leaderInfo":{"leader":"a8a69d5f6b7814500","startTime":"2014-10-24T13:15:51.186620747-07:00","uptime":"10m59.322358947s","abc":{"def1":"a:123","def2":"a:234"}},"name":"node3"}`,
		Config: `
name: jsonIntegrationTest
apis:
  - name: readEtcdSelfLeaderInfo
    file: FILE_PATH
    to_lower: true
    strip_keys:
      - leaderInfo>leader
      - name
    value_parser:
      def: "[0-9]+"
    value_transformer:
      id: 12345
`,
		ExpectedStdout: `{"name":"com.newrelic.nri-flex","protocol_version":"3","integration_version":"Unknown-SNAPSHOT","data":[{"metrics":[{"event_type":"readEtcdSelfLeaderInfoSample","id":12345,"integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT","leaderinfo.abc.def1":123,"leaderinfo.abc.def2":234,"leaderinfo.starttime":"2014-10-24T13:15:51.186620747-07:00","leaderinfo.uptime":"10m59.322358947s"},{"event_type":"flexStatusSample","flex.Hostname":"0e0a965295ba","flex.IntegrationVersion":"Unknown-SNAPSHOT","flex.counter.ConfigsProcessed":1,"flex.counter.EventCount":1,"flex.counter.EventDropCount":0,"flex.counter.readEtcdSelfLeaderInfoSample":1,"flex.time.elapsedMs":3,"flex.time.endMs":1654769186564,"flex.time.startMs":1654769186561}],"inventory":{},"events":[]}]}`,
	},
	{
		Name:        "Use split_array",
		FileContent: `{"status":1,"appstatus":-128,"statusstring":null,"appstatusstring":null,"results":[{"status":-128,"schema":[{"name":"TIMESTAMP","type":6},{"name":"HOST_ID","type":5},{"name":"HOSTNAME","type":9},{"name":"PERCENT_USED","type":6}],"data":[[1582159853733,0,"7605f6bec898",0],[1582159853733,2,"067ea6fc4c22",0],[1582159853733,1,"62a10d3f45e3",0]]}]}`,
		Config: `
name: example
apis:
  - name: voltdb_cpu
    event_type: voltdb
    file: FILE_PATH
    split_array: true
    set_header: [TIMESTAMP, HOST_ID, HOSTNAME, PERCENT_USED]
    start_key:
      - results>data
`,
		ExpectedStdout: `{"name":"com.newrelic.nri-flex","protocol_version":"3","integration_version":"Unknown-SNAPSHOT","data":[{"metrics":[{"HOSTNAME":"7605f6bec898","HOST_ID":0,"PERCENT_USED":0,"TIMESTAMP":1582159853733,"event_type":"voltdb","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"HOSTNAME":"067ea6fc4c22","HOST_ID":2,"PERCENT_USED":0,"TIMESTAMP":1582159853733,"event_type":"voltdb","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"HOSTNAME":"62a10d3f45e3","HOST_ID":1,"PERCENT_USED":0,"TIMESTAMP":1582159853733,"event_type":"voltdb","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"event_type":"flexStatusSample","flex.Hostname":"0e0a965295ba","flex.IntegrationVersion":"Unknown-SNAPSHOT","flex.counter.ConfigsProcessed":1,"flex.counter.EventCount":3,"flex.counter.EventDropCount":0,"flex.counter.voltdb":3,"flex.time.elapsedMs":45,"flex.time.endMs":1654776591203,"flex.time.startMs":1654776591158}],"inventory":{},"events":[]}]}`,
	},
	{
		Name:        "Use lookup",
		FileContent: `[{"brand":"honda","car":"civic"},{"brand":"toyota","car":"supra"},{"brand":"mistsubishi","car":"lancer"}]`,
		Config: `
name: LookUps
apis:
  - name: read
    event_type: read
    file: FILE_PATH

  - name: world
    commands:
      - run: echo "${lookup.read:brand}:${lookup.read:car}"
        split_by: ":"
`,
		ExpectedStdout: `{"name":"com.newrelic.nri-flex","protocol_version":"3","integration_version":"Unknown-SNAPSHOT","data":[{"metrics":[{"brand":"honda","car":"civic","event_type":"read","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"brand":"toyota","car":"supra","event_type":"read","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"brand":"mistsubishi","car":"lancer","event_type":"read","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"event_type":"worldSample","flex.commandTimeMs":3,"honda":"civic","integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT"},{"event_type":"worldSample","flex.commandTimeMs":0,"integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT","toyota":"supra"},{"event_type":"worldSample","flex.commandTimeMs":0,"integration_name":"com.newrelic.nri-flex","integration_version":"Unknown-SNAPSHOT","mistsubishi":"lancer"},{"event_type":"flexStatusSample","flex.Hostname":"ubuntu-2004-vm","flex.IntegrationVersion":"Unknown-SNAPSHOT","flex.counter.ConfigsProcessed":1,"flex.counter.EventCount":6,"flex.counter.EventDropCount":0,"flex.counter.read":3,"flex.counter.worldSample":3,"flex.time.elapsedMs":22,"flex.time.endMs":1672415688172,"flex.time.startMs":1672415688150}],"inventory":{},"events":[]}]}`,
	},
}
View Source
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":[]}]}`,
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL