Files
EvoBGP/internal/birdfmt/local_status.go
T
Denozordec 94a4c6acd4
CI / changes (push) Successful in 6s
CI / openapi (push) Has been skipped
CI / go (push) Successful in 25s
CI / docker-web (deploy/docker/evobgp-web/Dockerfile, , evobgp-web) (push) Successful in 1m7s
CI / docker-web (deploy/docker/evobgp-web/Dockerfile, evobgp-all, evobgp-web-all) (push) Successful in 1m5s
CI / docker-bird (push) Has been skipped
CI / bird2 (push) Successful in 16s
CI / docker-go (deploy/docker/evobgp-agent/Dockerfile, , evobgp-agent) (push) Successful in 1m0s
CI / docker-go (evobgp-all, 1, deploy/docker/gobinary/Dockerfile, , evobgp-all) (push) Successful in 1m25s
CI / docker-go (evobgp-api, 1, deploy/docker/gobinary/Dockerfile, , evobgp-api) (push) Successful in 1m30s
CI / docker-go (evobgp-deploy, 0, deploy/docker/gobinary/Dockerfile, , evobgp-deploy) (push) Successful in 1m30s
CI / docker-go (evobgp-ingest, 0, deploy/docker/gobinary/Dockerfile, , evobgp-ingest) (push) Successful in 1m27s
CI / docker-go (evobgp-node, 0, deploy/docker/gobinary/Dockerfile, , evobgp-node) (push) Successful in 1m13s
CI / docker-go (evobgp-render, 0, deploy/docker/gobinary/Dockerfile, , evobgp-render) (push) Successful in 1m32s
CI / docker-go (evobgp-scheduler, 0, deploy/docker/gobinary/Dockerfile, , evobgp-scheduler) (push) Successful in 1m23s
feat: add BIRD status endpoint and integrate birdc checks into job processing. Enhance UI to display BIRD runtime status and job metadata, improving user feedback on BIRD operations.
2026-04-06 00:25:43 +07:00

56 lines
1.8 KiB
Go

package birdfmt
import (
"context"
"os"
"strings"
)
// LocalBirdStatus is returned by GET /v1/bird/status (same host as birdc when socket is configured).
type LocalBirdStatus struct {
BirdcConfigured bool `json:"birdc_configured"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
ProtocolsExcerpt string `json:"protocols_excerpt,omitempty"`
BGPSessionsTotal int `json:"bgp_sessions_total"`
BGPEstablished int `json:"bgp_established"`
// Healthy: null if birdc not configured; false if birdc failed or BGP sessions exist but none Established; true otherwise.
Healthy *bool `json:"healthy"`
}
// InspectLocalBird runs `birdc show protocols all` using EVOBGP_BIRDC_SOCKET / EVOBGP_BIRDC_BIN.
func InspectLocalBird(ctx context.Context) LocalBirdStatus {
sock := strings.TrimSpace(os.Getenv("EVOBGP_BIRDC_SOCKET"))
if sock == "" {
return LocalBirdStatus{
BirdcConfigured: false,
Message: "EVOBGP_BIRDC_SOCKET не задан на этом процессе — статус BIRD недоступен (типично, если birdc только на ноде со спикером).",
Healthy: nil,
}
}
bin := strings.TrimSpace(os.Getenv("EVOBGP_BIRDC_BIN"))
out, err := ShowProtocols(ctx, sock, bin)
if err != nil {
f := false
return LocalBirdStatus{
BirdcConfigured: true,
Error: err.Error(),
Healthy: &f,
}
}
sum := SummarizeProtocolsOutput(out)
excerpt := out
const maxExcerpt = 20000
if len(excerpt) > maxExcerpt {
excerpt = excerpt[:maxExcerpt] + "\n# … truncated …\n"
}
ok := sum.BGPSessionsTotal == 0 || sum.BGPEstablished > 0
return LocalBirdStatus{
BirdcConfigured: true,
ProtocolsExcerpt: excerpt,
BGPSessionsTotal: sum.BGPSessionsTotal,
BGPEstablished: sum.BGPEstablished,
Healthy: &ok,
}
}