Beispiel #1
0
// Get information about a system.
func Get() (System, error) {
	s := System{}

	o, err := common.LoadFiles([]string{
		"/sys/devices/virtual/dmi/id/chassis_vendor",
		"/sys/devices/virtual/dmi/id/product_name",
		"/sys/devices/virtual/dmi/id/product_version",
		"/sys/devices/virtual/dmi/id/product_serial",
		"/sys/devices/virtual/dmi/id/bios_vendor",
		"/sys/devices/virtual/dmi/id/bios_date",
		"/sys/devices/virtual/dmi/id/bios_version",
	})
	if err != nil {
		return System{}, err
	}

	s.Manufacturer = o["chassis_vendor"]
	s.Product = o["product_name"]
	s.ProductVersion = o["product_version"]
	s.SerialNumber = o["product_serial"]
	s.BIOSVendor = o["bios_vendor"]
	s.BIOSDate = o["bios_date"]
	s.BIOSVersion = o["bios_version"]

	return s, nil
}
func (s *system) ForceUpdate() error {
	s.cache.LastUpdated = time.Now()
	s.cache.FromCache = false

	o, err := common.LoadFiles([]string{
		"/sys/devices/virtual/dmi/id/chassis_vendor",
		"/sys/devices/virtual/dmi/id/product_name",
		"/sys/devices/virtual/dmi/id/product_version",
		"/sys/devices/virtual/dmi/id/product_serial",
		"/sys/devices/virtual/dmi/id/bios_vendor",
		"/sys/devices/virtual/dmi/id/bios_date",
		"/sys/devices/virtual/dmi/id/bios_version",
	})
	if err != nil {
		return err
	}

	s.data.Manufacturer = o["chassis_vendor"]
	s.data.Product = o["product_name"]
	s.data.ProductVersion = o["product_version"]
	s.data.SerialNumber = o["product_serial"]
	s.data.BIOSVendor = o["bios_vendor"]
	s.data.BIOSDate = o["bios_date"]
	s.data.BIOSVersion = o["bios_version"]

	return nil
}
Beispiel #3
0
func (disks *disks) ForceUpdate() error {
	disks.cache.LastUpdated = time.Now()
	disks.cache.FromCache = false

	files, err := filepath.Glob("/sys/class/block/*")
	if err != nil {
		return err
	}

	for _, path := range files {
		o, err := common.LoadFiles([]string{
			filepath.Join(path, "dev"),
			filepath.Join(path, "size"),
		})
		if err != nil {
			return err
		}

		d := dataItem{}

		d.Name = filepath.Base(path)
		d.Device = o["dev"]

		d.SizeKB, err = strconv.Atoi(o["size"])
		if err != nil {
			return err
		}
		d.SizeKB = d.SizeKB * 512 / 1024
		d.SizeGB = d.SizeKB / 1024 / 1024

		*disks.data = append(*disks.data, d)
	}

	return nil
}
Beispiel #4
0
// Get system disks.
func Get() ([]Disk, error) {
	da := []Disk{}

	files, err := filepath.Glob("/sys/class/block/*")
	if err != nil {
		return []Disk{}, err
	}

	for _, path := range files {
		o, err := common.LoadFiles([]string{
			filepath.Join(path, "dev"),
			filepath.Join(path, "size"),
		})
		if err != nil {
			return []Disk{}, err
		}

		d := Disk{}

		d.Name = filepath.Base(path)
		d.Device = o["dev"]

		d.SizeGB, err = strconv.Atoi(o["size"])
		if err != nil {
			return []Disk{}, err
		}
		d.SizeGB = d.SizeGB * 512 / 1024 / 1024 / 1024

		da = append(da, d)
	}

	return da, nil
}
Beispiel #5
0
func (p *pci) ForceUpdate() error {
	p.cache.LastUpdated = time.Now()
	p.cache.FromCache = false

	files, err := filepath.Glob("/sys/bus/pci/devices/*")
	if err != nil {
		return err
	}

	for _, path := range files {
		slot := strings.SplitN(path, ":", 2)

		o, err := common.LoadFiles([]string{
			filepath.Join(path, "class"),
			filepath.Join(path, "vendor"),
			filepath.Join(path, "device"),
			filepath.Join(path, "subsystem_vendor"),
			filepath.Join(path, "subsystem_device"),
		})
		if err != nil {
			return err
		}

		classID := o["class"][2:]
		class, subClass, _, err := getPCIClass(classID)
		if err != nil {
			return err
		}
		if subClass != "" {
			class = subClass
		}

		vendorID := o["vendor"][2:]
		deviceID := o["device"][2:]
		sVendorID := o["subsystem_vendor"][2:]
		sDeviceID := o["subsystem_device"][2:]
		vendor, dev, sName, err := getPCIVendor(vendorID, deviceID, sVendorID, sDeviceID)
		if err != nil {
			return err
		}

		*p.data = append(*p.data, DataItem{
			Slot:      slot[1],
			ClassID:   classID,
			Class:     class,
			VendorID:  vendorID,
			DeviceID:  deviceID,
			SDeviceID: sDeviceID,
			SVendorID: sVendorID,
			Vendor:    vendor,
			Device:    dev,
			SName:     sName,
		})
	}

	return nil
}
Beispiel #6
0
// Get information about system PCI slots.
func Get() ([]PCI, error) {
	p := []PCI{}

	files, err := filepath.Glob("/sys/bus/pci/devices/*")
	if err != nil {
		return []PCI{}, err
	}

	for _, path := range files {
		slot := strings.SplitN(path, ":", 2)

		o, err := common.LoadFiles([]string{
			filepath.Join(path, "class"),
			filepath.Join(path, "vendor"),
			filepath.Join(path, "device"),
			filepath.Join(path, "subsystem_vendor"),
			filepath.Join(path, "subsystem_device"),
		})
		if err != nil {
			return []PCI{}, err
		}

		classID := o["class"][2:]
		class, subClass, _, err := getPCIClass(classID)
		if err != nil {
			return []PCI{}, err
		}
		if subClass != "" {
			class = subClass
		}

		vendorID := o["vendor"][2:]
		deviceID := o["device"][2:]
		sVendorID := o["subsystem_vendor"][2:]
		sDeviceID := o["subsystem_device"][2:]
		vendor, device, sName, err := getPCIVendor(vendorID, deviceID, sVendorID, sDeviceID)
		if err != nil {
			return []PCI{}, err
		}

		p = append(p, PCI{
			Slot:      slot[1],
			ClassID:   classID,
			Class:     class,
			VendorID:  vendorID,
			DeviceID:  deviceID,
			SDeviceID: sDeviceID,
			SVendorID: sVendorID,
			Vendor:    vendor,
			Device:    device,
			SName:     sName,
		})
	}

	return p, nil
}