-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add IPv4-only configuration option #12632
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥇
if self.ipv4_only: | ||
_, _, ipv4_list = socket.gethostbyname_ex(self.host) | ||
self._addrs = [AddrTuple(ipv4_addr, socket.AF_INET) for ipv4_addr in ipv4_list] | ||
else: | ||
self._addrs = [ | ||
AddrTuple(sockaddr[0], socket_type) | ||
for (socket_type, _, _, _, sockaddr) in socket.getaddrinfo( | ||
self.host, self.port, 0, 0, socket.IPPROTO_TCP | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note:
IP6 support was introduced on https://github.com/DataDog/integrations-core/pull/11740/files#diff-e1afdae3cf81bdf12d2888a230f697bfd8eda2d5ab2e8d7267e30183986a636bR104
AddrTuple was introduced on https://github.com/DataDog/integrations-core/pull/12526/files#diff-e1afdae3cf81bdf12d2888a230f697bfd8eda2d5ab2e8d7267e30183986a636bR13
What does this PR do?
Adds option to only check IPv4 addresses.
Motivation
A hostname may resolve to both IPv4 and IPv6 addresses despite the host lacking IPv6 connectivity. Enabling this option will check only IPv4 addresses and prevent false alerts from IPv6 addresses returning CRITICAL status due to "Network is unreachable" error returned from the socket.
Additional Notes
Also fixes the
has_ipv6_connectivity()
helper function in the tests, which was silently failing in the CI due to an exception fromsocket.gethostname()
not getting caught.Review checklist (to be filled by reviewers)
changelog/
andintegration/
labels attached