mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-23 09:18:51 +02: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:
@@ -23,6 +23,15 @@ func (n *Node) LXCCommand(ctx context.Context, vmid int, command string) (io.Rea
|
||||
return nil, fmt.Errorf("failed to get node: %w", err)
|
||||
}
|
||||
|
||||
lxc, err := node.Container(ctx, vmid)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get container: %w", err)
|
||||
}
|
||||
|
||||
if lxc.Status != "running" {
|
||||
return io.NopCloser(bytes.NewReader(fmt.Appendf(nil, "container %d is not running, status: %s\n", vmid, lxc.Status))), nil
|
||||
}
|
||||
|
||||
term, err := node.TermProxy(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get term proxy: %w", err)
|
||||
@@ -117,6 +126,16 @@ func (n *Node) LXCCommand(ctx context.Context, vmid int, command string) (io.Rea
|
||||
}
|
||||
|
||||
// LXCJournalctl streams journalctl output for the given service.
|
||||
func (n *Node) LXCJournalctl(ctx context.Context, vmid int, service string) (io.ReadCloser, error) {
|
||||
return n.LXCCommand(ctx, vmid, fmt.Sprintf("journalctl -u %q -f", service))
|
||||
//
|
||||
// If service is not empty, it will be used to filter the output by service.
|
||||
// If limit is greater than 0, it will be used to limit the number of lines of output.
|
||||
func (n *Node) LXCJournalctl(ctx context.Context, vmid int, service string, limit int) (io.ReadCloser, error) {
|
||||
command := "journalctl -f"
|
||||
if service != "" {
|
||||
command = fmt.Sprintf("journalctl -u %q -f", service)
|
||||
}
|
||||
if limit > 0 {
|
||||
command = fmt.Sprintf("%s -n %d", command, limit)
|
||||
}
|
||||
return n.LXCCommand(ctx, vmid, command)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user