From 07b39499cdeac7d4843b04b544c8fca2a3bcd209 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Tue, 10 Nov 2015 10:07:30 +0100 Subject: [PATCH] Fix protocol version setting in NTP collector. The upstream library changed their interface - the global Version variable is gone: https://github.com/beevik/ntp/commit/283ed9d548825a1dae0994311560e8dbf8efac68 --- collector/ntp.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/collector/ntp.go b/collector/ntp.go index 1b6c8211..5b8ea914 100644 --- a/collector/ntp.go +++ b/collector/ntp.go @@ -44,7 +44,9 @@ func NewNtpCollector() (Collector, error) { if *ntpServer == "" { return nil, fmt.Errorf("no NTP server specifies, see --ntpServer") } - ntp.Version = byte(*ntpProtocolVersion) + if *ntpProtocolVersion < 2 || *ntpProtocolVersion > 4 { + return nil, fmt.Errorf("invalid NTP protocol version %d; must be 2, 3, or 4") + } return &ntpCollector{ drift: prometheus.NewGauge(prometheus.GaugeOpts{ @@ -56,9 +58,9 @@ func NewNtpCollector() (Collector, error) { } func (c *ntpCollector) Update(ch chan<- prometheus.Metric) (err error) { - t, err := ntp.Time(*ntpServer) + t, err := ntp.TimeV(*ntpServer, byte(*ntpProtocolVersion)) if err != nil { - return fmt.Errorf("couldn't get ntp drift: %s", err) + return fmt.Errorf("couldn't get NTP drift: %s", err) } drift := t.Sub(time.Now()) log.Debugf("Set ntp_drift_seconds: %f", drift.Seconds())