From 0fc7986bd060a9bb28e86557c6060d84663fbb0a Mon Sep 17 00:00:00 2001 From: Simon Marsh Date: Wed, 29 May 2019 19:37:27 +0100 Subject: [PATCH] Allow checking multiple SOAs from different servers --- dns.go | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/dns.go b/dns.go index 8db104f..c66bc58 100644 --- a/dns.go +++ b/dns.go @@ -9,7 +9,7 @@ package main import ( "encoding/json" "errors" - // "fmt" + // "fmt" dns "github.com/miekg/dns" "github.com/prometheus/client_golang/prometheus" log "github.com/sirupsen/logrus" @@ -143,6 +143,11 @@ func (m *DNSMetrics) Collect() { now := uint64(time.Now().Unix()) + // icky icky icky + masters := make([]uint64, 2) + masters[0] = dns_servers[0].soa + masters[1] = dns_servers[6].soa + // go through each server in turn for ix, server := range dns_servers { @@ -161,12 +166,18 @@ func (m *DNSMetrics) Collect() { // didn't get a result, server issue valid = 2 } else { - if server.soa != dns_servers[0].soa { - // SOA didn't match - valid = 1 - } else { - valid = 0 + // check if the SOA matches any defined master SOA + + // assume not + valid = 1 + for _, soa := range masters { + if server.soa == soa { + // match was found + valid = 0 + break + } } + } // before setting whether the server is valid, calculate the stime @@ -280,8 +291,16 @@ func (m *DNSCommitMetrics) Collect() { m.mismatch = true } + since := now.Sub(m.since).Seconds() + + log.WithFields(log.Fields{ + "master": mc, + "explorer": ec, + "since": since, + }).Warn("DNS Commit Mismatch") + // set the metric to be the interval since last good match - m.match.With(m.labelInvalid).Set(float64(now.Sub(m.since).Seconds())) + m.match.With(m.labelInvalid).Set(float64(since)) } } else { @@ -326,7 +345,7 @@ func (m *DNSCommitMetrics) FetchExplorerCommit() (string, error) { func (m *DNSCommitMetrics) FetchMasterCommit() (string, error) { - response, err := http.Get("http://[2a0c:3800:1:1011:5054:ff:fe87:ea39]:8080/api/git-db-state") + response, err := http.Get("http://[fd42:180:3de0:10:5054:ff:fe87:ea39]:8080/api/git-db-state") if err != nil { log.WithFields(log.Fields{ "error": err,