open-nomad/client/fingerprint/host.go
Danielle Tomlinson 66c521ca17 client: Move fingerprint structs to pkg
This removes a cyclical dependency when importing client/structs from
dependencies of the plugin_loader, specifically, drivers. Due to
client/config also depending on the plugin_loader.

It also better reflects the ownership of fingerprint structs, as they
are fairly internal to the fingerprint manager.
2018-12-01 17:10:39 +01:00

40 lines
965 B
Go

package fingerprint
import (
"runtime"
log "github.com/hashicorp/go-hclog"
"github.com/shirou/gopsutil/host"
)
// HostFingerprint is used to fingerprint the host
type HostFingerprint struct {
StaticFingerprinter
logger log.Logger
}
// NewHostFingerprint is used to create a Host fingerprint
func NewHostFingerprint(logger log.Logger) Fingerprint {
f := &HostFingerprint{logger: logger.Named("host")}
return f
}
func (f *HostFingerprint) Fingerprint(req *FingerprintRequest, resp *FingerprintResponse) error {
hostInfo, err := host.Info()
if err != nil {
f.logger.Warn("error retrieving host information", "error", err)
return err
}
resp.AddAttribute("os.name", hostInfo.Platform)
resp.AddAttribute("os.version", hostInfo.PlatformVersion)
resp.AddAttribute("kernel.name", runtime.GOOS)
resp.AddAttribute("kernel.version", hostInfo.KernelVersion)
resp.AddAttribute("unique.hostname", hostInfo.Hostname)
resp.Detected = true
return nil
}