Skip to content

Check dns improve queries#405

Open
inqrphl wants to merge 12 commits into
mainfrom
check-dns-improve-queries
Open

Check dns improve queries#405
inqrphl wants to merge 12 commits into
mainfrom
check-dns-improve-queries

Conversation

@inqrphl

@inqrphl inqrphl commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

add support for performing multiple queries over given nameservers and search domains in resolv.conf file. previosuly, only the first nameserver was used, and search domains were not used at all

now check all combinations in the order specified by DNS standard similar to how system libraries resolve them. the combinations are tried until a non-empty answer is found

additionally, add helper functions to snclient codebase to insert logger to the context. this context is passed to builtin_checks: check_dns, check_http , check_nsc_web , check_ssh , check_tcp

added warning, critical thresholds. these work on total time needed to get a valid DNS response, which might need multiple DNS requests over different nameserver + search domain combinations. the program prints out the result, but raises the return status to warning/critical. it does not use the response time of the valid DNS query, but the total time required. this is analog to monitoring-plugins check_dns , which measures the time needed for nslookup and uses it

added timeout argument, this stops the DNS queries completely and returns critical status with the timeout message.

Ahmet Oeztuerk added 5 commits July 10, 2026 15:28
add the ability to specify /etc/resolv.conf

add the ability to append search domains to hostname

todo:

implement dns queries over multiple nameservers, currently it only uses the first one in config

implement dns queries over multiple search domains, currently it only uses the first one in config

implement warning critical timeouts
previously the code would parse a resolv.conf and pick the first option, not trying to combine all possible names and search paths. the code now checks multiple combinations, until it gets an non-empty answer

add a custom argument ResolvConfFile to point at a different resolv.conf

add logging support, takes the logger passed through context. use it to print logs if verbose mode is enabled

rework handling comparions required to check for expected strings from argumnets. use slice comparion functions
fix typo in platform check "darwin"

properly exit the DNS query loop after getting an answer

suppress linter from complaining about reutned context

regenerate docs
@inqrphl inqrphl marked this pull request as draft July 10, 2026 15:31
Ahmet Oeztuerk and others added 5 commits July 13, 2026 11:51
warning and critical thresholds on the total time for the DNS queries,
until a successfull non-empty answer is found. the program still returns
the query results , but raises a warning/critical status as well

warning/critical thresholds use the total time needed, just like
montioring-plugins check_dns, which launches nslookup executable. this
program does the dns queries itself, multiples of them if multiple
nameservers and search domains are configured

added also timeout, which stops the program and returns critical directly
when exceeded. default is 10 seconds.
…one.one address

test expected string functionality , MX and AAAA records
@inqrphl inqrphl marked this pull request as ready for review July 13, 2026 10:20
@inqrphl inqrphl marked this pull request as draft July 13, 2026 14:45
@inqrphl

inqrphl commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

todo: add time metric , get it from the valid and useful dns query. so far we have been ignoring it

@inqrphl

inqrphl commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

./snclient -vvv --logfile stdout run check_dns --host labs.consol.de

[17:33:41.973][T][check_dns:97] DNS nameservers: [10.250.0.20:53] 
[17:33:41.973][T][check_dns:107] DNS search paths: [wlan.consol.de int.consol.de] 
[17:33:41.973][T][check_dns:123] DNS host candidates: [labs.consol.de.wlan.consol.de. labs.consol.de.int.consol.de. labs.consol.de.] 
[17:33:41.976][T][check_dns:66] DNS query returned empty result, continuing to next combination, host: labs.consol.de.wlan.consol.de., nameserver: 10.250.0.20:53, duration: 2ms
[17:33:41.979][T][check_dns:66] DNS query returned empty result, continuing to next combination, host: labs.consol.de.int.consol.de., nameserver: 10.250.0.20:53, duration: 2ms
[17:33:41.986][D][check_dns:71] successfully queried DNS, host: labs.consol.de., nameserver: 10.250.0.20:53, duration: 7ms
[17:33:41.986][T][check_dns:66] DNS query took 0.012880 seconds, and it is lower than (if specified) warning threshold: <nil> and critical threshold: <nil>
...
[17:35:32.692][D][snclient:794] check check_dns took 9.664419ms to finish
OK - labs.consol.de returns 94.185.89.33 (A) |time=0.007439s;;
HEADER-> ;; opcode: QUERY, status: NOERROR, id: 41680
;; flags: qr aa rd ra;
ANSWER-> labs.consol.de.        7200    IN      A       94.185.89.33

./snclient -vvv --logfile stdout run check_dns --host thishostdoesnotexist.com

[17:34:41.964][T][check_dns:107] DNS search paths: [wlan.consol.de int.consol.de] 
[17:34:41.964][T][check_dns:123] DNS host candidates: [thishostdoesnotexist.com.wlan.consol.de. thishostdoesnotexist.com.int.consol.de. thishostdoesnotexist.com.] 
[17:34:41.975][T][check_dns:66] DNS query returned empty result, continuing to next combination, host: thishostdoesnotexist.com.wlan.consol.de., nameserver: 10.250.0.20:53, duration: 11ms
[17:34:41.981][T][check_dns:66] DNS query returned empty result, continuing to next combination, host: thishostdoesnotexist.com.int.consol.de., nameserver: 10.250.0.20:53, duration: 6ms
[17:34:42.004][T][check_dns:66] DNS query returned empty result, continuing to next combination, host: thishostdoesnotexist.com., nameserver: 10.250.0.20:53, duration: 22ms
[17:34:42.004][D][snclient:794] check check_dns took 40.722035ms to finish
CRITICAL - All 3 DNS queries gave empty results or failed, last error: <nil>

@inqrphl inqrphl marked this pull request as ready for review July 13, 2026 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant