From 18770ee3d6167519b581c7fab6e5b41f2e775aa6 Mon Sep 17 00:00:00 2001 From: Idriss Neumann Date: Tue, 10 Dec 2024 09:42:48 +0100 Subject: [PATCH] Implement PUT and body --- README.md | 3 ++- VERSION | 2 +- src/utils/monitor.py | 7 ++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 530f286..d303040 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/VERSION b/VERSION index 80c4caf..af253c1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.0.14 +4.0.15 diff --git a/src/utils/monitor.py b/src/utils/monitor.py index efc1ea7..7fd8a58 100644 --- a/src/utils/monitor.py +++ b/src/utils/monitor.py @@ -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 = {} @@ -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: