Add logs function (#1108)
This commit is contained in:
parent
c67ee1731c
commit
b420a2d930
4 changed files with 110 additions and 19 deletions
|
@ -59,6 +59,22 @@ paths:
|
||||||
$ref: "#/components/responses/GetHealthPortsOK"
|
$ref: "#/components/responses/GetHealthPortsOK"
|
||||||
"500":
|
"500":
|
||||||
$ref: "#/components/responses/ResponseInternalServerError"
|
$ref: "#/components/responses/ResponseInternalServerError"
|
||||||
|
/health/logs:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- Health methods
|
||||||
|
summary: Get log
|
||||||
|
operationId: getHealthlogs
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
content:
|
||||||
|
application/octet-stream:
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
format: binary
|
||||||
|
"500":
|
||||||
|
$ref: "#/components/responses/ResponseInternalServerError"
|
||||||
|
|
||||||
/file/test:
|
/file/test:
|
||||||
get:
|
get:
|
||||||
|
|
|
@ -65,6 +65,9 @@ type ServerInterface interface {
|
||||||
// Test file methods
|
// Test file methods
|
||||||
// (GET /file/test)
|
// (GET /file/test)
|
||||||
GetFileTest(ctx echo.Context) error
|
GetFileTest(ctx echo.Context) error
|
||||||
|
// Get log
|
||||||
|
// (GET /health/logs)
|
||||||
|
GetHealthlogs(ctx echo.Context) error
|
||||||
// Get port in use
|
// Get port in use
|
||||||
// (GET /health/ports)
|
// (GET /health/ports)
|
||||||
GetHealthPorts(ctx echo.Context) error
|
GetHealthPorts(ctx echo.Context) error
|
||||||
|
@ -89,6 +92,17 @@ func (w *ServerInterfaceWrapper) GetFileTest(ctx echo.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetHealthlogs converts echo context to params.
|
||||||
|
func (w *ServerInterfaceWrapper) GetHealthlogs(ctx echo.Context) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
ctx.Set(Access_tokenScopes, []string{""})
|
||||||
|
|
||||||
|
// Invoke the callback with all the unmarshalled arguments
|
||||||
|
err = w.Handler.GetHealthlogs(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// GetHealthPorts converts echo context to params.
|
// GetHealthPorts converts echo context to params.
|
||||||
func (w *ServerInterfaceWrapper) GetHealthPorts(ctx echo.Context) error {
|
func (w *ServerInterfaceWrapper) GetHealthPorts(ctx echo.Context) error {
|
||||||
var err error
|
var err error
|
||||||
|
@ -140,6 +154,7 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL
|
||||||
}
|
}
|
||||||
|
|
||||||
router.GET(baseURL+"/file/test", wrapper.GetFileTest)
|
router.GET(baseURL+"/file/test", wrapper.GetFileTest)
|
||||||
|
router.GET(baseURL+"/health/logs", wrapper.GetHealthlogs)
|
||||||
router.GET(baseURL+"/health/ports", wrapper.GetHealthPorts)
|
router.GET(baseURL+"/health/ports", wrapper.GetHealthPorts)
|
||||||
router.GET(baseURL+"/health/services", wrapper.GetHealthServices)
|
router.GET(baseURL+"/health/services", wrapper.GetHealthServices)
|
||||||
|
|
||||||
|
@ -148,24 +163,25 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL
|
||||||
// Base64 encoded, gzipped, json marshaled Swagger object
|
// Base64 encoded, gzipped, json marshaled Swagger object
|
||||||
var swaggerSpec = []string{
|
var swaggerSpec = []string{
|
||||||
|
|
||||||
"H4sIAAAAAAAC/8xW4W/bthP9Vwj+fh+aQbaMBAUKAf2QNksaBIODJcMGxIZLU2eJjURyd6QTL9D/PpCS",
|
"H4sIAAAAAAAC/8xX3W7bRhN9lcV+30VcUKIQI0BAIBf5aRwjKGQ0LlrAMpTVckRuQu5uZ4aKVYPvXuyS",
|
||||||
"Y8V2g6Rdh31yRB7fvfdyx+MDl6a2RoN2xLMHjkDWaIL4cQbuE4jKlZcGHY0vwpo02oF24U9hbaWkcMro",
|
"smhJEeykKXola3/OnHM8szO6ldrV3lmwTDK7lQjknSWIX86A34GquLxwyDR9H9a0swyWw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L03AuLeO9nNr1ZOk82RHcH0DfonnnffjPKz8Dx4IOpjTzBD3dbeb9",
|
"5VDrju9RU9cK14f4B9tUQTK7km+Hy9fhXlrGdzlkJg0s2dPbPd/x1GHFX2nYTjPwiBhB1fcb99JhrVhm",
|
||||||
"yqk3kvYWRIDtJgkjJ5wnZhYMhCzZ526G/PSZdTB7i2Vr9n2Xfb336I9xsBPSSX3WxN4cjE/dpxPwZtpM",
|
"cmFsYH6w7R2aYv5hv86AReWKgUud1sM++U0HPm5U16i/JTf25ugfozjoEMaKhuCBymnQug8WToDtO64g",
|
||||||
"Q0BIRnHfY8Uzni4Pu3uPh4AOftv1N9fjk/HBZnBuZQ+P5ecPPKn1kOh+4ERxhsbbNl8X98tOl+wInTZ/",
|
"VtyQcEsBSpfiY99rf/ooepiDRbUzI3yXfYO5/cc42AvppR41cTAvxJ8E9yeFq+v2OhwIwSjuN1jJTKar",
|
||||||
"BwAA///xoj5w+wwAAA==",
|
"p31/kOFAD7/r+pPL6ZvpyXbA2IkeflQcv3DvTQiBbkasijN0je/i9ed+2XtN9oRet38HAAD///s5WXsj",
|
||||||
|
"DgAA",
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSwagger returns the content of the embedded swagger specification file
|
// GetSwagger returns the content of the embedded swagger specification file
|
||||||
|
|
|
@ -73,7 +73,8 @@ func InitV2Router() http.Handler {
|
||||||
e.Use(echo_middleware.JWTWithConfig(echo_middleware.JWTConfig{
|
e.Use(echo_middleware.JWTWithConfig(echo_middleware.JWTConfig{
|
||||||
Skipper: func(c echo.Context) bool {
|
Skipper: func(c echo.Context) bool {
|
||||||
return c.RealIP() == "::1" || c.RealIP() == "127.0.0.1"
|
return c.RealIP() == "::1" || c.RealIP() == "127.0.0.1"
|
||||||
// return true
|
//return true
|
||||||
|
|
||||||
},
|
},
|
||||||
ParseTokenFunc: func(token string, c echo.Context) (interface{}, error) {
|
ParseTokenFunc: func(token string, c echo.Context) (interface{}, error) {
|
||||||
valid, claims, err := jwt.Validate(token, func() (*ecdsa.PublicKey, error) { return external.GetPublicKey(config.CommonInfo.RuntimePath) })
|
valid, claims, err := jwt.Validate(token, func() (*ecdsa.PublicKey, error) { return external.GetPublicKey(config.CommonInfo.RuntimePath) })
|
||||||
|
|
|
@ -2,10 +2,15 @@ package v2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/IceWhaleTech/CasaOS/codegen"
|
"github.com/IceWhaleTech/CasaOS/codegen"
|
||||||
|
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
|
||||||
"github.com/IceWhaleTech/CasaOS/service"
|
"github.com/IceWhaleTech/CasaOS/service"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/mholt/archiver/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *CasaOS) GetHealthServices(ctx echo.Context) error {
|
func (s *CasaOS) GetHealthServices(ctx echo.Context) error {
|
||||||
|
@ -41,3 +46,56 @@ func (s *CasaOS) GetHealthPorts(ctx echo.Context) error {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *CasaOS) GetHealthlogs(ctx echo.Context) error {
|
||||||
|
var name, currentPath, commonDir, extension string
|
||||||
|
var err error
|
||||||
|
var ar archiver.Writer
|
||||||
|
fileList, err := os.ReadDir("/var/log/casaos")
|
||||||
|
if err != nil {
|
||||||
|
message := err.Error()
|
||||||
|
return ctx.JSON(http.StatusInternalServerError, codegen.ResponseInternalServerError{
|
||||||
|
Message: &message,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
extension, ar, err = file.GetCompressionAlgorithm("zip")
|
||||||
|
if err != nil {
|
||||||
|
ctx.Response().Header().Set("Content-Type", "application/json")
|
||||||
|
message := err.Error()
|
||||||
|
return ctx.JSON(http.StatusNotFound, codegen.ResponseInternalServerError{
|
||||||
|
Message: &message,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
err = ar.Create(ctx.Response().Writer)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Response().Header().Set("Content-Type", "application/json")
|
||||||
|
message := err.Error()
|
||||||
|
return ctx.JSON(http.StatusNotFound, codegen.ResponseInternalServerError{
|
||||||
|
Message: &message,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer ar.Close()
|
||||||
|
|
||||||
|
commonDir = "/var/log/casaos"
|
||||||
|
|
||||||
|
currentPath = filepath.Base(commonDir)
|
||||||
|
|
||||||
|
name = currentPath
|
||||||
|
name += extension
|
||||||
|
ctx.Response().Header().Add("Content-Type", "application/octet-stream")
|
||||||
|
ctx.Response().Header().Add("Content-Transfer-Encoding", "binary")
|
||||||
|
ctx.Response().Header().Add("Cache-Control", "no-cache")
|
||||||
|
ctx.Response().Header().Add("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(name))
|
||||||
|
|
||||||
|
for _, fname := range fileList {
|
||||||
|
err := file.AddFile(ar, filepath.Join("/var/log/casaos", fname.Name()), commonDir)
|
||||||
|
if err != nil {
|
||||||
|
message := err.Error()
|
||||||
|
return ctx.JSON(http.StatusInternalServerError, codegen.ResponseInternalServerError{
|
||||||
|
Message: &message,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue