2015-08-26 21:27:44 +00:00
|
|
|
package fingerprint
|
|
|
|
|
|
|
|
import (
|
2015-08-28 00:37:37 +00:00
|
|
|
"runtime"
|
2015-08-26 21:27:44 +00:00
|
|
|
|
2018-09-16 00:48:59 +00:00
|
|
|
log "github.com/hashicorp/go-hclog"
|
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
|
2018-09-16 00:48:59 +00:00
|
|
|
logger log.Logger
|
2015-08-26 21:27:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewHostFingerprint is used to create a Host fingerprint
|
2018-09-16 00:48:59 +00:00
|
|
|
func NewHostFingerprint(logger log.Logger) Fingerprint {
|
|
|
|
f := &HostFingerprint{logger: logger.Named("host")}
|
2015-08-26 21:27:44 +00:00
|
|
|
return f
|
|
|
|
}
|
|
|
|
|
2018-12-01 16:10:39 +00:00
|
|
|
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 {
|
2018-09-16 00:48:59 +00:00
|
|
|
f.logger.Warn("error retrieving host information", "error", err)
|
2018-01-24 14:09:53 +00:00
|
|
|
return err
|
2015-08-26 21:27:44 +00:00
|
|
|
}
|
|
|
|
|
2018-01-26 16:21:07 +00:00
|
|
|
resp.AddAttribute("os.name", hostInfo.Platform)
|
|
|
|
resp.AddAttribute("os.version", hostInfo.PlatformVersion)
|
2015-08-28 00:37:37 +00:00
|
|
|
|
2018-01-26 16:21:07 +00:00
|
|
|
resp.AddAttribute("kernel.name", runtime.GOOS)
|
|
|
|
resp.AddAttribute("kernel.version", hostInfo.KernelVersion)
|
2015-08-28 00:37:37 +00:00
|
|
|
|
2018-01-26 16:21:07 +00:00
|
|
|
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
|
|
|
|
2018-01-24 14:09:53 +00:00
|
|
|
return nil
|
2015-08-26 21:27:44 +00:00
|
|
|
}
|