Validate providers and retain complete run debugging context
This commit is contained in:
@@ -1,63 +1,70 @@
|
||||
package statusview
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"net"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Offline(endpoint string) *protocol.SystemStatus {
|
||||
s := &protocol.SystemStatus{Server: protocol.ServiceStatus{Health: "unreachable"}, Ntfy: protocol.ServiceStatus{Health: "unknown (server unavailable)"}, Note: "Server information and ntfy configuration cannot be retrieved while disconnected."}
|
||||
s := &protocol.SystemStatus{Server: protocol.ServiceStatus{Health: "unreachable"}, Ntfy: protocol.ServiceStatus{Health: "unknown (server unavailable)"}}
|
||||
if u, err := url.Parse(endpoint); err == nil {
|
||||
u.User = nil
|
||||
u.RawQuery = ""
|
||||
u.Fragment = ""
|
||||
s.Server.URL = u.String()
|
||||
s.Server.Port = u.Port()
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// Lines is shared by the plain CLI and TUI popup. No credentials are included.
|
||||
func Lines(s *protocol.SystemStatus) []string {
|
||||
func ServerLines(s *protocol.SystemStatus) []string {
|
||||
if s == nil {
|
||||
return []string{"No status returned by server."}
|
||||
return []string{"Checking server…"}
|
||||
}
|
||||
lines := []string{"Pipelines server", " Health: " + s.Server.Health}
|
||||
if s.Hostname != "" {
|
||||
lines = append(lines, " Host: "+s.Hostname, " Started: "+s.StartedAt+" · uptime "+s.Uptime)
|
||||
lines := []string{"Status: " + s.Server.Health}
|
||||
seen := map[string]bool{}
|
||||
for _, address := range s.Addresses {
|
||||
ip := net.ParseIP(strings.Split(address.IP, "%")[0])
|
||||
if ip == nil || ip.IsLoopback() || ip.IsUnspecified() || ip.IsLinkLocalUnicast() || seen[address.IP] {
|
||||
continue
|
||||
}
|
||||
seen[address.IP] = true
|
||||
lines = append(lines, net.JoinHostPort(address.IP, s.Server.Port))
|
||||
if len(seen) == 6 {
|
||||
break
|
||||
}
|
||||
}
|
||||
lines = append(lines, " Connection: "+s.Server.URL, " Port: "+s.Server.Port, "", "ntfy", " Publishing health: "+s.Ntfy.Health)
|
||||
if len(seen) == 0 {
|
||||
lines = append(lines, "LAN address unavailable.", "For Docker: rerun ./install.sh on the server.")
|
||||
}
|
||||
if s.Server.Port != "" {
|
||||
lines = append(lines, "Port: "+s.Server.Port)
|
||||
}
|
||||
return lines
|
||||
}
|
||||
|
||||
func NtfyLines(s *protocol.SystemStatus) []string {
|
||||
if s == nil {
|
||||
return []string{"Checking ntfy…"}
|
||||
}
|
||||
lines := []string{"Status: " + s.Ntfy.Health}
|
||||
if s.Ntfy.URL != "" {
|
||||
lines = append(lines, " Phone server: "+s.Ntfy.URL)
|
||||
lines = append(lines, "Server: "+s.Ntfy.URL)
|
||||
}
|
||||
if s.Topic != "" {
|
||||
lines = append(lines, " Topic: "+s.Topic)
|
||||
lines = append(lines, "Topic: "+s.Topic)
|
||||
}
|
||||
if s.Ntfy.Port != "" {
|
||||
lines = append(lines, " Port: "+s.Ntfy.Port)
|
||||
if s.NtfyUser != "" {
|
||||
lines = append(lines, "Login: "+s.NtfyUser, "Use the password set during installation.")
|
||||
}
|
||||
if s.Topic != "" && s.Ntfy.URL == "" {
|
||||
lines = append(lines, " Phone address not configured (PIPELINES_NTFY_PUBLIC_URL).")
|
||||
if s.Ntfy.Health == "not configured" {
|
||||
lines = append(lines, "On the server: rerun ./install.sh.")
|
||||
} else if s.Ntfy.Health == "unreachable" || s.Ntfy.Health == "unhealthy" {
|
||||
lines = append(lines, "On the server: docker compose logs ntfy")
|
||||
}
|
||||
lines = append(lines, "", "Server computer IPs")
|
||||
for _, address := range s.Addresses {
|
||||
lines = append(lines, fmt.Sprintf(" %s · %s", address.Interface, address.IP))
|
||||
}
|
||||
if len(s.Addresses) == 0 {
|
||||
lines = append(lines, " No address information available.")
|
||||
}
|
||||
if len(s.Server.Candidates) > 0 {
|
||||
lines = append(lines, "", "Candidate Pipelines URLs (not verified)")
|
||||
for _, candidate := range s.Server.Candidates {
|
||||
lines = append(lines, " "+candidate)
|
||||
}
|
||||
}
|
||||
if len(s.Ntfy.Candidates) > 0 {
|
||||
lines = append(lines, "", "Candidate ntfy topic URLs (not verified)")
|
||||
for _, candidate := range s.Ntfy.Candidates {
|
||||
lines = append(lines, " "+candidate)
|
||||
}
|
||||
}
|
||||
return append(lines, "", s.Note)
|
||||
return lines
|
||||
}
|
||||
|
||||
// The human view has exactly two focused sections. --json retains full data.
|
||||
func Lines(s *protocol.SystemStatus) []string {
|
||||
lines := append([]string{"Pipelines server"}, ServerLines(s)...)
|
||||
return append(append(lines, "", "ntfy"), NtfyLines(s)...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user