From fc02470ebe6c2d894d2c3c08714520d09730d3f5 Mon Sep 17 00:00:00 2001 From: "Louizia, Rhoubin's" Date: Fri, 31 Mar 2017 11:00:05 -0400 Subject: [PATCH] Refactoring --- journald2graylog.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/journald2graylog.go b/journald2graylog.go index fbf9a76..df6f378 100644 --- a/journald2graylog.go +++ b/journald2graylog.go @@ -29,7 +29,7 @@ var ( graylogHostname = kingpin.Flag("hostname", "Hostname or IP of your Graylog server, it has no default and MUST be specified").Envar("J2G_HOSTNAME").Required().String() graylogPort = kingpin.Flag("port", "Port of the UDP GELF input of the Graylog server").Default("12201").Envar("J2G_PORT").Int() graylogPacketSize = kingpin.Flag("packet-size", "Maximum size of the TCP/IP packets you can use between the source (journald2graylg) and the destination (your Graylog server)").Default("1420").Envar("J2G_PACKET_SIZE").Int() - maxRetryConnectionDurationInMin = kingpin.Flag("maxRetryConnectionDurationInMin", "Max Fail connection retrial duration").Default("2").Envar("J2G_MAXRETRYCONNECTION").Int() + maxRetryConnectionDurationInMin = kingpin.Flag("max-retry-time", "Max Fail connection retrial duration").Default("2").Envar("J2G_MAX_RETRY_TIME").Int() ) func main() { @@ -54,17 +54,17 @@ func main() { timeexec := time.Since(timenow) - if err != nil && timeexec > (time.Duration(*maxRetryConnectionDurationInMin)*time.Minute) { - - syscall.Exit(1) - } - if err != nil { - d := be.Duration() - fmt.Printf("%s, reconnecting in %s ", err, d) - time.Sleep(d) - } else if err == nil { + if err == nil { break } + if timeexec > (time.Duration(*maxRetryConnectionDurationInMin)*time.Minute) { + syscall.Exit(1) + } + + d := be.Duration() + fmt.Printf("%s, reconnecting in %s ", err, d) + time.Sleep(d) + } // Determine what will be the default value of the "hostname" field in the // GELF payload.