Oto zmodyfikowany kod, który przy uruchomieniu wywołuje flagi w celu wyświetlenia określonych informacji:
package main
import (
"flag"
"fmt"
"log"
"os/exec"
"github.com/digitalocean/go-smbios/smbios"
)
func main() {
batteryFlag := flag.Bool("b", false, "Display Battery Information")
memoryDeviceFlag := flag.Bool("md", false, "Display Memory Device Information")
memoryControllerFlag := flag.Bool("mc", false, "Display Memory Controller Information")
cpuFlag := flag.Bool("cpu", false, "Display Processor Information")
chassisFlag := flag.Bool("c", false, "Display Chassis Information")
baseboardFlag := flag.Bool("bi", false, "Display Baseboard Information")
systemFlag := flag.Bool("si", false, "Display System Information")
biosFlag := flag.Bool("bios", false, "Display BIOS Information")
devFlag := flag.String("dev", "", "Specify device name for SMART Information")
flag.Parse()
s, err := smbios.NewSMBios()
if err != nil {
log.Fatal(err)
}
if *batteryFlag {
displayBatteryInformation(s)
}
if *memoryDeviceFlag {
displayMemoryDeviceInformation(s)
}
if *memoryControllerFlag {
displayMemoryControllerInformation(s)
}
if *cpuFlag {
displayProcessorInformation(s)
}
if *chassisFlag {
displayChassisInformation(s)
}
if *baseboardFlag {
displayBaseboardInformation(s)
}
if *systemFlag {
displaySystemInformation(s)
}
if *biosFlag {
displayBiosInformation(s)
}
if *devFlag != "" {
displaySmartInformation(*devFlag)
}
}
func displayBatteryInformation(s *smbios.SMBios) {
for _, t := range s.All() {
if t.Type == 22 {
fmt.Println("Portable Battery Information:")
fmt.Println("Location:", t.Text)
fmt.Println("Manufacturer:", t.Text)
fmt.Println("Manufacturer Date:", t.Text)
fmt.Println("Serial Number:", t.Text)
fmt.Println("Device Name:", t.Text)
fmt.Println("Device Chemistry:", t.Text)
fmt.Println("Designed Capacity:", t.Text)
fmt.Println("Full Charge Capacity:", t.Text)
fmt.Println("Device ID:", t.Text)
fmt.Println("Type:", t.Text)
break
}
}
}
func displayMemoryDeviceInformation(s *smbios.SMBios) {
for _, t := range s.All() {
if t.Type == 17 {
fmt.Println("Memory Device Information:")
fmt.Println("Array Handle:", t.Text)
fmt.Println("Error Information Handle:", t.Text)
fmt.Println("Total Width:", t.Text)
fmt.Println("Data Width:", t.Text)
fmt.Println("Size:", t.Text)
fmt.Println("Form Factor:", t.Text)
fmt.Println("Set:", t.Text)
fmt.Println("Locator:", t.Text)
fmt.Println("Bank Locator:", t.Text)
fmt.Println("Type:", t.Text)
fmt.Println("Type Detail:", t.Text)
fmt.Println("Speed:", t.Text)
fmt.Println("Manufacturer:", t.Text)
fmt.Println("Serial Number:", t.Text)
fmt.Println("Asset Tag:", t.Text)
fmt.Println("Part Number:", t.Text)
fmt.Println("Attributes:", t.Text)
break
}
}
}
func displayMemoryControllerInformation(s *smbios.SMBios) {
for _, t := range s.All() {
if t.Type == 5 {
fmt.Println("Memory Controller Information:")
fmt.Println("Error Detecting Method:", t.Text)
fmt.Println("Error Correcting Capabilities:", t.Text)
fmt.Println("Supported Interleave:", t.Text)
fmt.Println("Current Interleave:", t.Text)
fmt.Println("Max Memory Module Size:", t.Text)
fmt.Println("Supported Speeds:", t.Text)
fmt.Println("Supported Memory Types:", t.Text)
break
}
}
}
func displayProcessorInformation(s *smbios.SMBios) {
for _, t := range s.All() {
if t.Type == 4 {
fmt.Println("Processor Information:")
fmt.Println("Socket Designation:", t.Text)
fmt.Println("Type:", t.Text)
fmt.Println("Family:", t.Text)
fmt.Println("Manufacturer:", t.Text)
fmt.Println("ID:", t.Text)
fmt.Println("Version:", t.Text)
fmt.Println("Voltage:", t.Text)
fmt.Println("External Clock:", t.Text)
fmt.Println("Max Speed:", t.Text)
fmt.Println("Current Speed:", t.Text)
fmt.Println("Status:", t.Text)
fmt.Println("Upgrade:", t.Text)
fmt.Println("L1 Cache Handle:", t.Text)
fmt.Println("L2 Cache Handle:", t.Text)
fmt.Println("L3 Cache Handle:", t.Text)
break
}
}
}
func displayChassisInformation(s *smbios.SMBios) {
for _, t := range s.All() {
if t.Type == 3 {
fmt.Println("Chassis Information:")
fmt.Println("Manufacturer:", t.Text)
fmt.Println("Type:", t.Text)
fmt.Println("Version:", t.Text)
fmt.Println("Serial Number:", t.Text)
fmt.Println("Asset Tag:", t.Text)
break
}
}
}
func displayBaseboardInformation(s *smbios.SMBios) {
for _, t := range s.All() {
if t.Type == 2 {
fmt.Println("Baseboard Information:")
fmt.Println("Manufacturer:", t.Text)
fmt.Println("Product Name:", t.Text)
fmt.Println("Version:", t.Text)
fmt.Println("Serial Number:", t.Text)
fmt.Println("Asset Tag:", t.Text)
break
}
}
}
func displaySystemInformation(s *smbios.SMBios) {
for _, t := range s.All() {
if t.Type == 1 {
fmt.Println("System Information:")
fmt.Println("Manufacturer:", t.Text)
fmt.Println("Product Name:", t.Text)
fmt.Println("Serial Number:", t.Text)
fmt.Println("UUID:", t.Text)
fmt.Println("Family:", t.Text)
break
}
}
}
func displayBiosInformation(s *smbios.SMBios) {
for _, t := range s.All() {
if t.Type == 0 {
fmt.Println("BIOS Information:")
fmt.Println("Vendor:", t.Text)
fmt.Println("Version:", t.Text)
fmt.Println("Release Date:", t.Text)
break
}
}
}
func displaySmartInformation(deviceName string) {
out, err := exec.Command("smartctl", "-A", "/dev/"+deviceName).Output()
if err != nil {
log.Fatal(err)
}
fmt.Println("SMART Information for /dev/" + deviceName + ":")
fmt.Println(string(out))
}
Ten zmodyfikowany kod zawiera flagi, które można przekazać przy uruchamianiu programu, aby wywołać ż