-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
host.go
39 lines (30 loc) · 968 Bytes
/
host.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package fingerprint
import (
"runtime"
log "github.com/hashicorp/go-hclog"
"github.com/shirou/gopsutil/v3/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
}