Detects hostname/interface ip
- Hostname is monitor's id. Incidents will be created with the monitor id.
This commit is contained in:
24
system/config.go
Normal file
24
system/config.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user