Example #1
0
func (d *daemon) addAPIRoute(endpoint string, getHwType func() (interface{}, error)) {
	log.Infof("Add API endpoint: %s method: GET", endpoint)
	d.router.HandleFunc(endpoint, d.funcAPIRoute(endpoint, getHwType)).Methods("GET")

	log.Infof("Add API purge cache endpoint: %s method: PURGE", endpoint)
	d.router.HandleFunc(endpoint, d.funcAPIPurgeRoute(endpoint, getHwType)).Methods("PURGE")
}
Example #2
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
}
Example #3
0
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
}
Example #4
0
func (d *daemon) addStaticRoute(endpoint, path string) {
	endpoint = strings.TrimRight(endpoint, "/") + "/"
	log.Infof("Add static endpoint: %s path: %s", endpoint, path)
	d.router.PathPrefix(endpoint).Handler(http.StripPrefix(endpoint, http.FileServer(http.Dir(path))))
	http.Handle(endpoint, d.router)
}