diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index bb93cbdb..5419fe3e 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -33,6 +33,7 @@ import ( "fmt" "os/exec" "strconv" + "strings" "time" "bitbucket.org/ausocean/av/revid" @@ -93,7 +94,6 @@ const ( // Globals var ( - ns netsender.Netsender revidInst revid.Revid config revid.Config ) @@ -247,6 +247,7 @@ func main() { config.Timeout = *configFlags[timeoutPtr] config.IntraRefreshPeriod = *configFlags[intraRefreshPeriodPtr] + var ns netsender.Netsender var vs int if *netSenderFlagPtr { // initialize NetSender and use NetSender's logger @@ -267,7 +268,7 @@ func main() { // loop in NetSender mode for *netSenderFlagPtr { - if err := netSend(); err != nil { + if err := sendTo(ns); err != nil { config.Logger.Log(progName, "Error", err.Error()) time.Sleep(netSendRetryTime) continue @@ -305,24 +306,22 @@ func main() { stopRevid() } -// netSend implements the NetSender client, and is called every monPeriod seconds. -// It handles NetReceiver configuration and sends requested data to the cloud. -func netSend() error { +// sendTo handles NetReceiver configuration and sends requested data to the cloud. +func sendTo(ns netsender.Netsender) error { if !ns.IsConfigured() { - if err := ns.Config(); err != nil { + err := ns.Config() + if err != nil { return err } } - inputs := netsender.SplitCSV(ns.GetConfigParam("ip")) - if _, reconfig, err := ns.Send(netsender.RequestPoll, inputs); err != nil { + inputs := strings.Split(ns.GetConfigParam("ip"), ",") + _, reconfig, err := ns.Send(netsender.RequestPoll, inputs) + if err != nil { return err - } else { - if reconfig { - if err := ns.Config(); err != nil { - return err - } - } + } + if reconfig { + return ns.Config() } return nil }