CI / changes (push) Successful in 5s
CI / openapi (push) Has been skipped
CI / go (push) Successful in 23s
CI / bird2 (push) Has been cancelled
CI / docker-go (deploy/docker/evobgp-agent/Dockerfile, , evobgp-agent) (push) Has been cancelled
CI / docker-go (evobgp-all, 1, deploy/docker/gobinary/Dockerfile, , evobgp-all) (push) Has been cancelled
CI / docker-go (evobgp-api, 1, deploy/docker/gobinary/Dockerfile, , evobgp-api) (push) Has been cancelled
CI / docker-go (evobgp-deploy, 0, deploy/docker/gobinary/Dockerfile, , evobgp-deploy) (push) Has been cancelled
CI / docker-go (evobgp-ingest, 0, deploy/docker/gobinary/Dockerfile, , evobgp-ingest) (push) Has been cancelled
CI / docker-go (evobgp-node, 0, deploy/docker/gobinary/Dockerfile, , evobgp-node) (push) Has been cancelled
CI / docker-go (evobgp-render, 0, deploy/docker/gobinary/Dockerfile, , evobgp-render) (push) Has been cancelled
CI / docker-go (evobgp-scheduler, 0, deploy/docker/gobinary/Dockerfile, , evobgp-scheduler) (push) Has been cancelled
CI / docker-web (deploy/docker/evobgp-web/Dockerfile, , evobgp-web) (push) Has started running
CI / docker-web (deploy/docker/evobgp-web/Dockerfile, evobgp-all, evobgp-web-all) (push) Has been cancelled
CI / docker-bird (push) Has been cancelled
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package birdfmt
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// ProtocolsSummary is a lightweight parse of `birdc show protocols all` (BIRD 2).
|
|
type ProtocolsSummary struct {
|
|
BGPSessionsTotal int
|
|
BGPEstablished int
|
|
RawLineCount int
|
|
}
|
|
|
|
// isBGPProtocolSummaryRow is true for BIRD "show protocols" summary rows where the
|
|
// second column (Proto) is BGP. Substring checks are unsafe: names like evobgp_* contain "bgp".
|
|
func isBGPProtocolSummaryRow(line string) bool {
|
|
line = strings.TrimSpace(line)
|
|
if line == "" {
|
|
return false
|
|
}
|
|
low := strings.ToLower(line)
|
|
if strings.HasPrefix(low, "name") || strings.HasPrefix(low, "table") {
|
|
return false
|
|
}
|
|
fields := strings.Fields(line)
|
|
if len(fields) < 2 {
|
|
return false
|
|
}
|
|
return strings.EqualFold(fields[1], "BGP")
|
|
}
|
|
|
|
// SummarizeProtocolsOutput extracts BGP session heuristics from birdc output.
|
|
func SummarizeProtocolsOutput(output string) ProtocolsSummary {
|
|
var s ProtocolsSummary
|
|
lines := strings.Split(output, "\n")
|
|
s.RawLineCount = len(lines)
|
|
for _, line := range lines {
|
|
line = strings.TrimSpace(line)
|
|
if line == "" {
|
|
continue
|
|
}
|
|
low := strings.ToLower(line)
|
|
if !isBGPProtocolSummaryRow(line) {
|
|
continue
|
|
}
|
|
s.BGPSessionsTotal++
|
|
if strings.Contains(low, "established") {
|
|
s.BGPEstablished++
|
|
}
|
|
}
|
|
return s
|
|
}
|