bird_exporter/bird_client.go
2017-11-30 23:35:31 +01:00

39 lines
813 B
Go

package main
import (
"github.com/czerwonk/bird_exporter/protocol"
"github.com/czerwonk/bird_socket"
"github.com/czerwonk/bird_exporter/parser"
)
func getProtocols() ([]*protocol.Protocol, error) {
protocols := make([]*protocol.Protocol, 0)
if *birdEnabled {
s, err := getProtocolsFromBird(*birdSocket, 4)
if err != nil {
return nil, err
}
protocols = append(protocols, s...)
}
if *bird6Enabled {
s, err := getProtocolsFromBird(*bird6Socket, 6)
if err != nil {
return nil, err
}
protocols = append(protocols, s...)
}
return protocols, nil
}
func getProtocolsFromBird(socketPath string, ipVersion int) ([]*protocol.Protocol, error) {
b, err := birdsocket.Query(socketPath, "show protocols all")
if err != nil {
return nil, err
}
return parser.Parse(b, ipVersion), nil
}