github.com/anuvu/nomad@v0.8.7-atom1/client/fingerprint/host.go (about)

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