Add DNS Check#109
Conversation
|
Example output from {
"check": "google-com-dns",
"owner": "50f7c76a",
"status": "ok",
"count": 0,
"message": "N/A",
"date": "2017-03-05T13:50:06.577859813Z",
"config": {
"type": "dns",
"description": "google.com DNS check",
"host": "8.8.8.8",
"interval": "10s",
"timeout": "1s",
"dns-target": "google.com",
"dns-record-type": "A",
"dns-max-time": "100ms",
"dns-expected-count": 0,
"warning-threshold": 1,
"critical-threshold": 3,
"warning-alerter": [
"primary-slack"
],
"critical-alerter": [
"primary-email"
]
}
} |
| if foundCount > 0 && foundCount < expectedCount { | ||
| return fmt.Errorf( | ||
| "DNS check of %s against %s had %d records. Only %d matched", | ||
| dns.RMC.Config.DnsTarget, dns.RMC.Config.Host, dns.RMC.Config.Expect, |
There was a problem hiding this comment.
I think you're missing a field here.
|
I'll rebase/squash this PR once I've got a thumbs up. |
dselans
left a comment
There was a problem hiding this comment.
Looks awesome! One minor thing about the PTR record type.
| case "SRV": | ||
| msgType = resolver.TypeSRV | ||
| case "TXT": | ||
| msgType = resolver.TypeTXT |
There was a problem hiding this comment.
Probably should include PTR here as well.
There was a problem hiding this comment.
I spent forever looking and couldn't find a function in that lib that did this. But it turns out there is a map in there that will do it for all the records it will support. I'll push that up shortly.
Using this resolver lib because the built-in Go resolver will only use the resolv.conf settings and can't be pointed to an arbitrary host to resolve against.
079d0fd to
0a93f84
Compare
|
Thanks @skey! Fixed that issue as I described above. Also found small bug in the matcher which is fixed. Finally, squashed into a nice commit on this branch. Ready for merge if you're happy. |
|
I went ahead and added the validation -- if there's a reason you excluded it, we can pull it out in another PR. Going ahead and merging - this is awesome! |
| return dns | ||
| } | ||
|
|
||
| func (dns *DnsMonitor) Validate() error { |
There was a problem hiding this comment.
What do you think about adding a record type check in here? That way if someone puts in a "foo" record type in the config, it won't even bother starting the check. Another side note (and probably separate pr) - a failed validation should probably bubble up an event.
There was a problem hiding this comment.
Went ahead and added it to your branch.
There was a problem hiding this comment.
Great catch, just overlooked it.
| func (dns *DnsMonitor) dnsCheck() error { | ||
| msg := &resolver.Msg{} | ||
|
|
||
| qType, ok := resolver.StringToType[strings.ToUpper(dns.RecordType)] |
There was a problem hiding this comment.
Yeah, I couldn't believe it didn't, but the docs are not great and it took hours to find it.
This adds a DNS check and docs and resolves #28 . The test suite is not fully complete since I still need to figure out how to mock out the DNS calls. The check has been tested locally and seems to work. The docs explain the mechanics.
I had to add a dependency on miekg/dns because the built-in Go resolver only supports querying hosts that are contained in the normal host resolver (i.e.
/etc/resolv.conf) which is no good from a monitoring standpoint since it puts too much of the OS stuff in the way of the DNS query. That would be a useful check to make sure DNS resolution is working on a node, but not useful in checking if an arbitrary host can resolve an arbitrary record. Also, I can set a proper timeout with this library.The configuration of the check allows it to do a number of things and the defaults try to do the sane thing.
Let me know what you think.
@skey