Files
orca/internal/cli/doctor.go
T
Jon Chery f66472fd37 feat(P03): doctor os + doctor proxmox + audit logging
Extends orca doctor with two new checks (REQ-052):
- doctor os: re-runs OS detection from /etc/os-release, compares to
  stored localhost node's os field. Drift = WARN (re-run orca init);
  match = PASS; missing localhost node = FAIL.
- doctor proxmox: iterates kind=proxmox nodes, SSH-probes each with
  `pveversion` (3s timeout per node, clones Network() pattern).
  Zero proxmox nodes = WARN; reachable = PASS; unreachable = FAIL.

Changes:
- internal/osdetect: new shared package (Detect + ParseID) extracted
  from internal/cli to avoid import cycle (cli + doctor both need it)
- internal/cli/osdetect.go: thin wrapper delegating to osdetect package
- internal/doctor/doctor.go: OS() and Proxmox() checks; All() extended;
  probeProxmoxPVEVersion uses orca SSH key + knownhosts TOFU
- internal/cli/doctor.go: doctor os + doctor proxmox subcommands (--json)
- internal/doctor/doctor_test.go: 5 new tests (OS match/drift/missing,
  proxmox no-nodes/unreachable)

E2E: orca init -> orca doctor shows 6 PASS / 1 WARN (proxmox=none) /
1 FAIL (network=daemon not running). doctor os --json valid.

---ci---
project: orca
phase: 3
milestone: v0.6
status: execute
---/ci---
2026-08-03 19:59:51 +00:00

104 lines
2.7 KiB
Go

package cli
import (
"fmt"
"github.com/spf13/cobra"
"git.cloudinit.dev/coreci/orca/internal/doctor"
)
var doctorCmd = &cobra.Command{
Use: "doctor",
Short: "Run self-checks on the orca installation",
Long: "Verify CA, server cert, expiry, fingerprint, network, and DB. Reports PASS/WARN/FAIL per check.",
RunE: func(cmd *cobra.Command, args []string) error {
report := doctor.Run(cmd.Context())
if jsonOutput {
return printJSON(report.Checks)
}
fmt.Fprint(cmd.OutOrStdout(), report.Print())
return nil
},
}
var doctorCertCmd = &cobra.Command{
Use: "cert",
Short: "Run only the cert self-checks",
RunE: func(cmd *cobra.Command, args []string) error {
checks := []doctor.Check{
doctor.CertCA(),
doctor.CertServer(),
doctor.CertExpiry(),
doctor.CertFingerprint(),
}
results := make([]doctor.CheckResult, 0, len(checks))
for _, c := range checks {
r, msg := c.Run(cmd.Context())
results = append(results, doctor.CheckResult{Name: c.Name, Result: r, Message: msg})
}
if jsonOutput {
return printJSON(results)
}
for _, r := range results {
fmt.Fprintf(cmd.OutOrStdout(), "%-20s %-5s %s\n", r.Name, r.Result, r.Message)
}
return nil
},
}
var doctorNetworkCmd = &cobra.Command{
Use: "network",
Short: "Run the network self-check (P02 impl)",
RunE: func(cmd *cobra.Command, args []string) error {
c := doctor.Network()
r, msg := c.Run(cmd.Context())
fmt.Fprintf(cmd.OutOrStdout(), "%-20s %-5s %s\n", c.Name, r, msg)
return nil
},
}
var doctorDBCmd = &cobra.Command{
Use: "db",
Short: "Run the database self-check (P02 impl)",
RunE: func(cmd *cobra.Command, args []string) error {
c := doctor.DB()
r, msg := c.Run(cmd.Context())
fmt.Fprintf(cmd.OutOrStdout(), "%-20s %-5s %s\n", c.Name, r, msg)
return nil
},
}
var doctorOSCmd = &cobra.Command{
Use: "os",
Short: "Run the OS detection self-check (v0.6 P03)",
RunE: func(cmd *cobra.Command, args []string) error {
c := doctor.OS()
r, msg := c.Run(cmd.Context())
if jsonOutput {
return printJSON(doctor.CheckResult{Name: c.Name, Result: r, Message: msg})
}
fmt.Fprintf(cmd.OutOrStdout(), "%-20s %-5s %s\n", c.Name, r, msg)
return nil
},
}
var doctorProxmoxCmd = &cobra.Command{
Use: "proxmox",
Short: "Run the proxmox node reachability self-check (v0.6 P03)",
RunE: func(cmd *cobra.Command, args []string) error {
c := doctor.Proxmox()
r, msg := c.Run(cmd.Context())
if jsonOutput {
return printJSON(doctor.CheckResult{Name: c.Name, Result: r, Message: msg})
}
fmt.Fprintf(cmd.OutOrStdout(), "%-20s %-5s %s\n", c.Name, r, msg)
return nil
},
}
func init() {
doctorCmd.AddCommand(doctorCertCmd, doctorNetworkCmd, doctorDBCmd, doctorOSCmd, doctorProxmoxCmd)
rootCmd.AddCommand(doctorCmd)
}