From f531f2d111ccf23d75ac4a523a9b6ad4016f2668 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Nussbaumer?= Date: Wed, 8 Mar 2023 10:17:46 +0100 Subject: [PATCH] fix: log rcode as hex if not in RcodeToString map MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Clément Nussbaumer --- main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index e332234..ee078aa 100644 --- a/main.go +++ b/main.go @@ -211,8 +211,14 @@ func (l *lookuper) start(interval time.Duration) { m := new(dns.Msg) m.SetQuestion(fmt.Sprintf("%s.", l.host), dns.TypeA) msg, rtt, err := l.c.Exchange(m, l.dnsServer.address) + rcodeStr, ok := dns.RcodeToString[msg.Rcode] + + if !ok { // rcode not known in table. + rcodeStr = fmt.Sprintf("%#x", msg.Rcode) + } + metrics.GetOrCreateCounter(fmt.Sprintf("%s{%s,rcode=%q}", - dnsLookupTotalName, l.labels, dns.RcodeToString[msg.Rcode])).Inc() + dnsLookupTotalName, l.labels, rcodeStr)).Inc() if err != nil { metrics.GetOrCreateCounter(fmt.Sprintf("%s{%s}", dnsErrorsTotalName, l.labels)).Inc()