Skip to content

Commit

Permalink
allow user to manually set desired hostname (elastic#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioMeireles committed Mar 8, 2015
1 parent de79786 commit fe165a2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions logstash-forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var exitStat = struct {

var options = &struct {
configArg string
hostname string
spoolSize uint64
harvesterBufferSize int
cpuProfileFile string
Expand All @@ -37,6 +38,7 @@ var options = &struct {
func emitOptions() {
emit("\t--- options -------\n")
emit("\tconfig-arg: %s\n", options.configArg)
emit("\thostname: %s\n", options.hostname)
emit("\tidle-timeout: %v\n", options.idleTimeout)
emit("\tspool-size: %d\n", options.spoolSize)
emit("\tharvester-buff-size: %d\n", options.harvesterBufferSize)
Expand All @@ -63,6 +65,7 @@ const logflags = log.Ldate | log.Ltime | log.Lmicroseconds
func init() {
flag.StringVar(&options.configArg, "config", options.configArg, "path to logstash-forwarder configuration file or directory")

flag.StringVar(&options.hostname, "hostname", options.hostname, "hostname we want to advertise as")
flag.StringVar(&options.cpuProfileFile, "cpuprofile", options.cpuProfileFile, "path to cpu profile output - note: exits on profile end.")

flag.Uint64Var(&options.spoolSize, "spool-size", options.spoolSize, "event count spool threshold - forces network flush")
Expand Down
12 changes: 11 additions & 1 deletion publisher1.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"math/rand"
"net"
"os"
Expand All @@ -26,7 +27,16 @@ var hostname string
var hostport_re, _ = regexp.Compile("^(.+):([0-9]+)$")

func init() {
hostname, _ = os.Hostname()
var err error

hostname = options.hostname
if options.hostname == "" {
hostname, err = os.Hostname()
if err != nil {
log.Fatal("Hostname detection failed. Set -hostname flag or fix server's hostname reporting.",
err)
}
}
rand.Seed(time.Now().UnixNano())
}

Expand Down

0 comments on commit fe165a2

Please sign in to comment.