Exemple #1
0
func (d *daemon) Run(bind string, static string) error {
	// Add routes.
	d.addAPIRoute(apiURL+"/network", network.GetInterface)
	d.addAPIRoute(apiURL+"/network/interfaces", interfaces.GetInterface)
	d.addAPIRoute(apiURL+"/network/routes", routes.GetInterface)
	d.addAPIRoute(apiURL+"/system", system.GetInterface)
	d.addAPIRoute(apiURL+"/system/os", opsys.GetInterface)
	d.addAPIRoute(apiURL+"/system/kernel/config", config.GetInterface)
	d.addAPIRoute(apiURL+"/system/cpu", cpu.GetInterface)
	d.addAPIRoute(apiURL+"/system/cpu/load", load.GetInterface)
	d.addAPIRoute(apiURL+"/system/memory", memory.GetInterface)
	d.addAPIRoute(apiURL+"/system/sysctls", sysctls.GetInterface)
	d.addAPIRoute(apiURL+"/system/ipmi", ipmi.GetInterface)
	d.addAPIRoute(apiURL+"/system/ipmi/sensors", sensors.GetInterface)
	d.addAPIRoute(apiURL+"/system/rpms", rpms.GetInterface)
	d.addAPIRoute(apiURL+"/system/pcicards", pcicards.GetInterface)
	d.addAPIRoute(apiURL+"/system/kernel/modules", modules.GetInterface)
	d.addAPIRoute(apiURL+"/storage/disks", disks.GetInterface)
	d.addAPIRoute(apiURL+"/storage/mounts", mounts.GetInterface)
	d.addAPIRoute(apiURL+"/storage/lvm/physvols", physvols.GetInterface)
	d.addAPIRoute(apiURL+"/storage/lvm/logvols", logvols.GetInterface)
	d.addAPIRoute(apiURL+"/storage/lvm/volgrps", volgrps.GetInterface)
	d.addAPIRoute(apiURL+"/storage/filesystems", filesystems.GetInterface)
	d.addAPIRoute(apiURL+"/docker", docker.GetInterface)
	d.addAPIRoute(apiURL+"/docker/containers", containers.GetInterface)
	d.addAPIRoute(apiURL+"/docker/images", images.GetInterface)
	d.addStaticRoute("/", static)

	logr := handlers.LoggingHandler(os.Stderr, d.router)

	log.Infof("Bind to address and port: %s", bind)
	err := http.ListenAndServe(bind, logr)
	if err != nil {
		log.Fatal(err.Error())
	}

	return nil
}
func (d *daemon) Run(bind string, static string) error {
	// Add routes.
	d.addAPIRoute(apiURL+"/network/interfaces", interfaces.GetInterface)
	d.addAPIRoute(apiURL+"/network/routes", routes.GetInterface)
	d.addAPIRoute(apiURL+"/system", system.GetInterface)
	d.addAPIRoute(apiURL+"/system/os", opsys.GetInterface)
	d.addAPIRoute(apiURL+"/system/cpu", cpu.GetInterface)
	d.addAPIRoute(apiURL+"/system/cpu/load", load.GetInterface)
	d.addAPIRoute(apiURL+"/system/memory", memory.GetInterface)
	d.addAPIRoute(apiURL+"/docker", docker.GetInterface)
	d.addAPIRoute(apiURL+"/docker/containers", containers.GetInterface)
	d.addAPIRoute(apiURL+"/docker/images", images.GetInterface)
	d.addStaticRoute("/", static)

	logr := handlers.LoggingHandler(os.Stderr, d.router)

	log.Infof("Bind to address and port: %s", bind)
	err := http.ListenAndServe(bind, logr)
	if err != nil {
		log.Fatal(err.Error())
	}

	return nil
}
Exemple #3
0
func main() {
	usage := `Peekaboo

Usage:
  peekaboo daemon [--debug] [--bind=<addr>] [--static=<dir>]
  peekaboo list
  peekaboo get <hardware-type> [--filter=<path>]
  peekaboo -h | --help
  peekaboo --version

Commands:
  daemon               Start as a daemon serving HTTP requests.
  list                 List hardware names available.
  get                  Return information about hardware.

Arguments:
  hardware-type        Name of hardware to return information about.

Options:
  -h --help            Show this screen.
  --version            Show version.
  -d --debug           Debug.
  -b --bind=<addr>     Bind to address and port. [default: 0.0.0.0:5050]
  -s --static=<dir>    Directory for static content. [default: static]
  -f --filter=<path>   Filter result. [default: .]
`

	args, err := docopt.Parse(usage, nil, true, "Peekaboo "+version.Version, false)
	if err != nil {
		log.Fatalf(err.Error())
	}

	// Set verbose.
	if args["--debug"].(bool) {
		log.SetDebug()
	}

	// Check root.
	if runtime.GOOS != "darwin" && os.Getuid() != 0 {
		log.Fatal("This application requires root privileges to run.")
	}

	// List hardware types.
	if args["list"].(bool) {
		hwtypes.List()
	}

	// Get hardware type.
	if args["get"].(bool) {
		if err := hwtypes.Get(args["<hardware-type>"].(string), args["--filter"].(string)); err != nil {
			log.Fatal(err.Error())
		}
	}

	// Run as a daemon.
	if args["daemon"].(bool) {
		d := daemon.New()
		if err := d.Run(args["--bind"].(string), args["--static"].(string)); err != nil {
			log.Fatal(err.Error())
		}
	}
}