diff --git a/main.go b/main.go index d60c326..1e50715 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "errors" "flag" "fmt" "github.com/go-ping/ping" @@ -34,10 +35,11 @@ type Conf struct { } var ( - conf *Conf - journalLog = flag.Bool("journal", false, "Log to systemd journal instead of stdout") - configFlag = flag.String("config", "config.yaml", "Set config file to use") - reBandwidth = regexp.MustCompile(`(?m)bandwidth\s(\d+)Mbit`) + conf *Conf + journalLog = flag.Bool("journal", false, "Log to systemd journal instead of stdout") + configFlag = flag.String("config", "config.yaml", "Set config file to use") + reBandwidth = regexp.MustCompile(`(?m)bandwidth\s(\d+)Mbit`) + NoResponseError = errors.New("no response") ) type UploadManager struct { @@ -115,7 +117,7 @@ func doPing(host string, count int, interval time.Duration) (*ping.Statistics, e } log.Debugf("[PING] %s: %s±%s %d%% loss", host, pinger.Statistics().AvgRtt, pinger.Statistics().StdDevRtt, pinger.Statistics().PacketLoss) if pinger.Statistics().PacketLoss == 100 { - return nil, fmt.Errorf("no response") + return nil, NoResponseError } return pinger.Statistics(), nil } @@ -190,7 +192,9 @@ outerLoop: stats, err = doPing(conf.Host, conf.ConformationPPP, time.Second) if err != nil { log.Warningf("ping to %s failed: %v", conf.Host, err) - time.Sleep(time.Duration(conf.Interval) * time.Minute) + if !errors.Is(err, NoResponseError) { + time.Sleep(time.Duration(conf.Interval) * time.Minute) + } continue }