Closed mahbub570 closed 1 month ago
@mahbub570 Have a look at #81. which does the same with colors.
@bupd like this way?
Adjust the boudaries of the box
@mahbub570 Make these changes in pkg/views/health/view.go
package health
import (
"fmt"
"os"
"github.com/charmbracelet/bubbles/table"
"github.com/charmbracelet/bubbletea"
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/health"
"github.com/goharbor/harbor-cli/pkg/views"
"github.com/goharbor/harbor-cli/pkg/views/base/tablelist"
)
var columns = []table.Column{
{Title: "Component", Width: 18},
{Title: "Status", Width: 26},
}
func PrintHealthStatus(status *health.GetHealthOK) {
var rows []table.Row
fmt.Printf("Harbor Health Status:: %s\n", styleStatus(status.Payload.Status))
for _, component := range status.Payload.Components {
rows = append(rows, table.Row{
component.Name,
styleStatus(component.Status),
})
}
m := tablelist.NewModel(columns, rows, len(rows))
if _, err := tea.NewProgram(m).Run(); err != nil {
fmt.Println("Error running program:", err)
os.Exit(1)
}
}
func styleStatus(status string) string {
if status == "healthy" {
return views.GreenStyle.Render(status)
}
return views.RedStyle.Render(status)
}
pkg/api/health_handler.go
package api
import (
"fmt"
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/health"
"github.com/goharbor/harbor-cli/pkg/utils"
)
func GetHealth() (*health.GetHealthOK, error) {
ctx, client, err := utils.ContextWithClient()
if err != nil {
return nil, err
}
response, err := client.Health.GetHealth(ctx,&health.GetHealthParams{})
if err != nil {
return nil, fmt.Errorf("error getting health status: %w", err)
}
return response, nil
}
thanks @Althaf66 for your suggestions.
ready for review
This pr provides a status check of various system components, allowing administrators to quickly assess the overall health and operational status of the Harbor registry system.
Command:
harbor health
: Get the health status of Harbor components