diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-06-12 22:48:46 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-06-25 22:26:06 +0900 |
commit | ef51565a5eb91e7af7519eb75a365afcf6f84922 (patch) | |
tree | 49f2edeceb3324ac6ec3d7d2918190678b287052 | |
parent | 40f82a62ed9fe381fdcca71fbd77283a8077c1c5 (diff) |
cli: add a command to monitor changes of neighbor state
$ gobgp monitor neighbor
[NEIGH] 192.168.10.5 fsm: BGP_FSM_IDLE admin: ADMIN_STATE_UP
[NEIGH] 192.168.10.5 fsm: BGP_FSM_ACTIVE admin: ADMIN_STATE_UP
[NEIGH] 192.168.10.3 fsm: BGP_FSM_OPENSENT admin: ADMIN_STATE_UP
[NEIGH] 192.168.10.3 fsm: BGP_FSM_OPENCONFIRM admin: ADMIN_STATE_UP
[NEIGH] 192.168.10.3 fsm: BGP_FSM_ESTABLISHED admin: ADMIN_STATE_UP
[NEIGH] 192.168.10.4 fsm: BGP_FSM_OPENSENT admin: ADMIN_STATE_UP
[NEIGH] 192.168.10.4 fsm: BGP_FSM_OPENCONFIRM admin: ADMIN_STATE_UP
[NEIGH] 192.168.10.4 fsm: BGP_FSM_ESTABLISHED admin: ADMIN_STATE_UP
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-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 } |