From a02fa0b31f61ad13fbf4acb3f68be14d70d16837 Mon Sep 17 00:00:00 2001 From: Idriss Neumann Date: Wed, 11 Sep 2024 19:13:22 +0100 Subject: [PATCH] Fix: basic auth --- VERSION | 2 +- src/utils/monitor.py | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/VERSION b/VERSION index c5106e6..7636e75 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.0.4 +4.0.5 diff --git a/src/utils/monitor.py b/src/utils/monitor.py index 79fe517..baaf199 100644 --- a/src/utils/monitor.py +++ b/src/utils/monitor.py @@ -11,7 +11,7 @@ from time import sleep from requests.auth import HTTPBasicAuth -from utils.common import is_empty_key, get_or_else, is_not_empty, remove_key_safely +from utils.common import is_empty_key, get_or_else, is_not_empty, is_not_empty_key, remove_key_safely from utils.gauge import create_gauge, set_gauge from utils.heartbit import WAIT_TIME from utils.logger import log_msg @@ -46,24 +46,21 @@ 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) - username = get_or_else(monitor, 'username', None) - password = get_or_else(monitor, 'password', None) - - auth = None duration = None - if is_not_empty(username) and is_not_empty(password): - auth = HTTPBasicAuth(username, password) + auth = None - remove_key_safely(monitor, 'username') - remove_key_safely(monitor, 'password') + if is_not_empty_key(monitor, 'username') and is_not_empty_key(monitor, 'password'): + auth = HTTPBasicAuth(monitor['username'], monitor['password']) + remove_key_safely(monitor, 'username') + remove_key_safely(monitor, 'password') try: if method == "GET": - response = requests.get(monitor['url'], timeout=timeout, auth=auth) + response = requests.get(monitor['url'], auth=auth, timeout=timeout) duration = response.elapsed.total_seconds() set_gauge(gauges['duration'], duration) elif method == "POST": - response = requests.post(monitor['url'], timeout=timeout, auth=auth) + response = requests.post(monitor['url'], auth=auth, timeout=timeout) duration = response.elapsed.total_seconds() set_gauge(gauges['duration'], duration) else: