From f184eb78af4515ce440ecdebb1dff217aa880567 Mon Sep 17 00:00:00 2001 From: Pete Fraedrich Date: Fri, 24 Apr 2020 12:24:17 -0400 Subject: [PATCH] hypervisor discovery --- go.mod | 2 ++ go.sum | 2 ++ hypervisor.go | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 go.sum create mode 100644 hypervisor.go diff --git a/go.mod b/go.mod index bb1894e..89499b2 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/yeticloud/libdetectcloud go 1.14 + +require github.com/digitalocean/go-smbios v0.0.0-20180907143718-390a4f403a8e diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..b20a30a --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/digitalocean/go-smbios v0.0.0-20180907143718-390a4f403a8e h1:vUmf0yezR0y7jJ5pceLHthLaYf4bA5T14B6q39S4q2Q= +github.com/digitalocean/go-smbios v0.0.0-20180907143718-390a4f403a8e/go.mod h1:YTIHhz/QFSYnu/EhlF2SpU2Uk+32abacUYA5ZPljz1A= diff --git a/hypervisor.go b/hypervisor.go new file mode 100644 index 0000000..0109615 --- /dev/null +++ b/hypervisor.go @@ -0,0 +1,38 @@ +package libdetectcloud + +import ( + "fmt" + "log" + + "github.com/digitalocean/go-smbios/smbios" +) + +// BIOS type +type BIOS struct { + Manufacturer string + ProductName string + SerialNumber string + IsVM bool + Hypervisor string +} + +//BIOSInfo function gets information from the SMBIOS +func BIOSInfo() { + rc, _, err := smbios.Stream() + if err != nil { + log.Fatalf("failed to open stream: %v", err) + } + // Be sure to close the stream! + defer rc.Close() + + // Decode SMBIOS structures from the stream. + d := smbios.NewDecoder(rc) + ss, err := d.Decode() + if err != nil { + log.Fatalf("failed to decode structures: %v", err) + } + for _, s := range ss { + fmt.Println(s) + } + +}