diff --git a/app/models/agents/website_agent.rb b/app/models/agents/website_agent.rb index 1918186e..e8b97686 100644 --- a/app/models/agents/website_agent.rb +++ b/app/models/agents/website_agent.rb @@ -134,7 +134,7 @@ module Agents * `_response_`: A response object with the following keys: - * `status`: HTTP status as integer. (Almost always 200) When parsing `data_from_event`, this is set to the value of the `status` key in the incoming Event. + * `status`: HTTP status as integer. (Almost always 200) When parsing `data_from_event`, this is set to the value of the `status` key in the incoming Event, if it is a number or a string convertible to an integer. * `headers`: Response headers; for example, `{{ _response_.headers.Content-Type }}` expands to the value of the Content-Type header. Keys are insensitive to cases and -/_. When parsing `data_from_event`, this is constructed from the value of the `headers` key in the incoming Event. @@ -694,7 +694,7 @@ module Agents # Integer value of HTTP status def status - @object.payload[:status] + Integer(@object.payload[:status]) rescue nil end # The URL diff --git a/spec/models/agents/website_agent_spec.rb b/spec/models/agents/website_agent_spec.rb index d943ca77..556f9c33 100644 --- a/spec/models/agents/website_agent_spec.rb +++ b/spec/models/agents/website_agent_spec.rb @@ -1198,7 +1198,7 @@ fire: hot 'value' => '{{ value }}', 'url' => '{{ url | to_uri: _response_.url }}', 'type' => '{{ _response_.headers.content_type }}', - 'status' => '{{ _response_.status }}' + 'status' => '{{ _response_.status | as_object }}' } ) end @@ -1207,7 +1207,7 @@ fire: hot expect { @checker.receive([@event]) }.to change { Event.count }.by(1) - expect(@checker.events.last.payload).to eq({ 'value' => 'world', 'url' => 'http://example.com/world', 'type' => 'application/json', 'status' => '200' }) + expect(@checker.events.last.payload).to eq({ 'value' => 'world', 'url' => 'http://example.com/world', 'type' => 'application/json', 'status' => 200 }) end it "should support merge mode" do @@ -1216,7 +1216,7 @@ fire: hot expect { @checker.receive([@event]) }.to change { Event.count }.by(1) - expect(@checker.events.last.payload).to eq(@event.payload.merge('value' => 'world', 'url' => 'http://example.com/world', 'type' => 'application/json', 'status' => '200')) + expect(@checker.events.last.payload).to eq(@event.payload.merge('value' => 'world', 'url' => 'http://example.com/world', 'type' => 'application/json', 'status' => 200)) end it "should output an error when nothing can be found at the path" do