diff --git a/src/yangerd/internal/collector/containers.go b/src/yangerd/internal/collector/containers.go index 08008232..7cd2f509 100644 --- a/src/yangerd/internal/collector/containers.go +++ b/src/yangerd/internal/collector/containers.go @@ -362,12 +362,20 @@ func (c *ContainerCollector) container(ctx context.Context, ps map[string]interf "status": asString(ps["Status"]), } - cmd := strings.Join(asStringSlice(ps["Command"]), " ") - if cmd != "" { - out["command"] = cmd + inspect := c.podmanInspect(ctx, name) + + // Report the actual running command line as the config-false + // "cmdline" leaf (an unrestricted string), built from inspect's + // Path + Args like the legacy yanger collector. Do NOT report it + // into the config-true "command" leaf: that leaf has a restrictive + // pattern and a real command line (e.g. one containing "&&" or + // quotes) fails YANG validation, which rejects the entire + // containers subtree on read. + if path := asString(inspect["Path"]); path != "" { + parts := append([]string{path}, asStringSlice(inspect["Args"])...) + out["cmdline"] = strings.Join(parts, " ") } - inspect := c.podmanInspect(ctx, name) if net := c.network(ps, inspect); len(net) > 0 { out["network"] = net } diff --git a/src/yangerd/internal/collector/containers_test.go b/src/yangerd/internal/collector/containers_test.go index 2ee3abc5..fced4437 100644 --- a/src/yangerd/internal/collector/containers_test.go +++ b/src/yangerd/internal/collector/containers_test.go @@ -60,7 +60,7 @@ func TestContainerBasicInfo(t *testing.T) { "Ports": [] } ]`), - "podman inspect web": []byte(`[{}]`), + "podman inspect web": []byte(`[{"Path":"nginx","Args":["-g","daemon off;"]}]`), "podman stats --no-stream --format json --no-reset web": []byte(`[]`), }, Errors: map[string]error{}, @@ -87,8 +87,8 @@ func TestContainerBasicInfo(t *testing.T) { if c["status"] != "Up 2 hours" { t.Fatalf("status mismatch: %v", c["status"]) } - if c["command"] != "nginx -g daemon off;" { - t.Fatalf("command mismatch: %v", c["command"]) + if c["cmdline"] != "nginx -g daemon off;" { + t.Fatalf("cmdline mismatch: %v", c["cmdline"]) } if c["running"] != true { t.Fatalf("running expected true, got %v", c["running"])