dmidecode

package module
v0.0.0-...-8e8aebb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2020 License: MIT Imports: 6 Imported by: 1

README

dmidecode

dmidecode is a Go library that parses the output of the dmidecode command and makes it accessible via a simple map data structure.

In addition, the library exposes a couple of convenience methods for quicker record lookups.

Usage

import (
    dmidecode "github.com/7Linternational/dmidecode"
)

dmi := dmidecode.New()

if err := dmi.Run(); err != nil {
    fmt.Printf("Unable to get dmidecode information. Error: %v\n", err)
}

// You can search by record name
byNameData, byNameErr := dmi.SearchByName("System Information")

// or you can also search by record type
byTypeData, byTypeErr := dmi.SearchByType(1)

// or you can just access the data directly
for handle, record := range dmi.Data {
    fmt.Println("Checking record:", handle)
    for k, v := range record {
        fmt.Printf("Key: %v Val: %v\n", k, v)
    }
}

Note(s)

  • Record elements which contain an array/list, are stored as strings separated by 2 tabs (same as in dmidecode output). This may change in the future, but for the time being it's simple and quick.
  • dmidecode requires root privs to run as the binary reads /dev/mem.
  • I wrote this lib as I was learning Go - meaning, it is probably not idiomatic Go code and "things" could be (a lot) better :-)

Documentation

Index

Constants

View Source
const (
	DMIDecodeBinary = "dmidecode"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DMI

type DMI struct {
	Data   map[string][]Record
	Binary string
}

func New

func New() *DMI

func (*DMI) ExecDmidecode

func (d *DMI) ExecDmidecode(binary string) (string, error)

ExecDmiDecode will attempt to execute a given binary, capture its output and return it (or an any errors it encounters)

func (*DMI) FindBin

func (d *DMI) FindBin(binary string) (string, error)

FindBin will attempt to find a given binary in common bin paths.

func (*DMI) GenericSearchBy

func (d *DMI) GenericSearchBy(param, value string) ([]Record, error)

GenericSearchBy will search for any param w/ value in the d.Data map.

func (*DMI) ParseDmidecode

func (d *DMI) ParseDmidecode(output string) error

ParseDmiDecode will attempt to parse dmidecode output and place all matching content in d.Data.

func (*DMI) Run

func (d *DMI) Run() error

Run will attempt to find a a valid `dmidecode` bin, attempt to execute it and parse whatever data it gets.

func (*DMI) SearchByName

func (d *DMI) SearchByName(name string) ([]Record, error)

SearchByName will search for a specific DMI record by name in d.Data

func (*DMI) SearchByType

func (d *DMI) SearchByType(id int) ([]Record, error)

SearchByType will search for a specific DMI record by its type in d.Data

type Record

type Record map[string]string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL