github.com/hhrutter/nomad@v0.6.0-rc2.0.20170723054333-80c4b03f0705/client/fingerprint/host.go (about) 1 package fingerprint 2 3 import ( 4 "log" 5 "runtime" 6 7 "github.com/hashicorp/nomad/client/config" 8 "github.com/hashicorp/nomad/nomad/structs" 9 "github.com/shirou/gopsutil/host" 10 ) 11 12 // HostFingerprint is used to fingerprint the host 13 type HostFingerprint struct { 14 StaticFingerprinter 15 logger *log.Logger 16 } 17 18 // NewHostFingerprint is used to create a Host fingerprint 19 func NewHostFingerprint(logger *log.Logger) Fingerprint { 20 f := &HostFingerprint{logger: logger} 21 return f 22 } 23 24 func (f *HostFingerprint) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) { 25 hostInfo, err := host.Info() 26 if err != nil { 27 f.logger.Println("[WARN] Error retrieving host information: ", err) 28 return false, err 29 } 30 31 node.Attributes["os.name"] = hostInfo.Platform 32 node.Attributes["os.version"] = hostInfo.PlatformVersion 33 34 node.Attributes["kernel.name"] = runtime.GOOS 35 node.Attributes["kernel.version"] = hostInfo.KernelVersion 36 37 node.Attributes["unique.hostname"] = hostInfo.Hostname 38 39 return true, nil 40 }