diff options
-rw-r--r-- | gobgp/monitor.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/gobgp/monitor.go b/gobgp/monitor.go index b57b1451..578162ce 100644 --- a/gobgp/monitor.go +++ b/gobgp/monitor.go @@ -63,10 +63,41 @@ func NewMonitorCmd() *cobra.Command { } globalCmd.AddCommand(ribCmd) + neighborCmd := &cobra.Command{ + Use: CMD_NEIGHBOR, + Run: func(cmd *cobra.Command, args []string) { + var arg *api.Arguments + if len(args) > 0 { + arg = &api.Arguments{ + RouterId: args[0], + } + } else { + arg = &api.Arguments{} + } + + stream, err := client.MonitorPeerState(context.Background(), arg) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + for { + s, err := stream.Recv() + if err == io.EOF { + break + } else if err != nil { + fmt.Println(err) + os.Exit(1) + } + fmt.Printf("[NEIGH] %s fsm: %s admin: %s\n", s.Conf.RemoteIp, s.Info.BgpState, s.Info.AdminState) + } + }, + } + monitorCmd := &cobra.Command{ Use: CMD_MONITOR, } monitorCmd.AddCommand(globalCmd) + monitorCmd.AddCommand(neighborCmd) return monitorCmd } |