Skip to content

Commit

Permalink
Merge pull request #932 from ripienaar/report_conn_state
Browse files Browse the repository at this point in the history
Support connection state filter in report connz
  • Loading branch information
ripienaar authored Dec 7, 2023
2 parents ded94d8 + 5707c4f commit 380c461
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 13 additions & 0 deletions cli/server_report_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type SrvReportCmd struct {
server string
cluster string
tags []string
stateFilter string
}

type srvReportAccountInfo struct {
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -770,13 +772,24 @@ 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,
SubscriptionsDetail: false,
Username: true,
User: c.user,
Account: c.account,
State: state,
FilterSubject: c.subject,
},
EventFilterOptions: c.reqFilter(),
Expand Down
6 changes: 3 additions & 3 deletions cli/server_request_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()...)
Expand Down

0 comments on commit 380c461

Please sign in to comment.