Browse Source

Allow url_from_event in the WebsiteAgent to be an Array

Andrew Cantino 9 năm trước cách đây
mục cha
commit
48d5990146

+ 4 - 4
app/models/agents/website_agent.rb

@@ -251,11 +251,11 @@ module Agents
       check_urls(interpolated['url'])
     end
 
-    def check_urls(in_url)
+    def check_urls(in_url, payload = {})
       return unless in_url.present?
 
       Array(in_url).each do |url|
-        check_url(url)
+        check_url(url, payload)
       end
     end
 
@@ -322,11 +322,11 @@ module Agents
         interpolate_with(event) do
           url_to_scrape =
             if url_template = options['url_from_event'].presence
-              interpolate_string(url_template)
+              interpolate_options(url_template)
             else
               event.payload['url']
             end
-          check_url(url_to_scrape,
+          check_urls(url_to_scrape,
                     interpolated['mode'].to_s == "merge" ? event.payload : {})
         end
       end

+ 13 - 0
spec/models/agents/website_agent_spec.rb

@@ -673,6 +673,19 @@ fire: hot
         expect(stub).to have_been_requested
       end
 
+      it "should allow url_from_event to be an array of urls" do
+        stub1 = stub_request(:any, 'http://example.org/?url=http%3A%2F%2Fxkcd.com')
+        stub2 = stub_request(:any, 'http://google.org/?url=http%3A%2F%2Fxkcd.com')
+
+        @checker.options = @valid_options.merge(
+          'url_from_event' => ['http://example.org/?url={{url | uri_escape}}', 'http://google.org/?url={{url | uri_escape}}']
+        )
+        @checker.receive([@event])
+
+        expect(stub1).to have_been_requested
+        expect(stub2).to have_been_requested
+      end
+
       it "should interpolate values from incoming event payload" do
         expect {
           @valid_options['extract'] = {