open-nomad/client/fingerprint/host.go

40 lines
971 B
Go
Raw Normal View History

2015-08-26 21:27:44 +00:00
package fingerprint
import (
"log"
"runtime"
2015-08-26 21:27:44 +00:00
cstructs "github.com/hashicorp/nomad/client/structs"
2015-08-26 21:27:44 +00:00
"github.com/shirou/gopsutil/host"
)
// HostFingerprint is used to fingerprint the host
type HostFingerprint struct {
2015-11-05 21:46:02 +00:00
StaticFingerprinter
2015-08-26 21:27:44 +00:00
logger *log.Logger
}
// NewHostFingerprint is used to create a Host fingerprint
func NewHostFingerprint(logger *log.Logger) Fingerprint {
f := &HostFingerprint{logger: logger}
2015-08-26 21:27:44 +00:00
return f
}
func (f *HostFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp *cstructs.FingerprintResponse) error {
2016-05-09 15:19:04 +00:00
hostInfo, err := host.Info()
2015-08-26 21:27:44 +00:00
if err != nil {
f.logger.Println("[WARN] Error retrieving host information: ", err)
return err
2015-08-26 21:27:44 +00:00
}
resp.Attributes["os.name"] = hostInfo.Platform
resp.Attributes["os.version"] = hostInfo.PlatformVersion
resp.Attributes["kernel.name"] = runtime.GOOS
resp.Attributes["kernel.version"] = hostInfo.KernelVersion
resp.Attributes["unique.hostname"] = hostInfo.Hostname
2015-08-26 21:27:44 +00:00
return nil
2015-08-26 21:27:44 +00:00
}