Example #1
0
func Get(hwType string, filter string) error {
	var r interface{}
	var err error

	switch hwType {
	case "ifs", "network/interfaces":
		r, err = interfaces.Get()
	case "routes", "network/routes":
		r, err = routes.Get()
	case "sys", "system":
		r, err = system.Get()
	case "os", "system/os":
		r, err = opsys.Get()
	case "cpu", "system/cpu":
		r, err = cpu.Get()
	case "load", "system/cpu/load":
		r, err = load.Get()
	case "mem", "system/memory":
		r, err = memory.Get()
	case "dkr", "docker":
		r, err = docker.Get()
	case "cnts", "docker/containers":
		r, err = containers.Get()
	case "imgs", "docker/images":
		r, err = images.Get()
	default:
		return fmt.Errorf("Unknown hardware type: %s", hwType)
	}

	if err != nil {
		return err
	}

	b, _ := json.MarshalIndent(r, "", "  ")
	j, err := dquery.FilterJSON(filter, b)
	if err != nil {
		return err
	}
	fmt.Println(string(j))

	return nil
}
Example #2
0
func Get(hwType string, filter string) error {
	var r interface{}
	var err error

	switch hwType {
	case "net", "network":
		r, err = network.Get()
	case "ifs", "network/interfaces":
		r, err = interfaces.GetInterface()
	case "routes", "network/routes":
		r, err = routes.Get()
	case "sys", "system":
		r, err = system.Get()
	case "os", "system/os":
		r, err = opsys.Get()
	case "kcfg", "system/kernel/config":
		r, err = config.Get()
	case "cpu", "system/cpu":
		r, err = cpu.Get()
	case "load", "system/cpu/load":
		r, err = load.Get()
	case "sysctls", "system/sysctls":
		r, err = sysctls.Get()
	case "mem", "system/memory":
		r, err = memory.Get()
	case "ipmi", "system/ipmi":
		r, err = ipmi.Get()
	case "sensors", "system/ipmi/sensors":
		r, err = sensors.Get()
	case "rpms", "system/rpms":
		r, err = rpms.Get()
	case "pci", "system/pcicards":
		r, err = pcicards.Get()
	case "mods", "system/kernel/modules":
		r, err = modules.Get()
	case "disks", "storage/disks":
		r, err = disks.Get()
	case "mounts", "storage/mounts":
		r, err = mounts.Get()
	case "pvs", "storage/lvm/physvols":
		r, err = physvols.Get()
	case "lvs", "storage/lvm/logvols":
		r, err = logvols.Get()
	case "vgs", "storage/lvm/volgrps":
		r, err = volgrps.Get()
	case "fs", "storage/filesystems":
		r, err = filesystems.Get()
	case "dkr", "docker":
		r, err = docker.Get()
	case "cnts", "docker/containers":
		r, err = containers.Get()
	case "imgs", "docker/images":
		r, err = images.Get()
	default:
		return fmt.Errorf("Unknown hardware type: %s", hwType)
	}

	if err != nil {
		return err
	}

	j, err := dquery.FilterJSON(filter, r)
	if err != nil {
		return err
	}
	fmt.Println(string(j))

	return nil
}