Skip to content

Commit

Permalink
util: don't try to clean IP addresses. Also don't clean twice on Set (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gbrayut committed Sep 12, 2016
1 parent 8652fe4 commit 19f8e01
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions util/util.go
Expand Up @@ -2,6 +2,7 @@
package util // import "bosun.org/util" package util // import "bosun.org/util"


import ( import (
"net"
"os" "os"
"regexp" "regexp"
"strings" "strings"
Expand All @@ -18,19 +19,19 @@ var (
// Clean cleans a hostname based on the current FullHostname setting. // Clean cleans a hostname based on the current FullHostname setting.
func Clean(s string) string { func Clean(s string) string {
if !FullHostname { if !FullHostname {
s = strings.SplitN(s, ".", 2)[0] //only split if string is not an IP address
ip := net.ParseIP(s)
if ip == nil {
s = strings.SplitN(s, ".", 2)[0]
}
} }
return strings.ToLower(s) return strings.ToLower(s)
} }


// Set sets Hostntame based on the current preferences. // Set sets Hostntame based on the current preferences.
func Set() { func Set() {
h, err := os.Hostname() h, err := os.Hostname()
if err == nil { if err != nil {
if !FullHostname {
h = strings.SplitN(h, ".", 2)[0]
}
} else {
h = "unknown" h = "unknown"
} }
Hostname = Clean(h) Hostname = Clean(h)
Expand Down

0 comments on commit 19f8e01

Please sign in to comment.