# Passing Array and a Variable from Json output to a http request in Ruby

**URL:** https://discuss.elastic.co/t/passing-array-and-a-variable-from-json-output-to-a-http-request-in-ruby/307515
**Category:** Logstash
**Created:** [June 17, 2022, 1:32pm UTC](https://discuss.elastic.co/t/passing-array-and-a-variable-from-json-output-to-a-http-request-in-ruby/307515 "2022-06-17T13:32:43Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![santhoshi.p](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@santhoshi.p](https://discuss.elastic.co/u/santhoshi.p)
#### Post date: [June 17, 2022, 1:32pm UTC](https://discuss.elastic.co/t/passing-array-and-a-variable-from-json-output-to-a-http-request-in-ruby/307515/1 "2022-06-17T13:32:43Z")

</div>

Hi,

I have above output coming from one API and I need to pass this to another API where URL will have variable componets of **datasource array and nodeID**. And I need to store this data an ingest it to elastic as documents. Could you please help me with ruby code how I can achieve in logstash.

```auto
{
    "@timestamp" => 2022-06-17T13:18:26.431584Z,
        "nodeId" => "18",
    "datasource" => [
        [0] "ssh",
        [1] "icmp"
    ]
}
{
    "@timestamp" => 2022-06-17T13:18:26.431584Z,
        "nodeId" => "13"
}
{
    "@timestamp" => 2022-06-17T13:18:26.431584Z,
        "nodeId" => "14"
}
{
    "@timestamp" => 2022-06-17T13:18:26.431584Z,
        "nodeId" => "8",
    "datasource" => [
        [0] "ciscoMemoryPoolFree",
        [1] "ciscoSupyState",
        [2] "bufferNoMem",
        [3] "CiscoEnvMonState",
        [4] "tcpAttemptFails",
        [5] "ciscoMemoryPoolMax",
        [6] "ciscoSupSource",
        [7] "avgBusy5",
        [8] "tcpPassiveOpens",
        [9] "ciscoMemoryPoolUsed",
        [10] "tcpOutSegs",
        ......
    ]
}
{
    "@timestamp" => 2022-06-17T13:18:26.431584Z,
        "nodeId" => "10",
    "datasource" => [
        [0] "icmp"
    ]
}
{
    "@timestamp" => 2022-06-17T13:18:26.431584Z,
        "nodeId" => "1",
    "datasource" => [
        [0] "hrSystemUptime"
    ]
}

```

My ruby code:

```auto
#ruby {
# init => "
# require 'net/http'
# require 'uri'
# require 'json'
# "
# code => "
         event.get('nodeId')
# event.get('datasource').each { |i|
# uri = URI.parse('xxxxxxxxxx/rest/measurements/node%5B%{nodeId}%5D.nodeSnmp%5B%5D/%{#datasource[i]}?start=-7200000')
# request = Net::HTTP::Get.new(uri)
#}
#"
#}

#}

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 15, 2022, 1:32pm UTC](https://discuss.elastic.co/t/passing-array-and-a-variable-from-json-output-to-a-http-request-in-ruby/307515/2 "2022-07-15T13:32:52Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
