Add color to wwctl node status output and time based filter
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -85,10 +86,19 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
sort.Strings(keys)
|
||||
|
||||
for _, id := range keys {
|
||||
if SetTime > 0 && rightnow-nodeStatus.Nodes[id].Lastseen < SetTime {
|
||||
continue
|
||||
}
|
||||
if nodeStatus.Nodes[id].Lastseen > 0 {
|
||||
fmt.Printf("%-20s %-20s %-25s %-10d\n", id, nodeStatus.Nodes[id].Stage, nodeStatus.Nodes[id].Sent, rightnow-nodeStatus.Nodes[id].Lastseen)
|
||||
if rightnow-nodeStatus.Nodes[id].Lastseen >= 600 {
|
||||
color.Red("%-20s %-20s %-25s %-10d\n", id, nodeStatus.Nodes[id].Stage, nodeStatus.Nodes[id].Sent, rightnow-nodeStatus.Nodes[id].Lastseen)
|
||||
} else if rightnow-nodeStatus.Nodes[id].Lastseen >= 300 {
|
||||
color.Yellow("%-20s %-20s %-25s %-10d\n", id, nodeStatus.Nodes[id].Stage, nodeStatus.Nodes[id].Sent, rightnow-nodeStatus.Nodes[id].Lastseen)
|
||||
} else {
|
||||
fmt.Printf("%-20s %-20s %-25s %-10d\n", id, nodeStatus.Nodes[id].Stage, nodeStatus.Nodes[id].Sent, rightnow-nodeStatus.Nodes[id].Lastseen)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("%-20s %-20s %-25s %-10s\n", id, "--", "--", "--")
|
||||
color.HiBlack("%-20s %-20s %-25s %-10s\n", id, "--", "--", "--")
|
||||
}
|
||||
if count+4 >= height && SetWatch {
|
||||
if count+1 != len(keys) {
|
||||
|
||||
@@ -11,13 +11,16 @@ var (
|
||||
RunE: CobraRunE,
|
||||
Args: cobra.MinimumNArgs(0),
|
||||
}
|
||||
SetWatch bool
|
||||
SetUpdate int16
|
||||
SetWatch bool
|
||||
SetUpdate int
|
||||
SetTime int64
|
||||
)
|
||||
|
||||
func init() {
|
||||
baseCmd.PersistentFlags().BoolVarP(&SetWatch, "watch", "w", false, "Watch the status automatically")
|
||||
baseCmd.PersistentFlags().Int16VarP(&SetUpdate, "update", "u", 500, "Set the update frequency for 'watch' (ms)")
|
||||
baseCmd.PersistentFlags().IntVarP(&SetUpdate, "update", "u", 500, "Set the update frequency for 'watch' (ms)")
|
||||
baseCmd.PersistentFlags().Int64VarP(&SetTime, "time", "t", 0, "Filter by last checkin time (seconds)")
|
||||
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
|
||||
Reference in New Issue
Block a user