Skip to content

Commit

Permalink
Implement PUT and body
Browse files Browse the repository at this point in the history
  • Loading branch information
idrissneumann committed Dec 10, 2024
1 parent 820dcc7 commit 18770ee
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ monitors:
- type: http
name: imalive
url: http://localhost:8081
method: GET # optional (GET by default, only POST and GET are supported)
method: POST # optional (GET by default, only POST, PUT and GET are supported)
body: '{"foo": "bar"}' # optional (body is ignored if method is GET)
expected_http_code: 200 # optional (200 by default)
expected_contain: "\"status\":\"ok\"" # optional (no check on the body response if not present)
timeout: 30 # optional (30 seconds if not present)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.14
4.0.15
7 changes: 6 additions & 1 deletion src/utils/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def check_http_monitor(monitor, gauges):
timeout = get_or_else(monitor, 'timeout', 30)
expected_http_code = get_or_else(monitor, 'expected_http_code', 200)
expected_contain = get_or_else(monitor, 'expected_contain', None)
body = get_or_else(monitor, 'body', None)
duration = None
auth = None
headers = {}
Expand All @@ -73,7 +74,11 @@ def check_http_monitor(monitor, gauges):
duration = response.elapsed.total_seconds()
set_gauge(gauges['duration'], duration, {**labels, 'kind': 'duration'})
elif method == "POST":
response = requests.post(monitor['url'], auth=auth, headers=headers, timeout=timeout)
response = requests.post(monitor['url'], auth=auth, headers=headers, timeout=timeout, data=body)
duration = response.elapsed.total_seconds()
set_gauge(gauges['duration'], duration, {**labels, 'kind': 'duration'})
elif method == "PUT":
response = requests.put(monitor['url'], auth=auth, headers=headers, timeout=timeout, data=body)
duration = response.elapsed.total_seconds()
set_gauge(gauges['duration'], duration, {**labels, 'kind': 'duration'})
else:
Expand Down

0 comments on commit 18770ee

Please sign in to comment.