来自 ElasticSearch 的数据作为 http_poller 的输入

问题描述 投票:0回答:1

我正在尝试执行以下操作: 从elasticsearch 中获取一些数据(比如说单个浮点值),并通过Logstash 管道将它们添加到对某些Rest API 的http_poller 调用的主体中。这真的可能吗?我试图通过查询 elasticsearch 来做到这一点,但没有成功。在下面找到我的 Logstash 管道:

input {
  elasticsearch {
        hosts => ["...:9200"]
        index => ["demo_data"]
        query => '{ "query": { "match": { "statuscode": 200 } }, "sort": [ "_doc" ] }'
        #just a dummy query, need to save to a variable here?
  }  
  http_poller {
    urls => {
      test => {
        method => post
        url => "some url"
        body => '{"instances": [[20.0]]}'
      }
    }
    request_timeout => 60
    schedule => { cron => "* * * * * UTC"}
    codec => "json"
  }
}

filter {
}

output{
  elasticsearch {
    hosts => [ "elasticsearch:9200" ]
    index => "demo_results"
  }
}

换句话说,我不知道如何将数据从elastic发送到http_poller调用!

非常感谢,

乔治。

elasticsearch logstash logstash-configuration elk
1个回答
0
投票

您可以做的是利用 elasticsearch 输入的

 调度功能
,以便它定期执行以获取您需要的任何内容。

然后,当您获得所需的数据时,您可以使用

http
过滤器 使用从 Elasticsearch 获取的数据来调用远程 API。

input {
  elasticsearch {
    hosts => ["...:9200"]
    index => ["demo_data"]
    query => '{ "query": { "match": { "statuscode": 200 } }, "sort": [ "_doc" ] }'
    schedule => { cron => "* * * * * UTC"}
  }  
}
filter {
   http {
     verb => "POST"
     url => "http://some url"
     body_format => "json"
     body => {
       "instances" => "%{[field][from][elasticsearch]}"
     }
   }
}
output{
  elasticsearch {
    hosts => [ "elasticsearch:9200" ]
    index => "demo_results"
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.