From 5707c4f80e447ca8d7bc497cee61c5069b17bbf5 Mon Sep 17 00:00:00 2001 From: "R.I.Pienaar" Date: Thu, 7 Dec 2023 12:22:32 +0100 Subject: [PATCH] Support connection state filter in report connz Signed-off-by: R.I.Pienaar --- cli/server_report_command.go | 13 +++++++++++++ cli/server_request_command.go | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/cli/server_report_command.go b/cli/server_report_command.go index 463e58a0..42685626 100644 --- a/cli/server_report_command.go +++ b/cli/server_report_command.go @@ -44,6 +44,7 @@ type SrvReportCmd struct { server string cluster string tags []string + stateFilter string } type srvReportAccountInfo struct { @@ -78,6 +79,7 @@ func configureServerReportCommand(srv *fisk.CmdClause) { conns.Flag("top", "Limit results to the top results").Default("1000").IntVar(&c.topk) conns.Flag("subject", "Limits responses only to those connections with matching subscription interest").StringVar(&c.subject) conns.Flag("username", "Limits responses only to those connections for a specific authentication username").StringVar(&c.user) + conns.Flag("state", "Limits responses only to those connections that are in a specific state (open, closed, all)").PlaceHolder("STATE").Default("open").EnumVar(&c.stateFilter, "open", "closed", "all") conns.Flag("json", "Produce JSON output").Short('j').UnNegatableBoolVar(&c.json) conns.Flag("filter", "Expression based filter for connections").StringVar(&c.filterExpression) @@ -770,6 +772,16 @@ func (c *SrvReportCmd) getConnz(limit int, nc *nats.Conn) (connzList, error) { return nil } + state := server.ConnOpen + switch c.stateFilter { + case "open": + state = server.ConnOpen + case "closed": + state = server.ConnClosed + default: + state = server.ConnAll + } + req := &server.ConnzEventOptions{ ConnzOptions: server.ConnzOptions{ Subscriptions: true, @@ -777,6 +789,7 @@ func (c *SrvReportCmd) getConnz(limit int, nc *nats.Conn) (connzList, error) { Username: true, User: c.user, Account: c.account, + State: state, FilterSubject: c.subject, }, EventFilterOptions: c.reqFilter(), diff --git a/cli/server_request_command.go b/cli/server_request_command.go index 43219110..548e65ea 100644 --- a/cli/server_request_command.go +++ b/cli/server_request_command.go @@ -443,11 +443,11 @@ func (c *SrvRequestCmd) conns(_ *fisk.ParseContext) error { switch c.stateFilter { case "open": - opts.State = 0 + opts.State = server.ConnOpen case "closed": - opts.State = 1 + opts.State = server.ConnClosed default: - opts.State = 2 + opts.State = server.ConnAll } nc, _, err := prepareHelper("", natsOpts()...)