Skip to content

Commit

Permalink
[Heartbeat] Add mime type detection (#22976) (#23006)
Browse files Browse the repository at this point in the history
* Add mime type detection for heartbeat

* Update changelog

(cherry picked from commit ad1d651)
  • Loading branch information
Andrew Stucki committed Dec 9, 2020
1 parent 171a849 commit 36d51cb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d

*Heartbeat*

- Add mime type detection for http responses. {pull}22976[22976]

*Heartbeat*

Expand Down
13 changes: 13 additions & 0 deletions heartbeat/_meta/config/processors.yml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{header "Processors"}}

processors:
- add_observer_metadata:
# Optional, but recommended geo settings for the location Heartbeat is running in
#geo:
# Token describing this location
#name: us-east-1a
# Lat, Lon "
#location: "37.926868, -78.024902"
- detect_mime_type:
field: http.response.body.content
target: http.response.mime_type
4 changes: 3 additions & 1 deletion heartbeat/heartbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ processors:
#name: us-east-1a
# Lat, Lon "
#location: "37.926868, -78.024902"

- detect_mime_type:
field: http.response.body.content
target: http.response.mime_type

# ================================== Logging ===================================

Expand Down
5 changes: 5 additions & 0 deletions heartbeat/tests/system/config/heartbeat.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ fields:
{% endfor -%}
{% endif %}

processors:
- detect_mime_type:
field: http.response.body.content
target: http.response.mime_type

#================================ Queue =====================================

queue.mem:
Expand Down
4 changes: 4 additions & 0 deletions heartbeat/tests/system/test_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ def test_http_json(self, expected_status, body):
self.assert_last_status(expected_status)
if expected_status == "down":
self.assertEqual(self.last_output_line()["http.response.body.content"], body)
if body == "notjson":
self.assertEqual(self.last_output_line()["http.response.mime_type"], "text/plain; charset=utf-8")
else:
self.assertEqual(self.last_output_line()["http.response.mime_type"], "application/json")
else:
assert "http.response.body.content" not in self.last_output_line()
finally:
Expand Down

0 comments on commit 36d51cb

Please sign in to comment.