Files
pipelines/internal/statusview/status.go
T

64 lines
2.1 KiB
Go

package statusview
import (
"fmt"
"git.a-wan.net/alan/pipelines/internal/protocol"
"net/url"
)
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."}
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 {
if s == nil {
return []string{"No status returned by 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 = append(lines, " Connection: "+s.Server.URL, " Port: "+s.Server.Port, "", "ntfy", " Publishing health: "+s.Ntfy.Health)
if s.Ntfy.URL != "" {
lines = append(lines, " Phone server: "+s.Ntfy.URL)
}
if s.Topic != "" {
lines = append(lines, " Topic: "+s.Topic)
}
if s.Ntfy.Port != "" {
lines = append(lines, " Port: "+s.Ntfy.Port)
}
if s.Topic != "" && s.Ntfy.URL == "" {
lines = append(lines, " Phone address not configured (PIPELINES_NTFY_PUBLIC_URL).")
}
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)
}