From 112ccf90dbff573299fc6b7b81307a3f2027a789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ask=20Bj=C3=B8rn=20Hansen?= Date: Tue, 12 Jun 2018 12:48:50 -0700 Subject: [PATCH] [dns] Add serial number metric for dns soa queries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ask Bjørn Hansen --- example.yml | 5 +++++ prober/dns.go | 34 +++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/example.yml b/example.yml index 690cb3b76..17beee045 100644 --- a/example.yml +++ b/example.yml @@ -111,6 +111,11 @@ modules: validate_additional_rrs: fail_if_matches_regexp: - ".*127.0.0.1" + dns_soa: + prober: dns + dns: + query_name: "prometheus.io" + query_type: "SOA" dns_tcp_example: prober: dns dns: diff --git a/prober/dns.go b/prober/dns.go index 94e276d32..d11aa6407 100644 --- a/prober/dns.go +++ b/prober/dns.go @@ -107,6 +107,17 @@ func ProbeDNS(ctx context.Context, target string, module config.Module, registry registry.MustRegister(probeDNSAuthorityRRSGauge) registry.MustRegister(probeDNSAdditionalRRSGauge) + qt := dns.TypeANY + if module.DNS.QueryType != "" { + var ok bool + qt, ok = dns.StringToType[module.DNS.QueryType] + if !ok { + level.Error(logger).Log("msg", "Invalid query type", "Type seen", module.DNS.QueryType, "Existing types", dns.TypeToString) + return false + } + } + var probeDNSSOAGauge prometheus.Gauge + var ip *net.IPAddr if module.DNS.TransportProtocol == "" { module.DNS.TransportProtocol = "udp" @@ -154,15 +165,6 @@ func ProbeDNS(ctx context.Context, target string, module config.Module, registry } } - qt := dns.TypeANY - if module.DNS.QueryType != "" { - var ok bool - qt, ok = dns.StringToType[module.DNS.QueryType] - if !ok { - level.Error(logger).Log("msg", "Invalid query type", "Type seen", module.DNS.QueryType, "Existing types", dns.TypeToString) - return false - } - } msg := new(dns.Msg) msg.SetQuestion(dns.Fqdn(module.DNS.QueryName), qt) @@ -180,6 +182,20 @@ func ProbeDNS(ctx context.Context, target string, module config.Module, registry probeDNSAuthorityRRSGauge.Set(float64(len(response.Ns))) probeDNSAdditionalRRSGauge.Set(float64(len(response.Extra))) + if qt == dns.TypeSOA { + probeDNSSOAGauge = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "probe_dns_serial", + Help: "Returns the serial number of the zone", + }) + registry.MustRegister(probeDNSSOAGauge) + + for _, a := range response.Answer { + if soa, ok := a.(*dns.SOA); ok { + probeDNSSOAGauge.Set(float64(soa.Serial)) + } + } + } + if !validRcode(response.Rcode, module.DNS.ValidRcodes, logger) { return false }