Permalink
Browse files

util: don't try to clean IP addresses. Also don't clean twice on Set (#…

  • Loading branch information...
1 parent 8652fe4 commit 19f8e016ffcbbf4a949f1381537d2704ffe7f2d7 @gbrayut gbrayut committed on GitHub Sep 12, 2016
Showing with 7 additions and 6 deletions.
  1. +7 −6 util/util.go
View
@@ -2,6 +2,7 @@
package util // import "bosun.org/util"
import (
+ "net"
"os"
"regexp"
"strings"
@@ -18,19 +19,19 @@ var (
// Clean cleans a hostname based on the current FullHostname setting.
func Clean(s string) string {
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)
}
// Set sets Hostntame based on the current preferences.
func Set() {
h, err := os.Hostname()
- if err == nil {
- if !FullHostname {
- h = strings.SplitN(h, ".", 2)[0]
- }
- } else {
+ if err != nil {
h = "unknown"
}
Hostname = Clean(h)

0 comments on commit 19f8e01

Please sign in to comment.