Skip to content

Commit

Permalink
Fix: basic auth
Browse files Browse the repository at this point in the history
  • Loading branch information
idrissneumann committed Sep 11, 2024
1 parent 56912fb commit a02fa0b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.4
4.0.5
19 changes: 8 additions & 11 deletions src/utils/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit a02fa0b

Please sign in to comment.