Detects hostname/interface ip

- Hostname is monitor's id. Incidents will be created with the monitor id.
This commit is contained in:
Matej Kramny
2015-03-21 11:44:52 +01:00
parent bdb426c232
commit dce1978b51
4 changed files with 50 additions and 12 deletions

24
system/config.go Normal file
View File

@@ -0,0 +1,24 @@
package system
import (
"net"
"os"
)
// GetHostname returns id of the current system
func GetHostname() string {
hostname, err := os.Hostname()
if err != nil || len(hostname) == 0 {
addrs, err := net.InterfaceAddrs()
if err != nil {
return "unknown"
}
for _, addr := range addrs {
return addr.String()
}
}
return hostname
}