github.com/smithx10/nomad@v0.9.1-rc1/client/fingerprint/host.go (about)

     1  package fingerprint
     2  
     3  import (
     4  	"runtime"
     5  
     6  	log "github.com/hashicorp/go-hclog"
     7  	"github.com/shirou/gopsutil/host"
     8  )
     9  
    10  // HostFingerprint is used to fingerprint the host
    11  type HostFingerprint struct {
    12  	StaticFingerprinter
    13  	logger log.Logger
    14  }
    15  
    16  // NewHostFingerprint is used to create a Host fingerprint
    17  func NewHostFingerprint(logger log.Logger) Fingerprint {
    18  	f := &HostFingerprint{logger: logger.Named("host")}
    19  	return f
    20  }
    21  
    22  func (f *HostFingerprint) Fingerprint(req *FingerprintRequest, resp *FingerprintResponse) error {
    23  	hostInfo, err := host.Info()
    24  	if err != nil {
    25  		f.logger.Warn("error retrieving host information", "error", err)
    26  		return err
    27  	}
    28  
    29  	resp.AddAttribute("os.name", hostInfo.Platform)
    30  	resp.AddAttribute("os.version", hostInfo.PlatformVersion)
    31  
    32  	resp.AddAttribute("kernel.name", runtime.GOOS)
    33  	resp.AddAttribute("kernel.version", hostInfo.KernelVersion)
    34  
    35  	resp.AddAttribute("unique.hostname", hostInfo.Hostname)
    36  	resp.Detected = true
    37  
    38  	return nil
    39  }