mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-25 10:31:30 +01:00
feat(proxmox): add journalctl endpoint without service; add limit parameter
Added new Proxmox journalctl endpoint `/journalctl/:node/:vmid` for viewing all journalctl output without requiring a service name. Made the service parameter optional across both endpoints. Introduced configurable `limit` query parameter (1-1000, default 100) to both proxmox journalctl and docker logs APIs, replacing hardcoded 100-line tail. Added container status check in LXCCommand to prevent command execution on stopped containers, returning a clear status message instead. Refactored route validation to use pre-fetched IPs and improved References() method for proxmox routes with better alias handling.
This commit is contained in:
@@ -146,6 +146,7 @@ func NewHandler(requireAuth bool) *gin.Engine {
|
||||
|
||||
proxmox := v1.Group("/proxmox")
|
||||
{
|
||||
proxmox.GET("/journalctl/:node/:vmid", proxmoxApi.Journalctl)
|
||||
proxmox.GET("/journalctl/:node/:vmid/:service", proxmoxApi.Journalctl)
|
||||
proxmox.GET("/stats/:node/:vmid", proxmoxApi.Stats)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/moby/moby/api/pkg/stdcopy"
|
||||
@@ -22,6 +23,7 @@ type LogsQueryParams struct {
|
||||
Since string `form:"from"`
|
||||
Until string `form:"to"`
|
||||
Levels string `form:"levels"`
|
||||
Limit int `form:"limit,default=100" binding:"omitempty,min=1,max=1000"`
|
||||
} // @name LogsQueryParams
|
||||
|
||||
// @x-id "logs"
|
||||
@@ -34,9 +36,10 @@ type LogsQueryParams struct {
|
||||
// @Param id path string true "container id"
|
||||
// @Param stdout query bool false "show stdout"
|
||||
// @Param stderr query bool false "show stderr"
|
||||
// @Param from query string false "from timestamp"
|
||||
// @Param to query string false "to timestamp"
|
||||
// @Param from query string false "from timestamp"
|
||||
// @Param to query string false "to timestamp"
|
||||
// @Param levels query string false "levels"
|
||||
// @Param limit query int false "limit"
|
||||
// @Success 200
|
||||
// @Failure 400 {object} apitypes.ErrorResponse
|
||||
// @Failure 403 {object} apitypes.ErrorResponse
|
||||
@@ -77,7 +80,7 @@ func Logs(c *gin.Context) {
|
||||
Until: queryParams.Until,
|
||||
Timestamps: true,
|
||||
Follow: true,
|
||||
Tail: "100",
|
||||
Tail: strconv.Itoa(queryParams.Limit),
|
||||
}
|
||||
if queryParams.Levels != "" {
|
||||
opts.Details = true
|
||||
|
||||
@@ -165,6 +165,76 @@
|
||||
"operationId": "verify"
|
||||
}
|
||||
},
|
||||
"/api/v1/proxmox/journalctl/{node}/{vmid}": {
|
||||
"get": {
|
||||
"description": "Get journalctl output",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"proxmox",
|
||||
"websocket"
|
||||
],
|
||||
"summary": "Get journalctl output",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"name": "node",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"name": "vmid",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "limit",
|
||||
"name": "limit",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Journalctl output",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ErrorResponse"
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "Unauthorized",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ErrorResponse"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "Node not found",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ErrorResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal server error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ErrorResponse"
|
||||
}
|
||||
}
|
||||
},
|
||||
"x-id": "journalctl",
|
||||
"operationId": "journalctl"
|
||||
}
|
||||
},
|
||||
"/api/v1/proxmox/journalctl/{node}/{vmid}/{service}": {
|
||||
"get": {
|
||||
"description": "Get journalctl output",
|
||||
@@ -189,14 +259,19 @@
|
||||
{
|
||||
"type": "string",
|
||||
"name": "service",
|
||||
"in": "path",
|
||||
"required": true
|
||||
"in": "path"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"name": "vmid",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "limit",
|
||||
"name": "limit",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
@@ -703,6 +778,12 @@
|
||||
"description": "levels",
|
||||
"name": "levels",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "limit",
|
||||
"name": "limit",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
|
||||
@@ -2088,6 +2088,52 @@ paths:
|
||||
tags:
|
||||
- agent
|
||||
x-id: verify
|
||||
/api/v1/proxmox/journalctl/{node}/{vmid}:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Get journalctl output
|
||||
parameters:
|
||||
- in: path
|
||||
name: node
|
||||
required: true
|
||||
type: string
|
||||
- in: path
|
||||
name: vmid
|
||||
required: true
|
||||
type: integer
|
||||
- description: limit
|
||||
in: query
|
||||
name: limit
|
||||
type: integer
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: Journalctl output
|
||||
schema:
|
||||
type: string
|
||||
"400":
|
||||
description: Invalid request
|
||||
schema:
|
||||
$ref: '#/definitions/ErrorResponse'
|
||||
"403":
|
||||
description: Unauthorized
|
||||
schema:
|
||||
$ref: '#/definitions/ErrorResponse'
|
||||
"404":
|
||||
description: Node not found
|
||||
schema:
|
||||
$ref: '#/definitions/ErrorResponse'
|
||||
"500":
|
||||
description: Internal server error
|
||||
schema:
|
||||
$ref: '#/definitions/ErrorResponse'
|
||||
summary: Get journalctl output
|
||||
tags:
|
||||
- proxmox
|
||||
- websocket
|
||||
x-id: journalctl
|
||||
/api/v1/proxmox/journalctl/{node}/{vmid}/{service}:
|
||||
get:
|
||||
consumes:
|
||||
@@ -2100,12 +2146,15 @@ paths:
|
||||
type: string
|
||||
- in: path
|
||||
name: service
|
||||
required: true
|
||||
type: string
|
||||
- in: path
|
||||
name: vmid
|
||||
required: true
|
||||
type: integer
|
||||
- description: limit
|
||||
in: query
|
||||
name: limit
|
||||
type: integer
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
@@ -2438,6 +2487,10 @@ paths:
|
||||
in: query
|
||||
name: levels
|
||||
type: string
|
||||
- description: limit
|
||||
in: query
|
||||
name: limit
|
||||
type: integer
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
|
||||
@@ -13,7 +13,8 @@ import (
|
||||
type JournalctlRequest struct {
|
||||
Node string `uri:"node" binding:"required"`
|
||||
VMID int `uri:"vmid" binding:"required"`
|
||||
Service string `uri:"service" binding:"required"`
|
||||
Service string `uri:"service"`
|
||||
Limit int `query:"limit" binding:"omitempty,min=1,max=1000"`
|
||||
}
|
||||
|
||||
// @x-id "journalctl"
|
||||
@@ -24,12 +25,14 @@ type JournalctlRequest struct {
|
||||
// @Accept json
|
||||
// @Produce application/json
|
||||
// @Param path path JournalctlRequest true "Request"
|
||||
// @Param limit query int false "limit"
|
||||
// @Success 200 string plain "Journalctl output"
|
||||
// @Failure 400 {object} apitypes.ErrorResponse "Invalid request"
|
||||
// @Failure 403 {object} apitypes.ErrorResponse "Unauthorized"
|
||||
// @Failure 404 {object} apitypes.ErrorResponse "Node not found"
|
||||
// @Failure 500 {object} apitypes.ErrorResponse "Internal server error"
|
||||
// @Router /api/v1/proxmox/journalctl/{node}/{vmid}/{service} [get]
|
||||
// @Router /api/v1/proxmox/journalctl/{node}/{vmid} [get]
|
||||
// @Router /api/v1/proxmox/journalctl/{node}/{vmid}/{service} [get]
|
||||
func Journalctl(c *gin.Context) {
|
||||
var request JournalctlRequest
|
||||
if err := c.ShouldBindUri(&request); err != nil {
|
||||
@@ -50,7 +53,7 @@ func Journalctl(c *gin.Context) {
|
||||
}
|
||||
defer manager.Close()
|
||||
|
||||
reader, err := node.LXCJournalctl(c.Request.Context(), request.VMID, request.Service)
|
||||
reader, err := node.LXCJournalctl(c.Request.Context(), request.VMID, request.Service, request.Limit)
|
||||
if err != nil {
|
||||
c.Error(apitypes.InternalServerError(err, "failed to get journalctl output"))
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user