refactor: fix many linter warnings
This commit is contained in:
parent
43e4f2a6f0
commit
68b88bc766
7 changed files with 191 additions and 163 deletions
cmd/zoneserial
|
@ -5,15 +5,16 @@ import (
|
|||
"net"
|
||||
"os"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/karrick/golf"
|
||||
"github.com/miekg/dns"
|
||||
|
||||
"nocternity.net/gomonop/pkg/perfdata"
|
||||
"nocternity.net/gomonop/pkg/plugin"
|
||||
"nocternity.net/gomonop/pkg/program"
|
||||
|
||||
"github.com/karrick/golf"
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------
|
||||
|
@ -33,7 +34,7 @@ type (
|
|||
// Query a zone's SOA record through a given DNS and return the response using the channel.
|
||||
func queryZoneSOA(dnsq *dns.Msg, hostname string, port int, output responseChannel) {
|
||||
dnsc := new(dns.Client)
|
||||
in, rtt, err := dnsc.Exchange(dnsq, net.JoinHostPort(hostname, fmt.Sprintf("%d", port)))
|
||||
in, rtt, err := dnsc.Exchange(dnsq, net.JoinHostPort(hostname, strconv.Itoa(port)))
|
||||
output <- queryResponse{
|
||||
data: in,
|
||||
rtt: rtt,
|
||||
|
@ -88,7 +89,7 @@ func NewProgram() program.Program {
|
|||
func (program *checkProgram) Done() {
|
||||
if r := recover(); r != nil {
|
||||
program.plugin.SetState(plugin.UNKNOWN, "Internal error")
|
||||
program.plugin.AddLine("Error info: %v", r)
|
||||
program.plugin.AddLinef("Error info: %v", r)
|
||||
}
|
||||
program.plugin.Done()
|
||||
}
|
||||
|
@ -131,7 +132,7 @@ func (program *checkProgram) queryServers() (queryResponse, queryResponse) {
|
|||
go queryZoneSOA(dnsq, program.hostname, program.port, checkOut)
|
||||
go queryZoneSOA(dnsq, program.rsHostname, program.rsPort, refOut)
|
||||
var checkResponse, refResponse queryResponse
|
||||
for i := 0; i < 2; i++ {
|
||||
for range 2 {
|
||||
select {
|
||||
case m := <-checkOut:
|
||||
checkResponse = m
|
||||
|
@ -145,7 +146,7 @@ func (program *checkProgram) queryServers() (queryResponse, queryResponse) {
|
|||
// Add a server's RTT to the performance data.
|
||||
func (program *checkProgram) addRttPerf(name string, value time.Duration) {
|
||||
s := fmt.Sprintf("%f", value.Seconds())
|
||||
pd := perfdata.New(name, perfdata.UOM_SECONDS, s)
|
||||
pd := perfdata.New(name, perfdata.UomSeconds, s)
|
||||
program.plugin.AddPerfData(pd)
|
||||
}
|
||||
|
||||
|
@ -155,20 +156,20 @@ func (program *checkProgram) addRttPerf(name string, value time.Duration) {
|
|||
// successful.
|
||||
func (program *checkProgram) getSerial(server string, response queryResponse) (ok bool, serial uint32) {
|
||||
if response.err != nil {
|
||||
program.plugin.AddLine("%s server error : %s", server, response.err)
|
||||
program.plugin.AddLinef("%s server error : %s", server, response.err)
|
||||
return false, 0
|
||||
}
|
||||
program.addRttPerf(fmt.Sprintf("%s_rtt", server), response.rtt)
|
||||
program.addRttPerf(server+"_rtt", response.rtt)
|
||||
if len(response.data.Answer) != 1 {
|
||||
program.plugin.AddLine("%s server did not return exactly one record", server)
|
||||
program.plugin.AddLine(server + " server did not return exactly one record")
|
||||
return false, 0
|
||||
}
|
||||
if soa, ok := response.data.Answer[0].(*dns.SOA); ok {
|
||||
program.plugin.AddLine("serial on %s server: %d", server, soa.Serial)
|
||||
program.plugin.AddLinef("serial on %s server: %d", server, soa.Serial)
|
||||
return true, soa.Serial
|
||||
}
|
||||
t := reflect.TypeOf(response.data.Answer[0])
|
||||
program.plugin.AddLine("%s server did not return SOA record; record type: %v", server, t)
|
||||
program.plugin.AddLinef("%s server did not return SOA record; record type: %v", server, t)
|
||||
return false, 0
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue