Allow raw ip addresses
This commit is contained in:
+19
-11
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import dataclasses
|
||||
import logging
|
||||
import time
|
||||
@@ -32,19 +33,26 @@ def check_endpoint(ep, default_timeout: float, timestamp_ns: int) -> CheckResult
|
||||
timeout = ep.timeout_seconds or default_timeout
|
||||
start = time.monotonic()
|
||||
|
||||
try:
|
||||
resolved_ip = dns_resolver.resolve(ep.host, ep.dns_server, timeout)
|
||||
except dns.exception.DNSException as e:
|
||||
return CheckResult(
|
||||
endpoint_name=ep.name, host=ep.host, scheme=ep.scheme, port=ep.port,
|
||||
success=False, status_code=None, expected_status=ep.expected_status,
|
||||
response_time_ms=None, resolved_ip=None,
|
||||
error=f"dns_error: {e}", timestamp_ns=timestamp_ns,
|
||||
)
|
||||
if dns_resolver.is_ip_literal(ep.host):
|
||||
# Nothing to resolve — connect straight to the given IP. dns_server
|
||||
# is not required/used in this case (see config.py).
|
||||
resolved_ip = ep.host
|
||||
pin = contextlib.nullcontext()
|
||||
else:
|
||||
try:
|
||||
resolved_ip = dns_resolver.resolve(ep.host, ep.dns_server, timeout)
|
||||
except dns.exception.DNSException as e:
|
||||
return CheckResult(
|
||||
endpoint_name=ep.name, host=ep.host, scheme=ep.scheme, port=ep.port,
|
||||
success=False, status_code=None, expected_status=ep.expected_status,
|
||||
response_time_ms=None, resolved_ip=None,
|
||||
error=f"dns_error: {e}", timestamp_ns=timestamp_ns,
|
||||
)
|
||||
pin = dns_resolver.pin_resolution(ep.host, resolved_ip)
|
||||
|
||||
url = f"{ep.scheme}://{ep.host}:{ep.port}{ep.path}"
|
||||
url = f"{ep.scheme}://{dns_resolver.format_host_for_url(ep.host)}:{ep.port}{ep.path}"
|
||||
try:
|
||||
with dns_resolver.pin_resolution(ep.host, resolved_ip):
|
||||
with pin:
|
||||
resp = requests.get(
|
||||
url, timeout=timeout, verify=ep.verify_tls, allow_redirects=True
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user