Skip to content

Commit ab6c7c7

Browse files
author
Sebastian Wagner
committed
ENH: http collector: log request info for errors
also log the request's headers and body
1 parent 303ef38 commit ab6c7c7

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ CHANGELOG
2828
- `intelmq.bots.collectors.eset.collector`: Added (PR#1554 by Mikk Margus Möll).
2929
- `intelmq.bots.collectors.http.collector_http`:
3030
- Added PGP signature check functionality (PR#1602 by sinus-x).
31-
- If status code is not 2xx, the response header and body are logged in debug logging level (#1615).
31+
- If status code is not 2xx, the request's and response's headers and body are logged in debug logging level (#1615).
3232

3333
#### Parsers
3434
- `intelmq.bots.parsers.eset.parser`: Added (PR#1554 by Mikk Margus Möll).

docs/Bots.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ For extracted files, every extracted file is sent in its own report. Every repor
273273

274274
If the HTTP response' status code is not 2xx, this is treated as error.
275275

276-
In Debug logging level, the reponse's header and body are logged for further inspection.
276+
In Debug logging level, the request's and response's headers and body are logged for further inspection.
277277

278278
* * *
279279

intelmq/bots/collectors/http/collector_http.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def process(self):
7878
resp = self.session.get(url=http_url)
7979

8080
if resp.status_code // 100 != 2:
81+
self.logger.debug('Request headers: %r.', resp.request.headers)
82+
self.logger.debug('Request body: %r.', resp.request.body)
8183
self.logger.debug('Response headers: %r.', resp.headers)
8284
self.logger.debug('Response body: %r.', resp.text)
8385
raise ValueError('HTTP response status code was %i.' % resp.status_code)

intelmq/tests/bots/collectors/http/test_collector.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,17 @@ def test_pgp(self, mocker):
156156
)
157157
self.assertMessageEqual(0, OUTPUT[2])
158158

159-
def test_debug_response_log(self, mocker):
159+
def test_debug_request_response_log(self, mocker):
160160
"""
161-
Test if the reponse is logged in case of errors as DEBUG
161+
Test if the request and response is logged in case of errors as DEBUG
162162
"""
163163
mocker.get(self.sysconfig['http_url'], status_code=400,
164164
headers={'some': 'header'},
165165
text='Should be in logs')
166166
self.run_bot(allowed_error_count=1,
167167
parameters={'logging_level': 'DEBUG'})
168+
self.assertLogMatches(r"Request headers: .*\.", 'DEBUG')
169+
self.assertLogMatches("Request body: None.", 'DEBUG')
168170
self.assertLogMatches("Response headers: {'some': 'header'}.", 'DEBUG')
169171
self.assertLogMatches("Response body: 'Should be in logs'.", 'DEBUG')
170172

0 commit comments

Comments
 (0)