-
Notifications
You must be signed in to change notification settings - Fork 815
[dns] Allow expected address to be checked in dns_check. #2799
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
5e3ceaa
5f6a781
aa11e01
65787fe
474a1f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,21 +52,27 @@ def query_dns(self, instance, timeout): | |
resolver.nameservers = [nameserver] | ||
|
||
record_type = instance.get('record_type', 'A') | ||
expected_results = instance.get('addresses', []) | ||
|
||
status = AgentCheck.CRITICAL | ||
start_time = time.time() | ||
try: | ||
self.log.debug('Querying "%s" record for hostname "%s"...' % (record_type, hostname)) | ||
answer = resolver.query(hostname, rdtype=record_type) | ||
resolved_value = answer.rrset.items[0].to_text() | ||
assert(answer.rrset.items[0].to_text()) | ||
end_time = time.time() | ||
if len(expected_results) > 0: | ||
if resolved_value not in expected_results: | ||
raise Exception('DNS resolution of %s resulted in unexpected address %s.' % (hostname, resolved_value)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There might be a better way than raising an exception, since this verification can only take place if the DNS resolution was done correctly: put this block after the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noticed, this is also a way to fix https://travis-ci.org/DataDog/dd-agent/jobs/156839184#L608 |
||
|
||
except dns.exception.Timeout: | ||
self.log.error('DNS resolution of %s timed out' % hostname) | ||
self.service_check(self.SERVICE_CHECK_NAME, status, tags=self._get_tags(instance)) | ||
raise | ||
except Exception: | ||
self.log.exception('DNS resolution of %s has failed.' % hostname) | ||
self.service_check(self.SERVICE_CHECK_NAME, status, tags=self._get_tags(instance)) | ||
except Exception as err: | ||
self.log.exception(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Passing the exception is not needed, |
||
self.service_check(self.SERVICE_CHECK_NAME, status, tags=self._get_tags(instance), message=err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you know what kind of exception is going to be raised ? I'm wondering if seeing the python exception is useful. |
||
raise | ||
else: | ||
if end_time - start_time > 0: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,9 @@ instances: | |
# Specify an (optional) `record_type` to customize the record type | ||
# queried by the check (default: "A") | ||
# record_type: A | ||
|
||
# Specify expected results if you want to check that the returned IP | ||
# matches. If you supply multiple records then a match to any one will | ||
# be considered success | ||
# addressses: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only two |
||
# - 127.0.0.1 |
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.
What about multiple DNS records ? We should probably takes all the addresses and try to see if one of them matches (all of them maybe makes more sense). What do you think ?