Files
cachet-monitor/system/config.go
Matej Kramny dce1978b51 Detects hostname/interface ip
- Hostname is monitor's id. Incidents will be created with the monitor id.
2015-03-21 11:44:52 +01:00

25 lines
351 B
Go

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
}