Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow user to manually set desired hostname #260

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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