diff --git a/logstash-core/lib/logstash/modules/kibana_client.rb b/logstash-core/lib/logstash/modules/kibana_client.rb index 1dce000c69c..9e8290e6b79 100644 --- a/logstash-core/lib/logstash/modules/kibana_client.rb +++ b/logstash-core/lib/logstash/modules/kibana_client.rb @@ -91,7 +91,12 @@ def initialize(settings, client = nil) # allow for test mock injection @endpoint = "#{@scheme}://#{@host}" @client = client || Manticore::Client.new(client_options) - @http_options = {:headers => {'Content-Type' => 'application/json'}} + @http_options = { + :headers => { + 'Content-Type' => 'application/json', + "x-elastic-product-origin" => "logstash" + } + } username = @settings["var.kibana.username"] if username password = @settings["var.kibana.password"] diff --git a/logstash-core/spec/logstash/modules/kibana_client_spec.rb b/logstash-core/spec/logstash/modules/kibana_client_spec.rb index 42e5d9bde41..24b231909cc 100644 --- a/logstash-core/spec/logstash/modules/kibana_client_spec.rb +++ b/logstash-core/spec/logstash/modules/kibana_client_spec.rb @@ -101,5 +101,33 @@ def call end end end + + context "when making requests to Kibana" do + let(:test_client) { double("client") } + let(:mock_response) { double("response", + code: 200, + body: {"version" => {"number" => "1.2.3"}}.to_json, + headers: {} + )} + let(:mock_http) { double("http") } + let(:settings) { {"var.kibana.host" => "localhost:5601"} } + + it "includes product origin header" do + # The status API is checked on initialization, the `safely` method is used + # for any REST calls, so just checkiing this :get covers the header addition. + expect(test_client).to receive(:http) + .with(:get, "https://localhost:5601/api/status", + hash_including( + headers: hash_including( + "x-elastic-product-origin" => "logstash" + ) + ) + ) + .and_return(mock_http) + expect(mock_http).to receive(:call).and_return(mock_response) + + described_class.new(settings, test_client) + end + end end end end