mirror of
https://github.com/fankes/komari-agent.git
synced 2025-10-18 10:39:24 +08:00
feat: 添加 list-disk 命令以列出所有物理磁盘
This commit is contained in:
41
cmd/listDisk.go
Normal file
41
cmd/listDisk.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"text/tabwriter"
|
||||
|
||||
monitoring "github.com/komari-monitor/komari-agent/monitoring/unit"
|
||||
"github.com/shirou/gopsutil/v4/disk"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var ListDiskCmd = &cobra.Command{
|
||||
Use: "list-disk",
|
||||
Short: "List all physical disks",
|
||||
Long: `List all physical disks`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
dl, err := disk.Partitions(true)
|
||||
if err != nil {
|
||||
log.Println("Failed to get disk partitions:", err)
|
||||
return
|
||||
}
|
||||
log.Println("All Disk Partitions:")
|
||||
w := tabwriter.NewWriter(cmd.OutOrStdout(), 0, 0, 2, ' ', 0)
|
||||
fmt.Fprintln(w, "Mountpoint\tFstype")
|
||||
for _, part := range dl {
|
||||
fmt.Fprintf(w, "%s\t%s\n", part.Mountpoint, part.Fstype)
|
||||
}
|
||||
_ = w.Flush()
|
||||
diskList, err := monitoring.DiskList()
|
||||
if err != nil {
|
||||
log.Println("Failed to get disk list:", err)
|
||||
return
|
||||
}
|
||||
log.Println("Monitoring Mountpoints:", diskList)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
RootCmd.AddCommand(ListDiskCmd)
|
||||
}
|
@@ -83,7 +83,7 @@ func init() {
|
||||
RootCmd.PersistentFlags().StringVarP(&flags.Token, "token", "t", "", "API token")
|
||||
//RootCmd.MarkPersistentFlagRequired("token")
|
||||
RootCmd.PersistentFlags().StringVarP(&flags.Endpoint, "endpoint", "e", "", "API endpoint")
|
||||
RootCmd.MarkPersistentFlagRequired("endpoint")
|
||||
//RootCmd.MarkPersistentFlagRequired("endpoint")
|
||||
RootCmd.PersistentFlags().StringVar(&flags.AutoDiscoveryKey, "auto-discovery", "", "Auto discovery key for the agent")
|
||||
RootCmd.PersistentFlags().BoolVar(&flags.DisableAutoUpdate, "disable-auto-update", false, "Disable automatic updates")
|
||||
RootCmd.PersistentFlags().BoolVar(&flags.DisableWebSsh, "disable-web-ssh", false, "Disable remote control(web ssh and rce)")
|
||||
|
Reference in New Issue
Block a user