open-nomad/client/fingerprint/host.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

41 lines
1,023 B
Go
Raw Normal View History

2015-08-26 21:27:44 +00:00
package fingerprint
import (
"runtime"
2015-08-26 21:27:44 +00:00
log "github.com/hashicorp/go-hclog"
2021-03-30 18:47:33 +00:00
"github.com/shirou/gopsutil/v3/host"
2015-08-26 21:27:44 +00:00
)
// HostFingerprint is used to fingerprint the host
type HostFingerprint struct {
2015-11-05 21:46:02 +00:00
StaticFingerprinter
logger log.Logger
2015-08-26 21:27:44 +00:00
}
// NewHostFingerprint is used to create a Host fingerprint
func NewHostFingerprint(logger log.Logger) Fingerprint {
f := &HostFingerprint{logger: logger.Named("host")}
2015-08-26 21:27:44 +00:00
return f
}
func (f *HostFingerprint) Fingerprint(req *FingerprintRequest, resp *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.Warn("error retrieving host information", "error", err)
return err
2015-08-26 21:27:44 +00:00
}
resp.AddAttribute("os.name", hostInfo.Platform)
resp.AddAttribute("os.version", hostInfo.PlatformVersion)
resp.AddAttribute("kernel.name", runtime.GOOS)
resp.AddAttribute("kernel.arch", hostInfo.KernelArch)
resp.AddAttribute("kernel.version", hostInfo.KernelVersion)
resp.AddAttribute("unique.hostname", hostInfo.Hostname)
2018-01-31 22:03:55 +00:00
resp.Detected = true
2015-08-26 21:27:44 +00:00
return nil
2015-08-26 21:27:44 +00:00
}