[#3c9g25] Add endpoint for returning basic system information
This commit is contained in:
parent
89806427f9
commit
a1fa876734
16
http.go
16
http.go
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/buger/jsonparser"
|
"github.com/buger/jsonparser"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/pterodactyl/wings/installer"
|
"github.com/pterodactyl/wings/installer"
|
||||||
"github.com/pterodactyl/wings/server"
|
"github.com/pterodactyl/wings/server"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -449,6 +450,20 @@ func (rt *Router) routeCreateServer(w http.ResponseWriter, r *http.Request, ps h
|
||||||
w.WriteHeader(http.StatusAccepted)
|
w.WriteHeader(http.StatusAccepted)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rt *Router) routeSystemInformation(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
|
defer r.Body.Close()
|
||||||
|
|
||||||
|
s, err := GetSystemInformation()
|
||||||
|
if err != nil {
|
||||||
|
zap.S().Errorw("failed to retrieve system information", zap.Error(errors.WithStack(err)))
|
||||||
|
|
||||||
|
http.Error(w, "failed to retrieve information", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
json.NewEncoder(w).Encode(s)
|
||||||
|
}
|
||||||
|
|
||||||
func (rt *Router) ReaderToBytes(r io.Reader) []byte {
|
func (rt *Router) ReaderToBytes(r io.Reader) []byte {
|
||||||
buf := bytes.Buffer{}
|
buf := bytes.Buffer{}
|
||||||
buf.ReadFrom(r)
|
buf.ReadFrom(r)
|
||||||
|
@ -461,6 +476,7 @@ func (rt *Router) ConfigureRouter() *httprouter.Router {
|
||||||
router := httprouter.New()
|
router := httprouter.New()
|
||||||
|
|
||||||
router.GET("/", rt.routeIndex)
|
router.GET("/", rt.routeIndex)
|
||||||
|
router.GET("/api/system", rt.AuthenticateToken(rt.routeSystemInformation))
|
||||||
router.GET("/api/servers", rt.AuthenticateToken(rt.routeAllServers))
|
router.GET("/api/servers", rt.AuthenticateToken(rt.routeAllServers))
|
||||||
router.GET("/api/servers/:server", rt.AuthenticateRequest(rt.routeServer))
|
router.GET("/api/servers/:server", rt.AuthenticateRequest(rt.routeServer))
|
||||||
router.GET("/api/servers/:server/ws", rt.AuthenticateServer(rt.routeWebsocket))
|
router.GET("/api/servers/:server/ws", rt.AuthenticateServer(rt.routeWebsocket))
|
||||||
|
|
31
system.go
Normal file
31
system.go
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/docker/docker/pkg/parsers/kernel"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SystemInformation struct {
|
||||||
|
Version string `json:"version"`
|
||||||
|
KernelVersion string `json:"kernel_version"`
|
||||||
|
Architecture string `json:"architecture"`
|
||||||
|
OS string `json:"os"`
|
||||||
|
CpuCount int `json:"cpu_count"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetSystemInformation() (*SystemInformation, error) {
|
||||||
|
k, err := kernel.GetKernelVersion()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
s := &SystemInformation{
|
||||||
|
Version: Version,
|
||||||
|
KernelVersion: k.String(),
|
||||||
|
Architecture: runtime.GOARCH,
|
||||||
|
OS: runtime.GOOS,
|
||||||
|
CpuCount: runtime.NumCPU(),
|
||||||
|
}
|
||||||
|
|
||||||
|
return s, nil
|
||||||
|
}
|
3
wings.go
3
wings.go
|
@ -23,8 +23,6 @@ func main() {
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
zap.S().Infof("using configuration file: %s", configPath)
|
|
||||||
|
|
||||||
c, err := config.ReadConfiguration(configPath)
|
c, err := config.ReadConfiguration(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -40,6 +38,7 @@ func main() {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
zap.S().Infof("using configuration from path: %s", configPath)
|
||||||
if c.Debug {
|
if c.Debug {
|
||||||
zap.S().Debugw("running in debug mode")
|
zap.S().Debugw("running in debug mode")
|
||||||
zap.S().Infow("certificate checking is disabled")
|
zap.S().Infow("certificate checking is disabled")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user