Ejemplo n.º 1
0
func Get() (Disks, error) {
	disks := Disks{}

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

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

		d := Disk{}

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

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

		disks = append(disks, d)
	}

	return disks, nil
}
Ejemplo n.º 2
0
func Get() (System, error) {
	s := System{}

	host, err := os.Hostname()
	if err != nil {
		return System{}, err
	}
	s.Hostname = host
	s.ShortHostname = strings.Split(host, ".")[0]

	s.PeekabooVersion = version.Version

	m, err := parse.LoadFiles([]string{
		"/sys/devices/virtual/dmi/id/sys_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 = m["sys_vendor"]
	s.Product = m["product_name"]
	s.ProductVersion = m["product_version"]
	s.SerialNumber = m["product_serial"]
	s.BIOSVendor = m["bios_vendor"]
	s.BIOSDate = m["bios_date"]
	s.BIOSVersion = m["bios_version"]

	return s, nil
}